]>
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, | |
d14a1e28 | 24 | wxBITMAP_TYPE_ICO, |
d14a1e28 | 25 | wxBITMAP_TYPE_CUR, |
d14a1e28 RD |
26 | wxBITMAP_TYPE_XBM, |
27 | wxBITMAP_TYPE_XBM_DATA, | |
28 | wxBITMAP_TYPE_XPM, | |
29 | wxBITMAP_TYPE_XPM_DATA, | |
30 | wxBITMAP_TYPE_TIF, | |
d14a1e28 | 31 | wxBITMAP_TYPE_GIF, |
d14a1e28 | 32 | wxBITMAP_TYPE_PNG, |
d14a1e28 | 33 | wxBITMAP_TYPE_JPEG, |
d14a1e28 | 34 | wxBITMAP_TYPE_PNM, |
d14a1e28 | 35 | wxBITMAP_TYPE_PCX, |
d14a1e28 | 36 | wxBITMAP_TYPE_PICT, |
d14a1e28 | 37 | wxBITMAP_TYPE_ICON, |
d14a1e28 RD |
38 | wxBITMAP_TYPE_ANI, |
39 | wxBITMAP_TYPE_IFF, | |
40 | wxBITMAP_TYPE_MACCURSOR, | |
64e8a1f0 RD |
41 | |
42 | // wxBITMAP_TYPE_BMP_RESOURCE, | |
43 | // wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE, | |
44 | // wxBITMAP_TYPE_ICO_RESOURCE, | |
45 | // wxBITMAP_TYPE_CUR_RESOURCE, | |
46 | // wxBITMAP_TYPE_TIF_RESOURCE, | |
47 | // wxBITMAP_TYPE_GIF_RESOURCE, | |
48 | // wxBITMAP_TYPE_PNG_RESOURCE, | |
49 | // wxBITMAP_TYPE_JPEG_RESOURCE, | |
50 | // wxBITMAP_TYPE_PNM_RESOURCE, | |
51 | // wxBITMAP_TYPE_PCX_RESOURCE, | |
52 | // wxBITMAP_TYPE_PICT_RESOURCE, | |
53 | // wxBITMAP_TYPE_ICON_RESOURCE, | |
54 | // wxBITMAP_TYPE_MACCURSOR_RESOURCE, | |
55 | ||
d14a1e28 RD |
56 | wxBITMAP_TYPE_ANY = 50 |
57 | }; | |
58 | ||
59 | // Standard cursors | |
60 | enum wxStockCursor | |
61 | { | |
62 | wxCURSOR_NONE, // should be 0 | |
63 | wxCURSOR_ARROW, | |
64 | wxCURSOR_RIGHT_ARROW, | |
65 | wxCURSOR_BULLSEYE, | |
66 | wxCURSOR_CHAR, | |
67 | wxCURSOR_CROSS, | |
68 | wxCURSOR_HAND, | |
69 | wxCURSOR_IBEAM, | |
70 | wxCURSOR_LEFT_BUTTON, | |
71 | wxCURSOR_MAGNIFIER, | |
72 | wxCURSOR_MIDDLE_BUTTON, | |
73 | wxCURSOR_NO_ENTRY, | |
74 | wxCURSOR_PAINT_BRUSH, | |
75 | wxCURSOR_PENCIL, | |
76 | wxCURSOR_POINT_LEFT, | |
77 | wxCURSOR_POINT_RIGHT, | |
78 | wxCURSOR_QUESTION_ARROW, | |
79 | wxCURSOR_RIGHT_BUTTON, | |
80 | wxCURSOR_SIZENESW, | |
81 | wxCURSOR_SIZENS, | |
82 | wxCURSOR_SIZENWSE, | |
83 | wxCURSOR_SIZEWE, | |
84 | wxCURSOR_SIZING, | |
85 | wxCURSOR_SPRAYCAN, | |
86 | wxCURSOR_WAIT, | |
87 | wxCURSOR_WATCH, | |
88 | wxCURSOR_BLANK, | |
89 | wxCURSOR_DEFAULT, // standard X11 cursor | |
90 | wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow | |
91 | ||
92 | // #ifdef __X__ | |
93 | // // Not yet implemented for Windows | |
94 | // wxCURSOR_CROSS_REVERSE, | |
95 | // wxCURSOR_DOUBLE_ARROW, | |
96 | // wxCURSOR_BASED_ARROW_UP, | |
97 | // wxCURSOR_BASED_ARROW_DOWN, | |
98 | // #endif // X11 | |
99 | ||
100 | wxCURSOR_ARROWWAIT, | |
101 | ||
102 | wxCURSOR_MAX | |
103 | }; | |
104 | ||
105 | %{ | |
106 | #ifndef __WXMAC__ | |
107 | #define wxCURSOR_COPY_ARROW wxCURSOR_ARROW | |
108 | #endif | |
109 | %} | |
110 | ||
111 | //--------------------------------------------------------------------------- | |
112 | %newgroup | |
d14a1e28 | 113 | |
dd9f7fea RD |
114 | DocStr( wxSize, |
115 | "wx.Size is a useful data structure used to represent the size of something. | |
116 | It simply contians integer width and height proprtites. In most places in | |
117 | wxPython where a wx.Size is expected a (width,height) tuple can be used | |
118 | instead."); | |
119 | ||
d14a1e28 RD |
120 | class wxSize |
121 | { | |
122 | public: | |
d14a1e28 RD |
123 | %name(width) int x; |
124 | %name(height)int y; | |
61c5a8ac RD |
125 | %pythoncode { x = width; y = height } |
126 | ||
dd9f7fea RD |
127 | DocCtorStr( |
128 | wxSize(int w=0, int h=0), | |
129 | "Creates a size object."); | |
130 | ||
d14a1e28 RD |
131 | ~wxSize(); |
132 | ||
dd9f7fea RD |
133 | DocDeclStr( |
134 | bool, operator==(const wxSize& sz), | |
135 | "Test for equality of wx.Size objects."); | |
136 | ||
137 | DocDeclStr( | |
138 | bool, operator!=(const wxSize& sz), | |
139 | "Test for inequality."); | |
d14a1e28 | 140 | |
dd9f7fea RD |
141 | DocDeclStr( |
142 | wxSize, operator+(const wxSize& sz), | |
143 | "Add sz's proprties to this and return the result."); | |
d14a1e28 | 144 | |
dd9f7fea RD |
145 | DocDeclStr( |
146 | wxSize, operator-(const wxSize& sz), | |
147 | "Subtract sz's properties from this and return the result."); | |
d14a1e28 | 148 | |
dd9f7fea RD |
149 | DocDeclStr( |
150 | void, IncTo(const wxSize& sz), | |
151 | "Increments this object so that both of its dimensions are not less\n" | |
152 | "than the corresponding dimensions of the size."); | |
153 | ||
154 | DocDeclStr( | |
155 | void, DecTo(const wxSize& sz), | |
156 | "Decrements this object so that both of its dimensions are not greater\n" | |
157 | "than the corresponding dimensions of the size."); | |
158 | ||
159 | DocDeclStr( | |
160 | void, Set(int w, int h), | |
161 | "Set both width and height."); | |
162 | ||
d14a1e28 RD |
163 | void SetWidth(int w); |
164 | void SetHeight(int h); | |
165 | int GetWidth() const; | |
166 | int GetHeight() const; | |
167 | ||
dd9f7fea RD |
168 | //int GetX() const; |
169 | //int GetY() const; | |
d14a1e28 RD |
170 | |
171 | %extend { | |
dd9f7fea RD |
172 | DocAStr(Get, |
173 | "Get() -> (width,height)", | |
174 | "Returns the width and height properties as a tuple."); | |
175 | PyObject* Get() { | |
d14a1e28 RD |
176 | wxPyBeginBlockThreads(); |
177 | PyObject* tup = PyTuple_New(2); | |
178 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
179 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
180 | wxPyEndBlockThreads(); | |
181 | return tup; | |
182 | } | |
183 | } | |
184 | %pythoncode { | |
dd9f7fea RD |
185 | asTuple = Get |
186 | def __str__(self): return str(self.Get()) | |
187 | def __repr__(self): return 'wx.Size'+str(self.Get()) | |
188 | def __len__(self): return len(self.Get()) | |
189 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
190 | def __setitem__(self, index, val): |
191 | if index == 0: self.width = val | |
192 | elif index == 1: self.height = val | |
193 | else: raise IndexError | |
dd9f7fea | 194 | def __nonzero__(self): return self.Get() != (0,0) |
d14a1e28 | 195 | def __getinitargs__(self): return () |
dd9f7fea | 196 | def __getstate__(self): return self.Get() |
d14a1e28 RD |
197 | def __setstate__(self, state): self.Set(*state) |
198 | } | |
199 | ||
200 | }; | |
201 | ||
202 | //--------------------------------------------------------------------------- | |
203 | %newgroup | |
94d33c49 | 204 | |
dd9f7fea RD |
205 | DocStr( wxRealPoint, |
206 | "A data structure for representing a point or position with floating point x | |
207 | and y properties. In wxPython most places that expect a wx.RealPoint can also | |
208 | accept a (x,y) tuple."); | |
d14a1e28 RD |
209 | class wxRealPoint |
210 | { | |
211 | public: | |
212 | double x; | |
213 | double y; | |
214 | ||
dd9f7fea RD |
215 | DocCtorStr( |
216 | wxRealPoint(double x=0.0, double y=0.0), | |
217 | "Create a wx.RealPoint object"); | |
218 | ||
d14a1e28 RD |
219 | ~wxRealPoint(); |
220 | ||
dd9f7fea RD |
221 | DocDeclStr( |
222 | bool, operator==(const wxRealPoint& pt), | |
223 | "Test for equality of wx.RealPoint objects."); | |
224 | ||
225 | DocDeclStr( | |
226 | bool, operator!=(const wxRealPoint& pt), | |
227 | "Test for inequality of wx.RealPoint objects."); | |
228 | ||
229 | ||
230 | DocDeclStr( | |
231 | wxRealPoint, operator+(const wxRealPoint& pt), | |
232 | "Add pt's proprties to this and return the result."); | |
233 | ||
234 | DocDeclStr( | |
235 | wxRealPoint, operator-(const wxRealPoint& pt), | |
236 | "Subtract pt's proprties from this and return the result"); | |
d14a1e28 | 237 | |
d14a1e28 RD |
238 | |
239 | %extend { | |
dd9f7fea | 240 | DocStr(Set, "Set both the x and y properties"); |
d14a1e28 RD |
241 | void Set(double x, double y) { |
242 | self->x = x; | |
243 | self->y = y; | |
244 | } | |
dd9f7fea RD |
245 | |
246 | DocAStr(Get, | |
247 | "Get() -> (x,y)", | |
248 | "Return the x and y properties as a tuple. "); | |
249 | PyObject* Get() { | |
d14a1e28 RD |
250 | wxPyBeginBlockThreads(); |
251 | PyObject* tup = PyTuple_New(2); | |
252 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x)); | |
253 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y)); | |
254 | wxPyEndBlockThreads(); | |
255 | return tup; | |
256 | } | |
257 | } | |
258 | ||
259 | %pythoncode { | |
dd9f7fea RD |
260 | asTuple = Get |
261 | def __str__(self): return str(self.Get()) | |
262 | def __repr__(self): return 'wx.RealPoint'+str(self.Get()) | |
263 | def __len__(self): return len(self.Get()) | |
264 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 | 265 | def __setitem__(self, index, val): |
dd9f7fea RD |
266 | if index == 0: self.x = val |
267 | elif index == 1: self.y = val | |
d14a1e28 | 268 | else: raise IndexError |
dd9f7fea | 269 | def __nonzero__(self): return self.Get() != (0.0, 0.0) |
d14a1e28 | 270 | def __getinitargs__(self): return () |
dd9f7fea | 271 | def __getstate__(self): return self.Get() |
d14a1e28 RD |
272 | def __setstate__(self, state): self.Set(*state) |
273 | } | |
274 | }; | |
275 | ||
dd9f7fea | 276 | |
d14a1e28 RD |
277 | //--------------------------------------------------------------------------- |
278 | %newgroup | |
94d33c49 | 279 | |
d14a1e28 | 280 | |
dd9f7fea RD |
281 | DocStr(wxPoint, |
282 | "A data structure for representing a point or position with integer x and y | |
283 | properties. Most places in wxPython that expect a wx.Point can also accept a | |
284 | (x,y) tuple."); | |
285 | ||
d14a1e28 RD |
286 | class wxPoint |
287 | { | |
288 | public: | |
289 | int x, y; | |
290 | ||
dd9f7fea RD |
291 | DocCtorStr( |
292 | wxPoint(int x=0, int y=0), | |
293 | "Create a wx.Point object"); | |
294 | ||
d14a1e28 RD |
295 | ~wxPoint(); |
296 | ||
dd9f7fea RD |
297 | |
298 | DocDeclStr( | |
299 | bool, operator==(const wxPoint& pt), | |
300 | "Test for equality of wx.Point objects."); | |
d14a1e28 | 301 | |
dd9f7fea RD |
302 | DocDeclStr( |
303 | bool, operator!=(const wxPoint& pt), | |
304 | "Test for inequality of wx.Point objects."); | |
d14a1e28 | 305 | |
dd9f7fea RD |
306 | |
307 | DocDeclStr( | |
308 | wxPoint, operator+(const wxPoint& pt), | |
309 | "Add pt's proprties to this and return the result."); | |
d14a1e28 | 310 | |
dd9f7fea RD |
311 | DocDeclStr( |
312 | wxPoint, operator-(const wxPoint& pt), | |
313 | "Subtract pt's proprties from this and return the result"); | |
314 | ||
315 | ||
316 | DocDeclStr( | |
317 | wxPoint&, operator+=(const wxPoint& pt), | |
318 | "Add pt to this object."); | |
319 | ||
320 | DocDeclStr( | |
321 | wxPoint&, operator-=(const wxPoint& pt), | |
322 | "Subtract pt from this object."); | |
323 | ||
324 | ||
d14a1e28 | 325 | %extend { |
dd9f7fea | 326 | DocStr(Set, "Set both the x and y properties"); |
d14a1e28 RD |
327 | void Set(long x, long y) { |
328 | self->x = x; | |
329 | self->y = y; | |
330 | } | |
dd9f7fea RD |
331 | |
332 | DocAStr(Get, | |
333 | "Get() -> (x,y)", | |
334 | "Return the x and y properties as a tuple. "); | |
335 | PyObject* Get() { | |
d14a1e28 RD |
336 | wxPyBeginBlockThreads(); |
337 | PyObject* tup = PyTuple_New(2); | |
338 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
339 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
340 | wxPyEndBlockThreads(); | |
341 | return tup; | |
342 | } | |
343 | } | |
344 | ||
345 | %pythoncode { | |
dd9f7fea RD |
346 | asTuple = Get |
347 | def __str__(self): return str(self.Get()) | |
348 | def __repr__(self): return 'wx.Point'+str(self.Get()) | |
349 | def __len__(self): return len(self.Get()) | |
350 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
351 | def __setitem__(self, index, val): |
352 | if index == 0: self.x = val | |
353 | elif index == 1: self.y = val | |
354 | else: raise IndexError | |
dd9f7fea | 355 | def __nonzero__(self): return self.Get() != (0,0) |
d14a1e28 | 356 | def __getinitargs__(self): return () |
dd9f7fea | 357 | def __getstate__(self): return self.Get() |
d14a1e28 RD |
358 | def __setstate__(self, state): self.Set(*state) |
359 | } | |
360 | }; | |
361 | ||
362 | //--------------------------------------------------------------------------- | |
363 | %newgroup | |
94d33c49 | 364 | |
d14a1e28 | 365 | |
dd9f7fea RD |
366 | DocStr(wxRect, |
367 | "A class for representing and manipulating rectangles. It has x, y, width and | |
368 | height properties. In wxPython most palces that expect a wx.Rect can also | |
369 | accept a (x,y,width,height) tuple."); | |
370 | ||
d14a1e28 RD |
371 | class wxRect |
372 | { | |
373 | public: | |
dd9f7fea RD |
374 | DocCtorStr( |
375 | wxRect(int x=0, int y=0, int width=0, int height=0), | |
376 | "Create a new Rect object."); | |
377 | ||
378 | DocCtorStrName( | |
379 | wxRect(const wxPoint& topLeft, const wxPoint& bottomRight), | |
380 | "Create a new Rect object from Points representing two corners.", | |
381 | RectPP); | |
382 | ||
383 | DocCtorStrName( | |
384 | wxRect(const wxPoint& pos, const wxSize& size), | |
385 | "Create a new Rect from a position and size.", | |
386 | RectPS); | |
387 | ||
d14a1e28 RD |
388 | ~wxRect(); |
389 | ||
390 | int GetX() const; | |
391 | void SetX(int x); | |
392 | ||
393 | int GetY(); | |
394 | void SetY(int y); | |
395 | ||
396 | int GetWidth() const; | |
397 | void SetWidth(int w); | |
398 | ||
399 | int GetHeight() const; | |
400 | void SetHeight(int h); | |
401 | ||
402 | wxPoint GetPosition() const; | |
403 | void SetPosition( const wxPoint &p ); | |
404 | ||
405 | wxSize GetSize() const; | |
406 | void SetSize( const wxSize &s ); | |
407 | ||
3f0ff538 RD |
408 | wxPoint GetTopLeft() const; |
409 | void SetTopLeft(const wxPoint &p); | |
410 | wxPoint GetBottomRight() const; | |
411 | void SetBottomRight(const wxPoint &p); | |
412 | ||
413 | // wxPoint GetLeftTop() const; | |
414 | // void SetLeftTop(const wxPoint &p); | |
415 | // wxPoint GetRightBottom() const; | |
416 | // void SetRightBottom(const wxPoint &p); | |
417 | ||
d14a1e28 RD |
418 | int GetLeft() const; |
419 | int GetTop() const; | |
420 | int GetBottom() const; | |
421 | int GetRight() const; | |
422 | ||
423 | void SetLeft(int left); | |
424 | void SetRight(int right); | |
425 | void SetTop(int top); | |
426 | void SetBottom(int bottom); | |
427 | ||
dd9f7fea RD |
428 | %pythoncode { |
429 | position = property(GetPosition, SetPosition) | |
430 | size = property(GetSize, SetSize) | |
431 | left = property(GetLeft, SetLeft) | |
432 | right = property(GetRight, SetRight) | |
433 | top = property(GetTop, SetTop) | |
434 | bottom = property(GetBottom, SetBottom) | |
435 | } | |
436 | ||
437 | DocDeclStr( | |
438 | wxRect&, Inflate(wxCoord dx, wxCoord dy), | |
439 | "Increase the rectangle size by dx in x direction and dy in y direction. Both\n" | |
440 | "(or one of) parameters may be negative to decrease the rectangle size."); | |
441 | ||
442 | DocDeclStr( | |
443 | wxRect&, Deflate(wxCoord dx, wxCoord dy), | |
444 | "Decrease the rectangle size by dx in x direction and dy in y direction. Both\n" | |
445 | "(or one of) parameters may be negative to increase the rectngle size. This\n" | |
446 | "method is the opposite of Inflate."); | |
447 | ||
448 | DocDeclStrName( | |
449 | void, Offset(wxCoord dx, wxCoord dy), | |
450 | "Moves the rectangle by the specified offset. If dx is positive, the rectangle\n" | |
451 | "is moved to the right, if dy is positive, it is moved to the bottom, otherwise\n" | |
452 | "it is moved to the left or top respectively.", | |
453 | OffsetXY); | |
454 | ||
455 | DocDeclStr( | |
456 | void, Offset(const wxPoint& pt), | |
457 | "Same as OffsetXY but uses dx,dy from Point"); | |
458 | ||
459 | DocDeclStr( | |
460 | wxRect&, Intersect(const wxRect& rect), | |
461 | "Return the intersectsion of this rectangle and rect."); | |
d14a1e28 | 462 | |
dd9f7fea RD |
463 | DocDeclStr( |
464 | wxRect, operator+(const wxRect& rect) const, | |
465 | "Add the properties of rect to this rectangle and return the result."); | |
d14a1e28 | 466 | |
dd9f7fea RD |
467 | DocDeclStr( |
468 | wxRect&, operator+=(const wxRect& rect), | |
469 | "Add the properties of rect to this rectangle, updating this rectangle."); | |
d14a1e28 | 470 | |
dd9f7fea RD |
471 | DocDeclStr( |
472 | bool, operator==(const wxRect& rect) const, | |
473 | "Test for equality."); | |
d14a1e28 | 474 | |
dd9f7fea RD |
475 | DocDeclStr( |
476 | bool, operator!=(const wxRect& rect) const, | |
477 | "Test for inequality."); | |
d14a1e28 | 478 | |
dd9f7fea RD |
479 | |
480 | DocStr( Inside, "Return True if the point is (not strcitly) inside the rect."); | |
d14a1e28 RD |
481 | %name(InsideXY)bool Inside(int x, int y) const; |
482 | bool Inside(const wxPoint& pt) const; | |
483 | ||
dd9f7fea RD |
484 | DocDeclStr( |
485 | bool, Intersects(const wxRect& rect) const, | |
486 | "Returns True if the rectangles have a non empty intersection."); | |
d14a1e28 | 487 | |
dd9f7fea | 488 | |
d14a1e28 RD |
489 | int x, y, width, height; |
490 | ||
491 | ||
492 | %extend { | |
dd9f7fea RD |
493 | DocStr(Set, "Set all rectangle properties."); |
494 | void Set(int x=0, int y=0, int width=0, int height=0) { | |
d14a1e28 RD |
495 | self->x = x; |
496 | self->y = y; | |
497 | self->width = width; | |
498 | self->height = height; | |
499 | } | |
500 | ||
dd9f7fea RD |
501 | DocAStr(Get, |
502 | "Get() -> (x,y,width,height)", | |
503 | "Return the rectangle properties as a tuple."); | |
504 | PyObject* Get() { | |
d14a1e28 RD |
505 | wxPyBeginBlockThreads(); |
506 | PyObject* tup = PyTuple_New(4); | |
507 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
508 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
509 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width)); | |
510 | PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height)); | |
511 | wxPyEndBlockThreads(); | |
512 | return tup; | |
513 | } | |
514 | } | |
515 | ||
516 | %pythoncode { | |
dd9f7fea RD |
517 | asTuple = Get |
518 | def __str__(self): return str(self.Get()) | |
519 | def __repr__(self): return 'wx.Rect'+str(self.Get()) | |
520 | def __len__(self): return len(self.Get()) | |
521 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
522 | def __setitem__(self, index, val): |
523 | if index == 0: self.x = val | |
524 | elif index == 1: self.y = val | |
525 | elif index == 2: self.width = val | |
526 | elif index == 3: self.height = val | |
527 | else: raise IndexError | |
dd9f7fea | 528 | def __nonzero__(self): return self.Get() != (0,0,0,0) |
d14a1e28 | 529 | def __getinitargs__(self): return () |
dd9f7fea | 530 | def __getstate__(self): return self.Get() |
d14a1e28 RD |
531 | def __setstate__(self, state): self.Set(*state) |
532 | } | |
533 | }; | |
534 | ||
535 | ||
dd9f7fea RD |
536 | DocAStr(wxIntersectRect, |
537 | "IntersectRect(Rect r1, Rect r2) -> Rect", | |
538 | "Calculate and return the intersection of r1 and r2."); | |
d14a1e28 RD |
539 | %inline %{ |
540 | PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) { | |
541 | wxRegion reg1(*r1); | |
542 | wxRegion reg2(*r2); | |
543 | wxRect dest(0,0,0,0); | |
544 | PyObject* obj; | |
545 | ||
546 | reg1.Intersect(reg2); | |
547 | dest = reg1.GetBox(); | |
548 | ||
549 | if (dest != wxRect(0,0,0,0)) { | |
550 | wxPyBeginBlockThreads(); | |
551 | wxRect* newRect = new wxRect(dest); | |
dd9f7fea | 552 | obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), True); |
d14a1e28 RD |
553 | wxPyEndBlockThreads(); |
554 | return obj; | |
555 | } | |
556 | Py_INCREF(Py_None); | |
557 | return Py_None; | |
558 | } | |
559 | %} | |
560 | ||
561 | //--------------------------------------------------------------------------- | |
562 | %newgroup | |
94d33c49 | 563 | |
d14a1e28 | 564 | |
dd9f7fea RD |
565 | DocStr(wxPoint2D, |
566 | "wx.Point2Ds represent a point or a vector in a 2d coordinate system with floating point values."); | |
d14a1e28 RD |
567 | |
568 | class wxPoint2D | |
569 | { | |
dd9f7fea RD |
570 | public: |
571 | DocStr(wxPoint2D, "Create a w.Point2D object."); | |
d14a1e28 RD |
572 | wxPoint2D( double x=0.0 , double y=0.0 ); |
573 | %name(Point2DCopy) wxPoint2D( const wxPoint2D &pt ); | |
574 | %name(Point2DFromPoint) wxPoint2D( const wxPoint &pt ); | |
575 | ||
dd9f7fea RD |
576 | DocDeclAStr( |
577 | void, GetFloor( int *OUTPUT , int *OUTPUT ) const, | |
578 | "GetFloor() -> (x,y)", | |
579 | "Convert to integer"); | |
580 | ||
581 | DocDeclAStr( | |
582 | void, GetRounded( int *OUTPUT , int *OUTPUT ) const, | |
583 | "GetRounded() -> (x,y)", | |
584 | "Convert to integer"); | |
d14a1e28 RD |
585 | |
586 | double GetVectorLength() const; | |
587 | double GetVectorAngle() const ; | |
588 | void SetVectorLength( double length ); | |
589 | void SetVectorAngle( double degrees ); | |
dd9f7fea | 590 | |
d14a1e28 RD |
591 | // LinkError: void SetPolarCoordinates( double angle , double length ); |
592 | // LinkError: void Normalize(); | |
593 | %pythoncode { | |
594 | def SetPolarCoordinates(self, angle, length): | |
595 | self.SetVectorLength(length) | |
596 | self.SetVectorAngle(angle) | |
597 | def Normalize(self): | |
598 | self.SetVectorLength(1.0) | |
599 | } | |
600 | ||
601 | double GetDistance( const wxPoint2D &pt ) const; | |
602 | double GetDistanceSquare( const wxPoint2D &pt ) const; | |
603 | double GetDotProduct( const wxPoint2D &vec ) const; | |
604 | double GetCrossProduct( const wxPoint2D &vec ) const; | |
605 | ||
dd9f7fea RD |
606 | DocDeclStr( |
607 | wxPoint2D, operator-(), | |
608 | "the reflection of this point"); | |
d14a1e28 RD |
609 | |
610 | wxPoint2D& operator+=(const wxPoint2D& pt); | |
611 | wxPoint2D& operator-=(const wxPoint2D& pt); | |
612 | ||
613 | wxPoint2D& operator*=(const wxPoint2D& pt); | |
614 | wxPoint2D& operator/=(const wxPoint2D& pt); | |
615 | ||
dd9f7fea RD |
616 | DocDeclStr( |
617 | bool, operator==(const wxPoint2D& pt) const, | |
618 | "Test for equality"); | |
619 | ||
620 | DocDeclStr( | |
621 | bool, operator!=(const wxPoint2D& pt) const, | |
622 | "Test for inequality"); | |
d14a1e28 | 623 | |
d14a1e28 RD |
624 | %name(x)double m_x; |
625 | %name(y)double m_y; | |
626 | ||
627 | %extend { | |
628 | void Set( double x=0 , double y=0 ) { | |
629 | self->m_x = x; | |
630 | self->m_y = y; | |
631 | } | |
dd9f7fea RD |
632 | |
633 | DocAStr(Get, | |
634 | "Get() -> (x,y)", | |
635 | "Return x and y properties as a tuple."); | |
636 | PyObject* Get() { | |
d14a1e28 RD |
637 | wxPyBeginBlockThreads(); |
638 | PyObject* tup = PyTuple_New(2); | |
639 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x)); | |
640 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y)); | |
641 | wxPyEndBlockThreads(); | |
642 | return tup; | |
643 | } | |
644 | } | |
645 | ||
646 | %pythoncode { | |
dd9f7fea RD |
647 | asTuple = Get |
648 | def __str__(self): return str(self.Get()) | |
649 | def __repr__(self): return 'wx.Point2D'+str(self.Get()) | |
650 | def __len__(self): return len(self.Get()) | |
651 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 | 652 | def __setitem__(self, index, val): |
dd9f7fea RD |
653 | if index == 0: self.x = val |
654 | elif index == 1: self.y = val | |
d14a1e28 | 655 | else: raise IndexError |
dd9f7fea | 656 | def __nonzero__(self): return self.Get() != (0.0, 0.0) |
d14a1e28 | 657 | def __getinitargs__(self): return () |
dd9f7fea | 658 | def __getstate__(self): return self.Get() |
d14a1e28 RD |
659 | def __setstate__(self, state): self.Set(*state) |
660 | ||
661 | } | |
662 | }; | |
663 | ||
664 | ||
665 | //--------------------------------------------------------------------------- | |
666 | ||
667 | %immutable; | |
668 | const wxPoint wxDefaultPosition; | |
669 | const wxSize wxDefaultSize; | |
670 | %mutable; | |
671 | ||
672 | //--------------------------------------------------------------------------- |