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