]>
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 | 114 | DocStr( wxSize, |
d07d2bc9 | 115 | "wx.Size is a useful data structure used to represent the size of |
bea992c8 RD |
116 | something. It simply contains integer width and height |
117 | properties. In most places in wxPython where a wx.Size is | |
1b8c7ba6 | 118 | expected a (width, height) tuple can be used instead.", ""); |
dd9f7fea | 119 | |
d14a1e28 RD |
120 | class wxSize |
121 | { | |
122 | public: | |
1b8c7ba6 RD |
123 | %Rename(width, int, x); |
124 | %Rename(height,int, y); | |
61c5a8ac RD |
125 | %pythoncode { x = width; y = height } |
126 | ||
dd9f7fea RD |
127 | DocCtorStr( |
128 | wxSize(int w=0, int h=0), | |
d07d2bc9 | 129 | "Creates a size object.", ""); |
dd9f7fea | 130 | |
d14a1e28 RD |
131 | ~wxSize(); |
132 | ||
1fce4e96 RD |
133 | |
134 | %extend { | |
135 | KeepGIL(__eq__); | |
136 | DocStr(__eq__, "Test for equality of wx.Size objects.", ""); | |
137 | bool __eq__(PyObject* other) { | |
138 | wxSize temp, *obj = &temp; | |
139 | if ( other == Py_None ) return false; | |
140 | if ( ! wxSize_helper(other, &obj) ) { | |
141 | PyErr_Clear(); | |
142 | return false; | |
143 | } | |
144 | return self->operator==(*obj); | |
145 | } | |
dd9f7fea | 146 | |
1fce4e96 RD |
147 | |
148 | KeepGIL(__ne__); | |
149 | DocStr(__ne__, "Test for inequality of wx.Size objects.", ""); | |
150 | bool __ne__(PyObject* other) { | |
151 | wxSize temp, *obj = &temp; | |
152 | if ( other == Py_None ) return true; | |
153 | if ( ! wxSize_helper(other, &obj)) { | |
154 | PyErr_Clear(); | |
155 | return true; | |
156 | } | |
157 | return self->operator!=(*obj); | |
158 | } | |
159 | } | |
d14a1e28 | 160 | |
dd9f7fea RD |
161 | DocDeclStr( |
162 | wxSize, operator+(const wxSize& sz), | |
d07d2bc9 | 163 | "Add sz's proprties to this and return the result.", ""); |
d14a1e28 | 164 | |
dd9f7fea RD |
165 | DocDeclStr( |
166 | wxSize, operator-(const wxSize& sz), | |
d07d2bc9 | 167 | "Subtract sz's properties from this and return the result.", ""); |
d14a1e28 | 168 | |
dd9f7fea RD |
169 | DocDeclStr( |
170 | void, IncTo(const wxSize& sz), | |
d07d2bc9 RD |
171 | "Increments this object so that both of its dimensions are not less |
172 | than the corresponding dimensions of the size.", ""); | |
dd9f7fea RD |
173 | |
174 | DocDeclStr( | |
175 | void, DecTo(const wxSize& sz), | |
d07d2bc9 RD |
176 | "Decrements this object so that both of its dimensions are not greater |
177 | than the corresponding dimensions of the size.", ""); | |
dd9f7fea | 178 | |
f5263701 RD |
179 | |
180 | DocDeclStr( | |
181 | void , IncBy(int dx, int dy), | |
182 | "", ""); | |
183 | ||
184 | ||
185 | DocDeclStr( | |
186 | void , DecBy(int dx, int dy), | |
187 | "", ""); | |
188 | ||
189 | // TODO: handle these overloads too? | |
190 | // void IncBy(const wxSize& sz); | |
191 | // void IncBy(int d); | |
192 | // void DecBy(const wxSize& sz); | |
193 | // void DecBy(int d); | |
6aaca5ba RD |
194 | |
195 | DocDeclStr( | |
196 | void , Scale(float xscale, float yscale), | |
197 | "Scales the dimensions of this object by the given factors.", ""); | |
198 | ||
dd9f7fea RD |
199 | DocDeclStr( |
200 | void, Set(int w, int h), | |
d07d2bc9 | 201 | "Set both width and height.", ""); |
dd9f7fea | 202 | |
d14a1e28 RD |
203 | void SetWidth(int w); |
204 | void SetHeight(int h); | |
205 | int GetWidth() const; | |
206 | int GetHeight() const; | |
207 | ||
93a163f6 RD |
208 | |
209 | DocDeclStr( | |
210 | bool , IsFullySpecified() const, | |
d07d2bc9 | 211 | "Returns True if both components of the size are non-default values.", ""); |
93a163f6 RD |
212 | |
213 | ||
214 | DocDeclStr( | |
215 | void , SetDefaults(const wxSize& size), | |
d07d2bc9 RD |
216 | "Combine this size with the other one replacing the default components |
217 | of this object (i.e. equal to -1) with those of the other.", ""); | |
93a163f6 RD |
218 | |
219 | ||
dd9f7fea RD |
220 | //int GetX() const; |
221 | //int GetY() const; | |
d14a1e28 RD |
222 | |
223 | %extend { | |
dd9f7fea RD |
224 | DocAStr(Get, |
225 | "Get() -> (width,height)", | |
d07d2bc9 | 226 | "Returns the width and height properties as a tuple.", ""); |
dd9f7fea | 227 | PyObject* Get() { |
6e6b3557 | 228 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
229 | PyObject* tup = PyTuple_New(2); |
230 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
231 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
da32eb53 | 232 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
233 | return tup; |
234 | } | |
235 | } | |
236 | %pythoncode { | |
d07d2bc9 | 237 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
238 | def __str__(self): return str(self.Get()) |
239 | def __repr__(self): return 'wx.Size'+str(self.Get()) | |
240 | def __len__(self): return len(self.Get()) | |
241 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
242 | def __setitem__(self, index, val): |
243 | if index == 0: self.width = val | |
244 | elif index == 1: self.height = val | |
245 | else: raise IndexError | |
dd9f7fea | 246 | def __nonzero__(self): return self.Get() != (0,0) |
02376d73 RD |
247 | __safe_for_unpickling__ = True |
248 | def __reduce__(self): return (wx.Size, self.Get()) | |
d14a1e28 RD |
249 | } |
250 | ||
251 | }; | |
252 | ||
253 | //--------------------------------------------------------------------------- | |
254 | %newgroup | |
94d33c49 | 255 | |
dd9f7fea | 256 | DocStr( wxRealPoint, |
d07d2bc9 RD |
257 | "A data structure for representing a point or position with floating |
258 | point x and y properties. In wxPython most places that expect a | |
259 | wx.RealPoint can also accept a (x,y) tuple.", ""); | |
d14a1e28 RD |
260 | class wxRealPoint |
261 | { | |
262 | public: | |
263 | double x; | |
264 | double y; | |
265 | ||
dd9f7fea RD |
266 | DocCtorStr( |
267 | wxRealPoint(double x=0.0, double y=0.0), | |
d07d2bc9 | 268 | "Create a wx.RealPoint object", ""); |
dd9f7fea | 269 | |
d14a1e28 RD |
270 | ~wxRealPoint(); |
271 | ||
1fce4e96 RD |
272 | %extend { |
273 | KeepGIL(__eq__); | |
274 | DocStr(__eq__, "Test for equality of wx.RealPoint objects.", ""); | |
275 | bool __eq__(PyObject* other) { | |
276 | wxRealPoint temp, *obj = &temp; | |
277 | if ( other == Py_None ) return false; | |
278 | if ( ! wxRealPoint_helper(other, &obj) ) { | |
279 | PyErr_Clear(); | |
280 | return false; | |
281 | } | |
282 | return self->operator==(*obj); | |
283 | } | |
dd9f7fea | 284 | |
1fce4e96 RD |
285 | |
286 | KeepGIL(__ne__); | |
287 | DocStr(__ne__, "Test for inequality of wx.RealPoint objects.", ""); | |
288 | bool __ne__(PyObject* other) { | |
289 | wxRealPoint temp, *obj = &temp; | |
290 | if ( other == Py_None ) return true; | |
291 | if ( ! wxRealPoint_helper(other, &obj)) { | |
292 | PyErr_Clear(); | |
293 | return true; | |
294 | } | |
295 | return self->operator!=(*obj); | |
296 | } | |
297 | } | |
dd9f7fea RD |
298 | |
299 | ||
300 | DocDeclStr( | |
301 | wxRealPoint, operator+(const wxRealPoint& pt), | |
d07d2bc9 | 302 | "Add pt's proprties to this and return the result.", ""); |
dd9f7fea RD |
303 | |
304 | DocDeclStr( | |
305 | wxRealPoint, operator-(const wxRealPoint& pt), | |
d07d2bc9 | 306 | "Subtract pt's proprties from this and return the result", ""); |
d14a1e28 | 307 | |
d14a1e28 RD |
308 | |
309 | %extend { | |
d07d2bc9 | 310 | DocStr(Set, "Set both the x and y properties", ""); |
d14a1e28 RD |
311 | void Set(double x, double y) { |
312 | self->x = x; | |
313 | self->y = y; | |
314 | } | |
dd9f7fea RD |
315 | |
316 | DocAStr(Get, | |
317 | "Get() -> (x,y)", | |
d07d2bc9 | 318 | "Return the x and y properties as a tuple. ", ""); |
dd9f7fea | 319 | PyObject* Get() { |
6e6b3557 | 320 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
321 | PyObject* tup = PyTuple_New(2); |
322 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x)); | |
323 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y)); | |
da32eb53 | 324 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
325 | return tup; |
326 | } | |
327 | } | |
328 | ||
329 | %pythoncode { | |
d07d2bc9 | 330 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
331 | def __str__(self): return str(self.Get()) |
332 | def __repr__(self): return 'wx.RealPoint'+str(self.Get()) | |
333 | def __len__(self): return len(self.Get()) | |
334 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 | 335 | def __setitem__(self, index, val): |
dd9f7fea RD |
336 | if index == 0: self.x = val |
337 | elif index == 1: self.y = val | |
d14a1e28 | 338 | else: raise IndexError |
dd9f7fea | 339 | def __nonzero__(self): return self.Get() != (0.0, 0.0) |
02376d73 RD |
340 | __safe_for_unpickling__ = True |
341 | def __reduce__(self): return (wx.RealPoint, self.Get()) | |
d14a1e28 RD |
342 | } |
343 | }; | |
344 | ||
dd9f7fea | 345 | |
d14a1e28 RD |
346 | //--------------------------------------------------------------------------- |
347 | %newgroup | |
94d33c49 | 348 | |
d14a1e28 | 349 | |
dd9f7fea | 350 | DocStr(wxPoint, |
d07d2bc9 RD |
351 | "A data structure for representing a point or position with integer x |
352 | and y properties. Most places in wxPython that expect a wx.Point can | |
353 | also accept a (x,y) tuple.", ""); | |
dd9f7fea | 354 | |
d14a1e28 RD |
355 | class wxPoint |
356 | { | |
357 | public: | |
358 | int x, y; | |
359 | ||
dd9f7fea RD |
360 | DocCtorStr( |
361 | wxPoint(int x=0, int y=0), | |
d07d2bc9 | 362 | "Create a wx.Point object", ""); |
dd9f7fea | 363 | |
d14a1e28 RD |
364 | ~wxPoint(); |
365 | ||
dd9f7fea | 366 | |
1fce4e96 RD |
367 | %extend { |
368 | KeepGIL(__eq__); | |
369 | DocStr(__eq__, "Test for equality of wx.Point objects.", ""); | |
370 | bool __eq__(PyObject* other) { | |
371 | wxPoint temp, *obj = &temp; | |
372 | if ( other == Py_None ) return false; | |
373 | if ( ! wxPoint_helper(other, &obj) ) { | |
374 | PyErr_Clear(); | |
375 | return false; | |
376 | } | |
377 | return self->operator==(*obj); | |
378 | } | |
d14a1e28 | 379 | |
1fce4e96 RD |
380 | |
381 | KeepGIL(__ne__); | |
382 | DocStr(__ne__, "Test for inequality of wx.Point objects.", ""); | |
383 | bool __ne__(PyObject* other) { | |
384 | wxPoint temp, *obj = &temp; | |
385 | if ( other == Py_None ) return true; | |
386 | if ( ! wxPoint_helper(other, &obj)) { | |
387 | PyErr_Clear(); | |
388 | return true; | |
389 | } | |
390 | return self->operator!=(*obj); | |
391 | } | |
392 | } | |
093d613e RD |
393 | |
394 | ||
395 | // %nokwargs operator+; | |
396 | // %nokwargs operator-; | |
397 | // %nokwargs operator+=; | |
398 | // %nokwargs operator-=; | |
dd9f7fea RD |
399 | |
400 | DocDeclStr( | |
401 | wxPoint, operator+(const wxPoint& pt), | |
d07d2bc9 | 402 | "Add pt's proprties to this and return the result.", ""); |
d14a1e28 | 403 | |
093d613e | 404 | |
dd9f7fea RD |
405 | DocDeclStr( |
406 | wxPoint, operator-(const wxPoint& pt), | |
d07d2bc9 | 407 | "Subtract pt's proprties from this and return the result", ""); |
dd9f7fea RD |
408 | |
409 | ||
410 | DocDeclStr( | |
411 | wxPoint&, operator+=(const wxPoint& pt), | |
d07d2bc9 | 412 | "Add pt to this object.", ""); |
dd9f7fea RD |
413 | |
414 | DocDeclStr( | |
415 | wxPoint&, operator-=(const wxPoint& pt), | |
d07d2bc9 | 416 | "Subtract pt from this object.", ""); |
dd9f7fea | 417 | |
093d613e RD |
418 | |
419 | ||
420 | // DocDeclStr( | |
421 | // wxPoint, operator+(const wxSize& sz), | |
d07d2bc9 | 422 | // "Add sz to this Point and return the result.", ""); |
093d613e RD |
423 | |
424 | // DocDeclStr( | |
425 | // wxPoint, operator-(const wxSize& sz), | |
d07d2bc9 | 426 | // "Subtract sz from this Point and return the result", ""); |
093d613e RD |
427 | |
428 | ||
429 | // DocDeclStr( | |
430 | // wxPoint&, operator+=(const wxSize& sz), | |
d07d2bc9 | 431 | // "Add sz to this object.", ""); |
093d613e RD |
432 | |
433 | // DocDeclStr( | |
434 | // wxPoint&, operator-=(const wxSize& sz), | |
d07d2bc9 | 435 | // "Subtract sz from this object.", ""); |
093d613e RD |
436 | |
437 | ||
438 | ||
dd9f7fea | 439 | |
d14a1e28 | 440 | %extend { |
d07d2bc9 | 441 | DocStr(Set, "Set both the x and y properties", ""); |
d14a1e28 RD |
442 | void Set(long x, long y) { |
443 | self->x = x; | |
444 | self->y = y; | |
445 | } | |
dd9f7fea RD |
446 | |
447 | DocAStr(Get, | |
448 | "Get() -> (x,y)", | |
d07d2bc9 | 449 | "Return the x and y properties as a tuple. ", ""); |
dd9f7fea | 450 | PyObject* Get() { |
6e6b3557 | 451 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
452 | PyObject* tup = PyTuple_New(2); |
453 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
454 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
da32eb53 | 455 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
456 | return tup; |
457 | } | |
458 | } | |
459 | ||
460 | %pythoncode { | |
d07d2bc9 | 461 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
462 | def __str__(self): return str(self.Get()) |
463 | def __repr__(self): return 'wx.Point'+str(self.Get()) | |
464 | def __len__(self): return len(self.Get()) | |
465 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
466 | def __setitem__(self, index, val): |
467 | if index == 0: self.x = val | |
468 | elif index == 1: self.y = val | |
469 | else: raise IndexError | |
dd9f7fea | 470 | def __nonzero__(self): return self.Get() != (0,0) |
02376d73 RD |
471 | __safe_for_unpickling__ = True |
472 | def __reduce__(self): return (wx.Point, self.Get()) | |
d14a1e28 RD |
473 | } |
474 | }; | |
475 | ||
476 | //--------------------------------------------------------------------------- | |
477 | %newgroup | |
94d33c49 | 478 | |
d14a1e28 | 479 | |
dd9f7fea | 480 | DocStr(wxRect, |
d07d2bc9 RD |
481 | "A class for representing and manipulating rectangles. It has x, y, |
482 | width and height properties. In wxPython most palces that expect a | |
483 | wx.Rect can also accept a (x,y,width,height) tuple.", ""); | |
dd9f7fea | 484 | |
d14a1e28 RD |
485 | class wxRect |
486 | { | |
487 | public: | |
dd9f7fea RD |
488 | DocCtorStr( |
489 | wxRect(int x=0, int y=0, int width=0, int height=0), | |
d07d2bc9 | 490 | "Create a new Rect object.", ""); |
dd9f7fea RD |
491 | |
492 | DocCtorStrName( | |
493 | wxRect(const wxPoint& topLeft, const wxPoint& bottomRight), | |
d07d2bc9 | 494 | "Create a new Rect object from Points representing two corners.", "", |
dd9f7fea RD |
495 | RectPP); |
496 | ||
497 | DocCtorStrName( | |
498 | wxRect(const wxPoint& pos, const wxSize& size), | |
d07d2bc9 | 499 | "Create a new Rect from a position and size.", "", |
dd9f7fea | 500 | RectPS); |
7aada1e0 RD |
501 | |
502 | DocCtorStrName( | |
503 | wxRect(const wxSize& size), | |
504 | "Create a new Rect from a size only.", "", | |
505 | RectS); | |
506 | ||
d14a1e28 RD |
507 | ~wxRect(); |
508 | ||
509 | int GetX() const; | |
510 | void SetX(int x); | |
511 | ||
512 | int GetY(); | |
513 | void SetY(int y); | |
514 | ||
515 | int GetWidth() const; | |
516 | void SetWidth(int w); | |
517 | ||
518 | int GetHeight() const; | |
519 | void SetHeight(int h); | |
520 | ||
521 | wxPoint GetPosition() const; | |
522 | void SetPosition( const wxPoint &p ); | |
523 | ||
524 | wxSize GetSize() const; | |
525 | void SetSize( const wxSize &s ); | |
526 | ||
c3fc056e RD |
527 | bool IsEmpty() const; |
528 | ||
3f0ff538 RD |
529 | wxPoint GetTopLeft() const; |
530 | void SetTopLeft(const wxPoint &p); | |
531 | wxPoint GetBottomRight() const; | |
532 | void SetBottomRight(const wxPoint &p); | |
533 | ||
5acb46e0 RD |
534 | wxPoint GetTopRight() const; |
535 | void SetTopRight(const wxPoint &p); | |
536 | wxPoint GetBottomLeft() const; | |
537 | void SetBottomLeft(const wxPoint &p); | |
538 | ||
3f0ff538 RD |
539 | // wxPoint GetLeftTop() const; |
540 | // void SetLeftTop(const wxPoint &p); | |
541 | // wxPoint GetRightBottom() const; | |
542 | // void SetRightBottom(const wxPoint &p); | |
5acb46e0 RD |
543 | // wxPoint GetRightTop() const; |
544 | // void SetRightTop(const wxPoint &p); | |
545 | // wxPoint GetLeftBottom() const; | |
546 | // void SetLeftBottom(const wxPoint &p); | |
3f0ff538 | 547 | |
d14a1e28 RD |
548 | int GetLeft() const; |
549 | int GetTop() const; | |
550 | int GetBottom() const; | |
551 | int GetRight() const; | |
552 | ||
553 | void SetLeft(int left); | |
554 | void SetRight(int right); | |
555 | void SetTop(int top); | |
556 | void SetBottom(int bottom); | |
557 | ||
dd9f7fea RD |
558 | %pythoncode { |
559 | position = property(GetPosition, SetPosition) | |
560 | size = property(GetSize, SetSize) | |
561 | left = property(GetLeft, SetLeft) | |
562 | right = property(GetRight, SetRight) | |
563 | top = property(GetTop, SetTop) | |
564 | bottom = property(GetBottom, SetBottom) | |
565 | } | |
566 | ||
a9b95496 | 567 | |
dd9f7fea RD |
568 | DocDeclStr( |
569 | wxRect&, Inflate(wxCoord dx, wxCoord dy), | |
ca30acad RD |
570 | "Increases the size of the rectangle. |
571 | ||
572 | The left border is moved farther left and the right border is moved | |
573 | farther right by ``dx``. The upper border is moved farther up and the | |
574 | bottom border is moved farther down by ``dy``. (Note the the width and | |
575 | height of the rectangle thus change by ``2*dx`` and ``2*dy``, | |
576 | respectively.) If one or both of ``dx`` and ``dy`` are negative, the | |
577 | opposite happens: the rectangle size decreases in the respective | |
578 | direction. | |
579 | ||
580 | The change is made to the rectangle inplace, if instead you need a | |
581 | copy that is inflated, preserving the original then make the copy | |
582 | first:: | |
583 | ||
584 | copy = wx.Rect(*original) | |
585 | copy.Inflate(10,15) | |
586 | ||
587 | ", " | |
588 | Inflating and deflating behaves *naturally*. Defined more precisely, | |
589 | that means: | |
590 | ||
591 | * Real inflates (that is, ``dx`` and/or ``dy`` >= 0) are not | |
592 | constrained. Thus inflating a rectangle can cause its upper left | |
593 | corner to move into the negative numbers. (The versions prior to | |
594 | 2.5.4 forced the top left coordinate to not fall below (0, 0), | |
595 | which implied a forced move of the rectangle.) | |
596 | ||
597 | * Deflates are clamped to not reduce the width or height of the | |
598 | rectangle below zero. In such cases, the top-left corner is | |
599 | nonetheless handled properly. For example, a rectangle at (10, | |
600 | 10) with size (20, 40) that is inflated by (-15, -15) will | |
601 | become located at (20, 25) at size (0, 10). Finally, observe | |
602 | that the width and height are treated independently. In the | |
603 | above example, the width is reduced by 20, whereas the height is | |
604 | reduced by the full 30 (rather than also stopping at 20, when | |
605 | the width reached zero). | |
606 | ||
607 | :see: `Deflate` | |
608 | "); | |
dd9f7fea | 609 | |
a9b95496 RD |
610 | // There are also these versions... |
611 | //wxRect& Inflate(const wxSize& d); | |
612 | //wxRect& Inflate(wxCoord d); | |
613 | ||
614 | ||
dd9f7fea RD |
615 | DocDeclStr( |
616 | wxRect&, Deflate(wxCoord dx, wxCoord dy), | |
ca30acad RD |
617 | "Decrease the rectangle size. This method is the opposite of `Inflate` |
618 | in that Deflate(a,b) is equivalent to Inflate(-a,-b). Please refer to | |
619 | `Inflate` for a full description.", ""); | |
dd9f7fea | 620 | |
a9b95496 RD |
621 | // There are also these versions... |
622 | //wxRect& Deflate(const wxSize& d) { return Inflate(-d.x, -d.y); } | |
623 | //wxRect& Deflate(wxCoord d) { return Inflate(-d); } | |
624 | ||
dd9f7fea RD |
625 | DocDeclStrName( |
626 | void, Offset(wxCoord dx, wxCoord dy), | |
d07d2bc9 RD |
627 | "Moves the rectangle by the specified offset. If dx is positive, the |
628 | rectangle is moved to the right, if dy is positive, it is moved to the | |
629 | bottom, otherwise it is moved to the left or top respectively.", "", | |
dd9f7fea RD |
630 | OffsetXY); |
631 | ||
632 | DocDeclStr( | |
633 | void, Offset(const wxPoint& pt), | |
096e3ea1 | 634 | "Same as `OffsetXY` but uses dx,dy from Point", ""); |
dd9f7fea RD |
635 | |
636 | DocDeclStr( | |
9eefe9f0 RD |
637 | wxRect, Intersect(const wxRect& rect), |
638 | "Returns the intersectsion of this rectangle and rect.", ""); | |
d14a1e28 | 639 | |
9eefe9f0 RD |
640 | DocDeclStr( |
641 | wxRect , Union(const wxRect& rect), | |
642 | "Returns the union of this rectangle and rect.", ""); | |
643 | ||
644 | ||
dd9f7fea RD |
645 | DocDeclStr( |
646 | wxRect, operator+(const wxRect& rect) const, | |
d07d2bc9 | 647 | "Add the properties of rect to this rectangle and return the result.", ""); |
d14a1e28 | 648 | |
dd9f7fea RD |
649 | DocDeclStr( |
650 | wxRect&, operator+=(const wxRect& rect), | |
d07d2bc9 | 651 | "Add the properties of rect to this rectangle, updating this rectangle.", ""); |
d14a1e28 | 652 | |
1fce4e96 RD |
653 | %extend { |
654 | KeepGIL(__eq__); | |
655 | DocStr(__eq__, "Test for equality of wx.Rect objects.", ""); | |
656 | bool __eq__(PyObject* other) { | |
657 | wxRect temp, *obj = &temp; | |
658 | if ( other == Py_None ) return false; | |
659 | if ( ! wxRect_helper(other, &obj) ) { | |
660 | PyErr_Clear(); | |
661 | return false; | |
662 | } | |
663 | return self->operator==(*obj); | |
664 | } | |
d14a1e28 | 665 | |
1fce4e96 RD |
666 | |
667 | KeepGIL(__ne__); | |
668 | DocStr(__ne__, "Test for inequality of wx.Rect objects.", ""); | |
669 | bool __ne__(PyObject* other) { | |
670 | wxRect temp, *obj = &temp; | |
671 | if ( other == Py_None ) return true; | |
672 | if ( ! wxRect_helper(other, &obj)) { | |
673 | PyErr_Clear(); | |
674 | return true; | |
675 | } | |
676 | return self->operator!=(*obj); | |
677 | } | |
678 | } | |
d14a1e28 | 679 | |
dd9f7fea | 680 | |
8546a549 RD |
681 | DocStr( Contains, "Return True if the point is inside the rect.", ""); |
682 | %Rename(ContainsXY, bool, Contains(int x, int y) const); | |
683 | bool Contains(const wxPoint& pt) const; | |
d14a1e28 | 684 | |
8e1222c7 | 685 | DocDeclStrName( |
8546a549 | 686 | bool, Contains(const wxRect& rect) const, |
8e1222c7 RD |
687 | "Returns ``True`` if the given rectangle is completely inside this |
688 | rectangle or touches its boundary.", "", | |
8546a549 RD |
689 | ContainsRect); |
690 | %pythoncode { | |
691 | Inside = wx._deprecated(Contains, "Use `Contains` instead.") | |
692 | InsideXY = wx._deprecated(ContainsXY, "Use `ContainsXY` instead.") | |
693 | InsideRect = wx._deprecated(ContainsRect, "Use `ContainsRect` instead.") | |
694 | } | |
8e1222c7 | 695 | |
dd9f7fea RD |
696 | DocDeclStr( |
697 | bool, Intersects(const wxRect& rect) const, | |
d07d2bc9 | 698 | "Returns True if the rectangles have a non empty intersection.", ""); |
d14a1e28 | 699 | |
096e3ea1 RD |
700 | DocDeclStr( |
701 | wxRect, CenterIn(const wxRect& r, int dir = wxBOTH), | |
702 | "Center this rectangle within the one passed to the method, which is | |
703 | usually, but not necessarily, the larger one.", ""); | |
704 | %pythoncode { CentreIn = CenterIn } | |
705 | ||
dd9f7fea | 706 | |
d14a1e28 RD |
707 | int x, y, width, height; |
708 | ||
709 | ||
710 | %extend { | |
d07d2bc9 | 711 | DocStr(Set, "Set all rectangle properties.", ""); |
dd9f7fea | 712 | void Set(int x=0, int y=0, int width=0, int height=0) { |
d14a1e28 RD |
713 | self->x = x; |
714 | self->y = y; | |
715 | self->width = width; | |
716 | self->height = height; | |
717 | } | |
718 | ||
dd9f7fea RD |
719 | DocAStr(Get, |
720 | "Get() -> (x,y,width,height)", | |
d07d2bc9 | 721 | "Return the rectangle properties as a tuple.", ""); |
dd9f7fea | 722 | PyObject* Get() { |
6e6b3557 | 723 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
724 | PyObject* tup = PyTuple_New(4); |
725 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
726 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
727 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width)); | |
728 | PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height)); | |
da32eb53 | 729 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
730 | return tup; |
731 | } | |
732 | } | |
733 | ||
734 | %pythoncode { | |
d07d2bc9 | 735 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
736 | def __str__(self): return str(self.Get()) |
737 | def __repr__(self): return 'wx.Rect'+str(self.Get()) | |
738 | def __len__(self): return len(self.Get()) | |
739 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
740 | def __setitem__(self, index, val): |
741 | if index == 0: self.x = val | |
742 | elif index == 1: self.y = val | |
743 | elif index == 2: self.width = val | |
744 | elif index == 3: self.height = val | |
745 | else: raise IndexError | |
dd9f7fea | 746 | def __nonzero__(self): return self.Get() != (0,0,0,0) |
02376d73 RD |
747 | __safe_for_unpickling__ = True |
748 | def __reduce__(self): return (wx.Rect, self.Get()) | |
d14a1e28 | 749 | } |
7012bb9f RD |
750 | |
751 | ||
752 | %property(Bottom, GetBottom, SetBottom, doc="See `GetBottom` and `SetBottom`"); | |
753 | %property(BottomRight, GetBottomRight, SetBottomRight, doc="See `GetBottomRight` and `SetBottomRight`"); | |
5acb46e0 | 754 | %property(BottomLeft, GetBottomLeft, SetBottomLeft, doc="See `GetBottomLeft` and `SetBottomLeft`"); |
7012bb9f RD |
755 | %property(Height, GetHeight, SetHeight, doc="See `GetHeight` and `SetHeight`"); |
756 | %property(Left, GetLeft, SetLeft, doc="See `GetLeft` and `SetLeft`"); | |
757 | %property(Position, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`"); | |
758 | %property(Right, GetRight, SetRight, doc="See `GetRight` and `SetRight`"); | |
759 | %property(Size, GetSize, SetSize, doc="See `GetSize` and `SetSize`"); | |
760 | %property(Top, GetTop, SetTop, doc="See `GetTop` and `SetTop`"); | |
761 | %property(TopLeft, GetTopLeft, SetTopLeft, doc="See `GetTopLeft` and `SetTopLeft`"); | |
5acb46e0 | 762 | %property(TopRight, GetTopRight, SetTopRight, doc="See `GetTopRight` and `SetTopRight`"); |
7012bb9f RD |
763 | %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`"); |
764 | %property(X, GetX, SetX, doc="See `GetX` and `SetX`"); | |
765 | %property(Y, GetY, SetY, doc="See `GetY` and `SetY`"); | |
766 | ||
767 | %property(Empty, IsEmpty, doc="See `IsEmpty`"); | |
d14a1e28 RD |
768 | }; |
769 | ||
770 | ||
ab1f7d2a RD |
771 | MustHaveApp(wxIntersectRect); |
772 | ||
dd9f7fea RD |
773 | DocAStr(wxIntersectRect, |
774 | "IntersectRect(Rect r1, Rect r2) -> Rect", | |
d07d2bc9 | 775 | "Calculate and return the intersection of r1 and r2.", ""); |
d14a1e28 RD |
776 | %inline %{ |
777 | PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) { | |
778 | wxRegion reg1(*r1); | |
779 | wxRegion reg2(*r2); | |
780 | wxRect dest(0,0,0,0); | |
781 | PyObject* obj; | |
782 | ||
783 | reg1.Intersect(reg2); | |
784 | dest = reg1.GetBox(); | |
785 | ||
786 | if (dest != wxRect(0,0,0,0)) { | |
6e6b3557 | 787 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 | 788 | wxRect* newRect = new wxRect(dest); |
a72f4631 | 789 | obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true); |
da32eb53 | 790 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
791 | return obj; |
792 | } | |
793 | Py_INCREF(Py_None); | |
794 | return Py_None; | |
795 | } | |
796 | %} | |
797 | ||
798 | //--------------------------------------------------------------------------- | |
799 | %newgroup | |
94d33c49 | 800 | |
d14a1e28 | 801 | |
dd9f7fea | 802 | DocStr(wxPoint2D, |
d07d2bc9 RD |
803 | "wx.Point2Ds represent a point or a vector in a 2d coordinate system |
804 | with floating point values.", ""); | |
d14a1e28 RD |
805 | |
806 | class wxPoint2D | |
807 | { | |
dd9f7fea | 808 | public: |
d07d2bc9 | 809 | DocStr(wxPoint2D, "Create a w.Point2D object.", ""); |
d14a1e28 | 810 | wxPoint2D( double x=0.0 , double y=0.0 ); |
1b8c7ba6 RD |
811 | %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt )); |
812 | %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt )); | |
d14a1e28 | 813 | |
dd9f7fea RD |
814 | DocDeclAStr( |
815 | void, GetFloor( int *OUTPUT , int *OUTPUT ) const, | |
816 | "GetFloor() -> (x,y)", | |
d07d2bc9 | 817 | "Convert to integer", ""); |
dd9f7fea RD |
818 | |
819 | DocDeclAStr( | |
820 | void, GetRounded( int *OUTPUT , int *OUTPUT ) const, | |
821 | "GetRounded() -> (x,y)", | |
d07d2bc9 | 822 | "Convert to integer", ""); |
d14a1e28 RD |
823 | |
824 | double GetVectorLength() const; | |
825 | double GetVectorAngle() const ; | |
826 | void SetVectorLength( double length ); | |
827 | void SetVectorAngle( double degrees ); | |
dd9f7fea | 828 | |
d14a1e28 RD |
829 | // LinkError: void SetPolarCoordinates( double angle , double length ); |
830 | // LinkError: void Normalize(); | |
831 | %pythoncode { | |
832 | def SetPolarCoordinates(self, angle, length): | |
833 | self.SetVectorLength(length) | |
834 | self.SetVectorAngle(angle) | |
835 | def Normalize(self): | |
836 | self.SetVectorLength(1.0) | |
837 | } | |
838 | ||
839 | double GetDistance( const wxPoint2D &pt ) const; | |
840 | double GetDistanceSquare( const wxPoint2D &pt ) const; | |
841 | double GetDotProduct( const wxPoint2D &vec ) const; | |
842 | double GetCrossProduct( const wxPoint2D &vec ) const; | |
843 | ||
dd9f7fea RD |
844 | DocDeclStr( |
845 | wxPoint2D, operator-(), | |
d07d2bc9 | 846 | "the reflection of this point", ""); |
d14a1e28 RD |
847 | |
848 | wxPoint2D& operator+=(const wxPoint2D& pt); | |
849 | wxPoint2D& operator-=(const wxPoint2D& pt); | |
850 | ||
851 | wxPoint2D& operator*=(const wxPoint2D& pt); | |
852 | wxPoint2D& operator/=(const wxPoint2D& pt); | |
853 | ||
1fce4e96 RD |
854 | %extend { |
855 | KeepGIL(__eq__); | |
856 | DocStr(__eq__, "Test for equality of wx.Point2D objects.", ""); | |
857 | bool __eq__(PyObject* other) { | |
858 | wxPoint2D temp, *obj = &temp; | |
859 | if ( other == Py_None ) return false; | |
860 | if ( ! wxPoint2D_helper(other, &obj) ) { | |
861 | PyErr_Clear(); | |
862 | return false; | |
863 | } | |
864 | return self->operator==(*obj); | |
865 | } | |
866 | ||
867 | ||
868 | KeepGIL(__ne__); | |
869 | DocStr(__ne__, "Test for inequality of wx.Point2D objects.", ""); | |
870 | bool __ne__(PyObject* other) { | |
871 | wxPoint2D temp, *obj = &temp; | |
872 | if ( other == Py_None ) return true; | |
873 | if ( ! wxPoint2D_helper(other, &obj)) { | |
874 | PyErr_Clear(); | |
875 | return true; | |
876 | } | |
877 | return self->operator!=(*obj); | |
878 | } | |
879 | } | |
d14a1e28 | 880 | |
1b8c7ba6 RD |
881 | %Rename(x, double, m_x); |
882 | %Rename(y, double, m_y); | |
d14a1e28 RD |
883 | |
884 | %extend { | |
885 | void Set( double x=0 , double y=0 ) { | |
886 | self->m_x = x; | |
887 | self->m_y = y; | |
888 | } | |
dd9f7fea RD |
889 | |
890 | DocAStr(Get, | |
891 | "Get() -> (x,y)", | |
d07d2bc9 | 892 | "Return x and y properties as a tuple.", ""); |
dd9f7fea | 893 | PyObject* Get() { |
6e6b3557 | 894 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
895 | PyObject* tup = PyTuple_New(2); |
896 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x)); | |
897 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y)); | |
da32eb53 | 898 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
899 | return tup; |
900 | } | |
901 | } | |
902 | ||
903 | %pythoncode { | |
d07d2bc9 | 904 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
905 | def __str__(self): return str(self.Get()) |
906 | def __repr__(self): return 'wx.Point2D'+str(self.Get()) | |
907 | def __len__(self): return len(self.Get()) | |
908 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 | 909 | def __setitem__(self, index, val): |
dd9f7fea RD |
910 | if index == 0: self.x = val |
911 | elif index == 1: self.y = val | |
d14a1e28 | 912 | else: raise IndexError |
dd9f7fea | 913 | def __nonzero__(self): return self.Get() != (0.0, 0.0) |
02376d73 RD |
914 | __safe_for_unpickling__ = True |
915 | def __reduce__(self): return (wx.Point2D, self.Get()) | |
d14a1e28 | 916 | } |
7012bb9f RD |
917 | |
918 | %property(Floor, GetFloor, doc="See `GetFloor`"); | |
919 | %property(Rounded, GetRounded, doc="See `GetRounded`"); | |
920 | %property(VectorAngle, GetVectorAngle, SetVectorAngle, doc="See `GetVectorAngle` and `SetVectorAngle`"); | |
921 | %property(VectorLength, GetVectorLength, SetVectorLength, doc="See `GetVectorLength` and `SetVectorLength`"); | |
922 | ||
d14a1e28 RD |
923 | }; |
924 | ||
925 | ||
926 | //--------------------------------------------------------------------------- | |
927 | ||
928 | %immutable; | |
929 | const wxPoint wxDefaultPosition; | |
930 | const wxSize wxDefaultSize; | |
931 | %mutable; | |
932 | ||
933 | //--------------------------------------------------------------------------- |