]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/affinematrix2dbase.h | |
3 | // Purpose: Common interface for 2D transformation matrices. | |
4 | // Author: Catalin Raceanu | |
5 | // Created: 2011-04-06 | |
6 | // Copyright: (c) wxWidgets team | |
7 | // Licence: wxWidgets licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_AFFINEMATRIX2DBASE_H_ | |
11 | #define _WX_AFFINEMATRIX2DBASE_H_ | |
12 | ||
13 | #include "wx/defs.h" | |
14 | #include "wx/geometry.h" | |
15 | ||
16 | struct wxMatrix2D | |
17 | { | |
18 | wxMatrix2D(wxDouble v11 = 1, | |
19 | wxDouble v12 = 0, | |
20 | wxDouble v21 = 0, | |
21 | wxDouble v22 = 1) | |
22 | { | |
23 | m_11 = v11; m_12 = v12; | |
24 | m_21 = v21; m_22 = v22; | |
25 | } | |
26 | ||
27 | wxDouble m_11, m_12, m_21, m_22; | |
28 | }; | |
29 | ||
30 | // A 2x3 matrix representing an affine 2D transformation. | |
31 | // | |
32 | // This is an abstract base class implemented by wxAffineMatrix2D only so far, | |
33 | // but in the future we also plan to derive wxGraphicsMatrix from it (it should | |
34 | // also be documented then as currently only wxAffineMatrix2D itself is). | |
35 | class WXDLLIMPEXP_CORE wxAffineMatrix2DBase | |
36 | { | |
37 | public: | |
38 | wxAffineMatrix2DBase() {} | |
39 | ||
40 | // sets the matrix to the respective values | |
41 | virtual void Set(const wxMatrix2D& mat2D, const wxPoint2DDouble& tr) = 0; | |
42 | ||
43 | // gets the component valuess of the matrix | |
44 | virtual void Get(wxMatrix2D* mat2D, wxPoint2DDouble* tr) const = 0; | |
45 | ||
46 | // concatenates the matrix | |
47 | virtual void Concat(const wxAffineMatrix2DBase& t) = 0; | |
48 | ||
49 | // makes this the inverse matrix | |
50 | virtual bool Invert() = 0; | |
51 | ||
52 | // return true if this is the identity matrix | |
53 | virtual bool IsIdentity() const = 0; | |
54 | ||
55 | // returns true if the elements of the transformation matrix are equal ? | |
56 | virtual bool IsEqual(const wxAffineMatrix2DBase& t) const = 0; | |
57 | bool operator==(const wxAffineMatrix2DBase& t) const { return IsEqual(t); } | |
58 | bool operator!=(const wxAffineMatrix2DBase& t) const { return !IsEqual(t); } | |
59 | ||
60 | ||
61 | // | |
62 | // transformations | |
63 | // | |
64 | ||
65 | // add the translation to this matrix | |
66 | virtual void Translate(wxDouble dx, wxDouble dy) = 0; | |
67 | ||
68 | // add the scale to this matrix | |
69 | virtual void Scale(wxDouble xScale, wxDouble yScale) = 0; | |
70 | ||
71 | // add the rotation to this matrix (counter clockwise, radians) | |
72 | virtual void Rotate(wxDouble ccRadians) = 0; | |
73 | ||
74 | // add mirroring to this matrix | |
75 | void Mirror(int direction = wxHORIZONTAL) | |
76 | { | |
77 | wxDouble x = (direction & wxHORIZONTAL) ? -1 : 1; | |
78 | wxDouble y = (direction & wxVERTICAL) ? -1 : 1; | |
79 | Scale(x, y); | |
80 | } | |
81 | ||
82 | ||
83 | // applies that matrix to the point | |
84 | wxPoint2DDouble TransformPoint(const wxPoint2DDouble& src) const | |
85 | { | |
86 | return DoTransformPoint(src); | |
87 | } | |
88 | ||
89 | void TransformPoint(wxDouble* x, wxDouble* y) const | |
90 | { | |
91 | wxCHECK_RET( x && y, "Can't be NULL" ); | |
92 | ||
93 | const wxPoint2DDouble dst = DoTransformPoint(wxPoint2DDouble(*x, *y)); | |
94 | *x = dst.m_x; | |
95 | *y = dst.m_y; | |
96 | } | |
97 | ||
98 | // applies the matrix except for translations | |
99 | wxPoint2DDouble TransformDistance(const wxPoint2DDouble& src) const | |
100 | { | |
101 | return DoTransformDistance(src); | |
102 | } | |
103 | ||
104 | void TransformDistance(wxDouble* dx, wxDouble* dy) const | |
105 | { | |
106 | wxCHECK_RET( dx && dy, "Can't be NULL" ); | |
107 | ||
108 | const wxPoint2DDouble | |
109 | dst = DoTransformDistance(wxPoint2DDouble(*dx, *dy)); | |
110 | *dx = dst.m_x; | |
111 | *dy = dst.m_y; | |
112 | } | |
113 | ||
114 | protected: | |
115 | virtual | |
116 | wxPoint2DDouble DoTransformPoint(const wxPoint2DDouble& p) const = 0; | |
117 | virtual | |
118 | wxPoint2DDouble DoTransformDistance(const wxPoint2DDouble& p) const = 0; | |
119 | }; | |
120 | ||
121 | #endif // _WX_AFFINEMATRIX2DBASE_H_ |