]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_gdicmn.i
IsVisible --> IsShownOnScreen
[wxWidgets.git] / wxPython / src / _gdicmn.i
CommitLineData
d14a1e28
RD
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,
d14a1e28 24 wxBITMAP_TYPE_ICO,
d14a1e28 25 wxBITMAP_TYPE_CUR,
d14a1e28
RD
26 wxBITMAP_TYPE_XBM,
27 wxBITMAP_TYPE_XBM_DATA,
28 wxBITMAP_TYPE_XPM,
29 wxBITMAP_TYPE_XPM_DATA,
30 wxBITMAP_TYPE_TIF,
d14a1e28 31 wxBITMAP_TYPE_GIF,
d14a1e28 32 wxBITMAP_TYPE_PNG,
d14a1e28 33 wxBITMAP_TYPE_JPEG,
d14a1e28 34 wxBITMAP_TYPE_PNM,
d14a1e28 35 wxBITMAP_TYPE_PCX,
d14a1e28 36 wxBITMAP_TYPE_PICT,
d14a1e28 37 wxBITMAP_TYPE_ICON,
d14a1e28
RD
38 wxBITMAP_TYPE_ANI,
39 wxBITMAP_TYPE_IFF,
40 wxBITMAP_TYPE_MACCURSOR,
64e8a1f0
RD
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
d14a1e28
RD
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
d14a1e28 113
dd9f7fea 114DocStr( wxSize,
d07d2bc9 115"wx.Size is a useful data structure used to represent the size of
bea992c8
RD
116something. It simply contains integer width and height
117properties. In most places in wxPython where a wx.Size is
1b8c7ba6 118expected a (width, height) tuple can be used instead.", "");
dd9f7fea 119
d14a1e28
RD
120class wxSize
121{
122public:
1b8c7ba6
RD
123 %Rename(width, int, x);
124 %Rename(height,int, y);
61c5a8ac
RD
125 %pythoncode { x = width; y = height }
126
dd9f7fea
RD
127 DocCtorStr(
128 wxSize(int w=0, int h=0),
d07d2bc9 129 "Creates a size object.", "");
dd9f7fea 130
d14a1e28
RD
131 ~wxSize();
132
1fce4e96
RD
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 }
dd9f7fea 146
1fce4e96
RD
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 }
d14a1e28 160
dd9f7fea
RD
161 DocDeclStr(
162 wxSize, operator+(const wxSize& sz),
d07d2bc9 163 "Add sz's proprties to this and return the result.", "");
d14a1e28 164
dd9f7fea
RD
165 DocDeclStr(
166 wxSize, operator-(const wxSize& sz),
d07d2bc9 167 "Subtract sz's properties from this and return the result.", "");
d14a1e28 168
dd9f7fea
RD
169 DocDeclStr(
170 void, IncTo(const wxSize& sz),
d07d2bc9
RD
171 "Increments this object so that both of its dimensions are not less
172than the corresponding dimensions of the size.", "");
dd9f7fea
RD
173
174 DocDeclStr(
175 void, DecTo(const wxSize& sz),
d07d2bc9
RD
176 "Decrements this object so that both of its dimensions are not greater
177than the corresponding dimensions of the size.", "");
dd9f7fea 178
6aaca5ba
RD
179
180 DocDeclStr(
181 void , Scale(float xscale, float yscale),
182 "Scales the dimensions of this object by the given factors.", "");
183
dd9f7fea
RD
184 DocDeclStr(
185 void, Set(int w, int h),
d07d2bc9 186 "Set both width and height.", "");
dd9f7fea 187
d14a1e28
RD
188 void SetWidth(int w);
189 void SetHeight(int h);
190 int GetWidth() const;
191 int GetHeight() const;
192
93a163f6
RD
193
194 DocDeclStr(
195 bool , IsFullySpecified() const,
d07d2bc9 196 "Returns True if both components of the size are non-default values.", "");
93a163f6
RD
197
198
199 DocDeclStr(
200 void , SetDefaults(const wxSize& size),
d07d2bc9
RD
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.", "");
93a163f6
RD
203
204
dd9f7fea
RD
205 //int GetX() const;
206 //int GetY() const;
d14a1e28
RD
207
208 %extend {
dd9f7fea
RD
209 DocAStr(Get,
210 "Get() -> (width,height)",
d07d2bc9 211 "Returns the width and height properties as a tuple.", "");
dd9f7fea 212 PyObject* Get() {
6e6b3557 213 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
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));
da32eb53 217 wxPyEndBlockThreads(blocked);
d14a1e28
RD
218 return tup;
219 }
220 }
221 %pythoncode {
d07d2bc9 222 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
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]
d14a1e28
RD
227 def __setitem__(self, index, val):
228 if index == 0: self.width = val
229 elif index == 1: self.height = val
230 else: raise IndexError
dd9f7fea 231 def __nonzero__(self): return self.Get() != (0,0)
02376d73
RD
232 __safe_for_unpickling__ = True
233 def __reduce__(self): return (wx.Size, self.Get())
d14a1e28
RD
234 }
235
236};
237
238//---------------------------------------------------------------------------
239%newgroup
94d33c49 240
dd9f7fea 241DocStr( wxRealPoint,
d07d2bc9
RD
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.", "");
d14a1e28
RD
245class wxRealPoint
246{
247public:
248 double x;
249 double y;
250
dd9f7fea
RD
251 DocCtorStr(
252 wxRealPoint(double x=0.0, double y=0.0),
d07d2bc9 253 "Create a wx.RealPoint object", "");
dd9f7fea 254
d14a1e28
RD
255 ~wxRealPoint();
256
1fce4e96
RD
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 }
dd9f7fea 269
1fce4e96
RD
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 }
dd9f7fea
RD
283
284
285 DocDeclStr(
286 wxRealPoint, operator+(const wxRealPoint& pt),
d07d2bc9 287 "Add pt's proprties to this and return the result.", "");
dd9f7fea
RD
288
289 DocDeclStr(
290 wxRealPoint, operator-(const wxRealPoint& pt),
d07d2bc9 291 "Subtract pt's proprties from this and return the result", "");
d14a1e28 292
d14a1e28
RD
293
294 %extend {
d07d2bc9 295 DocStr(Set, "Set both the x and y properties", "");
d14a1e28
RD
296 void Set(double x, double y) {
297 self->x = x;
298 self->y = y;
299 }
dd9f7fea
RD
300
301 DocAStr(Get,
302 "Get() -> (x,y)",
d07d2bc9 303 "Return the x and y properties as a tuple. ", "");
dd9f7fea 304 PyObject* Get() {
6e6b3557 305 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
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));
da32eb53 309 wxPyEndBlockThreads(blocked);
d14a1e28
RD
310 return tup;
311 }
312 }
313
314 %pythoncode {
d07d2bc9 315 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
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]
d14a1e28 320 def __setitem__(self, index, val):
dd9f7fea
RD
321 if index == 0: self.x = val
322 elif index == 1: self.y = val
d14a1e28 323 else: raise IndexError
dd9f7fea 324 def __nonzero__(self): return self.Get() != (0.0, 0.0)
02376d73
RD
325 __safe_for_unpickling__ = True
326 def __reduce__(self): return (wx.RealPoint, self.Get())
d14a1e28
RD
327 }
328};
329
dd9f7fea 330
d14a1e28
RD
331//---------------------------------------------------------------------------
332%newgroup
94d33c49 333
d14a1e28 334
dd9f7fea 335DocStr(wxPoint,
d07d2bc9
RD
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.", "");
dd9f7fea 339
d14a1e28
RD
340class wxPoint
341{
342public:
343 int x, y;
344
dd9f7fea
RD
345 DocCtorStr(
346 wxPoint(int x=0, int y=0),
d07d2bc9 347 "Create a wx.Point object", "");
dd9f7fea 348
d14a1e28
RD
349 ~wxPoint();
350
dd9f7fea 351
1fce4e96
RD
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 }
d14a1e28 364
1fce4e96
RD
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 }
093d613e
RD
378
379
380// %nokwargs operator+;
381// %nokwargs operator-;
382// %nokwargs operator+=;
383// %nokwargs operator-=;
dd9f7fea
RD
384
385 DocDeclStr(
386 wxPoint, operator+(const wxPoint& pt),
d07d2bc9 387 "Add pt's proprties to this and return the result.", "");
d14a1e28 388
093d613e 389
dd9f7fea
RD
390 DocDeclStr(
391 wxPoint, operator-(const wxPoint& pt),
d07d2bc9 392 "Subtract pt's proprties from this and return the result", "");
dd9f7fea
RD
393
394
395 DocDeclStr(
396 wxPoint&, operator+=(const wxPoint& pt),
d07d2bc9 397 "Add pt to this object.", "");
dd9f7fea
RD
398
399 DocDeclStr(
400 wxPoint&, operator-=(const wxPoint& pt),
d07d2bc9 401 "Subtract pt from this object.", "");
dd9f7fea 402
093d613e
RD
403
404
405// DocDeclStr(
406// wxPoint, operator+(const wxSize& sz),
d07d2bc9 407// "Add sz to this Point and return the result.", "");
093d613e
RD
408
409// DocDeclStr(
410// wxPoint, operator-(const wxSize& sz),
d07d2bc9 411// "Subtract sz from this Point and return the result", "");
093d613e
RD
412
413
414// DocDeclStr(
415// wxPoint&, operator+=(const wxSize& sz),
d07d2bc9 416// "Add sz to this object.", "");
093d613e
RD
417
418// DocDeclStr(
419// wxPoint&, operator-=(const wxSize& sz),
d07d2bc9 420// "Subtract sz from this object.", "");
093d613e
RD
421
422
423
dd9f7fea 424
d14a1e28 425 %extend {
d07d2bc9 426 DocStr(Set, "Set both the x and y properties", "");
d14a1e28
RD
427 void Set(long x, long y) {
428 self->x = x;
429 self->y = y;
430 }
dd9f7fea
RD
431
432 DocAStr(Get,
433 "Get() -> (x,y)",
d07d2bc9 434 "Return the x and y properties as a tuple. ", "");
dd9f7fea 435 PyObject* Get() {
6e6b3557 436 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
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));
da32eb53 440 wxPyEndBlockThreads(blocked);
d14a1e28
RD
441 return tup;
442 }
443 }
444
445 %pythoncode {
d07d2bc9 446 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
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]
d14a1e28
RD
451 def __setitem__(self, index, val):
452 if index == 0: self.x = val
453 elif index == 1: self.y = val
454 else: raise IndexError
dd9f7fea 455 def __nonzero__(self): return self.Get() != (0,0)
02376d73
RD
456 __safe_for_unpickling__ = True
457 def __reduce__(self): return (wx.Point, self.Get())
d14a1e28
RD
458 }
459};
460
461//---------------------------------------------------------------------------
462%newgroup
94d33c49 463
d14a1e28 464
dd9f7fea 465DocStr(wxRect,
d07d2bc9
RD
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.", "");
dd9f7fea 469
d14a1e28
RD
470class wxRect
471{
472public:
dd9f7fea
RD
473 DocCtorStr(
474 wxRect(int x=0, int y=0, int width=0, int height=0),
d07d2bc9 475 "Create a new Rect object.", "");
dd9f7fea
RD
476
477 DocCtorStrName(
478 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
d07d2bc9 479 "Create a new Rect object from Points representing two corners.", "",
dd9f7fea
RD
480 RectPP);
481
482 DocCtorStrName(
483 wxRect(const wxPoint& pos, const wxSize& size),
d07d2bc9 484 "Create a new Rect from a position and size.", "",
dd9f7fea 485 RectPS);
7aada1e0
RD
486
487 DocCtorStrName(
488 wxRect(const wxSize& size),
489 "Create a new Rect from a size only.", "",
490 RectS);
491
d14a1e28
RD
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
c3fc056e
RD
512 bool IsEmpty() const;
513
3f0ff538
RD
514 wxPoint GetTopLeft() const;
515 void SetTopLeft(const wxPoint &p);
516 wxPoint GetBottomRight() const;
517 void SetBottomRight(const wxPoint &p);
518
519// wxPoint GetLeftTop() const;
520// void SetLeftTop(const wxPoint &p);
521// wxPoint GetRightBottom() const;
522// void SetRightBottom(const wxPoint &p);
523
d14a1e28
RD
524 int GetLeft() const;
525 int GetTop() const;
526 int GetBottom() const;
527 int GetRight() const;
528
529 void SetLeft(int left);
530 void SetRight(int right);
531 void SetTop(int top);
532 void SetBottom(int bottom);
533
dd9f7fea
RD
534 %pythoncode {
535 position = property(GetPosition, SetPosition)
536 size = property(GetSize, SetSize)
537 left = property(GetLeft, SetLeft)
538 right = property(GetRight, SetRight)
539 top = property(GetTop, SetTop)
540 bottom = property(GetBottom, SetBottom)
541 }
542
543 DocDeclStr(
544 wxRect&, Inflate(wxCoord dx, wxCoord dy),
ca30acad
RD
545 "Increases the size of the rectangle.
546
547The left border is moved farther left and the right border is moved
548farther right by ``dx``. The upper border is moved farther up and the
549bottom border is moved farther down by ``dy``. (Note the the width and
550height of the rectangle thus change by ``2*dx`` and ``2*dy``,
551respectively.) If one or both of ``dx`` and ``dy`` are negative, the
552opposite happens: the rectangle size decreases in the respective
553direction.
554
555The change is made to the rectangle inplace, if instead you need a
556copy that is inflated, preserving the original then make the copy
557first::
558
559 copy = wx.Rect(*original)
560 copy.Inflate(10,15)
561
562", "
563Inflating and deflating behaves *naturally*. Defined more precisely,
564that means:
565
566 * Real inflates (that is, ``dx`` and/or ``dy`` >= 0) are not
567 constrained. Thus inflating a rectangle can cause its upper left
568 corner to move into the negative numbers. (The versions prior to
569 2.5.4 forced the top left coordinate to not fall below (0, 0),
570 which implied a forced move of the rectangle.)
571
572 * Deflates are clamped to not reduce the width or height of the
573 rectangle below zero. In such cases, the top-left corner is
574 nonetheless handled properly. For example, a rectangle at (10,
575 10) with size (20, 40) that is inflated by (-15, -15) will
576 become located at (20, 25) at size (0, 10). Finally, observe
577 that the width and height are treated independently. In the
578 above example, the width is reduced by 20, whereas the height is
579 reduced by the full 30 (rather than also stopping at 20, when
580 the width reached zero).
581
582:see: `Deflate`
583");
dd9f7fea
RD
584
585 DocDeclStr(
586 wxRect&, Deflate(wxCoord dx, wxCoord dy),
ca30acad
RD
587 "Decrease the rectangle size. This method is the opposite of `Inflate`
588in that Deflate(a,b) is equivalent to Inflate(-a,-b). Please refer to
589`Inflate` for a full description.", "");
dd9f7fea
RD
590
591 DocDeclStrName(
592 void, Offset(wxCoord dx, wxCoord dy),
d07d2bc9
RD
593 "Moves the rectangle by the specified offset. If dx is positive, the
594rectangle is moved to the right, if dy is positive, it is moved to the
595bottom, otherwise it is moved to the left or top respectively.", "",
dd9f7fea
RD
596 OffsetXY);
597
598 DocDeclStr(
599 void, Offset(const wxPoint& pt),
096e3ea1 600 "Same as `OffsetXY` but uses dx,dy from Point", "");
dd9f7fea
RD
601
602 DocDeclStr(
9eefe9f0
RD
603 wxRect, Intersect(const wxRect& rect),
604 "Returns the intersectsion of this rectangle and rect.", "");
d14a1e28 605
9eefe9f0
RD
606 DocDeclStr(
607 wxRect , Union(const wxRect& rect),
608 "Returns the union of this rectangle and rect.", "");
609
610
dd9f7fea
RD
611 DocDeclStr(
612 wxRect, operator+(const wxRect& rect) const,
d07d2bc9 613 "Add the properties of rect to this rectangle and return the result.", "");
d14a1e28 614
dd9f7fea
RD
615 DocDeclStr(
616 wxRect&, operator+=(const wxRect& rect),
d07d2bc9 617 "Add the properties of rect to this rectangle, updating this rectangle.", "");
d14a1e28 618
1fce4e96
RD
619 %extend {
620 KeepGIL(__eq__);
621 DocStr(__eq__, "Test for equality of wx.Rect objects.", "");
622 bool __eq__(PyObject* other) {
623 wxRect temp, *obj = &temp;
624 if ( other == Py_None ) return false;
625 if ( ! wxRect_helper(other, &obj) ) {
626 PyErr_Clear();
627 return false;
628 }
629 return self->operator==(*obj);
630 }
d14a1e28 631
1fce4e96
RD
632
633 KeepGIL(__ne__);
634 DocStr(__ne__, "Test for inequality of wx.Rect objects.", "");
635 bool __ne__(PyObject* other) {
636 wxRect temp, *obj = &temp;
637 if ( other == Py_None ) return true;
638 if ( ! wxRect_helper(other, &obj)) {
639 PyErr_Clear();
640 return true;
641 }
642 return self->operator!=(*obj);
643 }
644 }
d14a1e28 645
dd9f7fea 646
d07d2bc9 647 DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.", "");
1b8c7ba6 648 %Rename(InsideXY, bool, Inside(int x, int y) const);
d14a1e28
RD
649 bool Inside(const wxPoint& pt) const;
650
8e1222c7
RD
651 DocDeclStrName(
652 bool, Inside(const wxRect& rect) const,
653 "Returns ``True`` if the given rectangle is completely inside this
654rectangle or touches its boundary.", "",
655 InsideRect);
656
dd9f7fea
RD
657 DocDeclStr(
658 bool, Intersects(const wxRect& rect) const,
d07d2bc9 659 "Returns True if the rectangles have a non empty intersection.", "");
d14a1e28 660
096e3ea1
RD
661 DocDeclStr(
662 wxRect, CenterIn(const wxRect& r, int dir = wxBOTH),
663 "Center this rectangle within the one passed to the method, which is
664usually, but not necessarily, the larger one.", "");
665 %pythoncode { CentreIn = CenterIn }
666
dd9f7fea 667
d14a1e28
RD
668 int x, y, width, height;
669
670
671 %extend {
d07d2bc9 672 DocStr(Set, "Set all rectangle properties.", "");
dd9f7fea 673 void Set(int x=0, int y=0, int width=0, int height=0) {
d14a1e28
RD
674 self->x = x;
675 self->y = y;
676 self->width = width;
677 self->height = height;
678 }
679
dd9f7fea
RD
680 DocAStr(Get,
681 "Get() -> (x,y,width,height)",
d07d2bc9 682 "Return the rectangle properties as a tuple.", "");
dd9f7fea 683 PyObject* Get() {
6e6b3557 684 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
685 PyObject* tup = PyTuple_New(4);
686 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
687 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
688 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
689 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
da32eb53 690 wxPyEndBlockThreads(blocked);
d14a1e28
RD
691 return tup;
692 }
693 }
694
695 %pythoncode {
d07d2bc9 696 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
697 def __str__(self): return str(self.Get())
698 def __repr__(self): return 'wx.Rect'+str(self.Get())
699 def __len__(self): return len(self.Get())
700 def __getitem__(self, index): return self.Get()[index]
d14a1e28
RD
701 def __setitem__(self, index, val):
702 if index == 0: self.x = val
703 elif index == 1: self.y = val
704 elif index == 2: self.width = val
705 elif index == 3: self.height = val
706 else: raise IndexError
dd9f7fea 707 def __nonzero__(self): return self.Get() != (0,0,0,0)
02376d73
RD
708 __safe_for_unpickling__ = True
709 def __reduce__(self): return (wx.Rect, self.Get())
d14a1e28 710 }
7012bb9f
RD
711
712
713 %property(Bottom, GetBottom, SetBottom, doc="See `GetBottom` and `SetBottom`");
714 %property(BottomRight, GetBottomRight, SetBottomRight, doc="See `GetBottomRight` and `SetBottomRight`");
715 %property(Height, GetHeight, SetHeight, doc="See `GetHeight` and `SetHeight`");
716 %property(Left, GetLeft, SetLeft, doc="See `GetLeft` and `SetLeft`");
717 %property(Position, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`");
718 %property(Right, GetRight, SetRight, doc="See `GetRight` and `SetRight`");
719 %property(Size, GetSize, SetSize, doc="See `GetSize` and `SetSize`");
720 %property(Top, GetTop, SetTop, doc="See `GetTop` and `SetTop`");
721 %property(TopLeft, GetTopLeft, SetTopLeft, doc="See `GetTopLeft` and `SetTopLeft`");
722 %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`");
723 %property(X, GetX, SetX, doc="See `GetX` and `SetX`");
724 %property(Y, GetY, SetY, doc="See `GetY` and `SetY`");
725
726 %property(Empty, IsEmpty, doc="See `IsEmpty`");
d14a1e28
RD
727};
728
729
ab1f7d2a
RD
730MustHaveApp(wxIntersectRect);
731
dd9f7fea
RD
732DocAStr(wxIntersectRect,
733 "IntersectRect(Rect r1, Rect r2) -> Rect",
d07d2bc9 734 "Calculate and return the intersection of r1 and r2.", "");
d14a1e28
RD
735%inline %{
736 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
737 wxRegion reg1(*r1);
738 wxRegion reg2(*r2);
739 wxRect dest(0,0,0,0);
740 PyObject* obj;
741
742 reg1.Intersect(reg2);
743 dest = reg1.GetBox();
744
745 if (dest != wxRect(0,0,0,0)) {
6e6b3557 746 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28 747 wxRect* newRect = new wxRect(dest);
a72f4631 748 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true);
da32eb53 749 wxPyEndBlockThreads(blocked);
d14a1e28
RD
750 return obj;
751 }
752 Py_INCREF(Py_None);
753 return Py_None;
754 }
755%}
756
757//---------------------------------------------------------------------------
758%newgroup
94d33c49 759
d14a1e28 760
dd9f7fea 761DocStr(wxPoint2D,
d07d2bc9
RD
762 "wx.Point2Ds represent a point or a vector in a 2d coordinate system
763with floating point values.", "");
d14a1e28
RD
764
765class wxPoint2D
766{
dd9f7fea 767public:
d07d2bc9 768 DocStr(wxPoint2D, "Create a w.Point2D object.", "");
d14a1e28 769 wxPoint2D( double x=0.0 , double y=0.0 );
1b8c7ba6
RD
770 %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt ));
771 %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt ));
d14a1e28 772
dd9f7fea
RD
773 DocDeclAStr(
774 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
775 "GetFloor() -> (x,y)",
d07d2bc9 776 "Convert to integer", "");
dd9f7fea
RD
777
778 DocDeclAStr(
779 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
780 "GetRounded() -> (x,y)",
d07d2bc9 781 "Convert to integer", "");
d14a1e28
RD
782
783 double GetVectorLength() const;
784 double GetVectorAngle() const ;
785 void SetVectorLength( double length );
786 void SetVectorAngle( double degrees );
dd9f7fea 787
d14a1e28
RD
788 // LinkError: void SetPolarCoordinates( double angle , double length );
789 // LinkError: void Normalize();
790 %pythoncode {
791 def SetPolarCoordinates(self, angle, length):
792 self.SetVectorLength(length)
793 self.SetVectorAngle(angle)
794 def Normalize(self):
795 self.SetVectorLength(1.0)
796 }
797
798 double GetDistance( const wxPoint2D &pt ) const;
799 double GetDistanceSquare( const wxPoint2D &pt ) const;
800 double GetDotProduct( const wxPoint2D &vec ) const;
801 double GetCrossProduct( const wxPoint2D &vec ) const;
802
dd9f7fea
RD
803 DocDeclStr(
804 wxPoint2D, operator-(),
d07d2bc9 805 "the reflection of this point", "");
d14a1e28
RD
806
807 wxPoint2D& operator+=(const wxPoint2D& pt);
808 wxPoint2D& operator-=(const wxPoint2D& pt);
809
810 wxPoint2D& operator*=(const wxPoint2D& pt);
811 wxPoint2D& operator/=(const wxPoint2D& pt);
812
1fce4e96
RD
813 %extend {
814 KeepGIL(__eq__);
815 DocStr(__eq__, "Test for equality of wx.Point2D objects.", "");
816 bool __eq__(PyObject* other) {
817 wxPoint2D temp, *obj = &temp;
818 if ( other == Py_None ) return false;
819 if ( ! wxPoint2D_helper(other, &obj) ) {
820 PyErr_Clear();
821 return false;
822 }
823 return self->operator==(*obj);
824 }
825
826
827 KeepGIL(__ne__);
828 DocStr(__ne__, "Test for inequality of wx.Point2D objects.", "");
829 bool __ne__(PyObject* other) {
830 wxPoint2D temp, *obj = &temp;
831 if ( other == Py_None ) return true;
832 if ( ! wxPoint2D_helper(other, &obj)) {
833 PyErr_Clear();
834 return true;
835 }
836 return self->operator!=(*obj);
837 }
838 }
d14a1e28 839
1b8c7ba6
RD
840 %Rename(x, double, m_x);
841 %Rename(y, double, m_y);
d14a1e28
RD
842
843 %extend {
844 void Set( double x=0 , double y=0 ) {
845 self->m_x = x;
846 self->m_y = y;
847 }
dd9f7fea
RD
848
849 DocAStr(Get,
850 "Get() -> (x,y)",
d07d2bc9 851 "Return x and y properties as a tuple.", "");
dd9f7fea 852 PyObject* Get() {
6e6b3557 853 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
854 PyObject* tup = PyTuple_New(2);
855 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
856 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
da32eb53 857 wxPyEndBlockThreads(blocked);
d14a1e28
RD
858 return tup;
859 }
860 }
861
862 %pythoncode {
d07d2bc9 863 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
dd9f7fea
RD
864 def __str__(self): return str(self.Get())
865 def __repr__(self): return 'wx.Point2D'+str(self.Get())
866 def __len__(self): return len(self.Get())
867 def __getitem__(self, index): return self.Get()[index]
d14a1e28 868 def __setitem__(self, index, val):
dd9f7fea
RD
869 if index == 0: self.x = val
870 elif index == 1: self.y = val
d14a1e28 871 else: raise IndexError
dd9f7fea 872 def __nonzero__(self): return self.Get() != (0.0, 0.0)
02376d73
RD
873 __safe_for_unpickling__ = True
874 def __reduce__(self): return (wx.Point2D, self.Get())
d14a1e28 875 }
7012bb9f
RD
876
877 %property(Floor, GetFloor, doc="See `GetFloor`");
878 %property(Rounded, GetRounded, doc="See `GetRounded`");
879 %property(VectorAngle, GetVectorAngle, SetVectorAngle, doc="See `GetVectorAngle` and `SetVectorAngle`");
880 %property(VectorLength, GetVectorLength, SetVectorLength, doc="See `GetVectorLength` and `SetVectorLength`");
881
d14a1e28
RD
882};
883
884
885//---------------------------------------------------------------------------
886
887%immutable;
888const wxPoint wxDefaultPosition;
889const wxSize wxDefaultSize;
890%mutable;
891
892//---------------------------------------------------------------------------