1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface defs for wxDC and releated classes
7 // Created: 7-July-1997
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
19 #include "wx/wxPython/pydrawxxx.h"
22 // TODO: 1. wrappers for wxDrawObject and wxDC::DrawObject
25 //---------------------------------------------------------------------------
27 %typemap(in) (int points, wxPoint* points_array ) {
28 $2 = wxPoint_LIST_helper($input, &$1);
29 if ($2 == NULL) SWIG_fail;
31 %typemap(freearg) (int points, wxPoint* points_array ) {
36 //---------------------------------------------------------------------------
40 // wxDC is the device context - object on which any drawing is done
41 class wxDC : public wxObject {
43 // wxDC(); **** abstract base class, can't instantiate.
47 virtual void BeginDrawing();
48 virtual void EndDrawing();
51 // virtual void DrawObject(wxDrawObject* drawobject);
57 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
58 //bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const;
60 wxColour GetPixel(wxCoord x, wxCoord y) {
62 self->GetPixel(x, y, &col);
66 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
67 void CrossHair(wxCoord x, wxCoord y);
68 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
69 void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
70 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea);
71 void DrawPoint(wxCoord x, wxCoord y);
72 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
73 %name(DrawRectangleRect)void DrawRectangle(const wxRect& rect);
74 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius);
75 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
76 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
77 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
78 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = False);
79 void DrawText(const wxString& text, wxCoord x, wxCoord y);
80 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
81 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
82 wxDC *source, wxCoord xsrc, wxCoord ysrc,
83 int rop = wxCOPY, bool useMask = False,
84 wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
90 %name(FloodFillXY) bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
91 bool FloodFill(const wxPoint& pt, const wxColour& col, int style = wxFLOOD_SURFACE);
93 //%name(GetPixelXY) bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const;
94 //bool GetPixel(const wxPoint& pt, wxColour *col) const;
96 wxColour GetPixelXY(wxCoord x, wxCoord y) {
98 self->GetPixel(x, y, &col);
101 wxColour GetPixel(const wxPoint& pt) {
103 self->GetPixel(pt, &col);
107 %name(DrawLineXY) void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
108 void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
110 %name(CrossHairXY) void CrossHair(wxCoord x, wxCoord y);
111 void CrossHair(const wxPoint& pt);
113 %name(DrawArcXY) void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
114 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre);
116 %name(DrawCheckMarkXY) void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
117 void DrawCheckMark(const wxRect& rect);
119 %name(DrawEllipticArcXY) void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea);
120 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz, double sa, double ea);
122 %name(DrawPointXY) void DrawPoint(wxCoord x, wxCoord y);
123 void DrawPoint(const wxPoint& pt);
125 %name(DrawRectangleXY) void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
126 void DrawRectangle(const wxPoint& pt, const wxSize& sz);
127 %name(DrawRectangleRect) void DrawRectangle(const wxRect& rect);
129 %name(DrawRoundedRectangleXY) void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius);
130 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius);
131 %name(DrawRoundedRectangleRect) void DrawRoundedRectangle(const wxRect& r, double radius);
133 %name(DrawCircleXY) void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
134 void DrawCircle(const wxPoint& pt, wxCoord radius);
136 %name(DrawEllipseXY) void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
137 void DrawEllipse(const wxPoint& pt, const wxSize& sz);
138 %name(DrawEllipseRect) void DrawEllipse(const wxRect& rect);
140 %name(DrawIconXY) void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
141 void DrawIcon(const wxIcon& icon, const wxPoint& pt);
143 %name(DrawBitmapXY) void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = False);
144 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, bool useMask = False);
146 %name(DrawTextXY) void DrawText(const wxString& text, wxCoord x, wxCoord y);
147 void DrawText(const wxString& text, const wxPoint& pt);
149 %name(DrawRotatedTextXY) void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
150 void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle);
153 %name(BlitXY) bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
154 wxDC *source, wxCoord xsrc, wxCoord ysrc,
155 int rop = wxCOPY, bool useMask = False,
156 wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
157 bool Blit(const wxPoint& destPt, const wxSize& sz,
158 wxDC *source, const wxPoint& srcPt,
159 int rop = wxCOPY, bool useMask = False,
160 const wxPoint& srcPtMask = wxDefaultPosition);
164 void DrawLines(int points, wxPoint* points_array, wxCoord xoffset = 0, wxCoord yoffset = 0);
166 void DrawPolygon(int points, wxPoint* points_array,
167 wxCoord xoffset = 0, wxCoord yoffset = 0,
168 int fillStyle = wxODDEVEN_RULE);
171 // this version puts both optional bitmap and the text into the given
172 // rectangle and aligns is as specified by alignment parameter; it also
173 // will emphasize the character with the given index if it is != -1 and
174 // return the bounding rectangle if required
175 void DrawLabel(const wxString& text, const wxRect& rect,
176 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
177 int indexAccel = -1);
179 wxRect DrawImageLabel(const wxString& text,
180 const wxBitmap& image,
182 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
183 int indexAccel = -1) {
185 self->DrawLabel(text, image, rect, alignment, indexAccel, &rv);
192 void DrawSpline(int points, wxPoint* points_array);
196 // global DC operations
197 // --------------------
199 virtual void Clear();
201 virtual bool StartDoc(const wxString& message);
202 virtual void EndDoc();
204 virtual void StartPage();
205 virtual void EndPage();
208 // set objects to use for drawing
209 // ------------------------------
211 virtual void SetFont(const wxFont& font);
212 virtual void SetPen(const wxPen& pen);
213 virtual void SetBrush(const wxBrush& brush);
214 virtual void SetBackground(const wxBrush& brush);
215 virtual void SetBackgroundMode(int mode);
216 virtual void SetPalette(const wxPalette& palette);
222 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
223 //void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
224 %name(SetClippingRect) void SetClippingRegion(const wxRect& rect);
225 %name(SetClippingRegionAsRegion) void SetClippingRegion(const wxRegion& region);
227 virtual void DestroyClippingRegion();
229 void GetClippingBox(wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT) const;
231 wxRect GetClippingRect() {
233 self->GetClippingBox(rect);
243 virtual wxCoord GetCharHeight() const;
244 virtual wxCoord GetCharWidth() const;
246 // only works for single line strings
247 void GetTextExtent(const wxString& string, wxCoord *OUTPUT, wxCoord *OUTPUT);
248 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
249 wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord* OUTPUT,
250 wxFont* font = NULL);
252 // works for single as well as multi-line strings
253 void GetMultiLineTextExtent(const wxString& text, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT,
254 wxFont *font = NULL);
257 // size and resolution
258 // -------------------
261 %name(GetSizeTuple)void GetSize(int* OUTPUT, int* OUTPUT);
265 %name(GetSizeMMWH)void GetSizeMM(int* OUTPUT, int* OUTPUT) const;
266 wxSize GetSizeMM() const;
269 // coordinates conversions
270 // -----------------------
272 // This group of functions does actual conversion of the input, as you'd
274 wxCoord DeviceToLogicalX(wxCoord x) const;
275 wxCoord DeviceToLogicalY(wxCoord y) const;
276 wxCoord DeviceToLogicalXRel(wxCoord x) const;
277 wxCoord DeviceToLogicalYRel(wxCoord y) const;
278 wxCoord LogicalToDeviceX(wxCoord x) const;
279 wxCoord LogicalToDeviceY(wxCoord y) const;
280 wxCoord LogicalToDeviceXRel(wxCoord x) const;
281 wxCoord LogicalToDeviceYRel(wxCoord y) const;
283 // query DC capabilities
284 // ---------------------
286 virtual bool CanDrawBitmap() const;
287 virtual bool CanGetTextExtent() const;
290 virtual int GetDepth() const;
292 // Resolution in Pixels per inch
293 virtual wxSize GetPPI() const;
295 virtual bool Ok() const;
299 int GetBackgroundMode() const;
300 const wxBrush& GetBackground() const;
301 const wxBrush& GetBrush() const;
302 const wxFont& GetFont() const;
303 const wxPen& GetPen() const;
304 const wxColour& GetTextBackground() const;
305 const wxColour& GetTextForeground() const;
307 virtual void SetTextForeground(const wxColour& colour);
308 virtual void SetTextBackground(const wxColour& colour);
310 int GetMapMode() const;
311 virtual void SetMapMode(int mode);
313 virtual void GetUserScale(double *OUTPUT, double *OUTPUT) const;
314 virtual void SetUserScale(double x, double y);
316 virtual void GetLogicalScale(double *OUTPUT, double *OUTPUT);
317 virtual void SetLogicalScale(double x, double y);
319 %name(GetLogicalOriginTuple) void GetLogicalOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const;
320 wxPoint GetLogicalOrigin() const;
321 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
324 %name(GetDeviceOriginTuple) void GetDeviceOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const;
325 wxPoint GetDeviceOrigin() const;
326 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
328 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
330 int GetLogicalFunction() const;
331 virtual void SetLogicalFunction(int function);
333 virtual void SetOptimization(bool opt);
334 virtual bool GetOptimization();
340 virtual void CalcBoundingBox(wxCoord x, wxCoord y);
341 void ResetBoundingBox();
343 // Get the final bounding box of the PostScript or Metafile picture.
344 wxCoord MinX() const;
345 wxCoord MaxX() const;
346 wxCoord MinY() const;
347 wxCoord MaxY() const;
351 void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT);
352 // See below for implementation
354 %pythoncode { def __nonzero__(self): return self.Ok() };
358 %extend { // See drawlist.cpp for impplementaion of these...
359 PyObject* _DrawPointList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
361 return wxPyDrawXXXList(*self, wxPyDrawXXXPoint, pyCoords, pyPens, pyBrushes);
364 PyObject* _DrawLineList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
366 return wxPyDrawXXXList(*self, wxPyDrawXXXLine, pyCoords, pyPens, pyBrushes);
369 PyObject* _DrawRectangleList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
371 return wxPyDrawXXXList(*self, wxPyDrawXXXRectangle, pyCoords, pyPens, pyBrushes);
374 PyObject* _DrawEllipseList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
376 return wxPyDrawXXXList(*self, wxPyDrawXXXEllipse, pyCoords, pyPens, pyBrushes);
379 PyObject* _DrawPolygonList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
381 return wxPyDrawXXXList(*self, wxPyDrawXXXPolygon, pyCoords, pyPens, pyBrushes);
384 PyObject* _DrawTextList(PyObject* textList, PyObject* pyPoints,
385 PyObject* foregroundList, PyObject* backgroundList) {
386 return wxPyDrawTextList(*self, textList, pyPoints, foregroundList, backgroundList);
391 def DrawPointList(self, points, pens=None):
394 elif isinstance(pens, wx.Pen):
396 elif len(pens) != len(points):
397 raise ValueError('points and pens must have same length')
398 return self._DrawPointList(points, pens, [])
401 def DrawLineList(self, lines, pens=None):
404 elif isinstance(pens, wx.Pen):
406 elif len(pens) != len(lines):
407 raise ValueError('lines and pens must have same length')
408 return self._DrawLineList(lines, pens, [])
411 def DrawRectangleList(self, rectangles, pens=None, brushes=None):
414 elif isinstance(pens, wx.Pen):
416 elif len(pens) != len(rectangles):
417 raise ValueError('rectangles and pens must have same length')
420 elif isinstance(brushes, wx.Brush):
422 elif len(brushes) != len(rectangles):
423 raise ValueError('rectangles and brushes must have same length')
424 return self._DrawRectangleList(rectangles, pens, brushes)
427 def DrawEllipseList(self, ellipses, pens=None, brushes=None):
430 elif isinstance(pens, wx.Pen):
432 elif len(pens) != len(ellipses):
433 raise ValueError('ellipses and pens must have same length')
436 elif isinstance(brushes, wx.Brush):
438 elif len(brushes) != len(ellipses):
439 raise ValueError('ellipses and brushes must have same length')
440 return self._DrawEllipseList(ellipses, pens, brushes)
443 def DrawPolygonList(self, polygons, pens=None, brushes=None):
444 ## Note: This does not currently support fill style or offset
445 ## you can always use the non-List version if need be.
448 elif isinstance(pens, wx.Pen):
450 elif len(pens) != len(polygons):
451 raise ValueError('polygons and pens must have same length')
454 elif isinstance(brushes, wx.Brush):
456 elif len(brushes) != len(polygons):
457 raise ValueError('polygons and brushes must have same length')
458 return self._DrawPolygonList(polygons, pens, brushes)
461 def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None, fonts = None):
462 ## NOTE: this does not currently support changing the font
463 ## Make sure you set Background mode to wxSolid (DC.SetBackgroundMode)
464 ## If you want backgounds to do anything.
465 if type(textList) == type(''):
466 textList = [textList]
467 elif len(textList) != len(coords):
468 raise ValueError('textlist and coords must have same length')
469 if foregrounds is None:
471 elif isinstance(foregrounds, wxColour):
472 foregrounds = [foregrounds]
473 elif len(foregrounds) != len(coords):
474 raise ValueError('foregrounds and coords must have same length')
475 if backgrounds is None:
477 elif isinstance(backgrounds, wxColour):
478 backgrounds = [backgrounds]
479 elif len(backgrounds) != len(coords):
480 raise ValueError('backgrounds and coords must have same length')
481 return self._DrawTextList(textList, coords, foregrounds, backgrounds)
489 static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) {
498 //---------------------------------------------------------------------------
501 class wxMemoryDC : public wxDC {
504 %name(MemoryDCFromDC) wxMemoryDC(wxDC* oldDC);
506 void SelectObject(const wxBitmap& bitmap);
509 //---------------------------------------------------------------------------
512 class wxBufferedDC : public wxMemoryDC
515 %addtofunc wxBufferedDC( wxDC *dc, const wxBitmap &buffer )
516 "self._dc = args[0] # save a ref so the other dc will not be deleted before self";
517 %addtofunc wxBufferedDC( wxDC *dc, const wxSize &area )
518 "val._dc = args[0] # save a ref so the other dc will not be deleted before self";
520 // Construct a wxBufferedDC using a user supplied buffer.
521 wxBufferedDC( wxDC *dc, const wxBitmap &buffer );
523 // Construct a wxBufferedDC with an internal buffer of 'area'
524 // (where area is usually something like the size of the window
526 %name(BufferedDCInternalBuffer) wxBufferedDC( wxDC *dc, const wxSize &area );
528 // Blits the buffer to the dc, and detaches the dc from
529 // the buffer. Usually called in the dtor or by the dtor
530 // of derived classes if the BufferedDC must blit before
531 // the derived class (which may own the dc it's blitting
537 class wxBufferedPaintDC : public wxBufferedDC
540 wxBufferedPaintDC( wxWindow *window, const wxBitmap &buffer = wxNullBitmap );
544 //---------------------------------------------------------------------------
547 class wxScreenDC : public wxDC {
551 %name(StartDrawingOnTopWin) bool StartDrawingOnTop(wxWindow* window);
552 bool StartDrawingOnTop(wxRect* rect = NULL);
553 bool EndDrawingOnTop();
556 //---------------------------------------------------------------------------
559 class wxClientDC : public wxDC {
561 wxClientDC(wxWindow* win);
564 //---------------------------------------------------------------------------
567 class wxPaintDC : public wxDC {
569 wxPaintDC(wxWindow* win);
572 //---------------------------------------------------------------------------
575 class wxWindowDC : public wxDC {
577 wxWindowDC(wxWindow* win);
580 //---------------------------------------------------------------------------
583 class wxMirrorDC : public wxDC
586 // constructs a mirror DC associated with the given real DC
588 // if mirror parameter is True, all vertical and horizontal coordinates are
589 // exchanged, otherwise this class behaves in exactly the same way as a
592 wxMirrorDC(wxDC& dc, bool mirror);
595 //---------------------------------------------------------------------------
602 class wxPostScriptDC : public wxDC {
604 wxPostScriptDC(const wxPrintData& printData);
605 // %name(PostScriptDC2)wxPostScriptDC(const wxString& output,
606 // bool interactive = True,
607 // wxWindow* parent = NULL);
609 wxPrintData& GetPrintData();
610 void SetPrintData(const wxPrintData& data);
612 static void SetResolution(int ppi);
613 static int GetResolution();
616 //---------------------------------------------------------------------------
623 #include <wx/metafile.h>
626 class wxMetaFile : public wxObject {
628 wxMetaFile(const wxString& filename = wxPyEmptyString);
632 bool SetClipboard(int width = 0, int height = 0);
638 const wxString& GetFileName() const;
640 %pythoncode { def __nonzero__(self): return self.Ok() }
643 // bool wxMakeMetaFilePlaceable(const wxString& filename,
644 // int minX, int minY, int maxX, int maxY, float scale=1.0);
647 class wxMetaFileDC : public wxDC {
649 wxMetaFileDC(const wxString& filename = wxPyEmptyString,
650 int width = 0, int height = 0,
651 const wxString& description = wxPyEmptyString);
657 #else // Make some dummies for the other platforms
660 class wxMetaFile : public wxObject {
662 wxMetaFile(const wxString&)
663 { PyErr_SetNone(PyExc_NotImplementedError); }
666 class wxMetaFileDC : public wxClientDC {
668 wxMetaFileDC(const wxString&, int, int, const wxString&)
669 { PyErr_SetNone(PyExc_NotImplementedError); }
674 class wxMetaFile : public wxObject {
676 wxMetaFile(const wxString& filename = wxPyEmptyString);
679 class wxMetaFileDC : public wxDC {
681 wxMetaFileDC(const wxString& filename = wxPyEmptyString,
682 int width = 0, int height = 0,
683 const wxString& description = wxPyEmptyString);
690 //---------------------------------------------------------------------------
692 #if defined(__WXMSW__) || defined(__WXMAC__)
694 class wxPrinterDC : public wxDC {
696 wxPrinterDC(const wxPrintData& printData);
697 // %name(PrinterDC2) wxPrinterDC(const wxString& driver,
698 // const wxString& device,
699 // const wxString& output,
700 // bool interactive = True,
701 // int orientation = wxPORTRAIT);
706 class wxPrinterDC : public wxClientDC {
708 wxPrinterDC(const wxPrintData&)
709 { PyErr_SetNone(PyExc_NotImplementedError); }
711 // wxPrinterDC(const wxString&, const wxString&, const wxString&, bool, int)
712 // { PyErr_SetNone(PyExc_NotImplementedError); }
716 class wxPrinterDC : public wxDC {
718 wxPrinterDC(const wxPrintData& printData);
719 // %name(PrinterDC2) wxPrinterDC(const wxString& driver,
720 // const wxString& device,
721 // const wxString& output,
722 // bool interactive = True,
723 // int orientation = wxPORTRAIT);
727 //---------------------------------------------------------------------------