1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     Wraper definitions for the wxPseudoDC Class
 
   8 // Copyright:   (c) wxWidgets team
 
   9 // Licence:     wxWindows licence
 
  10 /////////////////////////////////////////////////////////////////////////////
 
  14 #include "wx/wxPython/pseudodc.h"
 
  20 "A PseudoDC is an object that can be used as if it were a `wx.DC`.  All
 
  21 commands issued to the PseudoDC are stored in a list.  You can then
 
  22 play these commands back to a real DC object using the DrawToDC
 
  23 method.  Commands in the command list are indexed by ID.  You can use
 
  24 this to clear the operations associated with a single ID and then
 
  25 re-draw the object associated with that ID.", "");
 
  27 class wxPseudoDC : public wxObject
 
  32         "Constructs a new Pseudo device context for recording dc operations","");
 
  34         void , BeginDrawing(),
 
  35         "Allows for optimization of drawing code on platforms that need it.  On
 
  36 other platforms this is just an empty function and is harmless.  To
 
  37 take advantage of this postential optimization simply enclose each
 
  38 group of calls to the drawing primitives within calls to
 
  39 `BeginDrawing` and `EndDrawing`.", "");
 
  43         "Ends the group of drawing primitives started with `BeginDrawing`, and
 
  44 invokes whatever optimization is available for this DC type on the
 
  45 current platform.", "");
 
  48         "Frees memory used by the operation list of the pseudo dc","");
 
  51         "Removes all objects and operations from the recorded list.", "");
 
  54         "Returns the number of operations in the recorded list.", "");
 
  57         "Sets the id to be associated with subsequent operations.", "");
 
  59         void, ClearId(int id),
 
  60         "Removes all operations associated with id so the object can be redrawn.", "");
 
  62         void, RemoveId(int id),
 
  63         "Remove the object node (and all operations) associated with an id.", "");
 
  65         void, TranslateId(int id, wxCoord dx, wxCoord dy),
 
  66         "Translate the operations of id by dx,dy.", "");
 
  68         void, DrawIdToDC(int id, wxDC *dc),
 
  69         "Draw recorded operations of id to dc.", "");
 
  71         void, SetIdBounds(int id, wxRect& rect),
 
  72         "Set the bounding rect of a given object.  This will create 
 
  73 an object node if one doesn't exist.", "");
 
  77             "Returns the bounding rectangle previouly set with SetIdBounds.  If
 
  78 no bounds have been set, it returns wx.Rect(0,0,0,0).", "");
 
  79         wxRect GetIdBounds(int id) {
 
  81             self->GetIdBounds(id, rect);
 
  86         void, DrawToDCClipped(wxDC *dc, const wxRect& rect),
 
  87         "Draws the recorded operations to dc unless the operation is known to
 
  88 be outside rect.", "");
 
  90         void, DrawToDCClippedRgn(wxDC *dc, const wxRegion& region),
 
  91         "Draws the recorded operations to dc unless the operation is known to
 
  92 be outside rect.", "");
 
  94         void, DrawToDC(wxDC *dc),
 
  95         "Draws the recorded operations to dc.", "");
 
  97     //-------------------------------------------------------------------------
 
  98     // Methods Mirrored from wxDC
 
  99     //-------------------------------------------------------------------------
 
 102 //        void , SetFont(const wxFont& font),
 
 103 //        "Sets the current font for the DC. It must be a valid font, in
 
 104 //particular you should not pass ``wx.NullFont`` to this method.","
 
 109 //        void , SetPen(const wxPen& pen),
 
 110 //        "Sets the current pen for the DC.
 
 112 //If the argument is ``wx.NullPen``, the current pen is selected out of the
 
 113 //device context, and the original pen restored.", "
 
 118 //        void , SetBrush(const wxBrush& brush),
 
 119 //        "Sets the current brush for the DC.
 
 121 //If the argument is ``wx.NullBrush``, the current brush is selected out
 
 122 //of the device context, and the original brush restored, allowing the
 
 123 //current brush to be destroyed safely.","
 
 125 //:see: `wx.Brush`");
 
 128 //        void , SetBackground(const wxBrush& brush),
 
 129 //        "Sets the current background brush for the DC.", "");
 
 132 //        void , SetBackgroundMode(int mode),
 
 133 //        "*mode* may be one of ``wx.SOLID`` and ``wx.TRANSPARENT``. This setting
 
 134 //determines whether text will be drawn with a background colour or
 
 138 //        void , SetTextForeground(const wxColour& colour),
 
 139 //        "Sets the current text foreground colour for the DC.", "");
 
 142 //        void , SetTextBackground(const wxColour& colour),
 
 143 //        "Sets the current text background colour for the DC.", "");
 
 145 //        void , DrawLabel(const wxString& text, const wxRect& rect,
 
 146 //                         int alignment = wxALIGN_LEFT | wxALIGN_TOP,
 
 147 //                         int indexAccel = -1),
 
 148 //        "Draw *text* within the specified rectangle, abiding by the alignment
 
 149 //flags.  Will additionally emphasize the character at *indexAccel* if
 
 152 //:see: `DrawImageLabel`");
 
 155 //        "Draws a text string at the specified point, using the current text
 
 156 //font, and the current text foreground and background colours.
 
 158 //The coordinates refer to the top-left corner of the rectangle bounding
 
 159 //the string. See `GetTextExtent` for how to get the dimensions of a
 
 160 //text string, which can be used to position the text more precisely.
 
 162 //**NOTE**: under wxGTK the current logical function is used by this
 
 163 //function but it is ignored by wxMSW. Thus, you should avoid using
 
 164 //logical functions with this function in portable programs.", "
 
 166 //:see: `DrawRotatedText`");
 
 167 //    void DrawText(const wxString& text, wxCoord x, wxCoord y);
 
 170 //        "Draws a line from the first point to the second. The current pen is
 
 171 //used for drawing the line. Note that the second point is *not* part of
 
 172 //the line and is not drawn by this function (this is consistent with
 
 173 //the behaviour of many other toolkits).", "");
 
 174 //    void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
 
 176 //        void, DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height),
 
 177 //        "Draws a rectangle with the given top left corner, and with the given
 
 178 //size. The current pen is used for the outline and the current brush
 
 179 //for filling the shape.", "");
 
 182 //        "Clears the device context using the current background brush.", "");
 
 186         "Flood fills the device context starting from the given point, using
 
 187 the current brush colour, and using a style:
 
 189     - **wxFLOOD_SURFACE**: the flooding occurs until a colour other than
 
 190       the given colour is encountered.
 
 192     - **wxFLOOD_BORDER**: the area to be flooded is bounded by the given
 
 195 Returns False if the operation failed.
 
 197 Note: The present implementation for non-Windows platforms may fail to
 
 198 find colour borders if the pixels do not match the colour
 
 199 exactly. However the function will still return true.", "");
 
 200     void FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
 
 201     %Rename(FloodFillPoint, void, FloodFill(const wxPoint& pt, const wxColour& col, int style = wxFLOOD_SURFACE));
 
 206         "Draws a line from the first point to the second. The current pen is
 
 207 used for drawing the line. Note that the second point is *not* part of
 
 208 the line and is not drawn by this function (this is consistent with
 
 209 the behaviour of many other toolkits).", "");
 
 210     void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
 
 211     %Rename(DrawLinePoint, void, DrawLine(const wxPoint& pt1, const wxPoint& pt2));
 
 216         "Displays a cross hair using the current pen. This is a vertical and
 
 217 horizontal line the height and width of the window, centred on the
 
 219     void CrossHair(wxCoord x, wxCoord y);
 
 220     %Rename(CrossHairPoint, void, CrossHair(const wxPoint& pt));
 
 225         "Draws an arc of a circle, centred on the *center* point (xc, yc), from
 
 226 the first point to the second. The current pen is used for the outline
 
 227 and the current brush for filling the shape.
 
 229 The arc is drawn in an anticlockwise direction from the start point to
 
 230 the end point.", "");
 
 231     void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
 
 232     %Rename(DrawArcPoint, void, DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& center));
 
 237         "Draws a check mark inside the given rectangle.", "");
 
 238     void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
 
 239     %Rename(DrawCheckMarkRect, void, DrawCheckMark(const wxRect& rect));
 
 243         "Draws an arc of an ellipse, with the given rectangle defining the
 
 244 bounds of the ellipse. The current pen is used for drawing the arc and
 
 245 the current brush is used for drawing the pie.
 
 247 The *start* and *end* parameters specify the start and end of the arc
 
 248 relative to the three-o'clock position from the center of the
 
 249 rectangle. Angles are specified in degrees (360 is a complete
 
 250 circle). Positive values mean counter-clockwise motion. If start is
 
 251 equal to end, a complete ellipse will be drawn.", "");
 
 252     void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double start, double end);
 
 253     %Rename(DrawEllipticArcPointSize, void, DrawEllipticArc(const wxPoint& pt, const wxSize& sz, double start, double end));
 
 258         "Draws a point using the current pen.", "");
 
 259     void DrawPoint(wxCoord x, wxCoord y);
 
 260     %Rename(DrawPointPoint, void, DrawPoint(const wxPoint& pt));
 
 265         "Draws a rectangle with the given top left corner, and with the given
 
 266 size. The current pen is used for the outline and the current brush
 
 267 for filling the shape.", "");
 
 268     void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
 
 269     %Rename(DrawRectangleRect,void, DrawRectangle(const wxRect& rect));
 
 270     %Rename(DrawRectanglePointSize, void, DrawRectangle(const wxPoint& pt, const wxSize& sz));
 
 274         DrawRoundedRectangle,
 
 275         "Draws a rectangle with the given top left corner, and with the given
 
 276 size. The corners are quarter-circles using the given radius. The
 
 277 current pen is used for the outline and the current brush for filling
 
 280 If radius is positive, the value is assumed to be the radius of the
 
 281 rounded corner. If radius is negative, the absolute value is assumed
 
 282 to be the proportion of the smallest dimension of the rectangle. This
 
 283 means that the corner can be a sensible size relative to the size of
 
 284 the rectangle, and also avoids the strange effects X produces when the
 
 285 corners are too big for the rectangle.", "");
 
 286     void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius);
 
 287     %Rename(DrawRoundedRectangleRect, void, DrawRoundedRectangle(const wxRect& r, double radius));
 
 288     %Rename(DrawRoundedRectanglePointSize, void, DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius));
 
 293         "Draws a circle with the given center point and radius.  The current
 
 294 pen is used for the outline and the current brush for filling the
 
 297 :see: `DrawEllipse`");
 
 298     void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
 
 299     %Rename(DrawCirclePoint, void, DrawCircle(const wxPoint& pt, wxCoord radius));
 
 304         "Draws an ellipse contained in the specified rectangle. The current pen
 
 305 is used for the outline and the current brush for filling the shape.", "
 
 307 :see: `DrawCircle`");
 
 308     void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
 
 309     %Rename(DrawEllipseRect, void, DrawEllipse(const wxRect& rect));
 
 310     %Rename(DrawEllipsePointSize, void, DrawEllipse(const wxPoint& pt, const wxSize& sz));
 
 315         "Draw an icon on the display (does nothing if the device context is
 
 316 PostScript). This can be the simplest way of drawing bitmaps on a
 
 318     void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
 
 319     %Rename(DrawIconPoint, void, DrawIcon(const wxIcon& icon, const wxPoint& pt));
 
 324         "Draw a bitmap on the device context at the specified point. If
 
 325 *transparent* is true and the bitmap has a transparency mask, (or
 
 326 alpha channel on the platforms that support it) then the bitmap will
 
 327 be drawn transparently.", "
 
 329 When drawing a mono-bitmap, the current text foreground colour will be
 
 330 used to draw the foreground of the bitmap (all bits set to 1), and the
 
 331 current text background colour to draw the background (all bits set to
 
 334 :see: `SetTextForeground`, `SetTextBackground` and `wx.MemoryDC`");
 
 335     void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = false);
 
 336     %Rename(DrawBitmapPoint, void, DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, bool useMask = false));
 
 341         "Draws a text string at the specified point, using the current text
 
 342 font, and the current text foreground and background colours.
 
 344 The coordinates refer to the top-left corner of the rectangle bounding
 
 345 the string. See `wx.DC.GetTextExtent` for how to get the dimensions of
 
 346 a text string, which can be used to position the text more precisely,
 
 347 (you will need to use a real DC with GetTextExtent as wx.PseudoDC does
 
 350 **NOTE**: under wxGTK the current logical function is used by this
 
 351 function but it is ignored by wxMSW. Thus, you should avoid using
 
 352 logical functions with this function in portable programs.", "
 
 354 :see: `DrawRotatedText`");
 
 355     void DrawText(const wxString& text, wxCoord x, wxCoord y);
 
 356     %Rename(DrawTextPoint, void, DrawText(const wxString& text, const wxPoint& pt));
 
 361         "Draws the text rotated by *angle* degrees, if supported by the platform.
 
 363 **NOTE**: Under Win9x only TrueType fonts can be drawn by this
 
 364 function. In particular, a font different from ``wx.NORMAL_FONT``
 
 365 should be used as the it is not normally a TrueType
 
 366 font. ``wx.SWISS_FONT`` is an example of a font which is.","
 
 369     void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
 
 370     %Rename(DrawRotatedTextPoint, void, DrawRotatedText(const wxString& text, const wxPoint& pt, double angle));
 
 374 //        bool , Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
 
 375 //                    wxDC *source, wxCoord xsrc, wxCoord ysrc,
 
 376 //                    int rop = wxCOPY, bool useMask = false,
 
 377 //                    wxCoord xsrcMask = -1, wxCoord ysrcMask = -1),
 
 378 //        "Copy from a source DC to this DC.  Parameters specify the destination
 
 379 //coordinates, size of area to copy, source DC, source coordinates,
 
 380 //logical function, whether to use a bitmap mask, and mask source
 
 383 //    :param xdest:       Destination device context x position.
 
 384 //    :param ydest:       Destination device context y position.
 
 385 //    :param width:       Width of source area to be copied.
 
 386 //    :param height:      Height of source area to be copied.
 
 387 //    :param source:      Source device context.
 
 388 //    :param xsrc:        Source device context x position.
 
 389 //    :param ysrc:        Source device context y position.
 
 390 //    :param rop:         Logical function to use: see `SetLogicalFunction`.
 
 391 //    :param useMask:     If true, Blit does a transparent blit using the mask
 
 392 //                        that is associated with the bitmap selected into the
 
 393 //                        source device context.
 
 394 //    :param xsrcMask:    Source x position on the mask. If both xsrcMask and
 
 395 //                        ysrcMask are -1, xsrc and ysrc will be assumed for
 
 396 //                        the mask source position.
 
 397 //    :param ysrcMask:    Source y position on the mask. 
 
 401 //        bool , Blit(const wxPoint& destPt, const wxSize& sz,
 
 402 //                    wxDC *source, const wxPoint& srcPt,
 
 403 //                    int rop = wxCOPY, bool useMask = false,
 
 404 //                    const wxPoint& srcPtMask = wxDefaultPosition),
 
 405 //        "Copy from a source DC to this DC.  Parameters specify the destination
 
 406 //coordinates, size of area to copy, source DC, source coordinates,
 
 407 //logical function, whether to use a bitmap mask, and mask source
 
 410 //    :param destPt:      Destination device context position.
 
 411 //    :param sz:          Size of source area to be copied.
 
 412 //    :param source:      Source device context.
 
 413 //    :param srcPt:       Source device context position.
 
 414 //    :param rop:         Logical function to use: see `SetLogicalFunction`.
 
 415 //    :param useMask:     If true, Blit does a transparent blit using the mask
 
 416 //                        that is associated with the bitmap selected into the
 
 417 //                        source device context.
 
 418 //    :param srcPtMask:   Source position on the mask. 
 
 424         void , DrawLines(int points, wxPoint* points_array,
 
 425                          wxCoord xoffset = 0, wxCoord yoffset = 0),
 
 426         "DrawLines(self, List points, int xoffset=0, int yoffset=0)",
 
 427         "Draws lines using a sequence of `wx.Point` objects, adding the
 
 428 optional offset coordinate. The current pen is used for drawing the
 
 433         void , DrawPolygon(int points, wxPoint* points_array,
 
 434                      wxCoord xoffset = 0, wxCoord yoffset = 0,
 
 435                            int fillStyle = wxODDEVEN_RULE),
 
 436         "DrawPolygon(self, List points, int xoffset=0, int yoffset=0,
 
 437     int fillStyle=ODDEVEN_RULE)",
 
 438         "Draws a filled polygon using a sequence of `wx.Point` objects, adding
 
 439 the optional offset coordinate.  The last argument specifies the fill
 
 440 rule: ``wx.ODDEVEN_RULE`` (the default) or ``wx.WINDING_RULE``.
 
 442 The current pen is used for drawing the outline, and the current brush
 
 443 for filling the shape. Using a transparent brush suppresses
 
 444 filling. Note that wxWidgets automatically closes the first and last
 
 448     // TODO:  Figure out a good typemap for this...
 
 449     //        Convert the first 3 args from a sequence of sequences?
 
 450 //     void DrawPolyPolygon(int n, int count[], wxPoint points[],
 
 451 //                           wxCoord xoffset = 0, wxCoord yoffset = 0,
 
 452 //                           int fillStyle = wxODDEVEN_RULE);
 
 456         void , DrawLabel(const wxString& text, const wxRect& rect,
 
 457                          int alignment = wxALIGN_LEFT | wxALIGN_TOP,
 
 458                          int indexAccel = -1),
 
 459         "Draw *text* within the specified rectangle, abiding by the alignment
 
 460 flags.  Will additionally emphasize the character at *indexAccel* if
 
 463 :see: `DrawImageLabel`");
 
 466         void, DrawLabel(const wxString& text,
 
 467                               const wxBitmap& image,
 
 469                               int alignment = wxALIGN_LEFT | wxALIGN_TOP,
 
 470                               int indexAccel = -1),
 
 471        "Draw *text* and an image (which may be ``wx.NullBitmap`` to skip
 
 472 drawing it) within the specified rectangle, abiding by the alignment
 
 473 flags.  Will additionally emphasize the character at *indexAccel* if
 
 474 it is not -1.", "", DrawImageLabel);
 
 478         void , DrawSpline(int points, wxPoint* points_array),
 
 479         "DrawSpline(self, List points)",
 
 480         "Draws a spline between all given control points, (a list of `wx.Point`
 
 481 objects) using the current pen. The spline is drawn using a series of
 
 482 lines, using an algorithm taken from the X drawing program 'XFIG'.", "");
 
 486         virtual void , Clear(),
 
 487         "Clears the device context using the current background brush.", "");
 
 490     // set objects to use for drawing
 
 491     // ------------------------------
 
 494         virtual void , SetFont(const wxFont& font),
 
 495         "Sets the current font for the DC. It must be a valid font, in
 
 496 particular you should not pass ``wx.NullFont`` to this method.","
 
 501         virtual void , SetPen(const wxPen& pen),
 
 502         "Sets the current pen for the DC.
 
 504 If the argument is ``wx.NullPen``, the current pen is selected out of the
 
 505 device context, and the original pen restored.", "
 
 510         virtual void , SetBrush(const wxBrush& brush),
 
 511         "Sets the current brush for the DC.
 
 513 If the argument is ``wx.NullBrush``, the current brush is selected out
 
 514 of the device context, and the original brush restored, allowing the
 
 515 current brush to be destroyed safely.","
 
 520         virtual void , SetBackground(const wxBrush& brush),
 
 521         "Sets the current background brush for the DC.", "");
 
 524         virtual void , SetBackgroundMode(int mode),
 
 525         "*mode* may be one of ``wx.SOLID`` and ``wx.TRANSPARENT``. This setting
 
 526 determines whether text will be drawn with a background colour or
 
 530         virtual void , SetPalette(const wxPalette& palette),
 
 531         "If this is a window DC or memory DC, assigns the given palette to the
 
 532 window or bitmap associated with the DC. If the argument is
 
 533 ``wx.NullPalette``, the current palette is selected out of the device
 
 534 context, and the original palette restored.", "
 
 536 :see: `wx.Palette`");
 
 540         virtual void , SetTextForeground(const wxColour& colour),
 
 541         "Sets the current text foreground colour for the DC.", "");
 
 544         virtual void , SetTextBackground(const wxColour& colour),
 
 545         "Sets the current text background colour for the DC.", "");
 
 548         virtual void , SetLogicalFunction(int function),
 
 549         "Sets the current logical function for the device context. This
 
 550 determines how a source pixel (from a pen or brush colour, combines
 
 551 with a destination pixel in the current device context.
 
 553 The possible values and their meaning in terms of source and
 
 554 destination pixel values are as follows:
 
 556     ================       ==========================
 
 558     wx.AND_INVERT          (NOT src) AND dst
 
 559     wx.AND_REVERSE         src AND (NOT dst)
 
 562     wx.EQUIV               (NOT src) XOR dst
 
 564     wx.NAND                (NOT src) OR (NOT dst)
 
 565     wx.NOR                 (NOT src) AND (NOT dst)
 
 568     wx.OR_INVERT           (NOT src) OR dst
 
 569     wx.OR_REVERSE          src OR (NOT dst)
 
 571     wx.SRC_INVERT          NOT src
 
 573     ================       ==========================
 
 575 The default is wx.COPY, which simply draws with the current
 
 576 colour. The others combine the current colour and the background using
 
 577 a logical operation. wx.INVERT is commonly used for drawing rubber
 
 578 bands or moving outlines, since drawing twice reverts to the original