]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gdicmn.i
ensure that the MasedEditMixin's version of IsEmpty is the one used.
[wxWidgets.git] / wxPython / src / _gdicmn.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _gdicmn.i
3 // Purpose: SWIG interface for common GDI stuff and misc classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 13-Sept-2003
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 %newgroup
18
19
20 enum wxBitmapType
21 {
22 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
23 wxBITMAP_TYPE_BMP,
24 wxBITMAP_TYPE_ICO,
25 wxBITMAP_TYPE_CUR,
26 wxBITMAP_TYPE_XBM,
27 wxBITMAP_TYPE_XBM_DATA,
28 wxBITMAP_TYPE_XPM,
29 wxBITMAP_TYPE_XPM_DATA,
30 wxBITMAP_TYPE_TIF,
31 wxBITMAP_TYPE_GIF,
32 wxBITMAP_TYPE_PNG,
33 wxBITMAP_TYPE_JPEG,
34 wxBITMAP_TYPE_PNM,
35 wxBITMAP_TYPE_PCX,
36 wxBITMAP_TYPE_PICT,
37 wxBITMAP_TYPE_ICON,
38 wxBITMAP_TYPE_ANI,
39 wxBITMAP_TYPE_IFF,
40 wxBITMAP_TYPE_MACCURSOR,
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
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
113
114 DocStr( wxSize,
115 "wx.Size is a useful data structure used to represent the size of
116 something. It simply contains integer width and height
117 properties. In most places in wxPython where a wx.Size is
118 expected a (width, height) tuple can be used instead.", "");
119
120 class wxSize
121 {
122 public:
123 %Rename(width, int, x);
124 %Rename(height,int, y);
125 %pythoncode { x = width; y = height }
126
127 DocCtorStr(
128 wxSize(int w=0, int h=0),
129 "Creates a size object.", "");
130
131 ~wxSize();
132
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 }
146
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 }
160
161 DocDeclStr(
162 wxSize, operator+(const wxSize& sz),
163 "Add sz's proprties to this and return the result.", "");
164
165 DocDeclStr(
166 wxSize, operator-(const wxSize& sz),
167 "Subtract sz's properties from this and return the result.", "");
168
169 DocDeclStr(
170 void, IncTo(const wxSize& sz),
171 "Increments this object so that both of its dimensions are not less
172 than the corresponding dimensions of the size.", "");
173
174 DocDeclStr(
175 void, DecTo(const wxSize& sz),
176 "Decrements this object so that both of its dimensions are not greater
177 than the corresponding dimensions of the size.", "");
178
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);
194
195 DocDeclStr(
196 void , Scale(float xscale, float yscale),
197 "Scales the dimensions of this object by the given factors.", "");
198
199 DocDeclStr(
200 void, Set(int w, int h),
201 "Set both width and height.", "");
202
203 void SetWidth(int w);
204 void SetHeight(int h);
205 int GetWidth() const;
206 int GetHeight() const;
207
208
209 DocDeclStr(
210 bool , IsFullySpecified() const,
211 "Returns True if both components of the size are non-default values.", "");
212
213
214 DocDeclStr(
215 void , SetDefaults(const wxSize& size),
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.", "");
218
219
220 //int GetX() const;
221 //int GetY() const;
222
223 %extend {
224 DocAStr(Get,
225 "Get() -> (width,height)",
226 "Returns the width and height properties as a tuple.", "");
227 PyObject* Get() {
228 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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));
232 wxPyEndBlockThreads(blocked);
233 return tup;
234 }
235 }
236 %pythoncode {
237 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
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]
242 def __setitem__(self, index, val):
243 if index == 0: self.width = val
244 elif index == 1: self.height = val
245 else: raise IndexError
246 def __nonzero__(self): return self.Get() != (0,0)
247 __safe_for_unpickling__ = True
248 def __reduce__(self): return (wx.Size, self.Get())
249 }
250
251 };
252
253 //---------------------------------------------------------------------------
254 %newgroup
255
256 DocStr( wxRealPoint,
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.", "");
260 class wxRealPoint
261 {
262 public:
263 double x;
264 double y;
265
266 DocCtorStr(
267 wxRealPoint(double x=0.0, double y=0.0),
268 "Create a wx.RealPoint object", "");
269
270 ~wxRealPoint();
271
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 }
284
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 }
298
299
300 DocDeclStr(
301 wxRealPoint, operator+(const wxRealPoint& pt),
302 "Add pt's proprties to this and return the result.", "");
303
304 DocDeclStr(
305 wxRealPoint, operator-(const wxRealPoint& pt),
306 "Subtract pt's proprties from this and return the result", "");
307
308
309 %extend {
310 DocStr(Set, "Set both the x and y properties", "");
311 void Set(double x, double y) {
312 self->x = x;
313 self->y = y;
314 }
315
316 DocAStr(Get,
317 "Get() -> (x,y)",
318 "Return the x and y properties as a tuple. ", "");
319 PyObject* Get() {
320 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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));
324 wxPyEndBlockThreads(blocked);
325 return tup;
326 }
327 }
328
329 %pythoncode {
330 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
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]
335 def __setitem__(self, index, val):
336 if index == 0: self.x = val
337 elif index == 1: self.y = val
338 else: raise IndexError
339 def __nonzero__(self): return self.Get() != (0.0, 0.0)
340 __safe_for_unpickling__ = True
341 def __reduce__(self): return (wx.RealPoint, self.Get())
342 }
343 };
344
345
346 //---------------------------------------------------------------------------
347 %newgroup
348
349
350 DocStr(wxPoint,
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.", "");
354
355 class wxPoint
356 {
357 public:
358 int x, y;
359
360 DocCtorStr(
361 wxPoint(int x=0, int y=0),
362 "Create a wx.Point object", "");
363
364 ~wxPoint();
365
366
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 }
379
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 }
393
394
395 // %nokwargs operator+;
396 // %nokwargs operator-;
397 // %nokwargs operator+=;
398 // %nokwargs operator-=;
399
400 DocDeclStr(
401 wxPoint, operator+(const wxPoint& pt),
402 "Add pt's proprties to this and return the result.", "");
403
404
405 DocDeclStr(
406 wxPoint, operator-(const wxPoint& pt),
407 "Subtract pt's proprties from this and return the result", "");
408
409
410 DocDeclStr(
411 wxPoint&, operator+=(const wxPoint& pt),
412 "Add pt to this object.", "");
413
414 DocDeclStr(
415 wxPoint&, operator-=(const wxPoint& pt),
416 "Subtract pt from this object.", "");
417
418
419
420 // DocDeclStr(
421 // wxPoint, operator+(const wxSize& sz),
422 // "Add sz to this Point and return the result.", "");
423
424 // DocDeclStr(
425 // wxPoint, operator-(const wxSize& sz),
426 // "Subtract sz from this Point and return the result", "");
427
428
429 // DocDeclStr(
430 // wxPoint&, operator+=(const wxSize& sz),
431 // "Add sz to this object.", "");
432
433 // DocDeclStr(
434 // wxPoint&, operator-=(const wxSize& sz),
435 // "Subtract sz from this object.", "");
436
437
438
439
440 %extend {
441 DocStr(Set, "Set both the x and y properties", "");
442 void Set(long x, long y) {
443 self->x = x;
444 self->y = y;
445 }
446
447 DocAStr(Get,
448 "Get() -> (x,y)",
449 "Return the x and y properties as a tuple. ", "");
450 PyObject* Get() {
451 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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));
455 wxPyEndBlockThreads(blocked);
456 return tup;
457 }
458 }
459
460 %pythoncode {
461 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
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]
466 def __setitem__(self, index, val):
467 if index == 0: self.x = val
468 elif index == 1: self.y = val
469 else: raise IndexError
470 def __nonzero__(self): return self.Get() != (0,0)
471 __safe_for_unpickling__ = True
472 def __reduce__(self): return (wx.Point, self.Get())
473 }
474 };
475
476 //---------------------------------------------------------------------------
477 %newgroup
478
479
480 DocStr(wxRect,
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.", "");
484
485 class wxRect
486 {
487 public:
488 DocCtorStr(
489 wxRect(int x=0, int y=0, int width=0, int height=0),
490 "Create a new Rect object.", "");
491
492 DocCtorStrName(
493 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
494 "Create a new Rect object from Points representing two corners.", "",
495 RectPP);
496
497 DocCtorStrName(
498 wxRect(const wxPoint& pos, const wxSize& size),
499 "Create a new Rect from a position and size.", "",
500 RectPS);
501
502 DocCtorStrName(
503 wxRect(const wxSize& size),
504 "Create a new Rect from a size only.", "",
505 RectS);
506
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
527 bool IsEmpty() const;
528
529 wxPoint GetTopLeft() const;
530 void SetTopLeft(const wxPoint &p);
531 wxPoint GetBottomRight() const;
532 void SetBottomRight(const wxPoint &p);
533
534 wxPoint GetTopRight() const;
535 void SetTopRight(const wxPoint &p);
536 wxPoint GetBottomLeft() const;
537 void SetBottomLeft(const wxPoint &p);
538
539 // wxPoint GetLeftTop() const;
540 // void SetLeftTop(const wxPoint &p);
541 // wxPoint GetRightBottom() const;
542 // void SetRightBottom(const wxPoint &p);
543 // wxPoint GetRightTop() const;
544 // void SetRightTop(const wxPoint &p);
545 // wxPoint GetLeftBottom() const;
546 // void SetLeftBottom(const wxPoint &p);
547
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
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
567
568 DocDeclStr(
569 wxRect&, Inflate(wxCoord dx, wxCoord dy),
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 ");
609
610 // There are also these versions...
611 //wxRect& Inflate(const wxSize& d);
612 //wxRect& Inflate(wxCoord d);
613
614
615 DocDeclStr(
616 wxRect&, Deflate(wxCoord dx, wxCoord dy),
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.", "");
620
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
625 DocDeclStrName(
626 void, Offset(wxCoord dx, wxCoord dy),
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.", "",
630 OffsetXY);
631
632 DocDeclStr(
633 void, Offset(const wxPoint& pt),
634 "Same as `OffsetXY` but uses dx,dy from Point", "");
635
636 DocDeclStr(
637 wxRect, Intersect(const wxRect& rect),
638 "Returns the intersectsion of this rectangle and rect.", "");
639
640 DocDeclStr(
641 wxRect , Union(const wxRect& rect),
642 "Returns the union of this rectangle and rect.", "");
643
644
645 DocDeclStr(
646 wxRect, operator+(const wxRect& rect) const,
647 "Add the properties of rect to this rectangle and return the result.", "");
648
649 DocDeclStr(
650 wxRect&, operator+=(const wxRect& rect),
651 "Add the properties of rect to this rectangle, updating this rectangle.", "");
652
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 }
665
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 }
679
680
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;
684
685 DocDeclStrName(
686 bool, Contains(const wxRect& rect) const,
687 "Returns ``True`` if the given rectangle is completely inside this
688 rectangle or touches its boundary.", "",
689 ContainsRect);
690
691 %pythoncode {
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
698 }
699
700 DocDeclStr(
701 bool, Intersects(const wxRect& rect) const,
702 "Returns True if the rectangles have a non empty intersection.", "");
703
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
710
711 int x, y, width, height;
712
713
714 %extend {
715 DocStr(Set, "Set all rectangle properties.", "");
716 void Set(int x=0, int y=0, int width=0, int height=0) {
717 self->x = x;
718 self->y = y;
719 self->width = width;
720 self->height = height;
721 }
722
723 DocAStr(Get,
724 "Get() -> (x,y,width,height)",
725 "Return the rectangle properties as a tuple.", "");
726 PyObject* Get() {
727 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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));
733 wxPyEndBlockThreads(blocked);
734 return tup;
735 }
736 }
737
738 %pythoncode {
739 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
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]
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
750 def __nonzero__(self): return self.Get() != (0,0,0,0)
751 __safe_for_unpickling__ = True
752 def __reduce__(self): return (wx.Rect, self.Get())
753 }
754
755
756 %property(Bottom, GetBottom, SetBottom, doc="See `GetBottom` and `SetBottom`");
757 %property(BottomRight, GetBottomRight, SetBottomRight, doc="See `GetBottomRight` and `SetBottomRight`");
758 %property(BottomLeft, GetBottomLeft, SetBottomLeft, doc="See `GetBottomLeft` and `SetBottomLeft`");
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`");
766 %property(TopRight, GetTopRight, SetTopRight, doc="See `GetTopRight` and `SetTopRight`");
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`");
772 };
773
774
775 MustHaveApp(wxIntersectRect);
776
777 DocAStr(wxIntersectRect,
778 "IntersectRect(Rect r1, Rect r2) -> Rect",
779 "Calculate and return the intersection of r1 and r2.", "");
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)) {
791 wxPyBlock_t blocked = wxPyBeginBlockThreads();
792 wxRect* newRect = new wxRect(dest);
793 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true);
794 wxPyEndBlockThreads(blocked);
795 return obj;
796 }
797 Py_INCREF(Py_None);
798 return Py_None;
799 }
800 %}
801
802 //---------------------------------------------------------------------------
803 %newgroup
804
805
806 DocStr(wxPoint2D,
807 "wx.Point2Ds represent a point or a vector in a 2d coordinate system
808 with floating point values.", "");
809
810 class wxPoint2D
811 {
812 public:
813 DocStr(wxPoint2D, "Create a w.Point2D object.", "");
814 wxPoint2D( double x=0.0 , double y=0.0 );
815 %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt ));
816 %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt ));
817
818 ~wxPoint2D();
819
820 DocDeclAStr(
821 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
822 "GetFloor() -> (x,y)",
823 "Convert to integer", "");
824
825 DocDeclAStr(
826 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
827 "GetRounded() -> (x,y)",
828 "Convert to integer", "");
829
830 double GetVectorLength() const;
831 double GetVectorAngle() const ;
832 void SetVectorLength( double length );
833 void SetVectorAngle( double degrees );
834
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
850 DocDeclStr(
851 wxPoint2D, operator-(),
852 "the reflection of this point", "");
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
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 }
886
887 %Rename(x, double, m_x);
888 %Rename(y, double, m_y);
889
890 %extend {
891 void Set( double x=0 , double y=0 ) {
892 self->m_x = x;
893 self->m_y = y;
894 }
895
896 DocAStr(Get,
897 "Get() -> (x,y)",
898 "Return x and y properties as a tuple.", "");
899 PyObject* Get() {
900 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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));
904 wxPyEndBlockThreads(blocked);
905 return tup;
906 }
907 }
908
909 %pythoncode {
910 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
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]
915 def __setitem__(self, index, val):
916 if index == 0: self.x = val
917 elif index == 1: self.y = val
918 else: raise IndexError
919 def __nonzero__(self): return self.Get() != (0.0, 0.0)
920 __safe_for_unpickling__ = True
921 def __reduce__(self): return (wx.Point2D, self.Get())
922 }
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
929 };
930
931
932 //---------------------------------------------------------------------------
933
934 %immutable;
935 const wxPoint wxDefaultPosition;
936 const wxSize wxDefaultSize;
937 %mutable;
938
939 //---------------------------------------------------------------------------