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