]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _dc.i | |
3 | // Purpose: SWIG interface defs for wxDC and releated classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 7-July-1997 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
4942342c | 16 | |
d14a1e28 RD |
17 | //--------------------------------------------------------------------------- |
18 | ||
19 | %{ | |
20 | #include "wx/wxPython/pydrawxxx.h" | |
21 | %} | |
22 | ||
23 | // TODO: 1. wrappers for wxDrawObject and wxDC::DrawObject | |
24 | ||
25 | ||
26 | //--------------------------------------------------------------------------- | |
27 | ||
28 | %typemap(in) (int points, wxPoint* points_array ) { | |
29 | $2 = wxPoint_LIST_helper($input, &$1); | |
30 | if ($2 == NULL) SWIG_fail; | |
31 | } | |
32 | %typemap(freearg) (int points, wxPoint* points_array ) { | |
33 | if ($2) delete [] $2; | |
34 | } | |
35 | ||
36 | ||
37 | //--------------------------------------------------------------------------- | |
38 | %newgroup; | |
39 | ||
40 | ||
41 | // wxDC is the device context - object on which any drawing is done | |
42 | class wxDC : public wxObject { | |
43 | public: | |
44 | // wxDC(); **** abstract base class, can't instantiate. | |
45 | ~wxDC(); | |
46 | ||
47 | ||
48 | virtual void BeginDrawing(); | |
49 | virtual void EndDrawing(); | |
50 | ||
51 | ||
52 | // virtual void DrawObject(wxDrawObject* drawobject); | |
53 | ||
54 | ||
55 | ||
4942342c | 56 | #if defined(wxUSE_DC_OLD_METHODS) |
d14a1e28 RD |
57 | |
58 | bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE); | |
59 | //bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const; | |
60 | %extend { | |
61 | wxColour GetPixel(wxCoord x, wxCoord y) { | |
62 | wxColour col; | |
63 | self->GetPixel(x, y, &col); | |
64 | return col; | |
65 | } | |
66 | } | |
67 | void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
68 | void CrossHair(wxCoord x, wxCoord y); | |
69 | void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc); | |
70 | void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
71 | void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea); | |
72 | void DrawPoint(wxCoord x, wxCoord y); | |
73 | void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
74 | %name(DrawRectangleRect)void DrawRectangle(const wxRect& rect); | |
75 | void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius); | |
76 | void DrawCircle(wxCoord x, wxCoord y, wxCoord radius); | |
77 | void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
78 | void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); | |
dd9f7fea | 79 | void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = False); |
d14a1e28 RD |
80 | void DrawText(const wxString& text, wxCoord x, wxCoord y); |
81 | void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle); | |
82 | bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
83 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
dd9f7fea | 84 | int rop = wxCOPY, bool useMask = False, |
d14a1e28 RD |
85 | wxCoord xsrcMask = -1, wxCoord ysrcMask = -1); |
86 | ||
87 | ||
88 | ||
89 | #else // The new way | |
4942342c | 90 | |
d14a1e28 RD |
91 | %name(FloodFillXY) bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE); |
92 | bool FloodFill(const wxPoint& pt, const wxColour& col, int style = wxFLOOD_SURFACE); | |
93 | ||
94 | //%name(GetPixelXY) bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const; | |
95 | //bool GetPixel(const wxPoint& pt, wxColour *col) const; | |
96 | %extend { | |
97 | wxColour GetPixelXY(wxCoord x, wxCoord y) { | |
98 | wxColour col; | |
99 | self->GetPixel(x, y, &col); | |
100 | return col; | |
101 | } | |
102 | wxColour GetPixel(const wxPoint& pt) { | |
103 | wxColour col; | |
104 | self->GetPixel(pt, &col); | |
105 | return col; | |
106 | } | |
107 | } | |
108 | %name(DrawLineXY) void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
109 | void DrawLine(const wxPoint& pt1, const wxPoint& pt2); | |
110 | ||
111 | %name(CrossHairXY) void CrossHair(wxCoord x, wxCoord y); | |
112 | void CrossHair(const wxPoint& pt); | |
113 | ||
114 | %name(DrawArcXY) void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc); | |
115 | void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre); | |
116 | ||
117 | %name(DrawCheckMarkXY) void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
118 | void DrawCheckMark(const wxRect& rect); | |
119 | ||
120 | %name(DrawEllipticArcXY) void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea); | |
121 | void DrawEllipticArc(const wxPoint& pt, const wxSize& sz, double sa, double ea); | |
122 | ||
123 | %name(DrawPointXY) void DrawPoint(wxCoord x, wxCoord y); | |
124 | void DrawPoint(const wxPoint& pt); | |
125 | ||
126 | %name(DrawRectangleXY) void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
127 | void DrawRectangle(const wxPoint& pt, const wxSize& sz); | |
128 | %name(DrawRectangleRect) void DrawRectangle(const wxRect& rect); | |
129 | ||
130 | %name(DrawRoundedRectangleXY) void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius); | |
131 | void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius); | |
132 | %name(DrawRoundedRectangleRect) void DrawRoundedRectangle(const wxRect& r, double radius); | |
133 | ||
134 | %name(DrawCircleXY) void DrawCircle(wxCoord x, wxCoord y, wxCoord radius); | |
135 | void DrawCircle(const wxPoint& pt, wxCoord radius); | |
136 | ||
137 | %name(DrawEllipseXY) void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
138 | void DrawEllipse(const wxPoint& pt, const wxSize& sz); | |
139 | %name(DrawEllipseRect) void DrawEllipse(const wxRect& rect); | |
140 | ||
141 | %name(DrawIconXY) void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); | |
142 | void DrawIcon(const wxIcon& icon, const wxPoint& pt); | |
143 | ||
dd9f7fea RD |
144 | %name(DrawBitmapXY) void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = False); |
145 | void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, bool useMask = False); | |
d14a1e28 RD |
146 | |
147 | %name(DrawTextXY) void DrawText(const wxString& text, wxCoord x, wxCoord y); | |
148 | void DrawText(const wxString& text, const wxPoint& pt); | |
149 | ||
150 | %name(DrawRotatedTextXY) void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle); | |
151 | void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle); | |
152 | ||
4942342c | 153 | |
d14a1e28 RD |
154 | %name(BlitXY) bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
155 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
dd9f7fea | 156 | int rop = wxCOPY, bool useMask = False, |
d14a1e28 | 157 | wxCoord xsrcMask = -1, wxCoord ysrcMask = -1); |
4942342c | 158 | bool Blit(const wxPoint& destPt, const wxSize& sz, |
d14a1e28 | 159 | wxDC *source, const wxPoint& srcPt, |
dd9f7fea | 160 | int rop = wxCOPY, bool useMask = False, |
d14a1e28 RD |
161 | const wxPoint& srcPtMask = wxDefaultPosition); |
162 | ||
163 | #endif | |
4942342c | 164 | |
d14a1e28 RD |
165 | void DrawLines(int points, wxPoint* points_array, wxCoord xoffset = 0, wxCoord yoffset = 0); |
166 | ||
167 | void DrawPolygon(int points, wxPoint* points_array, | |
168 | wxCoord xoffset = 0, wxCoord yoffset = 0, | |
169 | int fillStyle = wxODDEVEN_RULE); | |
170 | ||
b159c5c4 RD |
171 | // TODO: Figure out what the start parameter means and devise a |
172 | // good typemap for this | |
173 | //void DrawPolyPolygon(int n, int start[], wxPoint points[], | |
174 | // wxCoord xoffset = 0, wxCoord yoffset = 0, | |
175 | // int fillStyle = wxODDEVEN_RULE) | |
d14a1e28 RD |
176 | |
177 | // this version puts both optional bitmap and the text into the given | |
178 | // rectangle and aligns is as specified by alignment parameter; it also | |
179 | // will emphasize the character with the given index if it is != -1 and | |
180 | // return the bounding rectangle if required | |
181 | void DrawLabel(const wxString& text, const wxRect& rect, | |
182 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
183 | int indexAccel = -1); | |
184 | %extend { | |
185 | wxRect DrawImageLabel(const wxString& text, | |
186 | const wxBitmap& image, | |
187 | const wxRect& rect, | |
188 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
189 | int indexAccel = -1) { | |
190 | wxRect rv; | |
191 | self->DrawLabel(text, image, rect, alignment, indexAccel, &rv); | |
192 | return rv; | |
193 | } | |
194 | } | |
195 | ||
196 | ||
197 | ||
198 | void DrawSpline(int points, wxPoint* points_array); | |
199 | ||
200 | ||
4942342c | 201 | |
d14a1e28 RD |
202 | // global DC operations |
203 | // -------------------- | |
204 | ||
205 | virtual void Clear(); | |
206 | ||
207 | virtual bool StartDoc(const wxString& message); | |
208 | virtual void EndDoc(); | |
209 | ||
210 | virtual void StartPage(); | |
211 | virtual void EndPage(); | |
212 | ||
4942342c | 213 | |
d14a1e28 RD |
214 | // set objects to use for drawing |
215 | // ------------------------------ | |
216 | ||
217 | virtual void SetFont(const wxFont& font); | |
218 | virtual void SetPen(const wxPen& pen); | |
219 | virtual void SetBrush(const wxBrush& brush); | |
220 | virtual void SetBackground(const wxBrush& brush); | |
221 | virtual void SetBackgroundMode(int mode); | |
222 | virtual void SetPalette(const wxPalette& palette); | |
223 | ||
4942342c | 224 | |
d14a1e28 RD |
225 | // clipping region |
226 | // --------------- | |
227 | ||
4da6d35e RD |
228 | %name(SetClippingRegionXY)void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
229 | void SetClippingRegion(const wxPoint& pt, const wxSize& sz); | |
d14a1e28 RD |
230 | %name(SetClippingRect) void SetClippingRegion(const wxRect& rect); |
231 | %name(SetClippingRegionAsRegion) void SetClippingRegion(const wxRegion& region); | |
232 | ||
233 | virtual void DestroyClippingRegion(); | |
234 | ||
322913ce RD |
235 | DocDeclA( |
236 | void, GetClippingBox(wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT) const, | |
237 | "GetClippingBox() -> (x, y, width, height)"); | |
4942342c | 238 | |
d14a1e28 RD |
239 | %extend { |
240 | wxRect GetClippingRect() { | |
241 | wxRect rect; | |
242 | self->GetClippingBox(rect); | |
243 | return rect; | |
244 | } | |
245 | } | |
d14a1e28 | 246 | |
4942342c RD |
247 | |
248 | ||
d14a1e28 RD |
249 | // text extent |
250 | // ----------- | |
251 | ||
252 | virtual wxCoord GetCharHeight() const; | |
253 | virtual wxCoord GetCharWidth() const; | |
254 | ||
d14a1e28 | 255 | |
322913ce RD |
256 | DocDeclAStr( |
257 | void, GetTextExtent(const wxString& string, wxCoord *OUTPUT, wxCoord *OUTPUT), | |
258 | "GetTextExtent(wxString string) -> (width, height)", | |
259 | "Get the width and height of the text using the current font.\n" | |
260 | "Only works for single line strings."); | |
261 | DocDeclAStrName( | |
262 | void, GetTextExtent(const wxString& string, | |
4942342c | 263 | wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord* OUTPUT, |
322913ce RD |
264 | wxFont* font = NULL), |
265 | "GetFullTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)", | |
266 | "Get the width, height, decent and leading of the text using the current or specified font.\n" | |
267 | "Only works for single line strings.", | |
268 | GetFullTextExtent); | |
269 | ||
4942342c | 270 | |
322913ce RD |
271 | // works for single as well as multi-line strings |
272 | DocDeclAStr( | |
273 | void, GetMultiLineTextExtent(const wxString& text, | |
274 | wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, | |
275 | wxFont *font = NULL), | |
276 | "GetMultiLineTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)", | |
277 | "Get the width, height, decent and leading of the text using the current or specified font.\n" | |
278 | "Works for single as well as multi-line strings."); | |
279 | ||
746ee6b8 RD |
280 | |
281 | %extend { | |
282 | wxArrayInt GetPartialTextExtents(const wxString& text) { | |
283 | wxArrayInt widths; | |
284 | self->GetPartialTextExtents(text, widths); | |
285 | return widths; | |
286 | } | |
287 | } | |
288 | ||
d14a1e28 RD |
289 | |
290 | // size and resolution | |
291 | // ------------------- | |
292 | ||
322913ce | 293 | DocStr(GetSize, "Get the DC size in device units."); |
d14a1e28 | 294 | wxSize GetSize(); |
322913ce RD |
295 | DocDeclAName( |
296 | void, GetSize( int *OUTPUT, int *OUTPUT ), | |
297 | "GetSizeTuple() -> (width, height)", | |
298 | GetSizeTuple); | |
4942342c | 299 | |
d14a1e28 | 300 | |
322913ce | 301 | DocStr(GetSizeMM, "Get the DC size in milimeters."); |
d14a1e28 | 302 | wxSize GetSizeMM() const; |
322913ce RD |
303 | DocDeclAName( |
304 | void, GetSizeMM( int *OUTPUT, int *OUTPUT ) const, | |
305 | "GetSizeMMTuple() -> (width, height)", | |
306 | GetSizeMMTuple); | |
4942342c RD |
307 | |
308 | ||
d14a1e28 RD |
309 | |
310 | // coordinates conversions | |
311 | // ----------------------- | |
312 | ||
313 | // This group of functions does actual conversion of the input, as you'd | |
314 | // expect. | |
315 | wxCoord DeviceToLogicalX(wxCoord x) const; | |
316 | wxCoord DeviceToLogicalY(wxCoord y) const; | |
317 | wxCoord DeviceToLogicalXRel(wxCoord x) const; | |
318 | wxCoord DeviceToLogicalYRel(wxCoord y) const; | |
319 | wxCoord LogicalToDeviceX(wxCoord x) const; | |
320 | wxCoord LogicalToDeviceY(wxCoord y) const; | |
321 | wxCoord LogicalToDeviceXRel(wxCoord x) const; | |
322 | wxCoord LogicalToDeviceYRel(wxCoord y) const; | |
323 | ||
324 | // query DC capabilities | |
325 | // --------------------- | |
326 | ||
327 | virtual bool CanDrawBitmap() const; | |
328 | virtual bool CanGetTextExtent() const; | |
329 | ||
330 | // colour depth | |
331 | virtual int GetDepth() const; | |
332 | ||
333 | // Resolution in Pixels per inch | |
334 | virtual wxSize GetPPI() const; | |
335 | ||
336 | virtual bool Ok() const; | |
337 | ||
4942342c | 338 | |
d14a1e28 RD |
339 | |
340 | int GetBackgroundMode() const; | |
341 | const wxBrush& GetBackground() const; | |
342 | const wxBrush& GetBrush() const; | |
343 | const wxFont& GetFont() const; | |
344 | const wxPen& GetPen() const; | |
345 | const wxColour& GetTextBackground() const; | |
346 | const wxColour& GetTextForeground() const; | |
347 | ||
348 | virtual void SetTextForeground(const wxColour& colour); | |
349 | virtual void SetTextBackground(const wxColour& colour); | |
350 | ||
351 | int GetMapMode() const; | |
352 | virtual void SetMapMode(int mode); | |
353 | ||
4942342c | 354 | |
322913ce RD |
355 | DocDeclA( |
356 | virtual void, GetUserScale(double *OUTPUT, double *OUTPUT) const, | |
357 | "GetUserScale() -> (xScale, yScale)"); | |
4942342c | 358 | |
d14a1e28 RD |
359 | virtual void SetUserScale(double x, double y); |
360 | ||
4942342c | 361 | |
322913ce RD |
362 | DocDeclA( |
363 | virtual void, GetLogicalScale(double *OUTPUT, double *OUTPUT), | |
364 | "GetLogicalScale() -> (xScale, yScale)"); | |
365 | ||
d14a1e28 RD |
366 | virtual void SetLogicalScale(double x, double y); |
367 | ||
322913ce | 368 | |
d14a1e28 | 369 | wxPoint GetLogicalOrigin() const; |
322913ce RD |
370 | DocDeclAName( |
371 | void, GetLogicalOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const, | |
372 | "GetLogicalOriginTuple() -> (x,y)", | |
373 | GetLogicalOriginTuple); | |
4942342c | 374 | |
d14a1e28 RD |
375 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); |
376 | ||
4942342c | 377 | |
d14a1e28 | 378 | wxPoint GetDeviceOrigin() const; |
322913ce RD |
379 | DocDeclAName( |
380 | void, GetDeviceOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const, | |
381 | "GetDeviceOriginTuple() -> (x,y)", | |
382 | GetDeviceOriginTuple); | |
4942342c | 383 | |
d14a1e28 RD |
384 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); |
385 | ||
386 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); | |
387 | ||
388 | int GetLogicalFunction() const; | |
389 | virtual void SetLogicalFunction(int function); | |
390 | ||
391 | virtual void SetOptimization(bool opt); | |
392 | virtual bool GetOptimization(); | |
4942342c | 393 | |
d14a1e28 RD |
394 | |
395 | // bounding box | |
396 | // ------------ | |
397 | ||
398 | virtual void CalcBoundingBox(wxCoord x, wxCoord y); | |
399 | void ResetBoundingBox(); | |
400 | ||
401 | // Get the final bounding box of the PostScript or Metafile picture. | |
402 | wxCoord MinX() const; | |
403 | wxCoord MaxX() const; | |
404 | wxCoord MinY() const; | |
405 | wxCoord MaxY() const; | |
406 | ||
407 | ||
322913ce RD |
408 | DocA(GetBoundingBox, |
409 | "GetBoundingBox() -> (x1,y1, x2,y2)"); | |
d14a1e28 RD |
410 | %extend { |
411 | void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT); | |
412 | // See below for implementation | |
4942342c | 413 | } |
d14a1e28 RD |
414 | %pythoncode { def __nonzero__(self): return self.Ok() }; |
415 | ||
416 | ||
417 | ||
418 | %extend { // See drawlist.cpp for impplementaion of these... | |
419 | PyObject* _DrawPointList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
420 | { | |
421 | return wxPyDrawXXXList(*self, wxPyDrawXXXPoint, pyCoords, pyPens, pyBrushes); | |
422 | } | |
423 | ||
424 | PyObject* _DrawLineList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
425 | { | |
426 | return wxPyDrawXXXList(*self, wxPyDrawXXXLine, pyCoords, pyPens, pyBrushes); | |
427 | } | |
428 | ||
429 | PyObject* _DrawRectangleList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
430 | { | |
431 | return wxPyDrawXXXList(*self, wxPyDrawXXXRectangle, pyCoords, pyPens, pyBrushes); | |
432 | } | |
433 | ||
434 | PyObject* _DrawEllipseList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
435 | { | |
436 | return wxPyDrawXXXList(*self, wxPyDrawXXXEllipse, pyCoords, pyPens, pyBrushes); | |
437 | } | |
438 | ||
439 | PyObject* _DrawPolygonList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
440 | { | |
441 | return wxPyDrawXXXList(*self, wxPyDrawXXXPolygon, pyCoords, pyPens, pyBrushes); | |
442 | } | |
443 | ||
444 | PyObject* _DrawTextList(PyObject* textList, PyObject* pyPoints, | |
445 | PyObject* foregroundList, PyObject* backgroundList) { | |
446 | return wxPyDrawTextList(*self, textList, pyPoints, foregroundList, backgroundList); | |
447 | } | |
448 | } | |
449 | ||
450 | %pythoncode { | |
451 | def DrawPointList(self, points, pens=None): | |
452 | if pens is None: | |
453 | pens = [] | |
454 | elif isinstance(pens, wx.Pen): | |
455 | pens = [pens] | |
456 | elif len(pens) != len(points): | |
457 | raise ValueError('points and pens must have same length') | |
458 | return self._DrawPointList(points, pens, []) | |
459 | ||
460 | ||
461 | def DrawLineList(self, lines, pens=None): | |
462 | if pens is None: | |
463 | pens = [] | |
464 | elif isinstance(pens, wx.Pen): | |
465 | pens = [pens] | |
466 | elif len(pens) != len(lines): | |
467 | raise ValueError('lines and pens must have same length') | |
468 | return self._DrawLineList(lines, pens, []) | |
469 | ||
470 | ||
471 | def DrawRectangleList(self, rectangles, pens=None, brushes=None): | |
472 | if pens is None: | |
473 | pens = [] | |
474 | elif isinstance(pens, wx.Pen): | |
475 | pens = [pens] | |
476 | elif len(pens) != len(rectangles): | |
477 | raise ValueError('rectangles and pens must have same length') | |
478 | if brushes is None: | |
479 | brushes = [] | |
480 | elif isinstance(brushes, wx.Brush): | |
481 | brushes = [brushes] | |
482 | elif len(brushes) != len(rectangles): | |
483 | raise ValueError('rectangles and brushes must have same length') | |
484 | return self._DrawRectangleList(rectangles, pens, brushes) | |
485 | ||
486 | ||
487 | def DrawEllipseList(self, ellipses, pens=None, brushes=None): | |
488 | if pens is None: | |
489 | pens = [] | |
490 | elif isinstance(pens, wx.Pen): | |
491 | pens = [pens] | |
492 | elif len(pens) != len(ellipses): | |
493 | raise ValueError('ellipses and pens must have same length') | |
494 | if brushes is None: | |
495 | brushes = [] | |
496 | elif isinstance(brushes, wx.Brush): | |
497 | brushes = [brushes] | |
498 | elif len(brushes) != len(ellipses): | |
499 | raise ValueError('ellipses and brushes must have same length') | |
500 | return self._DrawEllipseList(ellipses, pens, brushes) | |
501 | ||
502 | ||
503 | def DrawPolygonList(self, polygons, pens=None, brushes=None): | |
4942342c RD |
504 | %## Note: This does not currently support fill style or offset |
505 | %## you can always use the non-List version if need be. | |
d14a1e28 RD |
506 | if pens is None: |
507 | pens = [] | |
508 | elif isinstance(pens, wx.Pen): | |
509 | pens = [pens] | |
510 | elif len(pens) != len(polygons): | |
511 | raise ValueError('polygons and pens must have same length') | |
512 | if brushes is None: | |
513 | brushes = [] | |
514 | elif isinstance(brushes, wx.Brush): | |
515 | brushes = [brushes] | |
516 | elif len(brushes) != len(polygons): | |
517 | raise ValueError('polygons and brushes must have same length') | |
518 | return self._DrawPolygonList(polygons, pens, brushes) | |
519 | ||
520 | ||
521 | def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None, fonts = None): | |
4942342c RD |
522 | %## NOTE: this does not currently support changing the font |
523 | %## Make sure you set Background mode to wxSolid (DC.SetBackgroundMode) | |
524 | %## If you want backgounds to do anything. | |
d14a1e28 RD |
525 | if type(textList) == type(''): |
526 | textList = [textList] | |
527 | elif len(textList) != len(coords): | |
528 | raise ValueError('textlist and coords must have same length') | |
529 | if foregrounds is None: | |
530 | foregrounds = [] | |
fd3f2efe | 531 | elif isinstance(foregrounds, wx.Colour): |
d14a1e28 RD |
532 | foregrounds = [foregrounds] |
533 | elif len(foregrounds) != len(coords): | |
534 | raise ValueError('foregrounds and coords must have same length') | |
535 | if backgrounds is None: | |
536 | backgrounds = [] | |
fd3f2efe | 537 | elif isinstance(backgrounds, wx.Colour): |
d14a1e28 RD |
538 | backgrounds = [backgrounds] |
539 | elif len(backgrounds) != len(coords): | |
540 | raise ValueError('backgrounds and coords must have same length') | |
541 | return self._DrawTextList(textList, coords, foregrounds, backgrounds) | |
542 | } | |
543 | ||
544 | }; | |
545 | ||
546 | ||
547 | ||
548 | %{ | |
549 | static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) { | |
550 | *x1 = dc->MinX(); | |
551 | *y1 = dc->MinY(); | |
552 | *x2 = dc->MaxX(); | |
553 | *y2 = dc->MaxY(); | |
554 | } | |
555 | %} | |
556 | ||
557 | ||
558 | //--------------------------------------------------------------------------- | |
559 | %newgroup | |
560 | ||
561 | class wxMemoryDC : public wxDC { | |
562 | public: | |
563 | wxMemoryDC(); | |
564 | %name(MemoryDCFromDC) wxMemoryDC(wxDC* oldDC); | |
4942342c | 565 | |
d14a1e28 RD |
566 | void SelectObject(const wxBitmap& bitmap); |
567 | }; | |
568 | ||
569 | //--------------------------------------------------------------------------- | |
570 | %newgroup | |
571 | ||
b159c5c4 | 572 | |
ef22e3d3 RD |
573 | %{ |
574 | //-=-=-=-=-=-=-=-=-=-=- | |
575 | #if 0 | |
576 | #include <wx/dcbuffer.h> | |
577 | #else | |
578 | ||
579 | ||
580 | // Temporarily put a set of classes here similar to the old buffered DC | |
581 | // classes until the real ones can be fixed to work "correctly" again. | |
582 | ||
583 | class wxBufferedDC : public wxMemoryDC | |
584 | { | |
585 | private: | |
586 | wxDC *m_dc; | |
587 | wxBitmap m_buffer; | |
588 | ||
589 | public: | |
590 | ||
591 | wxBufferedDC() : m_dc( 0 ) {} | |
592 | ||
593 | wxBufferedDC( wxDC *dc, const wxBitmap &buffer ) | |
594 | : m_dc( dc ), m_buffer( buffer ) | |
595 | { | |
596 | SelectObject( m_buffer ); | |
597 | } | |
598 | ||
599 | wxBufferedDC( wxDC *dc, const wxSize &area ) | |
600 | : m_dc( dc ), m_buffer( area.GetWidth(), area.GetHeight() ) | |
601 | { | |
602 | SelectObject( m_buffer ); | |
603 | } | |
604 | ||
605 | ~wxBufferedDC() { | |
606 | if( m_dc != 0 ) | |
607 | UnMask(); | |
608 | } | |
609 | ||
610 | ||
611 | void Init( wxDC *dc, const wxBitmap &buffer ) { | |
612 | wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap, | |
613 | _T("wxBufferedDC already initialised") ); | |
614 | m_dc = dc; | |
615 | m_buffer = buffer; | |
616 | SelectObject( m_buffer ); | |
617 | } | |
618 | ||
619 | void Init( wxDC *dc, const wxSize &area ) { | |
620 | wxASSERT_MSG( m_dc == 0 && m_buffer == wxNullBitmap, | |
621 | _T("wxBufferedDC already initialised") ); | |
622 | m_dc = dc; | |
623 | m_buffer = wxBitmap( area.GetWidth(), area.GetHeight() ); | |
624 | SelectObject( m_buffer ); | |
625 | } | |
626 | ||
627 | void UnMask() { | |
628 | wxASSERT_MSG( m_dc != 0, _T("No low level DC associated with buffer (anymore)") ); | |
629 | m_dc->Blit( 0, 0, m_buffer.GetWidth(), m_buffer.GetHeight(), this, 0, 0 ); | |
630 | m_dc = 0; | |
631 | } | |
632 | }; | |
633 | ||
634 | ||
635 | class wxBufferedPaintDC : public wxBufferedDC | |
636 | { | |
637 | private: | |
638 | wxPaintDC m_paintdc; | |
639 | ||
640 | public: | |
641 | wxBufferedPaintDC( wxWindow *window, const wxBitmap &buffer = wxNullBitmap ) | |
642 | : m_paintdc( window ) | |
643 | { | |
644 | window->PrepareDC( m_paintdc ); | |
645 | ||
646 | if( buffer != wxNullBitmap ) | |
647 | Init( &m_paintdc, buffer ); | |
648 | else | |
649 | Init( &m_paintdc, window->GetClientSize() ); | |
650 | } | |
651 | ||
652 | ~wxBufferedPaintDC() { | |
653 | UnMask(); | |
654 | } | |
655 | }; | |
656 | ||
657 | #endif | |
658 | //-=-=-=-=-=-=-=-=-=-=- | |
659 | %} | |
660 | ||
661 | ||
662 | ||
663 | ||
d14a1e28 RD |
664 | class wxBufferedDC : public wxMemoryDC |
665 | { | |
666 | public: | |
e608d228 | 667 | %pythonAppend wxBufferedDC |
d14a1e28 | 668 | "self._dc = args[0] # save a ref so the other dc will not be deleted before self"; |
d14a1e28 | 669 | |
b159c5c4 RD |
670 | %nokwargs wxBufferedDC; |
671 | ||
d14a1e28 RD |
672 | // Construct a wxBufferedDC using a user supplied buffer. |
673 | wxBufferedDC( wxDC *dc, const wxBitmap &buffer ); | |
674 | ||
b159c5c4 RD |
675 | // Construct a wxBufferedDC with an internal buffer of 'area' |
676 | // (where area is usually something like the size of the window | |
677 | // being buffered) | |
7a0b15e9 | 678 | wxBufferedDC( wxDC *dc, const wxSize &area ); |
b159c5c4 | 679 | |
e608d228 | 680 | |
b159c5c4 | 681 | // TODO: Keep this one too? |
7a0b15e9 | 682 | %pythonAppend wxBufferedDC( wxDC *dc, const wxSize &area ) |
e608d228 | 683 | "val._dc = args[0] # save a ref so the other dc will not be deleted before self"; |
7a0b15e9 RD |
684 | %name(BufferedDCInternalBuffer) wxBufferedDC( wxDC *dc, const wxSize &area ); |
685 | ||
686 | ||
687 | // The buffer is blit to the real DC when the BufferedDC is destroyed. | |
688 | ~wxBufferedDC(); | |
d14a1e28 | 689 | |
e608d228 | 690 | |
b159c5c4 RD |
691 | // Blits the buffer to the dc, and detaches the dc from |
692 | // the buffer. Usually called in the dtor or by the dtor | |
693 | // of derived classes if the BufferedDC must blit before | |
694 | // the derived class (which may own the dc it's blitting | |
695 | // to) is destroyed. | |
d14a1e28 RD |
696 | void UnMask(); |
697 | }; | |
698 | ||
699 | ||
7a0b15e9 RD |
700 | |
701 | ||
702 | // Creates a double buffered wxPaintDC, optionally allowing the | |
703 | // user to specify their own buffer to use. | |
d14a1e28 RD |
704 | class wxBufferedPaintDC : public wxBufferedDC |
705 | { | |
706 | public: | |
b159c5c4 | 707 | |
ef22e3d3 | 708 | // If no bitmap is supplied by the user, a temporary one will be created. |
7a0b15e9 | 709 | wxBufferedPaintDC( wxWindow *window, const wxBitmap &buffer = wxNullBitmap ); |
b159c5c4 | 710 | |
d14a1e28 RD |
711 | }; |
712 | ||
713 | ||
714 | //--------------------------------------------------------------------------- | |
715 | %newgroup | |
716 | ||
717 | class wxScreenDC : public wxDC { | |
718 | public: | |
719 | wxScreenDC(); | |
720 | ||
721 | %name(StartDrawingOnTopWin) bool StartDrawingOnTop(wxWindow* window); | |
722 | bool StartDrawingOnTop(wxRect* rect = NULL); | |
723 | bool EndDrawingOnTop(); | |
724 | }; | |
725 | ||
726 | //--------------------------------------------------------------------------- | |
727 | %newgroup | |
728 | ||
729 | class wxClientDC : public wxDC { | |
730 | public: | |
731 | wxClientDC(wxWindow* win); | |
732 | }; | |
733 | ||
734 | //--------------------------------------------------------------------------- | |
735 | %newgroup | |
736 | ||
737 | class wxPaintDC : public wxDC { | |
738 | public: | |
739 | wxPaintDC(wxWindow* win); | |
740 | }; | |
741 | ||
742 | //--------------------------------------------------------------------------- | |
743 | %newgroup | |
744 | ||
745 | class wxWindowDC : public wxDC { | |
746 | public: | |
747 | wxWindowDC(wxWindow* win); | |
748 | }; | |
749 | ||
750 | //--------------------------------------------------------------------------- | |
751 | %newgroup | |
752 | ||
753 | class wxMirrorDC : public wxDC | |
754 | { | |
755 | public: | |
756 | // constructs a mirror DC associated with the given real DC | |
757 | // | |
dd9f7fea | 758 | // if mirror parameter is True, all vertical and horizontal coordinates are |
d14a1e28 RD |
759 | // exchanged, otherwise this class behaves in exactly the same way as a |
760 | // plain DC | |
761 | // | |
762 | wxMirrorDC(wxDC& dc, bool mirror); | |
763 | }; | |
764 | ||
765 | //--------------------------------------------------------------------------- | |
766 | %newgroup | |
767 | ||
768 | %{ | |
769 | #include <wx/dcps.h> | |
770 | %} | |
771 | ||
772 | class wxPostScriptDC : public wxDC { | |
773 | public: | |
774 | wxPostScriptDC(const wxPrintData& printData); | |
775 | // %name(PostScriptDC2)wxPostScriptDC(const wxString& output, | |
dd9f7fea | 776 | // bool interactive = True, |
d14a1e28 RD |
777 | // wxWindow* parent = NULL); |
778 | ||
779 | wxPrintData& GetPrintData(); | |
780 | void SetPrintData(const wxPrintData& data); | |
781 | ||
782 | static void SetResolution(int ppi); | |
783 | static int GetResolution(); | |
784 | }; | |
785 | ||
786 | //--------------------------------------------------------------------------- | |
787 | %newgroup | |
788 | ||
789 | ||
790 | #ifdef __WXMSW__ | |
791 | ||
792 | %{ | |
793 | #include <wx/metafile.h> | |
794 | %} | |
795 | ||
796 | class wxMetaFile : public wxObject { | |
797 | public: | |
798 | wxMetaFile(const wxString& filename = wxPyEmptyString); | |
799 | ~wxMetaFile(); | |
800 | ||
801 | bool Ok(); | |
802 | bool SetClipboard(int width = 0, int height = 0); | |
803 | ||
804 | wxSize GetSize(); | |
805 | int GetWidth(); | |
806 | int GetHeight(); | |
807 | ||
808 | const wxString& GetFileName() const; | |
809 | ||
810 | %pythoncode { def __nonzero__(self): return self.Ok() } | |
811 | }; | |
812 | ||
813 | // bool wxMakeMetaFilePlaceable(const wxString& filename, | |
814 | // int minX, int minY, int maxX, int maxY, float scale=1.0); | |
815 | ||
816 | ||
817 | class wxMetaFileDC : public wxDC { | |
818 | public: | |
819 | wxMetaFileDC(const wxString& filename = wxPyEmptyString, | |
820 | int width = 0, int height = 0, | |
821 | const wxString& description = wxPyEmptyString); | |
822 | wxMetaFile* Close(); | |
823 | }; | |
824 | ||
825 | ||
826 | ||
827 | #else // Make some dummies for the other platforms | |
828 | ||
829 | %{ | |
830 | class wxMetaFile : public wxObject { | |
831 | public: | |
832 | wxMetaFile(const wxString&) | |
81cfe5e1 | 833 | { wxPyRaiseNotImplemented(); } |
d14a1e28 RD |
834 | }; |
835 | ||
836 | class wxMetaFileDC : public wxClientDC { | |
837 | public: | |
838 | wxMetaFileDC(const wxString&, int, int, const wxString&) | |
81cfe5e1 | 839 | { wxPyRaiseNotImplemented(); } |
d14a1e28 RD |
840 | }; |
841 | ||
842 | %} | |
843 | ||
844 | class wxMetaFile : public wxObject { | |
845 | public: | |
846 | wxMetaFile(const wxString& filename = wxPyEmptyString); | |
847 | }; | |
848 | ||
849 | class wxMetaFileDC : public wxDC { | |
850 | public: | |
851 | wxMetaFileDC(const wxString& filename = wxPyEmptyString, | |
852 | int width = 0, int height = 0, | |
853 | const wxString& description = wxPyEmptyString); | |
854 | }; | |
855 | ||
856 | ||
857 | #endif | |
858 | ||
859 | ||
860 | //--------------------------------------------------------------------------- | |
861 | ||
862 | #if defined(__WXMSW__) || defined(__WXMAC__) | |
863 | ||
864 | class wxPrinterDC : public wxDC { | |
865 | public: | |
866 | wxPrinterDC(const wxPrintData& printData); | |
867 | // %name(PrinterDC2) wxPrinterDC(const wxString& driver, | |
868 | // const wxString& device, | |
869 | // const wxString& output, | |
dd9f7fea | 870 | // bool interactive = True, |
d14a1e28 RD |
871 | // int orientation = wxPORTRAIT); |
872 | }; | |
873 | ||
874 | #else | |
875 | %{ | |
876 | class wxPrinterDC : public wxClientDC { | |
877 | public: | |
878 | wxPrinterDC(const wxPrintData&) | |
81cfe5e1 | 879 | { wxPyRaiseNotImplemented(); } |
4942342c | 880 | |
d14a1e28 | 881 | // wxPrinterDC(const wxString&, const wxString&, const wxString&, bool, int) |
81cfe5e1 | 882 | // { wxPyRaiseNotImplemented(); } |
d14a1e28 RD |
883 | }; |
884 | %} | |
4942342c | 885 | |
d14a1e28 RD |
886 | class wxPrinterDC : public wxDC { |
887 | public: | |
888 | wxPrinterDC(const wxPrintData& printData); | |
889 | // %name(PrinterDC2) wxPrinterDC(const wxString& driver, | |
890 | // const wxString& device, | |
891 | // const wxString& output, | |
dd9f7fea | 892 | // bool interactive = True, |
d14a1e28 RD |
893 | // int orientation = wxPORTRAIT); |
894 | }; | |
895 | #endif | |
896 | ||
4942342c RD |
897 | //--------------------------------------------------------------------------- |
898 | //--------------------------------------------------------------------------- | |
899 | ||
900 | // Now define some Python classes that rename the Draw methods to be | |
901 | // compatible with the DC Draw methods in 2.4. See also wxPython/_wx.py. | |
902 | ||
903 | ||
904 | %define MAKE_OLD_DC_CLASS(classname) | |
905 | %pythoncode { | |
906 | class classname##_old(classname): | |
907 | """DC class that has methods with 2.4 compatible parameters.""" | |
908 | FloodFill = classname.FloodFillXY | |
909 | GetPixel = classname.GetPixelXY | |
910 | DrawLine = classname.DrawLineXY | |
911 | CrossHair = classname.CrossHairXY | |
912 | DrawArc = classname.DrawArcXY | |
913 | DrawCheckMark = classname.DrawCheckMarkXY | |
914 | DrawEllipticArc = classname.DrawEllipticArcXY | |
915 | DrawPoint = classname.DrawPointXY | |
916 | DrawRectangle = classname.DrawRectangleXY | |
917 | DrawRoundedRectangle = classname.DrawRoundedRectangleXY | |
918 | DrawCircle = classname.DrawCircleXY | |
919 | DrawEllipse = classname.DrawEllipseXY | |
920 | DrawIcon = classname.DrawIconXY | |
921 | DrawBitmap = classname.DrawBitmapXY | |
922 | DrawText = classname.DrawTextXY | |
923 | DrawRotatedText = classname.DrawRotatedTextXY | |
924 | Blit = classname.BlitXY | |
925 | } | |
926 | %enddef | |
927 | ||
928 | MAKE_OLD_DC_CLASS(DC); | |
929 | MAKE_OLD_DC_CLASS(MemoryDC); | |
930 | MAKE_OLD_DC_CLASS(BufferedDC); | |
931 | MAKE_OLD_DC_CLASS(BufferedPaintDC); | |
932 | MAKE_OLD_DC_CLASS(ScreenDC); | |
933 | MAKE_OLD_DC_CLASS(ClientDC); | |
934 | MAKE_OLD_DC_CLASS(PaintDC); | |
935 | MAKE_OLD_DC_CLASS(WindowDC); | |
936 | MAKE_OLD_DC_CLASS(MirrorDC); | |
937 | MAKE_OLD_DC_CLASS(PostScriptDC); | |
938 | MAKE_OLD_DC_CLASS(MetaFileDC); | |
939 | MAKE_OLD_DC_CLASS(PrinterDC); | |
940 | ||
941 | ||
d14a1e28 | 942 | //--------------------------------------------------------------------------- |