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