]>
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 | 689 | ContainsRect); |
ce60dd8e | 690 | |
8546a549 | 691 | %pythoncode { |
ce60dd8e RD |
692 | %#Inside = wx._deprecated(Contains, "Use `Contains` instead.") |
693 | %#InsideXY = wx._deprecated(ContainsXY, "Use `ContainsXY` instead.") | |
694 | %#InsideRect = wx._deprecated(ContainsRect, "Use `ContainsRect` instead.") | |
695 | Inside = Contains | |
696 | InsideXY = ContainsXY | |
697 | InsideRect = ContainsRect | |
8546a549 | 698 | } |
8e1222c7 | 699 | |
dd9f7fea RD |
700 | DocDeclStr( |
701 | bool, Intersects(const wxRect& rect) const, | |
d07d2bc9 | 702 | "Returns True if the rectangles have a non empty intersection.", ""); |
d14a1e28 | 703 | |
096e3ea1 RD |
704 | DocDeclStr( |
705 | wxRect, CenterIn(const wxRect& r, int dir = wxBOTH), | |
706 | "Center this rectangle within the one passed to the method, which is | |
707 | usually, but not necessarily, the larger one.", ""); | |
708 | %pythoncode { CentreIn = CenterIn } | |
709 | ||
dd9f7fea | 710 | |
d14a1e28 RD |
711 | int x, y, width, height; |
712 | ||
713 | ||
714 | %extend { | |
d07d2bc9 | 715 | DocStr(Set, "Set all rectangle properties.", ""); |
dd9f7fea | 716 | void Set(int x=0, int y=0, int width=0, int height=0) { |
d14a1e28 RD |
717 | self->x = x; |
718 | self->y = y; | |
719 | self->width = width; | |
720 | self->height = height; | |
721 | } | |
722 | ||
dd9f7fea RD |
723 | DocAStr(Get, |
724 | "Get() -> (x,y,width,height)", | |
d07d2bc9 | 725 | "Return the rectangle properties as a tuple.", ""); |
dd9f7fea | 726 | PyObject* Get() { |
6e6b3557 | 727 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
728 | PyObject* tup = PyTuple_New(4); |
729 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
730 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
731 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width)); | |
732 | PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height)); | |
da32eb53 | 733 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
734 | return tup; |
735 | } | |
736 | } | |
737 | ||
738 | %pythoncode { | |
d07d2bc9 | 739 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
740 | def __str__(self): return str(self.Get()) |
741 | def __repr__(self): return 'wx.Rect'+str(self.Get()) | |
742 | def __len__(self): return len(self.Get()) | |
743 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
744 | def __setitem__(self, index, val): |
745 | if index == 0: self.x = val | |
746 | elif index == 1: self.y = val | |
747 | elif index == 2: self.width = val | |
748 | elif index == 3: self.height = val | |
749 | else: raise IndexError | |
dd9f7fea | 750 | def __nonzero__(self): return self.Get() != (0,0,0,0) |
02376d73 RD |
751 | __safe_for_unpickling__ = True |
752 | def __reduce__(self): return (wx.Rect, self.Get()) | |
d14a1e28 | 753 | } |
7012bb9f RD |
754 | |
755 | ||
756 | %property(Bottom, GetBottom, SetBottom, doc="See `GetBottom` and `SetBottom`"); | |
757 | %property(BottomRight, GetBottomRight, SetBottomRight, doc="See `GetBottomRight` and `SetBottomRight`"); | |
5acb46e0 | 758 | %property(BottomLeft, GetBottomLeft, SetBottomLeft, doc="See `GetBottomLeft` and `SetBottomLeft`"); |
7012bb9f RD |
759 | %property(Height, GetHeight, SetHeight, doc="See `GetHeight` and `SetHeight`"); |
760 | %property(Left, GetLeft, SetLeft, doc="See `GetLeft` and `SetLeft`"); | |
761 | %property(Position, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`"); | |
762 | %property(Right, GetRight, SetRight, doc="See `GetRight` and `SetRight`"); | |
763 | %property(Size, GetSize, SetSize, doc="See `GetSize` and `SetSize`"); | |
764 | %property(Top, GetTop, SetTop, doc="See `GetTop` and `SetTop`"); | |
765 | %property(TopLeft, GetTopLeft, SetTopLeft, doc="See `GetTopLeft` and `SetTopLeft`"); | |
5acb46e0 | 766 | %property(TopRight, GetTopRight, SetTopRight, doc="See `GetTopRight` and `SetTopRight`"); |
7012bb9f RD |
767 | %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`"); |
768 | %property(X, GetX, SetX, doc="See `GetX` and `SetX`"); | |
769 | %property(Y, GetY, SetY, doc="See `GetY` and `SetY`"); | |
770 | ||
771 | %property(Empty, IsEmpty, doc="See `IsEmpty`"); | |
d14a1e28 RD |
772 | }; |
773 | ||
774 | ||
ab1f7d2a RD |
775 | MustHaveApp(wxIntersectRect); |
776 | ||
dd9f7fea RD |
777 | DocAStr(wxIntersectRect, |
778 | "IntersectRect(Rect r1, Rect r2) -> Rect", | |
d07d2bc9 | 779 | "Calculate and return the intersection of r1 and r2.", ""); |
d14a1e28 RD |
780 | %inline %{ |
781 | PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) { | |
782 | wxRegion reg1(*r1); | |
783 | wxRegion reg2(*r2); | |
784 | wxRect dest(0,0,0,0); | |
785 | PyObject* obj; | |
786 | ||
787 | reg1.Intersect(reg2); | |
788 | dest = reg1.GetBox(); | |
789 | ||
790 | if (dest != wxRect(0,0,0,0)) { | |
6e6b3557 | 791 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 | 792 | wxRect* newRect = new wxRect(dest); |
a72f4631 | 793 | obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true); |
da32eb53 | 794 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
795 | return obj; |
796 | } | |
797 | Py_INCREF(Py_None); | |
798 | return Py_None; | |
799 | } | |
800 | %} | |
801 | ||
802 | //--------------------------------------------------------------------------- | |
803 | %newgroup | |
94d33c49 | 804 | |
d14a1e28 | 805 | |
dd9f7fea | 806 | DocStr(wxPoint2D, |
d07d2bc9 RD |
807 | "wx.Point2Ds represent a point or a vector in a 2d coordinate system |
808 | with floating point values.", ""); | |
d14a1e28 RD |
809 | |
810 | class wxPoint2D | |
811 | { | |
dd9f7fea | 812 | public: |
d07d2bc9 | 813 | DocStr(wxPoint2D, "Create a w.Point2D object.", ""); |
d14a1e28 | 814 | wxPoint2D( double x=0.0 , double y=0.0 ); |
1b8c7ba6 RD |
815 | %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt )); |
816 | %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt )); | |
d14a1e28 | 817 | |
7b497846 RD |
818 | ~wxPoint2D(); |
819 | ||
dd9f7fea RD |
820 | DocDeclAStr( |
821 | void, GetFloor( int *OUTPUT , int *OUTPUT ) const, | |
822 | "GetFloor() -> (x,y)", | |
d07d2bc9 | 823 | "Convert to integer", ""); |
dd9f7fea RD |
824 | |
825 | DocDeclAStr( | |
826 | void, GetRounded( int *OUTPUT , int *OUTPUT ) const, | |
827 | "GetRounded() -> (x,y)", | |
d07d2bc9 | 828 | "Convert to integer", ""); |
d14a1e28 RD |
829 | |
830 | double GetVectorLength() const; | |
831 | double GetVectorAngle() const ; | |
832 | void SetVectorLength( double length ); | |
833 | void SetVectorAngle( double degrees ); | |
dd9f7fea | 834 | |
d14a1e28 RD |
835 | // LinkError: void SetPolarCoordinates( double angle , double length ); |
836 | // LinkError: void Normalize(); | |
837 | %pythoncode { | |
838 | def SetPolarCoordinates(self, angle, length): | |
839 | self.SetVectorLength(length) | |
840 | self.SetVectorAngle(angle) | |
841 | def Normalize(self): | |
842 | self.SetVectorLength(1.0) | |
843 | } | |
844 | ||
845 | double GetDistance( const wxPoint2D &pt ) const; | |
846 | double GetDistanceSquare( const wxPoint2D &pt ) const; | |
847 | double GetDotProduct( const wxPoint2D &vec ) const; | |
848 | double GetCrossProduct( const wxPoint2D &vec ) const; | |
849 | ||
dd9f7fea RD |
850 | DocDeclStr( |
851 | wxPoint2D, operator-(), | |
d07d2bc9 | 852 | "the reflection of this point", ""); |
d14a1e28 RD |
853 | |
854 | wxPoint2D& operator+=(const wxPoint2D& pt); | |
855 | wxPoint2D& operator-=(const wxPoint2D& pt); | |
856 | ||
857 | wxPoint2D& operator*=(const wxPoint2D& pt); | |
858 | wxPoint2D& operator/=(const wxPoint2D& pt); | |
859 | ||
1fce4e96 RD |
860 | %extend { |
861 | KeepGIL(__eq__); | |
862 | DocStr(__eq__, "Test for equality of wx.Point2D objects.", ""); | |
863 | bool __eq__(PyObject* other) { | |
864 | wxPoint2D temp, *obj = &temp; | |
865 | if ( other == Py_None ) return false; | |
866 | if ( ! wxPoint2D_helper(other, &obj) ) { | |
867 | PyErr_Clear(); | |
868 | return false; | |
869 | } | |
870 | return self->operator==(*obj); | |
871 | } | |
872 | ||
873 | ||
874 | KeepGIL(__ne__); | |
875 | DocStr(__ne__, "Test for inequality of wx.Point2D objects.", ""); | |
876 | bool __ne__(PyObject* other) { | |
877 | wxPoint2D temp, *obj = &temp; | |
878 | if ( other == Py_None ) return true; | |
879 | if ( ! wxPoint2D_helper(other, &obj)) { | |
880 | PyErr_Clear(); | |
881 | return true; | |
882 | } | |
883 | return self->operator!=(*obj); | |
884 | } | |
885 | } | |
d14a1e28 | 886 | |
1b8c7ba6 RD |
887 | %Rename(x, double, m_x); |
888 | %Rename(y, double, m_y); | |
d14a1e28 RD |
889 | |
890 | %extend { | |
891 | void Set( double x=0 , double y=0 ) { | |
892 | self->m_x = x; | |
893 | self->m_y = y; | |
894 | } | |
dd9f7fea RD |
895 | |
896 | DocAStr(Get, | |
897 | "Get() -> (x,y)", | |
d07d2bc9 | 898 | "Return x and y properties as a tuple.", ""); |
dd9f7fea | 899 | PyObject* Get() { |
6e6b3557 | 900 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
901 | PyObject* tup = PyTuple_New(2); |
902 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x)); | |
903 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y)); | |
da32eb53 | 904 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
905 | return tup; |
906 | } | |
907 | } | |
908 | ||
909 | %pythoncode { | |
d07d2bc9 | 910 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
911 | def __str__(self): return str(self.Get()) |
912 | def __repr__(self): return 'wx.Point2D'+str(self.Get()) | |
913 | def __len__(self): return len(self.Get()) | |
914 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 | 915 | def __setitem__(self, index, val): |
dd9f7fea RD |
916 | if index == 0: self.x = val |
917 | elif index == 1: self.y = val | |
d14a1e28 | 918 | else: raise IndexError |
dd9f7fea | 919 | def __nonzero__(self): return self.Get() != (0.0, 0.0) |
02376d73 RD |
920 | __safe_for_unpickling__ = True |
921 | def __reduce__(self): return (wx.Point2D, self.Get()) | |
d14a1e28 | 922 | } |
7012bb9f RD |
923 | |
924 | %property(Floor, GetFloor, doc="See `GetFloor`"); | |
925 | %property(Rounded, GetRounded, doc="See `GetRounded`"); | |
926 | %property(VectorAngle, GetVectorAngle, SetVectorAngle, doc="See `GetVectorAngle` and `SetVectorAngle`"); | |
927 | %property(VectorLength, GetVectorLength, SetVectorLength, doc="See `GetVectorLength` and `SetVectorLength`"); | |
928 | ||
d14a1e28 RD |
929 | }; |
930 | ||
931 | ||
932 | //--------------------------------------------------------------------------- | |
933 | ||
934 | %immutable; | |
935 | const wxPoint wxDefaultPosition; | |
936 | const wxSize wxDefaultSize; | |
937 | %mutable; | |
938 | ||
939 | //--------------------------------------------------------------------------- |