]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/geometry.h
put both versions of wxGetMousePosition in one place so they can use one implementation
[wxWidgets.git] / interface / wx / geometry.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: geometry.h
3 // Purpose: interface of geometry classes
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9
10 enum wxOutCode
11 {
12 wxInside = 0x00 ,
13 wxOutLeft = 0x01 ,
14 wxOutRight = 0x02 ,
15 wxOutTop = 0x08 ,
16 wxOutBottom = 0x04
17 };
18
19
20 class wxPoint2DInt
21 {
22 public :
23 wxPoint2DInt();
24 wxPoint2DInt( wxInt32 x , wxInt32 y );
25 wxPoint2DInt( const wxPoint2DInt &pt );
26 wxPoint2DInt( const wxPoint &pt );
27
28 // noops for this class, just return the coords
29 void GetFloor( wxInt32 *x , wxInt32 *y ) const;
30 void GetRounded( wxInt32 *x , wxInt32 *y ) const;
31
32 wxDouble GetVectorLength() const;
33 wxDouble GetVectorAngle() const;
34 void SetVectorLength( wxDouble length );
35 void SetVectorAngle( wxDouble degrees );
36 void SetPolarCoordinates( wxInt32 angle , wxInt32 length );
37 // set the vector length to 1.0, preserving the angle
38 void Normalize();
39
40 wxDouble GetDistance( const wxPoint2DInt &pt ) const;
41 wxDouble GetDistanceSquare( const wxPoint2DInt &pt ) const;
42 wxInt32 GetDotProduct( const wxPoint2DInt &vec ) const;
43 wxInt32 GetCrossProduct( const wxPoint2DInt &vec ) const;
44
45 // the reflection of this point
46 wxPoint2DInt operator-();
47
48 wxPoint2DInt& operator=(const wxPoint2DInt& pt);
49 wxPoint2DInt& operator+=(const wxPoint2DInt& pt);
50 wxPoint2DInt& operator-=(const wxPoint2DInt& pt);
51 wxPoint2DInt& operator*=(const wxPoint2DInt& pt);
52 wxPoint2DInt& operator*=(wxDouble n);
53 wxPoint2DInt& operator*=(wxInt32 n);
54 wxPoint2DInt& operator/=(const wxPoint2DInt& pt);
55 wxPoint2DInt& operator/=(wxDouble n);
56 wxPoint2DInt& operator/=(wxInt32 n);
57 operator wxPoint() const;
58 bool operator==(const wxPoint2DInt& pt) const;
59 bool operator!=(const wxPoint2DInt& pt) const;
60
61 wxInt32 m_x;
62 wxInt32 m_y;
63 };
64
65 wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
66 wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
67 wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
68 wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
69 wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
70 wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
71 wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
72 wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
73 wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
74 wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
75
76
77 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
78
79 class wxPoint2DDouble
80 {
81 public :
82 wxPoint2DDouble();
83 wxPoint2DDouble( wxDouble x , wxDouble y );
84 wxPoint2DDouble( const wxPoint2DDouble &pt );
85 wxPoint2DDouble( const wxPoint2DInt &pt );
86 wxPoint2DDouble( const wxPoint &pt );
87
88 // two different conversions to integers, floor and rounding
89 void GetFloor( wxInt32 *x , wxInt32 *y ) const;
90 void GetRounded( wxInt32 *x , wxInt32 *y ) const;
91
92 wxDouble GetVectorLength() const;
93 wxDouble GetVectorAngle() const ;
94 void SetVectorLength( wxDouble length );
95 void SetVectorAngle( wxDouble degrees );
96 void SetPolarCoordinates( wxDouble angle , wxDouble length );
97 // set the vector length to 1.0, preserving the angle
98 void Normalize();
99
100 wxDouble GetDistance( const wxPoint2DDouble &pt ) const;
101 wxDouble GetDistanceSquare( const wxPoint2DDouble &pt ) const;
102 wxDouble GetDotProduct( const wxPoint2DDouble &vec ) const;
103 wxDouble GetCrossProduct( const wxPoint2DDouble &vec ) const;
104
105 // the reflection of this point
106 wxPoint2DDouble operator-();
107
108 wxPoint2DDouble& operator=(const wxPoint2DDouble& pt);
109 wxPoint2DDouble& operator+=(const wxPoint2DDouble& pt);
110 wxPoint2DDouble& operator-=(const wxPoint2DDouble& pt);
111 wxPoint2DDouble& operator*=(const wxPoint2DDouble& pt);
112 wxPoint2DDouble& operator*=(wxDouble n);
113 wxPoint2DDouble& operator*=(wxInt32 n);
114 wxPoint2DDouble& operator/=(const wxPoint2DDouble& pt);
115 wxPoint2DDouble& operator/=(wxDouble n);
116 wxPoint2DDouble& operator/=(wxInt32 n);
117
118 bool operator==(const wxPoint2DDouble& pt) const;
119 bool operator!=(const wxPoint2DDouble& pt) const;
120
121 wxDouble m_x;
122 wxDouble m_y;
123 };
124
125 wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
126 wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
127 wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
128 wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt);
129 wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt);
130 wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n);
131 wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n);
132 wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
133 wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n);
134 wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n);
135
136
137
138 // wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the
139 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
140 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
141
142 class wxRect2DDouble
143 {
144 public:
145 wxRect2DDouble();
146 wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
147
148 // single attribute accessors
149
150 wxPoint2DDouble GetPosition() const;
151 wxSize GetSize() const;
152
153 // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their
154 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately
155
156 wxDouble GetLeft() const;
157 void SetLeft( wxDouble n );
158 void MoveLeftTo( wxDouble n );
159 wxDouble GetTop() const;
160 void SetTop( wxDouble n );
161 void MoveTopTo( wxDouble n );
162 wxDouble GetBottom() const;
163 void SetBottom( wxDouble n );
164 void MoveBottomTo( wxDouble n );
165 wxDouble GetRight() const;
166 void SetRight( wxDouble n );
167 void MoveRightTo( wxDouble n );
168
169 wxPoint2DDouble GetLeftTop() const;
170 void SetLeftTop( const wxPoint2DDouble &pt );
171 void MoveLeftTopTo( const wxPoint2DDouble &pt );
172 wxPoint2DDouble GetLeftBottom() const;
173 void SetLeftBottom( const wxPoint2DDouble &pt );
174 void MoveLeftBottomTo( const wxPoint2DDouble &pt );
175 wxPoint2DDouble GetRightTop() const;
176 void SetRightTop( const wxPoint2DDouble &pt );
177 void MoveRightTopTo( const wxPoint2DDouble &pt );
178 wxPoint2DDouble GetRightBottom() const;
179 void SetRightBottom( const wxPoint2DDouble &pt );
180 void MoveRightBottomTo( const wxPoint2DDouble &pt );
181 wxPoint2DDouble GetCentre() const;
182 void SetCentre( const wxPoint2DDouble &pt );
183 void MoveCentreTo( const wxPoint2DDouble &pt );
184 wxOutCode GetOutCode( const wxPoint2DDouble &pt ) const;
185 wxOutCode GetOutcode(const wxPoint2DDouble &pt) const;
186 bool Contains( const wxPoint2DDouble &pt ) const;
187 bool Contains( const wxRect2DDouble &rect ) const;
188 bool IsEmpty() const;
189 bool HaveEqualSize( const wxRect2DDouble &rect ) const;
190
191 void Inset( wxDouble x , wxDouble y );
192 void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom );
193 void Offset( const wxPoint2DDouble &pt );
194
195 void ConstrainTo( const wxRect2DDouble &rect );
196
197 wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor );
198
199 static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
200 void Intersect( const wxRect2DDouble &otherRect );
201 wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const;
202 bool Intersects( const wxRect2DDouble &rect ) const;
203
204 static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
205 void Union( const wxRect2DDouble &otherRect );
206 void Union( const wxPoint2DDouble &pt );
207 wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const;
208
209 void Scale( wxDouble f );
210 void Scale( wxInt32 num , wxInt32 denum );
211
212 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
213 bool operator == (const wxRect2DDouble& rect) const;
214 bool operator != (const wxRect2DDouble& rect) const;
215
216 wxDouble m_x;
217 wxDouble m_y;
218 wxDouble m_width;
219 wxDouble m_height;
220 };
221
222
223
224
225 // wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the
226 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
227 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
228
229 class wxRect2DInt
230 {
231 public:
232 wxRect2DInt();
233 wxRect2DInt( const wxRect& r );
234 wxRect2DInt(wxInt32 x, wxInt32 y, wxInt32 w, wxInt32 h);
235 wxRect2DInt(const wxPoint2DInt& topLeft, const wxPoint2DInt& bottomRight);
236 wxRect2DInt(const wxPoint2DInt& pos, const wxSize& size);
237 wxRect2DInt(const wxRect2DInt& rect);
238
239 // single attribute accessors
240
241 wxPoint2DInt GetPosition() const;
242 wxSize GetSize() const;
243
244 // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their
245 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately
246
247 wxInt32 GetLeft() const;
248 void SetLeft( wxInt32 n );
249 void MoveLeftTo( wxInt32 n );
250 wxInt32 GetTop() const;
251 void SetTop( wxInt32 n );
252 void MoveTopTo( wxInt32 n );
253 wxInt32 GetBottom() const;
254 void SetBottom( wxInt32 n );
255 void MoveBottomTo( wxInt32 n );
256 wxInt32 GetRight() const;
257 void SetRight( wxInt32 n );
258 void MoveRightTo( wxInt32 n );
259
260 wxPoint2DInt GetLeftTop() const;
261 void SetLeftTop( const wxPoint2DInt &pt ) ;
262 void MoveLeftTopTo( const wxPoint2DInt &pt ) ;
263 wxPoint2DInt GetLeftBottom() const ;
264 void SetLeftBottom( const wxPoint2DInt &pt ) ;
265 void MoveLeftBottomTo( const wxPoint2DInt &pt ) ;
266 wxPoint2DInt GetRightTop() const ;
267 void SetRightTop( const wxPoint2DInt &pt ) ;
268 void MoveRightTopTo( const wxPoint2DInt &pt ) ;
269 wxPoint2DInt GetRightBottom() const ;
270 void SetRightBottom( const wxPoint2DInt &pt ) ;
271 void MoveRightBottomTo( const wxPoint2DInt &pt ) ;
272 wxPoint2DInt GetCentre() const ;
273 void SetCentre( const wxPoint2DInt &pt ) ;
274 void MoveCentreTo( const wxPoint2DInt &pt ) ;
275 wxOutCode GetOutCode( const wxPoint2DInt &pt ) const;
276 wxOutCode GetOutcode( const wxPoint2DInt &pt ) const;
277 bool Contains( const wxPoint2DInt &pt ) const;
278 bool Contains( const wxRect2DInt &rect ) const;
279 bool IsEmpty() const;
280 bool HaveEqualSize( const wxRect2DInt &rect ) const;
281
282 void Inset( wxInt32 x , wxInt32 y );
283 void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom );
284 void Offset( const wxPoint2DInt &pt );
285 void ConstrainTo( const wxRect2DInt &rect );
286 wxPoint2DInt Interpolate( wxInt32 widthfactor , wxInt32 heightfactor );
287
288 static void Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest );
289 void Intersect( const wxRect2DInt &otherRect );
290 wxRect2DInt CreateIntersection( const wxRect2DInt &otherRect ) const;
291 bool Intersects( const wxRect2DInt &rect ) const;
292
293 static void Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest );
294 void Union( const wxRect2DInt &otherRect );
295 void Union( const wxPoint2DInt &pt );
296 wxRect2DInt CreateUnion( const wxRect2DInt &otherRect ) const;
297
298 void Scale( wxInt32 f );
299 void Scale( wxInt32 num , wxInt32 denum );
300
301 wxRect2DInt& operator = (const wxRect2DInt& rect);
302 bool operator == (const wxRect2DInt& rect) const;
303 bool operator != (const wxRect2DInt& rect) const;
304
305
306 wxInt32 m_x;
307 wxInt32 m_y;
308 wxInt32 m_width;
309 wxInt32 m_height;
310 };
311
312
313
314
315
316 class wxTransform2D
317 {
318 public :
319 virtual ~wxTransform2D();
320 virtual void Transform( wxPoint2DInt* pt )const = 0;
321 virtual void Transform( wxRect2DInt* r ) const;
322 virtual wxPoint2DInt Transform( const wxPoint2DInt &pt ) const;
323 virtual wxRect2DInt Transform( const wxRect2DInt &r ) const ;
324
325 virtual void InverseTransform( wxPoint2DInt* pt ) const = 0;
326 virtual void InverseTransform( wxRect2DInt* r ) const ;
327 virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ;
328 virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ;
329 };
330
331