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