]> git.saurik.com Git - wxWidgets.git/blob - include/wx/matrix.h
#ifdefed out a typedef not appropriate to MSW; added SetSelection to choice dialog
[wxWidgets.git] / include / wx / matrix.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: matrix.h
3 // Purpose: wxTransformMatrix class. NOT YET USED
4 // Author: Chris Breeze, Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __MATRIXH__
13 #define __MATRIXH__
14
15 #ifdef __GNUG__
16 #pragma interface "matrix.h"
17 #endif
18
19 #include "wx/object.h"
20
21 // A simple 3x3 matrix. This may be replaced by a more general matrix
22 // class some day.
23 //
24 // Note: this is intended to be used in wxDC at some point to replace
25 // the current system of scaling/translation. It is not yet used.
26
27 class WXDLLEXPORT wxTransformMatrix: public wxObject
28 {
29 public:
30 wxTransformMatrix(void);
31 wxTransformMatrix(const wxTransformMatrix& mat);
32
33 double GetValue(int row, int col) const;
34 void SetValue(int row, int col, double value);
35
36 void operator = (const wxTransformMatrix& mat);
37 bool operator == (const wxTransformMatrix& mat);
38 bool operator != (const wxTransformMatrix& mat);
39
40 double& operator()(int row, int col);
41 double operator()(int row, int col) const;
42
43 // Invert matrix
44 bool Invert(void);
45
46 // Make into identity matrix
47 bool Identity(void);
48
49 // Is the matrix the identity matrix?
50 // Only returns a flag, which is set whenever an operation
51 // is done.
52 inline bool IsIdentity(void) const { return m_isIdentity; };
53
54 // This does an actual check.
55 inline bool IsIdentity1(void) const ;
56
57 // Isotropic scaling
58 bool Scale(double scale);
59
60 // Translate
61 bool Translate(double x, double y);
62
63 // Rotate
64 bool Rotate(double angle);
65
66 // Transform X value from logical to device
67 inline double TransformX(double x) const;
68
69 // Transform Y value from logical to device
70 inline double TransformY(double y) const;
71
72 // Transform a point from logical to device coordinates
73 bool TransformPoint(double x, double y, double& tx, double& ty) const;
74
75 // Transform a point from device to logical coordinates.
76
77 // Example of use:
78 // wxTransformMatrix mat = dc.GetTransformation();
79 // mat.Invert();
80 // mat.InverseTransformPoint(x, y, x1, y1);
81 // OR (shorthand:)
82 // dc.LogicalToDevice(x, y, x1, y1);
83 // The latter is slightly less efficient if we're doing several
84 // conversions, since the matrix is inverted several times.
85
86 // N.B. 'this' matrix is the inverse at this point
87
88 bool InverseTransformPoint(double x, double y, double& tx, double& ty) const;
89
90 public:
91 double m_matrix[3][3];
92 bool m_isIdentity;
93 /*
94 double m11, m21, m31;
95 double m12, m22, m32;
96 double m13, m23, m33;
97 */
98 };
99
100 // Transform X value from logical to device
101 inline double wxTransformMatrix::TransformX(double x) const
102 {
103 // return (m_isIdentity ? x : (x * m_matrix[0][0] + y * m_matrix[1][0] + m_matrix[2][0]));
104 return 0;
105 }
106
107 // Transform Y value from logical to device
108 inline double wxTransformMatrix::TransformY(double y) const
109 {
110 // return (m_isIdentity ? y : (x * m_matrix[0][1] + y * m_matrix[1][1] + m_matrix[2][1]));
111 return 0;
112 }
113
114 // Is the matrix the identity matrix?
115 // Perhaps there's some kind of optimization we can do to make this
116 // a faster operation. E.g. each operation (scale, translate etc.)
117 // checks whether it's still the identity matrix and sets a flag.
118 inline bool wxTransformMatrix::IsIdentity1(void) const
119 {
120 return
121 (m_matrix[0][0] == 1.0 &&
122 m_matrix[1][1] == 1.0 &&
123 m_matrix[2][2] == 1.0 &&
124 m_matrix[1][0] == 0.0 &&
125 m_matrix[2][0] == 0.0 &&
126 m_matrix[0][1] == 0.0 &&
127 m_matrix[2][1] == 0.0 &&
128 m_matrix[0][2] == 0.0 &&
129 m_matrix[1][2] == 0.0) ;
130 }
131
132 // Calculates the determinant of a 2 x 2 matrix
133 inline double wxCalculateDet(double a11, double a21, double a12, double a22)
134 {
135 return a11 * a22 - a12 * a21;
136 }
137
138 #endif
139 // __MATRIXH__