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 /////////////////////////////////////////////////////////////////////////////
17 //---------------------------------------------------------------------------
20 #include "wx/wxPython/pydrawxxx.h"
23 // TODO: 1. wrappers for wxDrawObject and wxDC::DrawObject
26 //---------------------------------------------------------------------------
28 %typemap(in) (int points, wxPoint* points_array ) {
29 $2 = wxPoint_LIST_helper($input, &$1);
30 if ($2 == NULL) SWIG_fail;
32 %typemap(freearg) (int points, wxPoint* points_array ) {
37 //---------------------------------------------------------------------------
42 "A wx.DC is a device context onto which graphics and text can be
43 drawn. It is intended to represent a number of output devices in a
44 generic way, so a window can have a device context associated with it,
45 and a printer also has a device context. In this way, the same piece
46 of code may write to a number of different devices, if the device
47 context is used as a parameter.
49 Derived types of wxDC have documentation for specific features only,
50 so refer to this section for most device context information.
52 The wx.DC class is abstract and can not be instantiated, you must use
53 one of the derived classes instead. Which one will depend on the
54 situation in which it is used.", "");
56 class wxDC : public wxObject {
58 // wxDC(); **** abstract base class, can't instantiate.
63 %# These have been deprecated in wxWidgets. Since they never
64 %# really did anything to begin with, just make them be NOPs.
65 def BeginDrawing(self): pass
66 def EndDrawing(self): pass
71 // TODO virtual void DrawObject(wxDrawObject* drawobject);
76 "Flood fills the device context starting from the given point, using
77 the current brush colour, and using a style:
79 - **wxFLOOD_SURFACE**: the flooding occurs until a colour other than
80 the given colour is encountered.
82 - **wxFLOOD_BORDER**: the area to be flooded is bounded by the given
85 Returns False if the operation failed.
87 Note: The present implementation for non-Windows platforms may fail to
88 find colour borders if the pixels do not match the colour
89 exactly. However the function will still return true.", "");
90 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
91 %Rename(FloodFillPoint, bool, FloodFill(const wxPoint& pt, const wxColour& col, int style = wxFLOOD_SURFACE));
96 "Gets the colour at the specified location on the DC.","");
98 wxColour GetPixel(wxCoord x, wxCoord y) {
100 self->GetPixel(x, y, &col);
103 wxColour GetPixelPoint(const wxPoint& pt) {
105 self->GetPixel(pt, &col);
113 "Draws a line from the first point to the second. The current pen is
114 used for drawing the line. Note that the second point is *not* part of
115 the line and is not drawn by this function (this is consistent with
116 the behaviour of many other toolkits).", "");
117 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
118 %Rename(DrawLinePoint, void, DrawLine(const wxPoint& pt1, const wxPoint& pt2));
123 "Displays a cross hair using the current pen. This is a vertical and
124 horizontal line the height and width of the window, centred on the
126 void CrossHair(wxCoord x, wxCoord y);
127 %Rename(CrossHairPoint, void, CrossHair(const wxPoint& pt));
132 "Draws an arc of a circle, centred on the *center* point (xc, yc), from
133 the first point to the second. The current pen is used for the outline
134 and the current brush for filling the shape.
136 The arc is drawn in an anticlockwise direction from the start point to
137 the end point.", "");
138 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
139 %Rename(DrawArcPoint, void, DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& center));
144 "Draws a check mark inside the given rectangle.", "");
145 void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
146 %Rename(DrawCheckMarkRect, void, DrawCheckMark(const wxRect& rect));
150 "Draws an arc of an ellipse, with the given rectangle defining the
151 bounds of the ellipse. The current pen is used for drawing the arc and
152 the current brush is used for drawing the pie.
154 The *start* and *end* parameters specify the start and end of the arc
155 relative to the three-o'clock position from the center of the
156 rectangle. Angles are specified in degrees (360 is a complete
157 circle). Positive values mean counter-clockwise motion. If start is
158 equal to end, a complete ellipse will be drawn.", "");
159 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double start, double end);
160 %Rename(DrawEllipticArcPointSize, void, DrawEllipticArc(const wxPoint& pt, const wxSize& sz, double start, double end));
165 "Draws a point using the current pen.", "");
166 void DrawPoint(wxCoord x, wxCoord y);
167 %Rename(DrawPointPoint, void, DrawPoint(const wxPoint& pt));
172 "Draws a rectangle with the given top left corner, and with the given
173 size. The current pen is used for the outline and the current brush
174 for filling the shape.", "");
175 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
176 %Rename(DrawRectangleRect,void, DrawRectangle(const wxRect& rect));
177 %Rename(DrawRectanglePointSize, void, DrawRectangle(const wxPoint& pt, const wxSize& sz));
181 DrawRoundedRectangle,
182 "Draws a rectangle with the given top left corner, and with the given
183 size. The corners are quarter-circles using the given radius. The
184 current pen is used for the outline and the current brush for filling
187 If radius is positive, the value is assumed to be the radius of the
188 rounded corner. If radius is negative, the absolute value is assumed
189 to be the proportion of the smallest dimension of the rectangle. This
190 means that the corner can be a sensible size relative to the size of
191 the rectangle, and also avoids the strange effects X produces when the
192 corners are too big for the rectangle.", "");
193 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius);
194 %Rename(DrawRoundedRectangleRect, void, DrawRoundedRectangle(const wxRect& r, double radius));
195 %Rename(DrawRoundedRectanglePointSize, void, DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius));
200 "Draws a circle with the given center point and radius. The current
201 pen is used for the outline and the current brush for filling the
204 :see: `DrawEllipse`");
205 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
206 %Rename(DrawCirclePoint, void, DrawCircle(const wxPoint& pt, wxCoord radius));
211 "Draws an ellipse contained in the specified rectangle. The current pen
212 is used for the outline and the current brush for filling the shape.", "
214 :see: `DrawCircle`");
215 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
216 %Rename(DrawEllipseRect, void, DrawEllipse(const wxRect& rect));
217 %Rename(DrawEllipsePointSize, void, DrawEllipse(const wxPoint& pt, const wxSize& sz));
222 "Draw an icon on the display (does nothing if the device context is
223 PostScript). This can be the simplest way of drawing bitmaps on a
225 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
226 %Rename(DrawIconPoint, void, DrawIcon(const wxIcon& icon, const wxPoint& pt));
231 "Draw a bitmap on the device context at the specified point. If
232 *transparent* is true and the bitmap has a transparency mask, (or
233 alpha channel on the platforms that support it) then the bitmap will
234 be drawn transparently.", "
236 When drawing a mono-bitmap, the current text foreground colour will be
237 used to draw the foreground of the bitmap (all bits set to 1), and the
238 current text background colour to draw the background (all bits set to
241 :see: `SetTextForeground`, `SetTextBackground` and `wx.MemoryDC`");
242 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = false);
243 %Rename(DrawBitmapPoint, void, DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, bool useMask = false));
248 "Draws a text string at the specified point, using the current text
249 font, and the current text foreground and background colours.
251 The coordinates refer to the top-left corner of the rectangle bounding
252 the string. See `GetTextExtent` for how to get the dimensions of a
253 text string, which can be used to position the text more precisely.
255 **NOTE**: under wxGTK the current logical function is used by this
256 function but it is ignored by wxMSW. Thus, you should avoid using
257 logical functions with this function in portable programs.", "
259 :see: `DrawRotatedText`");
260 void DrawText(const wxString& text, wxCoord x, wxCoord y);
261 %Rename(DrawTextPoint, void, DrawText(const wxString& text, const wxPoint& pt));
266 "Draws the text rotated by *angle* degrees, if supported by the platform.
268 **NOTE**: Under Win9x only TrueType fonts can be drawn by this
269 function. In particular, a font different from ``wx.NORMAL_FONT``
270 should be used as the it is not normally a TrueType
271 font. ``wx.SWISS_FONT`` is an example of a font which is.","
274 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
275 %Rename(DrawRotatedTextPoint, void, DrawRotatedText(const wxString& text, const wxPoint& pt, double angle));
279 bool , Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
280 wxDC *source, wxCoord xsrc, wxCoord ysrc,
281 int rop = wxCOPY, bool useMask = false,
282 wxCoord xsrcMask = -1, wxCoord ysrcMask = -1),
283 "Copy from a source DC to this DC. Parameters specify the destination
284 coordinates, size of area to copy, source DC, source coordinates,
285 logical function, whether to use a bitmap mask, and mask source
288 :param xdest: Destination device context x position.
289 :param ydest: Destination device context y position.
290 :param width: Width of source area to be copied.
291 :param height: Height of source area to be copied.
292 :param source: Source device context.
293 :param xsrc: Source device context x position.
294 :param ysrc: Source device context y position.
295 :param rop: Logical function to use: see `SetLogicalFunction`.
296 :param useMask: If true, Blit does a transparent blit using the mask
297 that is associated with the bitmap selected into the
298 source device context.
299 :param xsrcMask: Source x position on the mask. If both xsrcMask and
300 ysrcMask are -1, xsrc and ysrc will be assumed for
301 the mask source position.
302 :param ysrcMask: Source y position on the mask.
306 bool , Blit(const wxPoint& destPt, const wxSize& sz,
307 wxDC *source, const wxPoint& srcPt,
308 int rop = wxCOPY, bool useMask = false,
309 const wxPoint& srcPtMask = wxDefaultPosition),
310 "Copy from a source DC to this DC. Parameters specify the destination
311 coordinates, size of area to copy, source DC, source coordinates,
312 logical function, whether to use a bitmap mask, and mask source
315 :param destPt: Destination device context position.
316 :param sz: Size of source area to be copied.
317 :param source: Source device context.
318 :param srcPt: Source device context position.
319 :param rop: Logical function to use: see `SetLogicalFunction`.
320 :param useMask: If true, Blit does a transparent blit using the mask
321 that is associated with the bitmap selected into the
322 source device context.
323 :param srcPtMask: Source position on the mask.
330 "Sets the clipping region for this device context to the intersection
331 of the given region described by the parameters of this method and the
332 previously set clipping region. You should call `DestroyClippingRegion`
333 if you want to set the clipping region exactly to the region
336 The clipping region is an area to which drawing is
337 restricted. Possible uses for the clipping region are for clipping
338 text or for speeding up window redraws when only a known area of the
339 screen is damaged.", "
341 :see: `DestroyClippingRegion`, `wx.Region`");
342 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
343 %Rename(SetClippingRegionPointSize, void, SetClippingRegion(const wxPoint& pt, const wxSize& sz));
344 %Rename(SetClippingRegionAsRegion, void, SetClippingRegion(const wxRegion& region));
345 %Rename(SetClippingRect, void, SetClippingRegion(const wxRect& rect));
350 void , DrawLines(int points, wxPoint* points_array,
351 wxCoord xoffset = 0, wxCoord yoffset = 0),
352 "DrawLines(self, List points, int xoffset=0, int yoffset=0)",
353 "Draws lines using a sequence of `wx.Point` objects, adding the
354 optional offset coordinate. The current pen is used for drawing the
359 void , DrawPolygon(int points, wxPoint* points_array,
360 wxCoord xoffset = 0, wxCoord yoffset = 0,
361 int fillStyle = wxODDEVEN_RULE),
362 "DrawPolygon(self, List points, int xoffset=0, int yoffset=0,
363 int fillStyle=ODDEVEN_RULE)",
364 "Draws a filled polygon using a sequence of `wx.Point` objects, adding
365 the optional offset coordinate. The last argument specifies the fill
366 rule: ``wx.ODDEVEN_RULE`` (the default) or ``wx.WINDING_RULE``.
368 The current pen is used for drawing the outline, and the current brush
369 for filling the shape. Using a transparent brush suppresses
370 filling. Note that wxWidgets automatically closes the first and last
374 // TODO: Figure out a good typemap for this...
375 // Convert the first 3 args from a sequence of sequences?
376 // void DrawPolyPolygon(int n, int count[], wxPoint points[],
377 // wxCoord xoffset = 0, wxCoord yoffset = 0,
378 // int fillStyle = wxODDEVEN_RULE);
382 void , DrawLabel(const wxString& text, const wxRect& rect,
383 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
384 int indexAccel = -1),
385 "Draw *text* within the specified rectangle, abiding by the alignment
386 flags. Will additionally emphasize the character at *indexAccel* if
389 :see: `DrawImageLabel`");
393 DocStr(DrawImageLabel,
394 "Draw *text* and an image (which may be ``wx.NullBitmap`` to skip
395 drawing it) within the specified rectangle, abiding by the alignment
396 flags. Will additionally emphasize the character at *indexAccel* if
397 it is not -1. Returns the bounding rectangle.", "");
398 wxRect DrawImageLabel(const wxString& text,
399 const wxBitmap& image,
401 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
402 int indexAccel = -1) {
404 self->DrawLabel(text, image, rect, alignment, indexAccel, &rv);
412 void , DrawSpline(int points, wxPoint* points_array),
413 "DrawSpline(self, List points)",
414 "Draws a spline between all given control points, (a list of `wx.Point`
415 objects) using the current pen. The spline is drawn using a series of
416 lines, using an algorithm taken from the X drawing program 'XFIG'.", "");
421 // global DC operations
422 // --------------------
425 virtual void , Clear(),
426 "Clears the device context using the current background brush.", "");
430 virtual bool , StartDoc(const wxString& message),
431 "Starts a document (only relevant when outputting to a
432 printer). *Message* is a message to show whilst printing.", "");
435 virtual void , EndDoc(),
436 "Ends a document (only relevant when outputting to a printer).", "");
440 virtual void , StartPage(),
441 "Starts a document page (only relevant when outputting to a printer).", "");
444 virtual void , EndPage(),
445 "Ends a document page (only relevant when outputting to a printer).", "");
449 // set objects to use for drawing
450 // ------------------------------
453 virtual void , SetFont(const wxFont& font),
454 "Sets the current font for the DC. It must be a valid font, in
455 particular you should not pass ``wx.NullFont`` to this method.","
460 virtual void , SetPen(const wxPen& pen),
461 "Sets the current pen for the DC.
463 If the argument is ``wx.NullPen``, the current pen is selected out of the
464 device context, and the original pen restored.", "
469 virtual void , SetBrush(const wxBrush& brush),
470 "Sets the current brush for the DC.
472 If the argument is ``wx.NullBrush``, the current brush is selected out
473 of the device context, and the original brush restored, allowing the
474 current brush to be destroyed safely.","
479 virtual void , SetBackground(const wxBrush& brush),
480 "Sets the current background brush for the DC.", "");
483 virtual void , SetBackgroundMode(int mode),
484 "*mode* may be one of ``wx.SOLID`` and ``wx.TRANSPARENT``. This setting
485 determines whether text will be drawn with a background colour or
489 virtual void , SetPalette(const wxPalette& palette),
490 "If this is a window DC or memory DC, assigns the given palette to the
491 window or bitmap associated with the DC. If the argument is
492 ``wx.NullPalette``, the current palette is selected out of the device
493 context, and the original palette restored.", "
495 :see: `wx.Palette`");
500 virtual void , DestroyClippingRegion(),
501 "Destroys the current clipping region so that none of the DC is
504 :see: `SetClippingRegion`");
508 void, GetClippingBox(wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT) const,
509 "GetClippingBox() -> (x, y, width, height)",
510 "Gets the rectangle surrounding the current clipping region.", "");
515 "Gets the rectangle surrounding the current clipping region.", "");
516 wxRect GetClippingRect() {
518 self->GetClippingBox(rect);
529 virtual wxCoord , GetCharHeight() const,
530 "Gets the character height of the currently set font.", "");
533 virtual wxCoord , GetCharWidth() const,
534 "Gets the average character width of the currently set font.", "");
539 void, GetTextExtent(const wxString& string, wxCoord *OUTPUT, wxCoord *OUTPUT),
540 "GetTextExtent(wxString string) -> (width, height)",
541 "Get the width and height of the text using the current font. Only
542 works for single line strings.", "");
545 void, GetTextExtent(const wxString& string,
546 wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord* OUTPUT,
547 wxFont* font = NULL),
548 "GetFullTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)",
549 "Get the width, height, decent and leading of the text using the
550 current or specified font. Only works for single line strings.", "",
554 // works for single as well as multi-line strings
556 void, GetMultiLineTextExtent(const wxString& text,
557 wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT,
558 wxFont *font = NULL),
559 "GetMultiLineTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)",
560 "Get the width, height, decent and leading of the text using the
561 current or specified font. Works for single as well as multi-line
566 DocAStr(GetPartialTextExtents,
567 "GetPartialTextExtents(self, text) -> [widths]",
568 "Returns a list of integers such that each value is the distance in
569 pixels from the begining of text to the coresponding character of
570 *text*. The generic version simply builds a running total of the widths
571 of each character using GetTextExtent, however if the various
572 platforms have a native API function that is faster or more accurate
573 than the generic implementation then it will be used instead.", "");
574 wxArrayInt GetPartialTextExtents(const wxString& text) {
576 self->GetPartialTextExtents(text, widths);
582 // size and resolution
583 // -------------------
587 "This gets the horizontal and vertical resolution in device units. It
588 can be used to scale graphics to fit the page. For example, if *maxX*
589 and *maxY* represent the maximum horizontal and vertical 'pixel' values
590 used in your application, the following code will scale the graphic to
591 fit on the printer page::
594 scaleX = maxX*1.0 / w
595 scaleY = maxY*1.0 / h
596 dc.SetUserScale(min(scaleX,scaleY),min(scaleX,scaleY))
600 void, GetSize( int *OUTPUT, int *OUTPUT ),
601 "GetSizeTuple() -> (width, height)",
605 DocStr(GetSizeMM, "Get the DC size in milimeters.", "");
606 wxSize GetSizeMM() const;
608 void, GetSizeMM( int *OUTPUT, int *OUTPUT ) const,
609 "GetSizeMMTuple() -> (width, height)",
614 // coordinates conversions
615 // -----------------------
618 wxCoord , DeviceToLogicalX(wxCoord x) const,
619 "Convert device X coordinate to logical coordinate, using the current
623 wxCoord , DeviceToLogicalY(wxCoord y) const,
624 "Converts device Y coordinate to logical coordinate, using the current
628 wxCoord , DeviceToLogicalXRel(wxCoord x) const,
629 "Convert device X coordinate to relative logical coordinate, using the
630 current mapping mode but ignoring the x axis orientation. Use this
631 function for converting a width, for example.", "");
634 wxCoord , DeviceToLogicalYRel(wxCoord y) const,
635 "Convert device Y coordinate to relative logical coordinate, using the
636 current mapping mode but ignoring the y axis orientation. Use this
637 function for converting a height, for example.", "");
640 wxCoord , LogicalToDeviceX(wxCoord x) const,
641 "Converts logical X coordinate to device coordinate, using the current
645 wxCoord , LogicalToDeviceY(wxCoord y) const,
646 "Converts logical Y coordinate to device coordinate, using the current
650 wxCoord , LogicalToDeviceXRel(wxCoord x) const,
651 "Converts logical X coordinate to relative device coordinate, using the
652 current mapping mode but ignoring the x axis orientation. Use this for
653 converting a width, for example.", "");
656 wxCoord , LogicalToDeviceYRel(wxCoord y) const,
657 "Converts logical Y coordinate to relative device coordinate, using the
658 current mapping mode but ignoring the y axis orientation. Use this for
659 converting a height, for example.", "");
663 // query DC capabilities
664 // ---------------------
666 virtual bool CanDrawBitmap() const;
667 virtual bool CanGetTextExtent() const;
671 virtual int , GetDepth() const,
672 "Returns the colour depth of the DC.", "");
676 virtual wxSize , GetPPI() const,
677 "Resolution in Pixels per inch", "");
681 virtual bool , Ok() const,
682 "Returns true if the DC is ok to use.", "");
687 int , GetBackgroundMode() const,
688 "Returns the current background mode, either ``wx.SOLID`` or
689 ``wx.TRANSPARENT``.","
691 :see: `SetBackgroundMode`");
694 const wxBrush& , GetBackground() const,
695 "Gets the brush used for painting the background.","
697 :see: `SetBackground`");
700 const wxBrush& , GetBrush() const,
701 "Gets the current brush", "");
704 const wxFont& , GetFont() const,
705 "Gets the current font", "");
708 const wxPen& , GetPen() const,
709 "Gets the current pen", "");
712 const wxColour& , GetTextBackground() const,
713 "Gets the current text background colour", "");
716 const wxColour& , GetTextForeground() const,
717 "Gets the current text foreground colour", "");
721 virtual void , SetTextForeground(const wxColour& colour),
722 "Sets the current text foreground colour for the DC.", "");
725 virtual void , SetTextBackground(const wxColour& colour),
726 "Sets the current text background colour for the DC.", "");
730 int , GetMapMode() const,
731 "Gets the current *mapping mode* for the device context ", "");
734 virtual void , SetMapMode(int mode),
735 "The *mapping mode* of the device context defines the unit of
736 measurement used to convert logical units to device units. The
737 mapping mode can be one of the following:
739 ================ =============================================
740 wx.MM_TWIPS Each logical unit is 1/20 of a point, or 1/1440
742 wx.MM_POINTS Each logical unit is a point, or 1/72 of an inch.
743 wx.MM_METRIC Each logical unit is 1 mm.
744 wx.MM_LOMETRIC Each logical unit is 1/10 of a mm.
745 wx.MM_TEXT Each logical unit is 1 pixel.
746 ================ =============================================
748 Note that in X, text drawing isn't handled consistently with the
749 mapping mode; a font is always specified in point size. However,
750 setting the user scale (see `SetUserScale`) scales the text
751 appropriately. In Windows, scalable TrueType fonts are always used; in
752 X, results depend on availability of fonts, but usually a reasonable
755 The coordinate origin is always at the top left of the screen/printer.
757 Drawing to a Windows printer device context uses the current mapping
758 mode, but mapping mode is currently ignored for PostScript output.
764 virtual void, GetUserScale(double *OUTPUT, double *OUTPUT) const,
765 "GetUserScale(self) -> (xScale, yScale)",
766 "Gets the current user scale factor (set by `SetUserScale`).", "");
769 virtual void , SetUserScale(double x, double y),
770 "Sets the user scaling factor, useful for applications which require
776 virtual void, GetLogicalScale(double *OUTPUT, double *OUTPUT),
777 "GetLogicalScale() -> (xScale, yScale)");
779 virtual void SetLogicalScale(double x, double y);
782 wxPoint GetLogicalOrigin() const;
784 void, GetLogicalOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const,
785 "GetLogicalOriginTuple() -> (x,y)",
786 GetLogicalOriginTuple);
788 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
790 void SetLogicalOriginPoint(const wxPoint& point) {
791 self->SetLogicalOrigin(point.x, point.y);
796 wxPoint GetDeviceOrigin() const;
798 void, GetDeviceOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const,
799 "GetDeviceOriginTuple() -> (x,y)",
800 GetDeviceOriginTuple);
802 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
804 void SetDeviceOriginPoint(const wxPoint& point) {
805 self->SetDeviceOrigin(point.x, point.y);
810 virtual void , SetAxisOrientation(bool xLeftRight, bool yBottomUp),
811 "Sets the x and y axis orientation (i.e., the direction from lowest to
812 highest values on the axis). The default orientation is the natural
813 orientation, e.g. x axis from left to right and y axis from bottom up.", "");
817 int , GetLogicalFunction() const,
818 "Gets the current logical function (set by `SetLogicalFunction`).", "");
821 virtual void , SetLogicalFunction(int function),
822 "Sets the current logical function for the device context. This
823 determines how a source pixel (from a pen or brush colour, or source
824 device context if using `Blit`) combines with a destination pixel in
825 the current device context.
827 The possible values and their meaning in terms of source and
828 destination pixel values are as follows:
830 ================ ==========================
832 wx.AND_INVERT (NOT src) AND dst
833 wx.AND_REVERSE src AND (NOT dst)
836 wx.EQUIV (NOT src) XOR dst
838 wx.NAND (NOT src) OR (NOT dst)
839 wx.NOR (NOT src) AND (NOT dst)
842 wx.OR_INVERT (NOT src) OR dst
843 wx.OR_REVERSE src OR (NOT dst)
845 wx.SRC_INVERT NOT src
847 ================ ==========================
849 The default is wx.COPY, which simply draws with the current
850 colour. The others combine the current colour and the background using
851 a logical operation. wx.INVERT is commonly used for drawing rubber
852 bands or moving outlines, since drawing twice reverts to the original
858 void , ComputeScaleAndOrigin(),
859 "Performs all necessary computations for given platform and context
860 type after each change of scale and origin parameters. Usually called
861 automatically internally after such changes.
867 // virtual void , SetOptimization(bool optimize),
868 // "If *optimize* is true this function sets optimization mode on. This
869 // currently means that under X, the device context will not try to set a
870 // pen or brush property if it is known to be set already. This approach
871 // can fall down if non-wxWidgets code is using the same device context
872 // or window, for example when the window is a panel on which the
873 // windowing system draws panel items. The wxWidgets device context
874 // 'memory' will now be out of step with reality.
876 // Setting optimization off, drawing, then setting it back on again, is a
877 // trick that must occasionally be employed.", "");
880 // virtual bool , GetOptimization(),
881 // "Returns true if device context optimization is on. See
882 // `SetOptimization` for details.", "");
885 def SetOptimization(self, optimize):
887 def GetOptimization(self):
890 SetOptimization = wx._deprecated(SetOptimization)
891 GetOptimization = wx._deprecated(GetOptimization)
899 virtual void , CalcBoundingBox(wxCoord x, wxCoord y),
900 "Adds the specified point to the bounding box which can be retrieved
901 with `MinX`, `MaxX` and `MinY`, `MaxY` or `GetBoundingBox` functions.", "");
904 DocStr(CalcBoundingBoxPoint,
905 "Adds the specified point to the bounding box which can be retrieved
906 with `MinX`, `MaxX` and `MinY`, `MaxY` or `GetBoundingBox` functions.","");
907 void CalcBoundingBoxPoint(const wxPoint& point) {
908 self->CalcBoundingBox(point.x, point.y);
913 void , ResetBoundingBox(),
914 "Resets the bounding box: after a call to this function, the bounding
915 box doesn't contain anything.", "");
918 // Get the final bounding box of the PostScript or Metafile picture.
920 wxCoord , MinX() const,
921 "Gets the minimum horizontal extent used in drawing commands so far.", "");
924 wxCoord , MaxX() const,
925 "Gets the maximum horizontal extent used in drawing commands so far.", "");
928 wxCoord , MinY() const,
929 "Gets the minimum vertical extent used in drawing commands so far.", "");
932 wxCoord , MaxY() const,
933 "Gets the maximum vertical extent used in drawing commands so far.", "");
937 DocAStr(GetBoundingBox,
938 "GetBoundingBox() -> (x1,y1, x2,y2)",
939 "Returns the min and max points used in drawing commands so far.", "");
941 void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT);
942 // See below for implementation
945 %pythoncode { def __nonzero__(self): return self.Ok() };
953 %extend { // See drawlist.cpp for impplementaion of these...
954 PyObject* _DrawPointList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
956 return wxPyDrawXXXList(*self, wxPyDrawXXXPoint, pyCoords, pyPens, pyBrushes);
959 PyObject* _DrawLineList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
961 return wxPyDrawXXXList(*self, wxPyDrawXXXLine, pyCoords, pyPens, pyBrushes);
964 PyObject* _DrawRectangleList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
966 return wxPyDrawXXXList(*self, wxPyDrawXXXRectangle, pyCoords, pyPens, pyBrushes);
969 PyObject* _DrawEllipseList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
971 return wxPyDrawXXXList(*self, wxPyDrawXXXEllipse, pyCoords, pyPens, pyBrushes);
974 PyObject* _DrawPolygonList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes)
976 return wxPyDrawXXXList(*self, wxPyDrawXXXPolygon, pyCoords, pyPens, pyBrushes);
979 PyObject* _DrawTextList(PyObject* textList, PyObject* pyPoints,
980 PyObject* foregroundList, PyObject* backgroundList) {
981 return wxPyDrawTextList(*self, textList, pyPoints, foregroundList, backgroundList);
986 def DrawPointList(self, points, pens=None):
988 Draw a list of points as quickly as possible.
990 :param points: A sequence of 2-element sequences representing
991 each point to draw, (x,y).
992 :param pens: If None, then the current pen is used. If a
993 single pen then it will be used for all points. If
994 a list of pens then there should be one for each point
999 elif isinstance(pens, wx.Pen):
1001 elif len(pens) != len(points):
1002 raise ValueError('points and pens must have same length')
1003 return self._DrawPointList(points, pens, [])
1006 def DrawLineList(self, lines, pens=None):
1008 Draw a list of lines as quickly as possible.
1010 :param lines: A sequence of 4-element sequences representing
1011 each line to draw, (x1,y1, x2,y2).
1012 :param pens: If None, then the current pen is used. If a
1013 single pen then it will be used for all lines. If
1014 a list of pens then there should be one for each line
1019 elif isinstance(pens, wx.Pen):
1021 elif len(pens) != len(lines):
1022 raise ValueError('lines and pens must have same length')
1023 return self._DrawLineList(lines, pens, [])
1026 def DrawRectangleList(self, rectangles, pens=None, brushes=None):
1028 Draw a list of rectangles as quickly as possible.
1030 :param rectangles: A sequence of 4-element sequences representing
1031 each rectangle to draw, (x,y, w,h).
1032 :param pens: If None, then the current pen is used. If a
1033 single pen then it will be used for all rectangles.
1034 If a list of pens then there should be one for each
1035 rectangle in rectangles.
1036 :param brushes: A brush or brushes to be used to fill the rectagles,
1037 with similar semantics as the pens parameter.
1041 elif isinstance(pens, wx.Pen):
1043 elif len(pens) != len(rectangles):
1044 raise ValueError('rectangles and pens must have same length')
1047 elif isinstance(brushes, wx.Brush):
1049 elif len(brushes) != len(rectangles):
1050 raise ValueError('rectangles and brushes must have same length')
1051 return self._DrawRectangleList(rectangles, pens, brushes)
1054 def DrawEllipseList(self, ellipses, pens=None, brushes=None):
1056 Draw a list of ellipses as quickly as possible.
1058 :param ellipses: A sequence of 4-element sequences representing
1059 each ellipse to draw, (x,y, w,h).
1060 :param pens: If None, then the current pen is used. If a
1061 single pen then it will be used for all ellipses.
1062 If a list of pens then there should be one for each
1063 ellipse in ellipses.
1064 :param brushes: A brush or brushes to be used to fill the ellipses,
1065 with similar semantics as the pens parameter.
1069 elif isinstance(pens, wx.Pen):
1071 elif len(pens) != len(ellipses):
1072 raise ValueError('ellipses and pens must have same length')
1075 elif isinstance(brushes, wx.Brush):
1077 elif len(brushes) != len(ellipses):
1078 raise ValueError('ellipses and brushes must have same length')
1079 return self._DrawEllipseList(ellipses, pens, brushes)
1082 def DrawPolygonList(self, polygons, pens=None, brushes=None):
1084 Draw a list of polygons, each of which is a list of points.
1086 :param polygons: A sequence of sequences of sequences.
1087 [[(x1,y1),(x2,y2),(x3,y3)...],
1088 [(x1,y1),(x2,y2),(x3,y3)...]]
1090 :param pens: If None, then the current pen is used. If a
1091 single pen then it will be used for all polygons.
1092 If a list of pens then there should be one for each
1094 :param brushes: A brush or brushes to be used to fill the polygons,
1095 with similar semantics as the pens parameter.
1099 elif isinstance(pens, wx.Pen):
1101 elif len(pens) != len(polygons):
1102 raise ValueError('polygons and pens must have same length')
1105 elif isinstance(brushes, wx.Brush):
1107 elif len(brushes) != len(polygons):
1108 raise ValueError('polygons and brushes must have same length')
1109 return self._DrawPolygonList(polygons, pens, brushes)
1112 def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None):
1114 Draw a list of strings using a list of coordinants for positioning each string.
1116 :param textList: A list of strings
1117 :param coords: A list of (x,y) positions
1118 :param foregrounds: A list of `wx.Colour` objects to use for the
1119 foregrounds of the strings.
1120 :param backgrounds: A list of `wx.Colour` objects to use for the
1121 backgrounds of the strings.
1123 NOTE: Make sure you set Background mode to wx.Solid (DC.SetBackgroundMode)
1124 If you want backgrounds to do anything.
1126 if type(textList) == type(''):
1127 textList = [textList]
1128 elif len(textList) != len(coords):
1129 raise ValueError('textlist and coords must have same length')
1130 if foregrounds is None:
1132 elif isinstance(foregrounds, wx.Colour):
1133 foregrounds = [foregrounds]
1134 elif len(foregrounds) != len(coords):
1135 raise ValueError('foregrounds and coords must have same length')
1136 if backgrounds is None:
1138 elif isinstance(backgrounds, wx.Colour):
1139 backgrounds = [backgrounds]
1140 elif len(backgrounds) != len(coords):
1141 raise ValueError('backgrounds and coords must have same length')
1142 return self._DrawTextList(textList, coords, foregrounds, backgrounds)
1150 static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) {
1159 //---------------------------------------------------------------------------
1162 MustHaveApp(wxMemoryDC);
1165 "A memory device context provides a means to draw graphics onto a
1166 bitmap. A bitmap must be selected into the new memory DC before it may
1167 be used for anything. Typical usage is as follows::
1170 dc.SelectObject(bitmap)
1171 # draw on the dc usign any of the Draw methods
1172 dc.SelectObject(wx.NullBitmap)
1173 # the bitmap now contains wahtever was drawn upon it
1175 Note that the memory DC *must* be deleted (or the bitmap selected out
1176 of it) before a bitmap can be reselected into another memory DC.
1179 class wxMemoryDC : public wxDC {
1183 "Constructs a new memory device context.
1185 Use the Ok member to test whether the constructor was successful in
1186 creating a usable device context. Don't forget to select a bitmap into
1187 the DC before drawing on it.", "
1189 :see: `MemoryDCFromDC`");
1192 wxMemoryDC(wxDC* oldDC),
1193 "Creates a DC that is compatible with the oldDC.", "",
1198 void , SelectObject(const wxBitmap& bitmap),
1199 "Selects the bitmap into the device context, to use as the memory
1200 bitmap. Selecting the bitmap into a memory DC allows you to draw into
1201 the DC, and therefore the bitmap, and also to use Blit to copy the
1204 If the argument is wx.NullBitmap (or some other uninitialised
1205 `wx.Bitmap`) the current bitmap is selected out of the device context,
1206 and the original bitmap restored, allowing the current bitmap to be
1207 destroyed safely.", "");
1211 //---------------------------------------------------------------------------
1216 #include <wx/dcbuffer.h>
1220 wxBUFFER_VIRTUAL_AREA,
1221 wxBUFFER_CLIENT_AREA
1224 MustHaveApp(wxBufferedDC);
1226 DocStr(wxBufferedDC,
1227 "This simple class provides a simple way to avoid flicker: when drawing
1228 on it, everything is in fact first drawn on an in-memory buffer (a
1229 `wx.Bitmap`) and then copied to the screen only once, when this object
1232 It can be used in the same way as any other device
1233 context. wx.BufferedDC itself typically replaces `wx.ClientDC`, if you
1234 want to use it in your EVT_PAINT handler, you should look at
1235 `wx.BufferedPaintDC`.
1238 class wxBufferedDC : public wxMemoryDC
1241 %pythonAppend wxBufferedDC
1242 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
1244 %nokwargs wxBufferedDC;
1248 "Constructs a buffered DC.", "
1250 :param dc: The underlying DC: everything drawn to this object will
1251 be flushed to this DC when this object is destroyed. You may
1252 pass ``None`` in order to just initialize the buffer, and not
1255 :param buffer: If a `wx.Size` object is passed as the 2nd arg then
1256 it is the size of the bitmap that will be created internally
1257 and used for an implicit buffer. If the 2nd arg is a
1258 `wx.Bitmap` then it is the explicit buffer that will be
1259 used. Using an explicit buffer is the most efficient solution
1260 as the bitmap doesn't have to be recreated each time but it
1261 also requires more memory as the bitmap is never freed. The
1262 bitmap should have appropriate size, anything drawn outside of
1263 its bounds is clipped. If wx.NullBitmap is used then a new
1264 buffer will be allocated that is the same size as the dc.
1266 :param style: The style parameter indicates whether the supplied buffer is
1267 intended to cover the entire virtual size of a `wx.ScrolledWindow` or
1268 if it only covers the client area. Acceptable values are
1269 ``wx.BUFFER_VIRTUAL_AREA`` and ``wx.BUFFER_CLIENT_AREA``.
1272 wxBufferedDC( wxDC* dc,
1273 const wxBitmap& buffer=wxNullBitmap,
1274 int style = wxBUFFER_CLIENT_AREA );
1275 wxBufferedDC( wxDC* dc,
1277 int style = wxBUFFER_CLIENT_AREA );
1281 "Copies everything drawn on the DC so far to the underlying DC
1282 associated with this object, if any.", "");
1287 "Blits the buffer to the dc, and detaches the dc from the buffer (so it
1288 can be effectively used once only). This is usually only called in
1289 the destructor.", "");
1296 MustHaveApp(wxBufferedPaintDC);
1298 DocStr(wxBufferedPaintDC,
1299 "This is a subclass of `wx.BufferedDC` which can be used inside of an
1300 EVT_PAINT event handler. Just create an object of this class instead
1301 of `wx.PaintDC` and that's all you have to do to (mostly) avoid
1302 flicker. The only thing to watch out for is that if you are using this
1303 class together with `wx.ScrolledWindow`, you probably do **not** want
1304 to call `wx.Window.PrepareDC` on it as it already does this internally
1305 for the real underlying `wx.PaintDC`.
1307 If your window is already fully buffered in a `wx.Bitmap` then your
1308 EVT_PAINT handler can be as simple as just creating a
1309 ``wx.BufferedPaintDC`` as it will `Blit` the buffer to the window
1310 automatically when it is destroyed. For example::
1312 def OnPaint(self, event):
1313 dc = wx.BufferedPaintDC(self, self.buffer)
1320 class wxBufferedPaintDC : public wxBufferedDC
1325 wxBufferedPaintDC( wxWindow *window,
1326 const wxBitmap &buffer = wxNullBitmap,
1327 int style = wxBUFFER_CLIENT_AREA),
1328 "Create a buffered paint DC. As with `wx.BufferedDC`, you may either
1329 provide the bitmap to be used for buffering or let this object create
1330 one internally (in the latter case, the size of the client part of the
1331 window is automatically used).
1338 //---------------------------------------------------------------------------
1341 MustHaveApp(wxScreenDC);
1344 "A wxScreenDC can be used to paint anywhere on the screen. This should
1345 normally be constructed as a temporary stack object; don't store a
1348 class wxScreenDC : public wxDC {
1353 bool , StartDrawingOnTop(wxWindow* window),
1354 "Specify that the area of the screen to be drawn upon coincides with
1357 :see: `EndDrawingOnTop`", "",
1358 StartDrawingOnTopWin);
1362 bool , StartDrawingOnTop(wxRect* rect = NULL),
1363 "Specify that the area is the given rectangle, or the whole screen if
1366 :see: `EndDrawingOnTop`", "");
1370 bool , EndDrawingOnTop(),
1371 "Use this in conjunction with `StartDrawingOnTop` or
1372 `StartDrawingOnTopWin` to ensure that drawing to the screen occurs on
1373 top of existing windows. Without this, some window systems (such as X)
1374 only allow drawing to take place underneath other windows.
1376 You might use this pair of functions when implementing a drag feature,
1377 for example as in the `wx.SplitterWindow` implementation.
1379 These functions are probably obsolete since the X implementations
1380 allow drawing directly on the screen now. However, the fact that this
1381 function allows the screen to be refreshed afterwards may be useful
1382 to some applications.", "");
1386 //---------------------------------------------------------------------------
1389 MustHaveApp(wxClientDC);
1392 "A wx.ClientDC must be constructed if an application wishes to paint on
1393 the client area of a window from outside an EVT_PAINT event. This should
1394 normally be constructed as a temporary stack object; don't store a
1395 wx.ClientDC object long term.
1397 To draw on a window from within an EVT_PAINT handler, construct a
1398 `wx.PaintDC` object.
1400 To draw on the whole window including decorations, construct a
1401 `wx.WindowDC` object (Windows only).
1403 class wxClientDC : public wxDC {
1406 wxClientDC(wxWindow* win),
1407 "Constructor. Pass the window on which you wish to paint.", "");
1410 //---------------------------------------------------------------------------
1413 MustHaveApp(wxPaintDC);
1416 "A wx.PaintDC must be constructed if an application wishes to paint on
1417 the client area of a window from within an EVT_PAINT event
1418 handler. This should normally be constructed as a temporary stack
1419 object; don't store a wx.PaintDC object. If you have an EVT_PAINT
1420 handler, you **must** create a wx.PaintDC object within it even if you
1421 don't actually use it.
1423 Using wx.PaintDC within EVT_PAINT handlers is important because it
1424 automatically sets the clipping area to the damaged area of the
1425 window. Attempts to draw outside this area do not appear.
1427 To draw on a window from outside EVT_PAINT handlers, construct a
1428 `wx.ClientDC` object.
1430 class wxPaintDC : public wxDC {
1433 wxPaintDC(wxWindow* win),
1434 "Constructor. Pass the window on which you wish to paint.", "");
1437 //---------------------------------------------------------------------------
1440 MustHaveApp(wxWindowDC);
1443 "A wx.WindowDC must be constructed if an application wishes to paint on
1444 the whole area of a window (client and decorations). This should
1445 normally be constructed as a temporary stack object; don't store a
1446 wx.WindowDC object.","");
1447 class wxWindowDC : public wxDC {
1450 wxWindowDC(wxWindow* win),
1451 "Constructor. Pass the window on which you wish to paint.","");
1454 //---------------------------------------------------------------------------
1457 MustHaveApp(wxMirrorDC);
1460 "wx.MirrorDC is a simple wrapper class which is always associated with a
1461 real `wx.DC` object and either forwards all of its operations to it
1462 without changes (no mirroring takes place) or exchanges x and y
1463 coordinates which makes it possible to reuse the same code to draw a
1464 figure and its mirror -- i.e. reflection related to the diagonal line
1466 class wxMirrorDC : public wxDC
1470 wxMirrorDC(wxDC& dc, bool mirror),
1471 "Creates a mirrored DC associated with the real *dc*. Everything drawn
1472 on the wx.MirrorDC will appear on the *dc*, and will be mirrored if
1473 *mirror* is True.","");
1476 //---------------------------------------------------------------------------
1480 #include <wx/dcps.h>
1483 MustHaveApp(wxPostScriptDC);
1485 DocStr(wxPostScriptDC,
1486 "This is a `wx.DC` that can write to PostScript files on any platform.","");
1488 class wxPostScriptDC : public wxDC {
1491 wxPostScriptDC(const wxPrintData& printData),
1492 "Constructs a PostScript printer device context from a `wx.PrintData`
1495 wxPrintData& GetPrintData();
1496 void SetPrintData(const wxPrintData& data);
1499 static void , SetResolution(int ppi),
1500 "Set resolution (in pixels per inch) that will be used in PostScript
1501 output. Default is 720ppi.", "");
1504 static int , GetResolution(),
1505 "Return resolution used in PostScript output.", "");
1508 //---------------------------------------------------------------------------
1512 MustHaveApp(wxMetaFile);
1513 MustHaveApp(wxMetaFileDC);
1516 #if defined(__WXMSW__) || defined(__WXMAC__)
1519 #include <wx/metafile.h>
1522 class wxMetaFile : public wxObject {
1524 wxMetaFile(const wxString& filename = wxPyEmptyString);
1528 bool SetClipboard(int width = 0, int height = 0);
1535 const wxString& GetFileName() const;
1538 %pythoncode { def __nonzero__(self): return self.Ok() }
1541 // bool wxMakeMetaFilePlaceable(const wxString& filename,
1542 // int minX, int minY, int maxX, int maxY, float scale=1.0);
1545 class wxMetaFileDC : public wxDC {
1547 wxMetaFileDC(const wxString& filename = wxPyEmptyString,
1548 int width = 0, int height = 0,
1549 const wxString& description = wxPyEmptyString);
1550 wxMetaFile* Close();
1555 #else // Make some dummies for the other platforms
1558 class wxMetaFile : public wxObject {
1560 wxMetaFile(const wxString&)
1561 { wxPyRaiseNotImplemented(); }
1564 class wxMetaFileDC : public wxClientDC {
1566 wxMetaFileDC(const wxString&, int, int, const wxString&)
1567 { wxPyRaiseNotImplemented(); }
1572 class wxMetaFile : public wxObject {
1574 wxMetaFile(const wxString& filename = wxPyEmptyString);
1577 class wxMetaFileDC : public wxDC {
1579 wxMetaFileDC(const wxString& filename = wxPyEmptyString,
1580 int width = 0, int height = 0,
1581 const wxString& description = wxPyEmptyString);
1588 //---------------------------------------------------------------------------
1590 MustHaveApp(wxPrinterDC);
1592 #if defined(__WXMSW__) || defined(__WXMAC__)
1594 class wxPrinterDC : public wxDC {
1596 wxPrinterDC(const wxPrintData& printData);
1601 class wxPrinterDC : public wxClientDC {
1603 wxPrinterDC(const wxPrintData&)
1604 { wxPyRaiseNotImplemented(); }
1609 class wxPrinterDC : public wxDC {
1611 wxPrinterDC(const wxPrintData& printData);
1615 //---------------------------------------------------------------------------
1616 //---------------------------------------------------------------------------