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