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();
230 void, GetClippingBox(wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT) const,
231 "GetClippingBox() -> (x, y, width, height)");
234 wxRect GetClippingRect() {
236 self->GetClippingBox(rect);
246 virtual wxCoord GetCharHeight() const;
247 virtual wxCoord GetCharWidth() const;
251 void, GetTextExtent(const wxString& string, wxCoord *OUTPUT, wxCoord *OUTPUT),
252 "GetTextExtent(wxString string) -> (width, height)",
253 "Get the width and height of the text using the current font.\n"
254 "Only works for single line strings.");
256 void, GetTextExtent(const wxString& string,
257 wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord* OUTPUT,
258 wxFont* font = NULL),
259 "GetFullTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)",
260 "Get the width, height, decent and leading of the text using the current or specified font.\n"
261 "Only works for single line strings.",
265 // works for single as well as multi-line strings
267 void, GetMultiLineTextExtent(const wxString& text,
268 wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT,
269 wxFont *font = NULL),
270 "GetMultiLineTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)",
271 "Get the width, height, decent and leading of the text using the current or specified font.\n"
272 "Works for single as well as multi-line strings.");
275 // size and resolution
276 // -------------------
278 DocStr(GetSize, "Get the DC size in device units.");
281 void, GetSize( int *OUTPUT, int *OUTPUT ),
282 "GetSizeTuple() -> (width, height)",
286 DocStr(GetSizeMM, "Get the DC size in milimeters.");
287 wxSize GetSizeMM() const;
289 void, GetSizeMM( int *OUTPUT, int *OUTPUT ) const,
290 "GetSizeMMTuple() -> (width, height)",
295 // coordinates conversions
296 // -----------------------
298 // This group of functions does actual conversion of the input, as you'd
300 wxCoord DeviceToLogicalX(wxCoord x) const;
301 wxCoord DeviceToLogicalY(wxCoord y) const;
302 wxCoord DeviceToLogicalXRel(wxCoord x) const;
303 wxCoord DeviceToLogicalYRel(wxCoord y) const;
304 wxCoord LogicalToDeviceX(wxCoord x) const;
305 wxCoord LogicalToDeviceY(wxCoord y) const;
306 wxCoord LogicalToDeviceXRel(wxCoord x) const;
307 wxCoord LogicalToDeviceYRel(wxCoord y) const;
309 // query DC capabilities
310 // ---------------------
312 virtual bool CanDrawBitmap() const;
313 virtual bool CanGetTextExtent() const;
316 virtual int GetDepth() const;
318 // Resolution in Pixels per inch
319 virtual wxSize GetPPI() const;
321 virtual bool Ok() const;
325 int GetBackgroundMode() const;
326 const wxBrush& GetBackground() const;
327 const wxBrush& GetBrush() const;
328 const wxFont& GetFont() const;
329 const wxPen& GetPen() const;
330 const wxColour& GetTextBackground() const;
331 const wxColour& GetTextForeground() const;
333 virtual void SetTextForeground(const wxColour& colour);
334 virtual void SetTextBackground(const wxColour& colour);
336 int GetMapMode() const;
337 virtual void SetMapMode(int mode);
341 virtual void, GetUserScale(double *OUTPUT, double *OUTPUT) const,
342 "GetUserScale() -> (xScale, yScale)");
344 virtual void SetUserScale(double x, double y);
348 virtual void, GetLogicalScale(double *OUTPUT, double *OUTPUT),
349 "GetLogicalScale() -> (xScale, yScale)");
351 virtual void SetLogicalScale(double x, double y);
354 wxPoint GetLogicalOrigin() const;
356 void, GetLogicalOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const,
357 "GetLogicalOriginTuple() -> (x,y)",
358 GetLogicalOriginTuple);
360 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
363 wxPoint GetDeviceOrigin() const;
365 void, GetDeviceOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const,
366 "GetDeviceOriginTuple() -> (x,y)",
367 GetDeviceOriginTuple);
369 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
371 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
373 int GetLogicalFunction() const;
374 virtual void SetLogicalFunction(int function);
376 virtual void SetOptimization(bool opt);
377 virtual bool GetOptimization();
383 virtual void CalcBoundingBox(wxCoord x, wxCoord y);
384 void ResetBoundingBox();
386 // Get the final bounding box of the PostScript or Metafile picture.
387 wxCoord MinX() const;
388 wxCoord MaxX() const;
389 wxCoord MinY() const;
390 wxCoord MaxY() const;
394 "GetBoundingBox() -> (x1,y1, x2,y2)");
396 void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT);
397 // See below for implementation
399 %pythoncode { def __nonzero__(self): return self.Ok() };
403 %extend { // See drawlist.cpp for impplementaion of these...
404 PyObject* _DrawPointList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
406 return wxPyDrawXXXList(*self, wxPyDrawXXXPoint, pyCoords, pyPens, pyBrushes);
409 PyObject* _DrawLineList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
411 return wxPyDrawXXXList(*self, wxPyDrawXXXLine, pyCoords, pyPens, pyBrushes);
414 PyObject* _DrawRectangleList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
416 return wxPyDrawXXXList(*self, wxPyDrawXXXRectangle, pyCoords, pyPens, pyBrushes);
419 PyObject* _DrawEllipseList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
421 return wxPyDrawXXXList(*self, wxPyDrawXXXEllipse, pyCoords, pyPens, pyBrushes);
424 PyObject* _DrawPolygonList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
426 return wxPyDrawXXXList(*self, wxPyDrawXXXPolygon, pyCoords, pyPens, pyBrushes);
429 PyObject* _DrawTextList(PyObject* textList, PyObject* pyPoints,
430 PyObject* foregroundList, PyObject* backgroundList) {
431 return wxPyDrawTextList(*self, textList, pyPoints, foregroundList, backgroundList);
436 def DrawPointList(self, points, pens=None):
439 elif isinstance(pens, wx.Pen):
441 elif len(pens) != len(points):
442 raise ValueError('points and pens must have same length')
443 return self._DrawPointList(points, pens, [])
446 def DrawLineList(self, lines, pens=None):
449 elif isinstance(pens, wx.Pen):
451 elif len(pens) != len(lines):
452 raise ValueError('lines and pens must have same length')
453 return self._DrawLineList(lines, pens, [])
456 def DrawRectangleList(self, rectangles, pens=None, brushes=None):
459 elif isinstance(pens, wx.Pen):
461 elif len(pens) != len(rectangles):
462 raise ValueError('rectangles and pens must have same length')
465 elif isinstance(brushes, wx.Brush):
467 elif len(brushes) != len(rectangles):
468 raise ValueError('rectangles and brushes must have same length')
469 return self._DrawRectangleList(rectangles, pens, brushes)
472 def DrawEllipseList(self, ellipses, pens=None, brushes=None):
475 elif isinstance(pens, wx.Pen):
477 elif len(pens) != len(ellipses):
478 raise ValueError('ellipses and pens must have same length')
481 elif isinstance(brushes, wx.Brush):
483 elif len(brushes) != len(ellipses):
484 raise ValueError('ellipses and brushes must have same length')
485 return self._DrawEllipseList(ellipses, pens, brushes)
488 def DrawPolygonList(self, polygons, pens=None, brushes=None):
489 ## Note: This does not currently support fill style or offset
490 ## you can always use the non-List version if need be.
493 elif isinstance(pens, wx.Pen):
495 elif len(pens) != len(polygons):
496 raise ValueError('polygons and pens must have same length')
499 elif isinstance(brushes, wx.Brush):
501 elif len(brushes) != len(polygons):
502 raise ValueError('polygons and brushes must have same length')
503 return self._DrawPolygonList(polygons, pens, brushes)
506 def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None, fonts = None):
507 ## NOTE: this does not currently support changing the font
508 ## Make sure you set Background mode to wxSolid (DC.SetBackgroundMode)
509 ## If you want backgounds to do anything.
510 if type(textList) == type(''):
511 textList = [textList]
512 elif len(textList) != len(coords):
513 raise ValueError('textlist and coords must have same length')
514 if foregrounds is None:
516 elif isinstance(foregrounds, wx.Colour):
517 foregrounds = [foregrounds]
518 elif len(foregrounds) != len(coords):
519 raise ValueError('foregrounds and coords must have same length')
520 if backgrounds is None:
522 elif isinstance(backgrounds, wx.Colour):
523 backgrounds = [backgrounds]
524 elif len(backgrounds) != len(coords):
525 raise ValueError('backgrounds and coords must have same length')
526 return self._DrawTextList(textList, coords, foregrounds, backgrounds)
534 static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) {
543 //---------------------------------------------------------------------------
546 class wxMemoryDC : public wxDC {
549 %name(MemoryDCFromDC) wxMemoryDC(wxDC* oldDC);
551 void SelectObject(const wxBitmap& bitmap);
554 //---------------------------------------------------------------------------
557 class wxBufferedDC : public wxMemoryDC
560 %addtofunc wxBufferedDC( wxDC *dc, const wxBitmap &buffer )
561 "self._dc = args[0] # save a ref so the other dc will not be deleted before self";
562 %addtofunc wxBufferedDC( wxDC *dc, const wxSize &area )
563 "val._dc = args[0] # save a ref so the other dc will not be deleted before self";
565 // Construct a wxBufferedDC using a user supplied buffer.
566 wxBufferedDC( wxDC *dc, const wxBitmap &buffer );
568 // Construct a wxBufferedDC with an internal buffer of 'area'
569 // (where area is usually something like the size of the window
571 %name(BufferedDCInternalBuffer) wxBufferedDC( wxDC *dc, const wxSize &area );
573 // Blits the buffer to the dc, and detaches the dc from
574 // the buffer. Usually called in the dtor or by the dtor
575 // of derived classes if the BufferedDC must blit before
576 // the derived class (which may own the dc it's blitting
582 class wxBufferedPaintDC : public wxBufferedDC
585 wxBufferedPaintDC( wxWindow *window, const wxBitmap &buffer = wxNullBitmap );
589 //---------------------------------------------------------------------------
592 class wxScreenDC : public wxDC {
596 %name(StartDrawingOnTopWin) bool StartDrawingOnTop(wxWindow* window);
597 bool StartDrawingOnTop(wxRect* rect = NULL);
598 bool EndDrawingOnTop();
601 //---------------------------------------------------------------------------
604 class wxClientDC : public wxDC {
606 wxClientDC(wxWindow* win);
609 //---------------------------------------------------------------------------
612 class wxPaintDC : public wxDC {
614 wxPaintDC(wxWindow* win);
617 //---------------------------------------------------------------------------
620 class wxWindowDC : public wxDC {
622 wxWindowDC(wxWindow* win);
625 //---------------------------------------------------------------------------
628 class wxMirrorDC : public wxDC
631 // constructs a mirror DC associated with the given real DC
633 // if mirror parameter is True, all vertical and horizontal coordinates are
634 // exchanged, otherwise this class behaves in exactly the same way as a
637 wxMirrorDC(wxDC& dc, bool mirror);
640 //---------------------------------------------------------------------------
647 class wxPostScriptDC : public wxDC {
649 wxPostScriptDC(const wxPrintData& printData);
650 // %name(PostScriptDC2)wxPostScriptDC(const wxString& output,
651 // bool interactive = True,
652 // wxWindow* parent = NULL);
654 wxPrintData& GetPrintData();
655 void SetPrintData(const wxPrintData& data);
657 static void SetResolution(int ppi);
658 static int GetResolution();
661 //---------------------------------------------------------------------------
668 #include <wx/metafile.h>
671 class wxMetaFile : public wxObject {
673 wxMetaFile(const wxString& filename = wxPyEmptyString);
677 bool SetClipboard(int width = 0, int height = 0);
683 const wxString& GetFileName() const;
685 %pythoncode { def __nonzero__(self): return self.Ok() }
688 // bool wxMakeMetaFilePlaceable(const wxString& filename,
689 // int minX, int minY, int maxX, int maxY, float scale=1.0);
692 class wxMetaFileDC : public wxDC {
694 wxMetaFileDC(const wxString& filename = wxPyEmptyString,
695 int width = 0, int height = 0,
696 const wxString& description = wxPyEmptyString);
702 #else // Make some dummies for the other platforms
705 class wxMetaFile : public wxObject {
707 wxMetaFile(const wxString&)
708 { PyErr_SetNone(PyExc_NotImplementedError); }
711 class wxMetaFileDC : public wxClientDC {
713 wxMetaFileDC(const wxString&, int, int, const wxString&)
714 { PyErr_SetNone(PyExc_NotImplementedError); }
719 class wxMetaFile : public wxObject {
721 wxMetaFile(const wxString& filename = wxPyEmptyString);
724 class wxMetaFileDC : public wxDC {
726 wxMetaFileDC(const wxString& filename = wxPyEmptyString,
727 int width = 0, int height = 0,
728 const wxString& description = wxPyEmptyString);
735 //---------------------------------------------------------------------------
737 #if defined(__WXMSW__) || defined(__WXMAC__)
739 class wxPrinterDC : public wxDC {
741 wxPrinterDC(const wxPrintData& printData);
742 // %name(PrinterDC2) wxPrinterDC(const wxString& driver,
743 // const wxString& device,
744 // const wxString& output,
745 // bool interactive = True,
746 // int orientation = wxPORTRAIT);
751 class wxPrinterDC : public wxClientDC {
753 wxPrinterDC(const wxPrintData&)
754 { PyErr_SetNone(PyExc_NotImplementedError); }
756 // wxPrinterDC(const wxString&, const wxString&, const wxString&, bool, int)
757 // { PyErr_SetNone(PyExc_NotImplementedError); }
761 class wxPrinterDC : public wxDC {
763 wxPrinterDC(const wxPrintData& printData);
764 // %name(PrinterDC2) wxPrinterDC(const wxString& driver,
765 // const wxString& device,
766 // const wxString& output,
767 // bool interactive = True,
768 // int orientation = wxPORTRAIT);
772 //---------------------------------------------------------------------------