]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gdicmn.i
Bug fix.
[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 // Turn off the aquisition of the Global Interpreter Lock for the classes and
21 // functions in this file
22 %threadWrapperOff
23
24
25 enum wxBitmapType
26 {
27 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
28 wxBITMAP_TYPE_BMP,
29 wxBITMAP_TYPE_ICO,
30 wxBITMAP_TYPE_CUR,
31 wxBITMAP_TYPE_XBM,
32 wxBITMAP_TYPE_XBM_DATA,
33 wxBITMAP_TYPE_XPM,
34 wxBITMAP_TYPE_XPM_DATA,
35 wxBITMAP_TYPE_TIF,
36 wxBITMAP_TYPE_GIF,
37 wxBITMAP_TYPE_PNG,
38 wxBITMAP_TYPE_JPEG,
39 wxBITMAP_TYPE_PNM,
40 wxBITMAP_TYPE_PCX,
41 wxBITMAP_TYPE_PICT,
42 wxBITMAP_TYPE_ICON,
43 wxBITMAP_TYPE_ANI,
44 wxBITMAP_TYPE_IFF,
45 wxBITMAP_TYPE_MACCURSOR,
46
47 // wxBITMAP_TYPE_BMP_RESOURCE,
48 // wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
49 // wxBITMAP_TYPE_ICO_RESOURCE,
50 // wxBITMAP_TYPE_CUR_RESOURCE,
51 // wxBITMAP_TYPE_TIF_RESOURCE,
52 // wxBITMAP_TYPE_GIF_RESOURCE,
53 // wxBITMAP_TYPE_PNG_RESOURCE,
54 // wxBITMAP_TYPE_JPEG_RESOURCE,
55 // wxBITMAP_TYPE_PNM_RESOURCE,
56 // wxBITMAP_TYPE_PCX_RESOURCE,
57 // wxBITMAP_TYPE_PICT_RESOURCE,
58 // wxBITMAP_TYPE_ICON_RESOURCE,
59 // wxBITMAP_TYPE_MACCURSOR_RESOURCE,
60
61 wxBITMAP_TYPE_ANY = 50
62 };
63
64 // Standard cursors
65 enum wxStockCursor
66 {
67 wxCURSOR_NONE, // should be 0
68 wxCURSOR_ARROW,
69 wxCURSOR_RIGHT_ARROW,
70 wxCURSOR_BULLSEYE,
71 wxCURSOR_CHAR,
72 wxCURSOR_CROSS,
73 wxCURSOR_HAND,
74 wxCURSOR_IBEAM,
75 wxCURSOR_LEFT_BUTTON,
76 wxCURSOR_MAGNIFIER,
77 wxCURSOR_MIDDLE_BUTTON,
78 wxCURSOR_NO_ENTRY,
79 wxCURSOR_PAINT_BRUSH,
80 wxCURSOR_PENCIL,
81 wxCURSOR_POINT_LEFT,
82 wxCURSOR_POINT_RIGHT,
83 wxCURSOR_QUESTION_ARROW,
84 wxCURSOR_RIGHT_BUTTON,
85 wxCURSOR_SIZENESW,
86 wxCURSOR_SIZENS,
87 wxCURSOR_SIZENWSE,
88 wxCURSOR_SIZEWE,
89 wxCURSOR_SIZING,
90 wxCURSOR_SPRAYCAN,
91 wxCURSOR_WAIT,
92 wxCURSOR_WATCH,
93 wxCURSOR_BLANK,
94 wxCURSOR_DEFAULT, // standard X11 cursor
95 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
96
97 // #ifdef __X__
98 // // Not yet implemented for Windows
99 // wxCURSOR_CROSS_REVERSE,
100 // wxCURSOR_DOUBLE_ARROW,
101 // wxCURSOR_BASED_ARROW_UP,
102 // wxCURSOR_BASED_ARROW_DOWN,
103 // #endif // X11
104
105 wxCURSOR_ARROWWAIT,
106
107 wxCURSOR_MAX
108 };
109
110 %{
111 #ifndef __WXMAC__
112 #define wxCURSOR_COPY_ARROW wxCURSOR_ARROW
113 #endif
114 %}
115
116 //---------------------------------------------------------------------------
117 %newgroup
118
119 DocStr( wxSize,
120 "wx.Size is a useful data structure used to represent the size of
121 something. It simply contains integer width and height
122 properties. In most places in wxPython where a wx.Size is
123 expected a (width, height) tuple can be used instead.", "");
124
125 class wxSize
126 {
127 public:
128 %Rename(width, int, x);
129 %Rename(height,int, y);
130 %pythoncode { x = width; y = height }
131
132 DocCtorStr(
133 wxSize(int w=0, int h=0),
134 "Creates a size object.", "");
135
136 ~wxSize();
137
138
139 %extend {
140 //KeepGIL(__eq__);
141 DocStr(__eq__, "Test for equality of wx.Size objects.", "");
142 bool __eq__(PyObject* other) {
143 wxSize temp, *obj = &temp;
144 if ( other == Py_None ) return false;
145 if ( ! wxSize_helper(other, &obj) ) {
146 PyErr_Clear();
147 return false;
148 }
149 return self->operator==(*obj);
150 }
151
152
153 //KeepGIL(__ne__);
154 DocStr(__ne__, "Test for inequality of wx.Size objects.", "");
155 bool __ne__(PyObject* other) {
156 wxSize temp, *obj = &temp;
157 if ( other == Py_None ) return true;
158 if ( ! wxSize_helper(other, &obj)) {
159 PyErr_Clear();
160 return true;
161 }
162 return self->operator!=(*obj);
163 }
164 }
165
166 DocDeclStr(
167 wxSize, operator+(const wxSize& sz),
168 "Add sz's proprties to this and return the result.", "");
169
170 DocDeclStr(
171 wxSize, operator-(const wxSize& sz),
172 "Subtract sz's properties from this and return the result.", "");
173
174 DocDeclStr(
175 void, IncTo(const wxSize& sz),
176 "Increments this object so that both of its dimensions are not less
177 than the corresponding dimensions of the size.", "");
178
179 DocDeclStr(
180 void, DecTo(const wxSize& sz),
181 "Decrements this object so that both of its dimensions are not greater
182 than the corresponding dimensions of the size.", "");
183
184
185 DocDeclStr(
186 void , IncBy(int dx, int dy),
187 "", "");
188
189
190 DocDeclStr(
191 void , DecBy(int dx, int dy),
192 "", "");
193
194 // TODO: handle these overloads too?
195 // void IncBy(const wxSize& sz);
196 // void IncBy(int d);
197 // void DecBy(const wxSize& sz);
198 // void DecBy(int d);
199
200 DocDeclStr(
201 void , Scale(float xscale, float yscale),
202 "Scales the dimensions of this object by the given factors.", "");
203
204 DocDeclStr(
205 void, Set(int w, int h),
206 "Set both width and height.", "");
207
208 void SetWidth(int w);
209 void SetHeight(int h);
210 int GetWidth() const;
211 int GetHeight() const;
212
213
214 DocDeclStr(
215 bool , IsFullySpecified() const,
216 "Returns True if both components of the size are non-default values.", "");
217
218
219 DocDeclStr(
220 void , SetDefaults(const wxSize& size),
221 "Combine this size with the other one replacing the default components
222 of this object (i.e. equal to -1) with those of the other.", "");
223
224
225 //int GetX() const;
226 //int GetY() const;
227
228 %extend {
229 DocAStr(Get,
230 "Get() -> (width,height)",
231 "Returns the width and height properties as a tuple.", "");
232 PyObject* Get() {
233 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
234 PyObject* tup = PyTuple_New(2);
235 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
236 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
237 //wxPyEndBlockThreads(blocked);
238 return tup;
239 }
240 }
241 %pythoncode {
242 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
243 def __str__(self): return str(self.Get())
244 def __repr__(self): return 'wx.Size'+str(self.Get())
245 def __len__(self): return len(self.Get())
246 def __getitem__(self, index): return self.Get()[index]
247 def __setitem__(self, index, val):
248 if index == 0: self.width = val
249 elif index == 1: self.height = val
250 else: raise IndexError
251 def __nonzero__(self): return self.Get() != (0,0)
252 __safe_for_unpickling__ = True
253 def __reduce__(self): return (wx.Size, self.Get())
254 }
255
256 };
257
258 //---------------------------------------------------------------------------
259 %newgroup
260
261 DocStr( wxRealPoint,
262 "A data structure for representing a point or position with floating
263 point x and y properties. In wxPython most places that expect a
264 wx.RealPoint can also accept a (x,y) tuple.", "");
265 class wxRealPoint
266 {
267 public:
268 double x;
269 double y;
270
271 DocCtorStr(
272 wxRealPoint(double x=0.0, double y=0.0),
273 "Create a wx.RealPoint object", "");
274
275 ~wxRealPoint();
276
277 %extend {
278 //KeepGIL(__eq__);
279 DocStr(__eq__, "Test for equality of wx.RealPoint objects.", "");
280 bool __eq__(PyObject* other) {
281 wxRealPoint temp, *obj = &temp;
282 if ( other == Py_None ) return false;
283 if ( ! wxRealPoint_helper(other, &obj) ) {
284 PyErr_Clear();
285 return false;
286 }
287 return self->operator==(*obj);
288 }
289
290
291 //KeepGIL(__ne__);
292 DocStr(__ne__, "Test for inequality of wx.RealPoint objects.", "");
293 bool __ne__(PyObject* other) {
294 wxRealPoint temp, *obj = &temp;
295 if ( other == Py_None ) return true;
296 if ( ! wxRealPoint_helper(other, &obj)) {
297 PyErr_Clear();
298 return true;
299 }
300 return self->operator!=(*obj);
301 }
302 }
303
304
305 DocDeclStr(
306 wxRealPoint, operator+(const wxRealPoint& pt),
307 "Add pt's proprties to this and return the result.", "");
308
309 DocDeclStr(
310 wxRealPoint, operator-(const wxRealPoint& pt),
311 "Subtract pt's proprties from this and return the result", "");
312
313
314 %extend {
315 DocStr(Set, "Set both the x and y properties", "");
316 void Set(double x, double y) {
317 self->x = x;
318 self->y = y;
319 }
320
321 DocAStr(Get,
322 "Get() -> (x,y)",
323 "Return the x and y properties as a tuple. ", "");
324 PyObject* Get() {
325 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
326 PyObject* tup = PyTuple_New(2);
327 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
328 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
329 //PyEndBlockThreads(blocked);
330 return tup;
331 }
332 }
333
334 %pythoncode {
335 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
336 def __str__(self): return str(self.Get())
337 def __repr__(self): return 'wx.RealPoint'+str(self.Get())
338 def __len__(self): return len(self.Get())
339 def __getitem__(self, index): return self.Get()[index]
340 def __setitem__(self, index, val):
341 if index == 0: self.x = val
342 elif index == 1: self.y = val
343 else: raise IndexError
344 def __nonzero__(self): return self.Get() != (0.0, 0.0)
345 __safe_for_unpickling__ = True
346 def __reduce__(self): return (wx.RealPoint, self.Get())
347 }
348 };
349
350
351 //---------------------------------------------------------------------------
352 %newgroup
353
354
355 DocStr(wxPoint,
356 "A data structure for representing a point or position with integer x
357 and y properties. Most places in wxPython that expect a wx.Point can
358 also accept a (x,y) tuple.", "");
359
360 class wxPoint
361 {
362 public:
363 int x, y;
364
365 DocCtorStr(
366 wxPoint(int x=0, int y=0),
367 "Create a wx.Point object", "");
368
369 ~wxPoint();
370
371
372 %extend {
373 //KeepGIL(__eq__);
374 DocStr(__eq__, "Test for equality of wx.Point objects.", "");
375 bool __eq__(PyObject* other) {
376 wxPoint temp, *obj = &temp;
377 if ( other == Py_None ) return false;
378 if ( ! wxPoint_helper(other, &obj) ) {
379 PyErr_Clear();
380 return false;
381 }
382 return self->operator==(*obj);
383 }
384
385
386 //KeepGIL(__ne__);
387 DocStr(__ne__, "Test for inequality of wx.Point objects.", "");
388 bool __ne__(PyObject* other) {
389 wxPoint temp, *obj = &temp;
390 if ( other == Py_None ) return true;
391 if ( ! wxPoint_helper(other, &obj)) {
392 PyErr_Clear();
393 return true;
394 }
395 return self->operator!=(*obj);
396 }
397 }
398
399
400 // %nokwargs operator+;
401 // %nokwargs operator-;
402 // %nokwargs operator+=;
403 // %nokwargs operator-=;
404
405 DocDeclStr(
406 wxPoint, operator+(const wxPoint& pt),
407 "Add pt's proprties to this and return the result.", "");
408
409
410 DocDeclStr(
411 wxPoint, operator-(const wxPoint& pt),
412 "Subtract pt's proprties from this and return the result", "");
413
414
415 DocDeclStr(
416 wxPoint&, operator+=(const wxPoint& pt),
417 "Add pt to this object.", "");
418
419 DocDeclStr(
420 wxPoint&, operator-=(const wxPoint& pt),
421 "Subtract pt from this object.", "");
422
423
424
425 // DocDeclStr(
426 // wxPoint, operator+(const wxSize& sz),
427 // "Add sz to this Point and return the result.", "");
428
429 // DocDeclStr(
430 // wxPoint, operator-(const wxSize& sz),
431 // "Subtract sz from this Point and return the result", "");
432
433
434 // DocDeclStr(
435 // wxPoint&, operator+=(const wxSize& sz),
436 // "Add sz to this object.", "");
437
438 // DocDeclStr(
439 // wxPoint&, operator-=(const wxSize& sz),
440 // "Subtract sz from this object.", "");
441
442
443
444
445 %extend {
446 DocStr(Set, "Set both the x and y properties", "");
447 void Set(long x, long y) {
448 self->x = x;
449 self->y = y;
450 }
451
452 DocAStr(Get,
453 "Get() -> (x,y)",
454 "Return the x and y properties as a tuple. ", "");
455 PyObject* Get() {
456 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
457 PyObject* tup = PyTuple_New(2);
458 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
459 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
460 //wxPyEndBlockThreads(blocked);
461 return tup;
462 }
463 }
464
465 %pythoncode {
466 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
467 def __str__(self): return str(self.Get())
468 def __repr__(self): return 'wx.Point'+str(self.Get())
469 def __len__(self): return len(self.Get())
470 def __getitem__(self, index): return self.Get()[index]
471 def __setitem__(self, index, val):
472 if index == 0: self.x = val
473 elif index == 1: self.y = val
474 else: raise IndexError
475 def __nonzero__(self): return self.Get() != (0,0)
476 __safe_for_unpickling__ = True
477 def __reduce__(self): return (wx.Point, self.Get())
478 }
479 };
480
481 //---------------------------------------------------------------------------
482 %newgroup
483
484
485 DocStr(wxRect,
486 "A class for representing and manipulating rectangles. It has x, y,
487 width and height properties. In wxPython most palces that expect a
488 wx.Rect can also accept a (x,y,width,height) tuple.", "");
489
490 class wxRect
491 {
492 public:
493 DocCtorStr(
494 wxRect(int x=0, int y=0, int width=0, int height=0),
495 "Create a new Rect object.", "");
496
497 DocCtorStrName(
498 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
499 "Create a new Rect object from Points representing two corners.", "",
500 RectPP);
501
502 DocCtorStrName(
503 wxRect(const wxPoint& pos, const wxSize& size),
504 "Create a new Rect from a position and size.", "",
505 RectPS);
506
507 DocCtorStrName(
508 wxRect(const wxSize& size),
509 "Create a new Rect from a size only.", "",
510 RectS);
511
512 ~wxRect();
513
514 int GetX() const;
515 void SetX(int x);
516
517 int GetY();
518 void SetY(int y);
519
520 int GetWidth() const;
521 void SetWidth(int w);
522
523 int GetHeight() const;
524 void SetHeight(int h);
525
526 wxPoint GetPosition() const;
527 void SetPosition( const wxPoint &p );
528
529 wxSize GetSize() const;
530 void SetSize( const wxSize &s );
531
532 bool IsEmpty() const;
533
534 wxPoint GetTopLeft() const;
535 void SetTopLeft(const wxPoint &p);
536 wxPoint GetBottomRight() const;
537 void SetBottomRight(const wxPoint &p);
538
539 wxPoint GetTopRight() const;
540 void SetTopRight(const wxPoint &p);
541 wxPoint GetBottomLeft() const;
542 void SetBottomLeft(const wxPoint &p);
543
544 // wxPoint GetLeftTop() const;
545 // void SetLeftTop(const wxPoint &p);
546 // wxPoint GetRightBottom() const;
547 // void SetRightBottom(const wxPoint &p);
548 // wxPoint GetRightTop() const;
549 // void SetRightTop(const wxPoint &p);
550 // wxPoint GetLeftBottom() const;
551 // void SetLeftBottom(const wxPoint &p);
552
553 int GetLeft() const;
554 int GetTop() const;
555 int GetBottom() const;
556 int GetRight() const;
557
558 void SetLeft(int left);
559 void SetRight(int right);
560 void SetTop(int top);
561 void SetBottom(int bottom);
562
563 %pythoncode {
564 position = property(GetPosition, SetPosition)
565 size = property(GetSize, SetSize)
566 left = property(GetLeft, SetLeft)
567 right = property(GetRight, SetRight)
568 top = property(GetTop, SetTop)
569 bottom = property(GetBottom, SetBottom)
570 }
571
572
573 DocDeclStr(
574 wxRect&, Inflate(wxCoord dx, wxCoord dy),
575 "Increases the size of the rectangle.
576
577 The left border is moved farther left and the right border is moved
578 farther right by ``dx``. The upper border is moved farther up and the
579 bottom border is moved farther down by ``dy``. (Note the the width and
580 height of the rectangle thus change by ``2*dx`` and ``2*dy``,
581 respectively.) If one or both of ``dx`` and ``dy`` are negative, the
582 opposite happens: the rectangle size decreases in the respective
583 direction.
584
585 The change is made to the rectangle inplace, if instead you need a
586 copy that is inflated, preserving the original then make the copy
587 first::
588
589 copy = wx.Rect(*original)
590 copy.Inflate(10,15)
591
592 ", "
593 Inflating and deflating behaves *naturally*. Defined more precisely,
594 that means:
595
596 * Real inflates (that is, ``dx`` and/or ``dy`` >= 0) are not
597 constrained. Thus inflating a rectangle can cause its upper left
598 corner to move into the negative numbers. (The versions prior to
599 2.5.4 forced the top left coordinate to not fall below (0, 0),
600 which implied a forced move of the rectangle.)
601
602 * Deflates are clamped to not reduce the width or height of the
603 rectangle below zero. In such cases, the top-left corner is
604 nonetheless handled properly. For example, a rectangle at (10,
605 10) with size (20, 40) that is inflated by (-15, -15) will
606 become located at (20, 25) at size (0, 10). Finally, observe
607 that the width and height are treated independently. In the
608 above example, the width is reduced by 20, whereas the height is
609 reduced by the full 30 (rather than also stopping at 20, when
610 the width reached zero).
611
612 :see: `Deflate`
613 ");
614
615 // There are also these versions...
616 //wxRect& Inflate(const wxSize& d);
617 //wxRect& Inflate(wxCoord d);
618
619
620 DocDeclStr(
621 wxRect&, Deflate(wxCoord dx, wxCoord dy),
622 "Decrease the rectangle size. This method is the opposite of `Inflate`
623 in that Deflate(a,b) is equivalent to Inflate(-a,-b). Please refer to
624 `Inflate` for a full description.", "");
625
626 // There are also these versions...
627 //wxRect& Deflate(const wxSize& d) { return Inflate(-d.x, -d.y); }
628 //wxRect& Deflate(wxCoord d) { return Inflate(-d); }
629
630 DocDeclStrName(
631 void, Offset(wxCoord dx, wxCoord dy),
632 "Moves the rectangle by the specified offset. If dx is positive, the
633 rectangle is moved to the right, if dy is positive, it is moved to the
634 bottom, otherwise it is moved to the left or top respectively.", "",
635 OffsetXY);
636
637 DocDeclStr(
638 void, Offset(const wxPoint& pt),
639 "Same as `OffsetXY` but uses dx,dy from Point", "");
640
641 DocDeclStr(
642 wxRect, Intersect(const wxRect& rect),
643 "Returns the intersectsion of this rectangle and rect.", "");
644
645 DocDeclStr(
646 wxRect , Union(const wxRect& rect),
647 "Returns the union of this rectangle and rect.", "");
648
649
650 DocDeclStr(
651 wxRect, operator+(const wxRect& rect) const,
652 "Add the properties of rect to this rectangle and return the result.", "");
653
654 DocDeclStr(
655 wxRect&, operator+=(const wxRect& rect),
656 "Add the properties of rect to this rectangle, updating this rectangle.", "");
657
658 %extend {
659 //KeepGIL(__eq__);
660 DocStr(__eq__, "Test for equality of wx.Rect objects.", "");
661 bool __eq__(PyObject* other) {
662 wxRect temp, *obj = &temp;
663 if ( other == Py_None ) return false;
664 if ( ! wxRect_helper(other, &obj) ) {
665 PyErr_Clear();
666 return false;
667 }
668 return self->operator==(*obj);
669 }
670
671
672 //KeepGIL(__ne__);
673 DocStr(__ne__, "Test for inequality of wx.Rect objects.", "");
674 bool __ne__(PyObject* other) {
675 wxRect temp, *obj = &temp;
676 if ( other == Py_None ) return true;
677 if ( ! wxRect_helper(other, &obj)) {
678 PyErr_Clear();
679 return true;
680 }
681 return self->operator!=(*obj);
682 }
683 }
684
685
686 DocStr( Contains, "Return True if the point is inside the rect.", "");
687 %Rename(ContainsXY, bool, Contains(int x, int y) const);
688 bool Contains(const wxPoint& pt) const;
689
690 DocDeclStrName(
691 bool, Contains(const wxRect& rect) const,
692 "Returns ``True`` if the given rectangle is completely inside this
693 rectangle or touches its boundary.", "",
694 ContainsRect);
695
696 %pythoncode {
697 %#Inside = wx._deprecated(Contains, "Use `Contains` instead.")
698 %#InsideXY = wx._deprecated(ContainsXY, "Use `ContainsXY` instead.")
699 %#InsideRect = wx._deprecated(ContainsRect, "Use `ContainsRect` instead.")
700 Inside = Contains
701 InsideXY = ContainsXY
702 InsideRect = ContainsRect
703 }
704
705 DocDeclStr(
706 bool, Intersects(const wxRect& rect) const,
707 "Returns True if the rectangles have a non empty intersection.", "");
708
709 DocDeclStr(
710 wxRect, CenterIn(const wxRect& r, int dir = wxBOTH),
711 "Center this rectangle within the one passed to the method, which is
712 usually, but not necessarily, the larger one.", "");
713 %pythoncode { CentreIn = CenterIn }
714
715
716 int x, y, width, height;
717
718
719 %extend {
720 DocStr(Set, "Set all rectangle properties.", "");
721 void Set(int x=0, int y=0, int width=0, int height=0) {
722 self->x = x;
723 self->y = y;
724 self->width = width;
725 self->height = height;
726 }
727
728 DocAStr(Get,
729 "Get() -> (x,y,width,height)",
730 "Return the rectangle properties as a tuple.", "");
731 PyObject* Get() {
732 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
733 PyObject* tup = PyTuple_New(4);
734 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
735 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
736 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
737 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
738 //wxPyEndBlockThreads(blocked);
739 return tup;
740 }
741 }
742
743 %pythoncode {
744 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
745 def __str__(self): return str(self.Get())
746 def __repr__(self): return 'wx.Rect'+str(self.Get())
747 def __len__(self): return len(self.Get())
748 def __getitem__(self, index): return self.Get()[index]
749 def __setitem__(self, index, val):
750 if index == 0: self.x = val
751 elif index == 1: self.y = val
752 elif index == 2: self.width = val
753 elif index == 3: self.height = val
754 else: raise IndexError
755 def __nonzero__(self): return self.Get() != (0,0,0,0)
756 __safe_for_unpickling__ = True
757 def __reduce__(self): return (wx.Rect, self.Get())
758 }
759
760
761 %property(Bottom, GetBottom, SetBottom, doc="See `GetBottom` and `SetBottom`");
762 %property(BottomRight, GetBottomRight, SetBottomRight, doc="See `GetBottomRight` and `SetBottomRight`");
763 %property(BottomLeft, GetBottomLeft, SetBottomLeft, doc="See `GetBottomLeft` and `SetBottomLeft`");
764 %property(Height, GetHeight, SetHeight, doc="See `GetHeight` and `SetHeight`");
765 %property(Left, GetLeft, SetLeft, doc="See `GetLeft` and `SetLeft`");
766 %property(Position, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`");
767 %property(Right, GetRight, SetRight, doc="See `GetRight` and `SetRight`");
768 %property(Size, GetSize, SetSize, doc="See `GetSize` and `SetSize`");
769 %property(Top, GetTop, SetTop, doc="See `GetTop` and `SetTop`");
770 %property(TopLeft, GetTopLeft, SetTopLeft, doc="See `GetTopLeft` and `SetTopLeft`");
771 %property(TopRight, GetTopRight, SetTopRight, doc="See `GetTopRight` and `SetTopRight`");
772 %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`");
773 %property(X, GetX, SetX, doc="See `GetX` and `SetX`");
774 %property(Y, GetY, SetY, doc="See `GetY` and `SetY`");
775
776 %property(Empty, IsEmpty, doc="See `IsEmpty`");
777 };
778
779
780 MustHaveApp(wxIntersectRect);
781
782 DocAStr(wxIntersectRect,
783 "IntersectRect(Rect r1, Rect r2) -> Rect",
784 "Calculate and return the intersection of r1 and r2.", "");
785 %inline %{
786 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
787 wxRegion reg1(*r1);
788 wxRegion reg2(*r2);
789 wxRect dest(0,0,0,0);
790 PyObject* obj;
791
792 reg1.Intersect(reg2);
793 dest = reg1.GetBox();
794
795 if (dest != wxRect(0,0,0,0)) {
796 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
797 wxRect* newRect = new wxRect(dest);
798 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true);
799 //wxPyEndBlockThreads(blocked);
800 return obj;
801 }
802 Py_INCREF(Py_None);
803 return Py_None;
804 }
805 %}
806
807 //---------------------------------------------------------------------------
808 %newgroup
809
810
811 DocStr(wxPoint2D,
812 "wx.Point2Ds represent a point or a vector in a 2d coordinate system
813 with floating point values.", "");
814
815 class wxPoint2D
816 {
817 public:
818 DocStr(wxPoint2D, "Create a w.Point2D object.", "");
819 wxPoint2D( double x=0.0 , double y=0.0 );
820 %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt ));
821 %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt ));
822
823 ~wxPoint2D();
824
825 DocDeclAStr(
826 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
827 "GetFloor() -> (x,y)",
828 "Convert to integer", "");
829
830 DocDeclAStr(
831 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
832 "GetRounded() -> (x,y)",
833 "Convert to integer", "");
834
835 double GetVectorLength() const;
836 double GetVectorAngle() const ;
837 void SetVectorLength( double length );
838 void SetVectorAngle( double degrees );
839
840 // LinkError: void SetPolarCoordinates( double angle , double length );
841 // LinkError: void Normalize();
842 %pythoncode {
843 def SetPolarCoordinates(self, angle, length):
844 self.SetVectorLength(length)
845 self.SetVectorAngle(angle)
846 def Normalize(self):
847 self.SetVectorLength(1.0)
848 }
849
850 double GetDistance( const wxPoint2D &pt ) const;
851 double GetDistanceSquare( const wxPoint2D &pt ) const;
852 double GetDotProduct( const wxPoint2D &vec ) const;
853 double GetCrossProduct( const wxPoint2D &vec ) const;
854
855 DocDeclStr(
856 wxPoint2D, operator-(),
857 "the reflection of this point", "");
858
859 wxPoint2D& operator+=(const wxPoint2D& pt);
860 wxPoint2D& operator-=(const wxPoint2D& pt);
861
862 wxPoint2D& operator*=(const wxPoint2D& pt);
863 wxPoint2D& operator/=(const wxPoint2D& pt);
864
865 %extend {
866 //KeepGIL(__eq__);
867 DocStr(__eq__, "Test for equality of wx.Point2D objects.", "");
868 bool __eq__(PyObject* other) {
869 wxPoint2D temp, *obj = &temp;
870 if ( other == Py_None ) return false;
871 if ( ! wxPoint2D_helper(other, &obj) ) {
872 PyErr_Clear();
873 return false;
874 }
875 return self->operator==(*obj);
876 }
877
878
879 //KeepGIL(__ne__);
880 DocStr(__ne__, "Test for inequality of wx.Point2D objects.", "");
881 bool __ne__(PyObject* other) {
882 wxPoint2D temp, *obj = &temp;
883 if ( other == Py_None ) return true;
884 if ( ! wxPoint2D_helper(other, &obj)) {
885 PyErr_Clear();
886 return true;
887 }
888 return self->operator!=(*obj);
889 }
890 }
891
892 %Rename(x, double, m_x);
893 %Rename(y, double, m_y);
894
895 %extend {
896 void Set( double x=0 , double y=0 ) {
897 self->m_x = x;
898 self->m_y = y;
899 }
900
901 DocAStr(Get,
902 "Get() -> (x,y)",
903 "Return x and y properties as a tuple.", "");
904 PyObject* Get() {
905 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
906 PyObject* tup = PyTuple_New(2);
907 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
908 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
909 //wxPyEndBlockThreads(blocked);
910 return tup;
911 }
912 }
913
914 %pythoncode {
915 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
916 def __str__(self): return str(self.Get())
917 def __repr__(self): return 'wx.Point2D'+str(self.Get())
918 def __len__(self): return len(self.Get())
919 def __getitem__(self, index): return self.Get()[index]
920 def __setitem__(self, index, val):
921 if index == 0: self.x = val
922 elif index == 1: self.y = val
923 else: raise IndexError
924 def __nonzero__(self): return self.Get() != (0.0, 0.0)
925 __safe_for_unpickling__ = True
926 def __reduce__(self): return (wx.Point2D, self.Get())
927 }
928
929 %property(Floor, GetFloor, doc="See `GetFloor`");
930 %property(Rounded, GetRounded, doc="See `GetRounded`");
931 %property(VectorAngle, GetVectorAngle, SetVectorAngle, doc="See `GetVectorAngle` and `SetVectorAngle`");
932 %property(VectorLength, GetVectorLength, SetVectorLength, doc="See `GetVectorLength` and `SetVectorLength`");
933
934 };
935
936
937 //---------------------------------------------------------------------------
938 %newgroup
939
940
941 enum wxOutCode
942 {
943 wxInside = 0x00 ,
944 wxOutLeft = 0x01 ,
945 wxOutRight = 0x02 ,
946 wxOutTop = 0x08 ,
947 wxOutBottom = 0x04
948 };
949
950
951 DocStr(wxRect2D,
952 "wx.Rect2D is a rectangle, with position and size, in a 2D coordinate system
953 with floating point component values.", "");
954
955 class wxRect2D
956 {
957 public:
958 wxRect2D(wxDouble x=0.0, wxDouble y=0.0, wxDouble w=0.0, wxDouble h=0.0);
959
960 ~wxRect2D();
961
962 wxPoint2D GetPosition();
963 wxSize GetSize();
964
965 // for the edge and corner accessors there are two setters conterparts,
966 // the Set.. functions keep the other corners at their position whenever
967 // sensible, the Move.. functions keep the size of the rect and move the
968 // other corners apropriately
969
970 wxDouble GetLeft() const;
971 void SetLeft( wxDouble n );
972 void MoveLeftTo( wxDouble n );
973 wxDouble GetTop() const;
974 void SetTop( wxDouble n );
975 void MoveTopTo( wxDouble n );
976 wxDouble GetBottom() const;
977 void SetBottom( wxDouble n );
978 void MoveBottomTo( wxDouble n );
979 wxDouble GetRight() const;
980 void SetRight( wxDouble n );
981 void MoveRightTo( wxDouble n );
982
983 wxPoint2D GetLeftTop() const;
984 void SetLeftTop( const wxPoint2D &pt );
985 void MoveLeftTopTo( const wxPoint2D &pt );
986 wxPoint2D GetLeftBottom() const;
987 void SetLeftBottom( const wxPoint2D &pt );
988 void MoveLeftBottomTo( const wxPoint2D &pt );
989 wxPoint2D GetRightTop() const;
990 void SetRightTop( const wxPoint2D &pt );
991 void MoveRightTopTo( const wxPoint2D &pt );
992 wxPoint2D GetRightBottom() const;
993 void SetRightBottom( const wxPoint2D &pt );
994 void MoveRightBottomTo( const wxPoint2D &pt );
995 wxPoint2D GetCentre() const;
996 void SetCentre( const wxPoint2D &pt );
997 void MoveCentreTo( const wxPoint2D &pt );
998 wxOutCode GetOutcode(const wxPoint2D &pt) const;
999 bool Contains( const wxPoint2D &pt ) const;
1000 %Rename(ContainsRect, bool , Contains( const wxRect2D &rect ) const);
1001 bool IsEmpty() const;
1002 bool HaveEqualSize( const wxRect2D &rect ) const;
1003
1004 %nokwargs Inset;
1005 void Inset( wxDouble x , wxDouble y );
1006 void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom );
1007 void Offset( const wxPoint2D &pt );
1008
1009 void ConstrainTo( const wxRect2D &rect );
1010
1011 wxPoint2D Interpolate( wxInt32 widthfactor , wxInt32 heightfactor );
1012
1013 //static void Intersect( const wxRect2D &src1 , const wxRect2D &src2 , wxRect2D *dest );
1014
1015 void Intersect( const wxRect2D &otherRect );
1016 wxRect2D CreateIntersection( const wxRect2D &otherRect ) const;
1017 bool Intersects( const wxRect2D &rect ) const;
1018
1019 // static void Union( const wxRect2D &src1 , const wxRect2D &src2 , wxRect2D *dest );
1020
1021 void Union( const wxRect2D &otherRect );
1022 //void Union( const wxPoint2D &pt );
1023
1024 wxRect2D CreateUnion( const wxRect2D &otherRect ) const;
1025
1026 %nokwargs Scale;
1027 void Scale( wxDouble f );
1028 void Scale( int num , int denum );
1029
1030 //wxRect2D& operator = (const wxRect2D& rect);
1031 //bool operator == (const wxRect2D& rect) const;
1032 //bool operator != (const wxRect2D& rect) const;
1033
1034 %extend {
1035 //KeepGIL(__eq__);
1036 DocStr(__eq__, "Test for equality of wx.Rect2D objects.", "");
1037 bool __eq__(PyObject* other) {
1038 wxRect2D temp, *obj = &temp;
1039 if ( other == Py_None ) return false;
1040 if ( ! wxRect2D_helper(other, &obj) ) {
1041 PyErr_Clear();
1042 return false;
1043 }
1044 return self->operator==(*obj);
1045 }
1046
1047
1048 //KeepGIL(__ne__);
1049 DocStr(__ne__, "Test for inequality of wx.Rect2D objects.", "");
1050 bool __ne__(PyObject* other) {
1051 wxRect2D temp, *obj = &temp;
1052 if ( other == Py_None ) return true;
1053 if ( ! wxRect2D_helper(other, &obj)) {
1054 PyErr_Clear();
1055 return true;
1056 }
1057 return self->operator!=(*obj);
1058 }
1059 }
1060
1061
1062 %Rename(x, wxDouble , m_x);
1063 %Rename(y, wxDouble , m_y);
1064 %Rename(width, wxDouble , m_width);
1065 %Rename(height, wxDouble , m_height);
1066
1067 %extend {
1068 void Set( wxDouble x=0 , wxDouble y=0, wxDouble width=0, wxDouble height=0 ) {
1069 self->m_x = x;
1070 self->m_y = y;
1071 self->m_width = width;
1072 self->m_height = height;
1073 }
1074
1075 DocAStr(Get,
1076 "Get() -> (x,y, width, height)",
1077 "Return x, y, width and height y properties as a tuple.", "");
1078 PyObject* Get() {
1079 //wxPyBlock_t blocked = wxPyBeginBlockThreads();
1080 PyObject* tup = PyTuple_New(4);
1081 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
1082 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
1083 PyTuple_SET_ITEM(tup, 2, PyFloat_FromDouble(self->m_width));
1084 PyTuple_SET_ITEM(tup, 3, PyFloat_FromDouble(self->m_height));
1085 //wxPyEndBlockThreads(blocked);
1086 return tup;
1087 }
1088 }
1089
1090 %pythoncode {
1091 def __str__(self): return str(self.Get())
1092 def __repr__(self): return 'wx.Rect2D'+str(self.Get())
1093 def __len__(self): return len(self.Get())
1094 def __getitem__(self, index): return self.Get()[index]
1095 def __setitem__(self, index, val):
1096 if index == 0: self.x = val
1097 elif index == 1: self.y = val
1098 elif index == 2: self.width = val
1099 elif index == 3: self.height = val
1100 else: raise IndexError
1101 def __nonzero__(self): return self.Get() != (0.0, 0.0, 0.0, 0.0)
1102 __safe_for_unpickling__ = True
1103 def __reduce__(self): return (wx.Rect2D, self.Get())
1104 }
1105
1106 };
1107
1108 //---------------------------------------------------------------------------
1109
1110 %immutable;
1111 const wxPoint wxDefaultPosition;
1112 const wxSize wxDefaultSize;
1113 %mutable;
1114
1115 //---------------------------------------------------------------------------
1116
1117 // Turn GIL acquisition back on.
1118 %threadWrapperOn