]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _gdicmn.i | |
3 | // Purpose: SWIG interface for common GDI stuff and misc classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 13-Sept-2003 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | %newgroup | |
18 | ||
19 | ||
20 | enum wxBitmapType | |
21 | { | |
22 | wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility! | |
23 | wxBITMAP_TYPE_BMP, | |
24 | wxBITMAP_TYPE_BMP_RESOURCE, | |
25 | wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE, | |
26 | wxBITMAP_TYPE_ICO, | |
27 | wxBITMAP_TYPE_ICO_RESOURCE, | |
28 | wxBITMAP_TYPE_CUR, | |
29 | wxBITMAP_TYPE_CUR_RESOURCE, | |
30 | wxBITMAP_TYPE_XBM, | |
31 | wxBITMAP_TYPE_XBM_DATA, | |
32 | wxBITMAP_TYPE_XPM, | |
33 | wxBITMAP_TYPE_XPM_DATA, | |
34 | wxBITMAP_TYPE_TIF, | |
35 | wxBITMAP_TYPE_TIF_RESOURCE, | |
36 | wxBITMAP_TYPE_GIF, | |
37 | wxBITMAP_TYPE_GIF_RESOURCE, | |
38 | wxBITMAP_TYPE_PNG, | |
39 | wxBITMAP_TYPE_PNG_RESOURCE, | |
40 | wxBITMAP_TYPE_JPEG, | |
41 | wxBITMAP_TYPE_JPEG_RESOURCE, | |
42 | wxBITMAP_TYPE_PNM, | |
43 | wxBITMAP_TYPE_PNM_RESOURCE, | |
44 | wxBITMAP_TYPE_PCX, | |
45 | wxBITMAP_TYPE_PCX_RESOURCE, | |
46 | wxBITMAP_TYPE_PICT, | |
47 | wxBITMAP_TYPE_PICT_RESOURCE, | |
48 | wxBITMAP_TYPE_ICON, | |
49 | wxBITMAP_TYPE_ICON_RESOURCE, | |
50 | wxBITMAP_TYPE_ANI, | |
51 | wxBITMAP_TYPE_IFF, | |
52 | wxBITMAP_TYPE_MACCURSOR, | |
53 | wxBITMAP_TYPE_MACCURSOR_RESOURCE, | |
54 | wxBITMAP_TYPE_ANY = 50 | |
55 | }; | |
56 | ||
57 | // Standard cursors | |
58 | enum wxStockCursor | |
59 | { | |
60 | wxCURSOR_NONE, // should be 0 | |
61 | wxCURSOR_ARROW, | |
62 | wxCURSOR_RIGHT_ARROW, | |
63 | wxCURSOR_BULLSEYE, | |
64 | wxCURSOR_CHAR, | |
65 | wxCURSOR_CROSS, | |
66 | wxCURSOR_HAND, | |
67 | wxCURSOR_IBEAM, | |
68 | wxCURSOR_LEFT_BUTTON, | |
69 | wxCURSOR_MAGNIFIER, | |
70 | wxCURSOR_MIDDLE_BUTTON, | |
71 | wxCURSOR_NO_ENTRY, | |
72 | wxCURSOR_PAINT_BRUSH, | |
73 | wxCURSOR_PENCIL, | |
74 | wxCURSOR_POINT_LEFT, | |
75 | wxCURSOR_POINT_RIGHT, | |
76 | wxCURSOR_QUESTION_ARROW, | |
77 | wxCURSOR_RIGHT_BUTTON, | |
78 | wxCURSOR_SIZENESW, | |
79 | wxCURSOR_SIZENS, | |
80 | wxCURSOR_SIZENWSE, | |
81 | wxCURSOR_SIZEWE, | |
82 | wxCURSOR_SIZING, | |
83 | wxCURSOR_SPRAYCAN, | |
84 | wxCURSOR_WAIT, | |
85 | wxCURSOR_WATCH, | |
86 | wxCURSOR_BLANK, | |
87 | wxCURSOR_DEFAULT, // standard X11 cursor | |
88 | wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow | |
89 | ||
90 | // #ifdef __X__ | |
91 | // // Not yet implemented for Windows | |
92 | // wxCURSOR_CROSS_REVERSE, | |
93 | // wxCURSOR_DOUBLE_ARROW, | |
94 | // wxCURSOR_BASED_ARROW_UP, | |
95 | // wxCURSOR_BASED_ARROW_DOWN, | |
96 | // #endif // X11 | |
97 | ||
98 | wxCURSOR_ARROWWAIT, | |
99 | ||
100 | wxCURSOR_MAX | |
101 | }; | |
102 | ||
103 | %{ | |
104 | #ifndef __WXMAC__ | |
105 | #define wxCURSOR_COPY_ARROW wxCURSOR_ARROW | |
106 | #endif | |
107 | %} | |
108 | ||
109 | //--------------------------------------------------------------------------- | |
110 | %newgroup | |
d14a1e28 RD |
111 | |
112 | class wxSize | |
113 | { | |
114 | public: | |
115 | //int x; // TODO: Can these be removed and just use width and height? | |
116 | //int y; | |
117 | %name(width) int x; | |
118 | %name(height)int y; | |
119 | ||
120 | wxSize(int w=0, int h=0); | |
121 | ~wxSize(); | |
122 | ||
123 | bool operator==(const wxSize& sz) const; | |
124 | bool operator!=(const wxSize& sz) const; | |
125 | ||
126 | wxSize operator+(const wxSize& sz); | |
127 | wxSize operator-(const wxSize& sz); | |
128 | ||
129 | void IncTo(const wxSize& sz); | |
130 | void DecTo(const wxSize& sz); | |
131 | ||
132 | void Set(int xx, int yy); | |
133 | void SetWidth(int w); | |
134 | void SetHeight(int h); | |
135 | int GetWidth() const; | |
136 | int GetHeight() const; | |
137 | ||
138 | int GetX() const; | |
139 | int GetY() const; | |
140 | ||
141 | %extend { | |
142 | PyObject* asTuple() { | |
143 | wxPyBeginBlockThreads(); | |
144 | PyObject* tup = PyTuple_New(2); | |
145 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
146 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
147 | wxPyEndBlockThreads(); | |
148 | return tup; | |
149 | } | |
150 | } | |
151 | %pythoncode { | |
152 | def __str__(self): return str(self.asTuple()) | |
153 | def __repr__(self): return 'wxSize'+str(self.asTuple()) | |
154 | def __len__(self): return len(self.asTuple()) | |
155 | def __getitem__(self, index): return self.asTuple()[index] | |
156 | def __setitem__(self, index, val): | |
157 | if index == 0: self.width = val | |
158 | elif index == 1: self.height = val | |
159 | else: raise IndexError | |
160 | def __nonzero__(self): return self.asTuple() != (0,0) | |
161 | def __getinitargs__(self): return () | |
162 | def __getstate__(self): return self.asTuple() | |
163 | def __setstate__(self, state): self.Set(*state) | |
164 | } | |
165 | ||
166 | }; | |
167 | ||
168 | //--------------------------------------------------------------------------- | |
169 | %newgroup | |
94d33c49 | 170 | |
d14a1e28 RD |
171 | |
172 | class wxRealPoint | |
173 | { | |
174 | public: | |
175 | double x; | |
176 | double y; | |
177 | ||
178 | wxRealPoint(double x=0.0, double y=0.0); | |
179 | ~wxRealPoint(); | |
180 | ||
181 | wxRealPoint operator+(const wxRealPoint& pt) const; | |
182 | wxRealPoint operator-(const wxRealPoint& pt) const; | |
183 | ||
184 | bool operator==(const wxRealPoint& pt) const; | |
185 | bool operator!=(const wxRealPoint& pt) const; | |
186 | ||
187 | %extend { | |
188 | void Set(double x, double y) { | |
189 | self->x = x; | |
190 | self->y = y; | |
191 | } | |
192 | PyObject* asTuple() { | |
193 | wxPyBeginBlockThreads(); | |
194 | PyObject* tup = PyTuple_New(2); | |
195 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x)); | |
196 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y)); | |
197 | wxPyEndBlockThreads(); | |
198 | return tup; | |
199 | } | |
200 | } | |
201 | ||
202 | %pythoncode { | |
203 | def __str__(self): return str(self.asTuple()) | |
204 | def __repr__(self): return 'wxRealPoint'+str(self.asTuple()) | |
205 | def __len__(self): return len(self.asTuple()) | |
206 | def __getitem__(self, index): return self.asTuple()[index] | |
207 | def __setitem__(self, index, val): | |
208 | if index == 0: self.width = val | |
209 | elif index == 1: self.height = val | |
210 | else: raise IndexError | |
211 | def __nonzero__(self): return self.asTuple() != (0.0, 0.0) | |
212 | def __getinitargs__(self): return () | |
213 | def __getstate__(self): return self.asTuple() | |
214 | def __setstate__(self, state): self.Set(*state) | |
215 | } | |
216 | }; | |
217 | ||
218 | //--------------------------------------------------------------------------- | |
219 | %newgroup | |
94d33c49 | 220 | |
d14a1e28 RD |
221 | |
222 | class wxPoint | |
223 | { | |
224 | public: | |
225 | int x, y; | |
226 | ||
227 | wxPoint(int x=0, int y=0); | |
228 | ~wxPoint(); | |
229 | ||
230 | bool operator==(const wxPoint& p) const; | |
231 | bool operator!=(const wxPoint& p) const; | |
232 | ||
233 | wxPoint operator+(const wxPoint& p) const; | |
234 | wxPoint operator-(const wxPoint& p) const; | |
235 | ||
236 | wxPoint& operator+=(const wxPoint& p); | |
237 | wxPoint& operator-=(const wxPoint& p); | |
238 | ||
239 | %extend { | |
240 | void Set(long x, long y) { | |
241 | self->x = x; | |
242 | self->y = y; | |
243 | } | |
244 | PyObject* asTuple() { | |
245 | wxPyBeginBlockThreads(); | |
246 | PyObject* tup = PyTuple_New(2); | |
247 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
248 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
249 | wxPyEndBlockThreads(); | |
250 | return tup; | |
251 | } | |
252 | } | |
253 | ||
254 | %pythoncode { | |
255 | def __str__(self): return str(self.asTuple()) | |
256 | def __repr__(self): return 'wxPoint'+str(self.asTuple()) | |
257 | def __len__(self): return len(self.asTuple()) | |
258 | def __getitem__(self, index): return self.asTuple()[index] | |
259 | def __setitem__(self, index, val): | |
260 | if index == 0: self.x = val | |
261 | elif index == 1: self.y = val | |
262 | else: raise IndexError | |
263 | def __nonzero__(self): return self.asTuple() != (0,0) | |
264 | def __getinitargs__(self): return () | |
265 | def __getstate__(self): return self.asTuple() | |
266 | def __setstate__(self, state): self.Set(*state) | |
267 | } | |
268 | }; | |
269 | ||
270 | //--------------------------------------------------------------------------- | |
271 | %newgroup | |
94d33c49 | 272 | |
d14a1e28 RD |
273 | |
274 | class wxRect | |
275 | { | |
276 | public: | |
277 | wxRect(int x=0, int y=0, int width=0, int height=0); | |
278 | %name(RectPP) wxRect(const wxPoint& topLeft, const wxPoint& bottomRight); | |
279 | %name(RectPS) wxRect(const wxPoint& pos, const wxSize& size); | |
280 | ~wxRect(); | |
281 | ||
282 | int GetX() const; | |
283 | void SetX(int x); | |
284 | ||
285 | int GetY(); | |
286 | void SetY(int y); | |
287 | ||
288 | int GetWidth() const; | |
289 | void SetWidth(int w); | |
290 | ||
291 | int GetHeight() const; | |
292 | void SetHeight(int h); | |
293 | ||
294 | wxPoint GetPosition() const; | |
295 | void SetPosition( const wxPoint &p ); | |
296 | ||
297 | wxSize GetSize() const; | |
298 | void SetSize( const wxSize &s ); | |
299 | ||
300 | int GetLeft() const; | |
301 | int GetTop() const; | |
302 | int GetBottom() const; | |
303 | int GetRight() const; | |
304 | ||
305 | void SetLeft(int left); | |
306 | void SetRight(int right); | |
307 | void SetTop(int top); | |
308 | void SetBottom(int bottom); | |
309 | ||
310 | wxRect& Inflate(wxCoord dx, wxCoord dy); | |
311 | wxRect& Deflate(wxCoord dx, wxCoord dy); | |
312 | ||
313 | %name(OffsetXY)void Offset(wxCoord dx, wxCoord dy); | |
314 | void Offset(const wxPoint& pt); | |
315 | ||
316 | wxRect& Intersect(const wxRect& rect); | |
317 | ||
318 | wxRect operator+(const wxRect& rect) const; | |
319 | wxRect& operator+=(const wxRect& rect); | |
320 | ||
321 | bool operator==(const wxRect& rect) const; | |
322 | bool operator!=(const wxRect& rect) const { return !(*this == rect); } | |
323 | ||
324 | // return TRUE if the point is (not strcitly) inside the rect | |
325 | %name(InsideXY)bool Inside(int x, int y) const; | |
326 | bool Inside(const wxPoint& pt) const; | |
327 | ||
328 | // return TRUE if the rectangles have a non empty intersection | |
329 | bool Intersects(const wxRect& rect) const; | |
330 | ||
331 | int x, y, width, height; | |
332 | ||
333 | ||
334 | %extend { | |
335 | void Set(int x=0, int y=0, int width=0, int height=0) { | |
336 | self->x = x; | |
337 | self->y = y; | |
338 | self->width = width; | |
339 | self->height = height; | |
340 | } | |
341 | ||
342 | PyObject* asTuple() { | |
343 | wxPyBeginBlockThreads(); | |
344 | PyObject* tup = PyTuple_New(4); | |
345 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
346 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
347 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width)); | |
348 | PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height)); | |
349 | wxPyEndBlockThreads(); | |
350 | return tup; | |
351 | } | |
352 | } | |
353 | ||
354 | %pythoncode { | |
355 | def __str__(self): return str(self.asTuple()) | |
356 | def __repr__(self): return 'wxRect'+str(self.asTuple()) | |
357 | def __len__(self): return len(self.asTuple()) | |
358 | def __getitem__(self, index): return self.asTuple()[index] | |
359 | def __setitem__(self, index, val): | |
360 | if index == 0: self.x = val | |
361 | elif index == 1: self.y = val | |
362 | elif index == 2: self.width = val | |
363 | elif index == 3: self.height = val | |
364 | else: raise IndexError | |
365 | def __nonzero__(self): return self.asTuple() != (0,0,0,0) | |
366 | def __getinitargs__(self): return () | |
367 | def __getstate__(self): return self.asTuple() | |
368 | def __setstate__(self, state): self.Set(*state) | |
369 | } | |
370 | }; | |
371 | ||
372 | ||
373 | %inline %{ | |
374 | PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) { | |
375 | wxRegion reg1(*r1); | |
376 | wxRegion reg2(*r2); | |
377 | wxRect dest(0,0,0,0); | |
378 | PyObject* obj; | |
379 | ||
380 | reg1.Intersect(reg2); | |
381 | dest = reg1.GetBox(); | |
382 | ||
383 | if (dest != wxRect(0,0,0,0)) { | |
384 | wxPyBeginBlockThreads(); | |
385 | wxRect* newRect = new wxRect(dest); | |
386 | obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true); | |
387 | wxPyEndBlockThreads(); | |
388 | return obj; | |
389 | } | |
390 | Py_INCREF(Py_None); | |
391 | return Py_None; | |
392 | } | |
393 | %} | |
394 | ||
395 | //--------------------------------------------------------------------------- | |
396 | %newgroup | |
94d33c49 | 397 | |
d14a1e28 RD |
398 | |
399 | // wxPoint2Ds represent a point or a vector in a 2d coordinate system | |
400 | ||
401 | class wxPoint2D | |
402 | { | |
403 | public : | |
404 | wxPoint2D( double x=0.0 , double y=0.0 ); | |
405 | %name(Point2DCopy) wxPoint2D( const wxPoint2D &pt ); | |
406 | %name(Point2DFromPoint) wxPoint2D( const wxPoint &pt ); | |
407 | ||
408 | // two different conversions to integers, floor and rounding | |
409 | void GetFloor( int *OUTPUT , int *OUTPUT ) const; | |
410 | void GetRounded( int *OUTPUT , int *OUTPUT ) const; | |
411 | ||
412 | double GetVectorLength() const; | |
413 | double GetVectorAngle() const ; | |
414 | void SetVectorLength( double length ); | |
415 | void SetVectorAngle( double degrees ); | |
416 | // LinkError: void SetPolarCoordinates( double angle , double length ); | |
417 | // LinkError: void Normalize(); | |
418 | %pythoncode { | |
419 | def SetPolarCoordinates(self, angle, length): | |
420 | self.SetVectorLength(length) | |
421 | self.SetVectorAngle(angle) | |
422 | def Normalize(self): | |
423 | self.SetVectorLength(1.0) | |
424 | } | |
425 | ||
426 | double GetDistance( const wxPoint2D &pt ) const; | |
427 | double GetDistanceSquare( const wxPoint2D &pt ) const; | |
428 | double GetDotProduct( const wxPoint2D &vec ) const; | |
429 | double GetCrossProduct( const wxPoint2D &vec ) const; | |
430 | ||
431 | // the reflection of this point | |
432 | wxPoint2D operator-(); | |
433 | ||
434 | wxPoint2D& operator+=(const wxPoint2D& pt); | |
435 | wxPoint2D& operator-=(const wxPoint2D& pt); | |
436 | ||
437 | wxPoint2D& operator*=(const wxPoint2D& pt); | |
438 | wxPoint2D& operator/=(const wxPoint2D& pt); | |
439 | ||
440 | bool operator==(const wxPoint2D& pt) const; | |
441 | bool operator!=(const wxPoint2D& pt) const; | |
442 | ||
443 | double m_x; | |
444 | double m_y; | |
445 | %name(x)double m_x; | |
446 | %name(y)double m_y; | |
447 | ||
448 | %extend { | |
449 | void Set( double x=0 , double y=0 ) { | |
450 | self->m_x = x; | |
451 | self->m_y = y; | |
452 | } | |
453 | PyObject* asTuple() { | |
454 | wxPyBeginBlockThreads(); | |
455 | PyObject* tup = PyTuple_New(2); | |
456 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x)); | |
457 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y)); | |
458 | wxPyEndBlockThreads(); | |
459 | return tup; | |
460 | } | |
461 | } | |
462 | ||
463 | %pythoncode { | |
464 | def __str__(self): return str(self.asTuple()) | |
465 | def __repr__(self): return 'wxPoint2D'+str(self.asTuple()) | |
466 | def __len__(self): return len(self.asTuple()) | |
467 | def __getitem__(self, index): return self.asTuple()[index] | |
468 | def __setitem__(self, index, val): | |
469 | if index == 0: self.m_x = val | |
470 | elif index == 1: self.m_yt = val | |
471 | else: raise IndexError | |
472 | def __nonzero__(self): return self.asTuple() != (0.0, 0.0) | |
473 | def __getinitargs__(self): return () | |
474 | def __getstate__(self): return self.asTuple() | |
475 | def __setstate__(self, state): self.Set(*state) | |
476 | ||
477 | } | |
478 | }; | |
479 | ||
480 | ||
481 | //--------------------------------------------------------------------------- | |
482 | ||
483 | %immutable; | |
484 | const wxPoint wxDefaultPosition; | |
485 | const wxSize wxDefaultSize; | |
486 | %mutable; | |
487 | ||
488 | //--------------------------------------------------------------------------- |