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