]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/_gdicmn.i
fixes for compilation with wxUSE_XXX==0 and some other minor fixes (patch 1569904)
[wxWidgets.git] / wxPython / src / _gdicmn.i
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: _gdicmn.i
3// Purpose: SWIG interface for common GDI stuff and misc classes
4//
5// Author: Robin Dunn
6//
7// Created: 13-Sept-2003
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup
18
19
20enum wxBitmapType
21{
22 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
23 wxBITMAP_TYPE_BMP,
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
60enum wxStockCursor
61{
62 wxCURSOR_NONE, // should be 0
63 wxCURSOR_ARROW,
64 wxCURSOR_RIGHT_ARROW,
65 wxCURSOR_BULLSEYE,
66 wxCURSOR_CHAR,
67 wxCURSOR_CROSS,
68 wxCURSOR_HAND,
69 wxCURSOR_IBEAM,
70 wxCURSOR_LEFT_BUTTON,
71 wxCURSOR_MAGNIFIER,
72 wxCURSOR_MIDDLE_BUTTON,
73 wxCURSOR_NO_ENTRY,
74 wxCURSOR_PAINT_BRUSH,
75 wxCURSOR_PENCIL,
76 wxCURSOR_POINT_LEFT,
77 wxCURSOR_POINT_RIGHT,
78 wxCURSOR_QUESTION_ARROW,
79 wxCURSOR_RIGHT_BUTTON,
80 wxCURSOR_SIZENESW,
81 wxCURSOR_SIZENS,
82 wxCURSOR_SIZENWSE,
83 wxCURSOR_SIZEWE,
84 wxCURSOR_SIZING,
85 wxCURSOR_SPRAYCAN,
86 wxCURSOR_WAIT,
87 wxCURSOR_WATCH,
88 wxCURSOR_BLANK,
89 wxCURSOR_DEFAULT, // standard X11 cursor
90 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
91
92// #ifdef __X__
93// // Not yet implemented for Windows
94// wxCURSOR_CROSS_REVERSE,
95// wxCURSOR_DOUBLE_ARROW,
96// wxCURSOR_BASED_ARROW_UP,
97// wxCURSOR_BASED_ARROW_DOWN,
98// #endif // X11
99
100 wxCURSOR_ARROWWAIT,
101
102 wxCURSOR_MAX
103};
104
105%{
106#ifndef __WXMAC__
107#define wxCURSOR_COPY_ARROW wxCURSOR_ARROW
108#endif
109%}
110
111//---------------------------------------------------------------------------
112%newgroup
113
114DocStr( wxSize,
115"wx.Size is a useful data structure used to represent the size of
116something. It simply contains integer width and height
117properties. In most places in wxPython where a wx.Size is
118expected a (width, height) tuple can be used instead.", "");
119
120class wxSize
121{
122public:
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
172than 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
177than 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
217of 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
256DocStr( wxRealPoint,
257"A data structure for representing a point or position with floating
258point x and y properties. In wxPython most places that expect a
259wx.RealPoint can also accept a (x,y) tuple.", "");
260class wxRealPoint
261{
262public:
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
350DocStr(wxPoint,
351"A data structure for representing a point or position with integer x
352and y properties. Most places in wxPython that expect a wx.Point can
353also accept a (x,y) tuple.", "");
354
355class wxPoint
356{
357public:
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
480DocStr(wxRect,
481"A class for representing and manipulating rectangles. It has x, y,
482width and height properties. In wxPython most palces that expect a
483wx.Rect can also accept a (x,y,width,height) tuple.", "");
484
485class wxRect
486{
487public:
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
572The left border is moved farther left and the right border is moved
573farther right by ``dx``. The upper border is moved farther up and the
574bottom border is moved farther down by ``dy``. (Note the the width and
575height of the rectangle thus change by ``2*dx`` and ``2*dy``,
576respectively.) If one or both of ``dx`` and ``dy`` are negative, the
577opposite happens: the rectangle size decreases in the respective
578direction.
579
580The change is made to the rectangle inplace, if instead you need a
581copy that is inflated, preserving the original then make the copy
582first::
583
584 copy = wx.Rect(*original)
585 copy.Inflate(10,15)
586
587", "
588Inflating and deflating behaves *naturally*. Defined more precisely,
589that 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`
618in 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
628rectangle is moved to the right, if dy is positive, it is moved to the
629bottom, 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
688rectangle or touches its boundary.", "",
689 ContainsRect);
690 %pythoncode {
691 Inside = wx._deprecated(Contains, "Use `Contains` instead.")
692 InsideXY = wx._deprecated(ContainsXY, "Use `ContainsXY` instead.")
693 InsideRect = wx._deprecated(ContainsRect, "Use `ContainsRect` instead.")
694 }
695
696 DocDeclStr(
697 bool, Intersects(const wxRect& rect) const,
698 "Returns True if the rectangles have a non empty intersection.", "");
699
700 DocDeclStr(
701 wxRect, CenterIn(const wxRect& r, int dir = wxBOTH),
702 "Center this rectangle within the one passed to the method, which is
703usually, but not necessarily, the larger one.", "");
704 %pythoncode { CentreIn = CenterIn }
705
706
707 int x, y, width, height;
708
709
710 %extend {
711 DocStr(Set, "Set all rectangle properties.", "");
712 void Set(int x=0, int y=0, int width=0, int height=0) {
713 self->x = x;
714 self->y = y;
715 self->width = width;
716 self->height = height;
717 }
718
719 DocAStr(Get,
720 "Get() -> (x,y,width,height)",
721 "Return the rectangle properties as a tuple.", "");
722 PyObject* Get() {
723 wxPyBlock_t blocked = wxPyBeginBlockThreads();
724 PyObject* tup = PyTuple_New(4);
725 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
726 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
727 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
728 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
729 wxPyEndBlockThreads(blocked);
730 return tup;
731 }
732 }
733
734 %pythoncode {
735 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
736 def __str__(self): return str(self.Get())
737 def __repr__(self): return 'wx.Rect'+str(self.Get())
738 def __len__(self): return len(self.Get())
739 def __getitem__(self, index): return self.Get()[index]
740 def __setitem__(self, index, val):
741 if index == 0: self.x = val
742 elif index == 1: self.y = val
743 elif index == 2: self.width = val
744 elif index == 3: self.height = val
745 else: raise IndexError
746 def __nonzero__(self): return self.Get() != (0,0,0,0)
747 __safe_for_unpickling__ = True
748 def __reduce__(self): return (wx.Rect, self.Get())
749 }
750
751
752 %property(Bottom, GetBottom, SetBottom, doc="See `GetBottom` and `SetBottom`");
753 %property(BottomRight, GetBottomRight, SetBottomRight, doc="See `GetBottomRight` and `SetBottomRight`");
754 %property(BottomLeft, GetBottomLeft, SetBottomLeft, doc="See `GetBottomLeft` and `SetBottomLeft`");
755 %property(Height, GetHeight, SetHeight, doc="See `GetHeight` and `SetHeight`");
756 %property(Left, GetLeft, SetLeft, doc="See `GetLeft` and `SetLeft`");
757 %property(Position, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`");
758 %property(Right, GetRight, SetRight, doc="See `GetRight` and `SetRight`");
759 %property(Size, GetSize, SetSize, doc="See `GetSize` and `SetSize`");
760 %property(Top, GetTop, SetTop, doc="See `GetTop` and `SetTop`");
761 %property(TopLeft, GetTopLeft, SetTopLeft, doc="See `GetTopLeft` and `SetTopLeft`");
762 %property(TopRight, GetTopRight, SetTopRight, doc="See `GetTopRight` and `SetTopRight`");
763 %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`");
764 %property(X, GetX, SetX, doc="See `GetX` and `SetX`");
765 %property(Y, GetY, SetY, doc="See `GetY` and `SetY`");
766
767 %property(Empty, IsEmpty, doc="See `IsEmpty`");
768};
769
770
771MustHaveApp(wxIntersectRect);
772
773DocAStr(wxIntersectRect,
774 "IntersectRect(Rect r1, Rect r2) -> Rect",
775 "Calculate and return the intersection of r1 and r2.", "");
776%inline %{
777 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
778 wxRegion reg1(*r1);
779 wxRegion reg2(*r2);
780 wxRect dest(0,0,0,0);
781 PyObject* obj;
782
783 reg1.Intersect(reg2);
784 dest = reg1.GetBox();
785
786 if (dest != wxRect(0,0,0,0)) {
787 wxPyBlock_t blocked = wxPyBeginBlockThreads();
788 wxRect* newRect = new wxRect(dest);
789 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true);
790 wxPyEndBlockThreads(blocked);
791 return obj;
792 }
793 Py_INCREF(Py_None);
794 return Py_None;
795 }
796%}
797
798//---------------------------------------------------------------------------
799%newgroup
800
801
802DocStr(wxPoint2D,
803 "wx.Point2Ds represent a point or a vector in a 2d coordinate system
804with floating point values.", "");
805
806class wxPoint2D
807{
808public:
809 DocStr(wxPoint2D, "Create a w.Point2D object.", "");
810 wxPoint2D( double x=0.0 , double y=0.0 );
811 %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt ));
812 %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt ));
813
814 DocDeclAStr(
815 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
816 "GetFloor() -> (x,y)",
817 "Convert to integer", "");
818
819 DocDeclAStr(
820 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
821 "GetRounded() -> (x,y)",
822 "Convert to integer", "");
823
824 double GetVectorLength() const;
825 double GetVectorAngle() const ;
826 void SetVectorLength( double length );
827 void SetVectorAngle( double degrees );
828
829 // LinkError: void SetPolarCoordinates( double angle , double length );
830 // LinkError: void Normalize();
831 %pythoncode {
832 def SetPolarCoordinates(self, angle, length):
833 self.SetVectorLength(length)
834 self.SetVectorAngle(angle)
835 def Normalize(self):
836 self.SetVectorLength(1.0)
837 }
838
839 double GetDistance( const wxPoint2D &pt ) const;
840 double GetDistanceSquare( const wxPoint2D &pt ) const;
841 double GetDotProduct( const wxPoint2D &vec ) const;
842 double GetCrossProduct( const wxPoint2D &vec ) const;
843
844 DocDeclStr(
845 wxPoint2D, operator-(),
846 "the reflection of this point", "");
847
848 wxPoint2D& operator+=(const wxPoint2D& pt);
849 wxPoint2D& operator-=(const wxPoint2D& pt);
850
851 wxPoint2D& operator*=(const wxPoint2D& pt);
852 wxPoint2D& operator/=(const wxPoint2D& pt);
853
854 %extend {
855 KeepGIL(__eq__);
856 DocStr(__eq__, "Test for equality of wx.Point2D objects.", "");
857 bool __eq__(PyObject* other) {
858 wxPoint2D temp, *obj = &temp;
859 if ( other == Py_None ) return false;
860 if ( ! wxPoint2D_helper(other, &obj) ) {
861 PyErr_Clear();
862 return false;
863 }
864 return self->operator==(*obj);
865 }
866
867
868 KeepGIL(__ne__);
869 DocStr(__ne__, "Test for inequality of wx.Point2D objects.", "");
870 bool __ne__(PyObject* other) {
871 wxPoint2D temp, *obj = &temp;
872 if ( other == Py_None ) return true;
873 if ( ! wxPoint2D_helper(other, &obj)) {
874 PyErr_Clear();
875 return true;
876 }
877 return self->operator!=(*obj);
878 }
879 }
880
881 %Rename(x, double, m_x);
882 %Rename(y, double, m_y);
883
884 %extend {
885 void Set( double x=0 , double y=0 ) {
886 self->m_x = x;
887 self->m_y = y;
888 }
889
890 DocAStr(Get,
891 "Get() -> (x,y)",
892 "Return x and y properties as a tuple.", "");
893 PyObject* Get() {
894 wxPyBlock_t blocked = wxPyBeginBlockThreads();
895 PyObject* tup = PyTuple_New(2);
896 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
897 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
898 wxPyEndBlockThreads(blocked);
899 return tup;
900 }
901 }
902
903 %pythoncode {
904 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
905 def __str__(self): return str(self.Get())
906 def __repr__(self): return 'wx.Point2D'+str(self.Get())
907 def __len__(self): return len(self.Get())
908 def __getitem__(self, index): return self.Get()[index]
909 def __setitem__(self, index, val):
910 if index == 0: self.x = val
911 elif index == 1: self.y = val
912 else: raise IndexError
913 def __nonzero__(self): return self.Get() != (0.0, 0.0)
914 __safe_for_unpickling__ = True
915 def __reduce__(self): return (wx.Point2D, self.Get())
916 }
917
918 %property(Floor, GetFloor, doc="See `GetFloor`");
919 %property(Rounded, GetRounded, doc="See `GetRounded`");
920 %property(VectorAngle, GetVectorAngle, SetVectorAngle, doc="See `GetVectorAngle` and `SetVectorAngle`");
921 %property(VectorLength, GetVectorLength, SetVectorLength, doc="See `GetVectorLength` and `SetVectorLength`");
922
923};
924
925
926//---------------------------------------------------------------------------
927
928%immutable;
929const wxPoint wxDefaultPosition;
930const wxSize wxDefaultSize;
931%mutable;
932
933//---------------------------------------------------------------------------