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, SetIdGreyedOut(int id, bool greyout=true),
 
  69         "Set whether an object is drawn greyed out or not.", "");
 
  71         bool, GetIdGreyedOut(int id),
 
  72         "Get whether an object is drawn greyed out or not.", "");
 
  75         PyObject*, FindObjects(wxCoord x, wxCoord y, 
 
  76                                wxCoord radius=1, const wxColor& bg=*wxWHITE),
 
  77         "Returns a list of all the id's that draw a pixel with color
 
  78 not equal to bg within radius of (x,y).
 
  79 Returns an empty list if nothing is found.  The list is in
 
  80 reverse drawing order so list[0] is the top id.","");
 
  81     KeepGIL(FindObjectsByBBox);
 
  83         PyObject*, FindObjectsByBBox(wxCoord x, wxCoord y),
 
  84         "Returns a list of all the id's whose bounding boxes include (x,y).
 
  85 Returns an empty list if nothing is found.  The list is in
 
  86 reverse drawing order so list[0] is the top id.","");
 
  88         void, DrawIdToDC(int id, wxDC *dc),
 
  89         "Draw recorded operations of id to dc.", "");
 
  91         void, SetIdBounds(int id, wxRect& rect),
 
  92         "Set the bounding rect of a given object.  This will create 
 
  93 an object node if one doesn't exist.", "");
 
  97             "Returns the bounding rectangle previouly set with SetIdBounds.  If
 
  98 no bounds have been set, it returns wx.Rect(0,0,0,0).", "");
 
  99         wxRect GetIdBounds(int id) {
 
 101             self->GetIdBounds(id, rect);
 
 106         void, DrawToDCClipped(wxDC *dc, const wxRect& rect),
 
 107         "Draws the recorded operations to dc unless the operation is known to
 
 108 be outside rect.", "");
 
 110         void, DrawToDCClippedRgn(wxDC *dc, const wxRegion& region),
 
 111         "Draws the recorded operations to dc unless the operation is known to
 
 112 be outside rect.", "");
 
 114         void, DrawToDC(wxDC *dc),
 
 115         "Draws the recorded operations to dc.", "");
 
 117     //-------------------------------------------------------------------------
 
 118     // Methods Mirrored from wxDC
 
 119     //-------------------------------------------------------------------------
 
 122 //        void , SetFont(const wxFont& font),
 
 123 //        "Sets the current font for the DC. It must be a valid font, in
 
 124 //particular you should not pass ``wx.NullFont`` to this method.","
 
 129 //        void , SetPen(const wxPen& pen),
 
 130 //        "Sets the current pen for the DC.
 
 132 //If the argument is ``wx.NullPen``, the current pen is selected out of the
 
 133 //device context, and the original pen restored.", "
 
 138 //        void , SetBrush(const wxBrush& brush),
 
 139 //        "Sets the current brush for the DC.
 
 141 //If the argument is ``wx.NullBrush``, the current brush is selected out
 
 142 //of the device context, and the original brush restored, allowing the
 
 143 //current brush to be destroyed safely.","
 
 145 //:see: `wx.Brush`");
 
 148 //        void , SetBackground(const wxBrush& brush),
 
 149 //        "Sets the current background brush for the DC.", "");
 
 152 //        void , SetBackgroundMode(int mode),
 
 153 //        "*mode* may be one of ``wx.SOLID`` and ``wx.TRANSPARENT``. This setting
 
 154 //determines whether text will be drawn with a background colour or
 
 158 //        void , SetTextForeground(const wxColour& colour),
 
 159 //        "Sets the current text foreground colour for the DC.", "");
 
 162 //        void , SetTextBackground(const wxColour& colour),
 
 163 //        "Sets the current text background colour for the DC.", "");
 
 165 //        void , DrawLabel(const wxString& text, const wxRect& rect,
 
 166 //                         int alignment = wxALIGN_LEFT | wxALIGN_TOP,
 
 167 //                         int indexAccel = -1),
 
 168 //        "Draw *text* within the specified rectangle, abiding by the alignment
 
 169 //flags.  Will additionally emphasize the character at *indexAccel* if
 
 172 //:see: `DrawImageLabel`");
 
 175 //        "Draws a text string at the specified point, using the current text
 
 176 //font, and the current text foreground and background colours.
 
 178 //The coordinates refer to the top-left corner of the rectangle bounding
 
 179 //the string. See `GetTextExtent` for how to get the dimensions of a
 
 180 //text string, which can be used to position the text more precisely.
 
 182 //**NOTE**: under wxGTK the current logical function is used by this
 
 183 //function but it is ignored by wxMSW. Thus, you should avoid using
 
 184 //logical functions with this function in portable programs.", "
 
 186 //:see: `DrawRotatedText`");
 
 187 //    void DrawText(const wxString& text, wxCoord x, wxCoord y);
 
 190 //        "Draws a line from the first point to the second. The current pen is
 
 191 //used for drawing the line. Note that the second point is *not* part of
 
 192 //the line and is not drawn by this function (this is consistent with
 
 193 //the behaviour of many other toolkits).", "");
 
 194 //    void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
 
 196 //        void, DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height),
 
 197 //        "Draws a rectangle with the given top left corner, and with the given
 
 198 //size. The current pen is used for the outline and the current brush
 
 199 //for filling the shape.", "");
 
 202 //        "Clears the device context using the current background brush.", "");
 
 206         "Flood fills the device context starting from the given point, using
 
 207 the current brush colour, and using a style:
 
 209     - **wxFLOOD_SURFACE**: the flooding occurs until a colour other than
 
 210       the given colour is encountered.
 
 212     - **wxFLOOD_BORDER**: the area to be flooded is bounded by the given
 
 215 Returns False if the operation failed.
 
 217 Note: The present implementation for non-Windows platforms may fail to
 
 218 find colour borders if the pixels do not match the colour
 
 219 exactly. However the function will still return true.", "");
 
 220     void FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
 
 221     %Rename(FloodFillPoint, void, FloodFill(const wxPoint& pt, const wxColour& col, int style = wxFLOOD_SURFACE));
 
 226         "Draws a line from the first point to the second. The current pen is
 
 227 used for drawing the line. Note that the second point is *not* part of
 
 228 the line and is not drawn by this function (this is consistent with
 
 229 the behaviour of many other toolkits).", "");
 
 230     void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
 
 231     %Rename(DrawLinePoint, void, DrawLine(const wxPoint& pt1, const wxPoint& pt2));
 
 236         "Displays a cross hair using the current pen. This is a vertical and
 
 237 horizontal line the height and width of the window, centred on the
 
 239     void CrossHair(wxCoord x, wxCoord y);
 
 240     %Rename(CrossHairPoint, void, CrossHair(const wxPoint& pt));
 
 245         "Draws an arc of a circle, centred on the *center* point (xc, yc), from
 
 246 the first point to the second. The current pen is used for the outline
 
 247 and the current brush for filling the shape.
 
 249 The arc is drawn in an anticlockwise direction from the start point to
 
 250 the end point.", "");
 
 251     void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc);
 
 252     %Rename(DrawArcPoint, void, DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& center));
 
 257         "Draws a check mark inside the given rectangle.", "");
 
 258     void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
 
 259     %Rename(DrawCheckMarkRect, void, DrawCheckMark(const wxRect& rect));
 
 263         "Draws an arc of an ellipse, with the given rectangle defining the
 
 264 bounds of the ellipse. The current pen is used for drawing the arc and
 
 265 the current brush is used for drawing the pie.
 
 267 The *start* and *end* parameters specify the start and end of the arc
 
 268 relative to the three-o'clock position from the center of the
 
 269 rectangle. Angles are specified in degrees (360 is a complete
 
 270 circle). Positive values mean counter-clockwise motion. If start is
 
 271 equal to end, a complete ellipse will be drawn.", "");
 
 272     void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double start, double end);
 
 273     %Rename(DrawEllipticArcPointSize, void, DrawEllipticArc(const wxPoint& pt, const wxSize& sz, double start, double end));
 
 278         "Draws a point using the current pen.", "");
 
 279     void DrawPoint(wxCoord x, wxCoord y);
 
 280     %Rename(DrawPointPoint, void, DrawPoint(const wxPoint& pt));
 
 285         "Draws a rectangle with the given top left corner, and with the given
 
 286 size. The current pen is used for the outline and the current brush
 
 287 for filling the shape.", "");
 
 288     void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
 
 289     %Rename(DrawRectangleRect,void, DrawRectangle(const wxRect& rect));
 
 290     %Rename(DrawRectanglePointSize, void, DrawRectangle(const wxPoint& pt, const wxSize& sz));
 
 294         DrawRoundedRectangle,
 
 295         "Draws a rectangle with the given top left corner, and with the given
 
 296 size. The corners are quarter-circles using the given radius. The
 
 297 current pen is used for the outline and the current brush for filling
 
 300 If radius is positive, the value is assumed to be the radius of the
 
 301 rounded corner. If radius is negative, the absolute value is assumed
 
 302 to be the proportion of the smallest dimension of the rectangle. This
 
 303 means that the corner can be a sensible size relative to the size of
 
 304 the rectangle, and also avoids the strange effects X produces when the
 
 305 corners are too big for the rectangle.", "");
 
 306     void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius);
 
 307     %Rename(DrawRoundedRectangleRect, void, DrawRoundedRectangle(const wxRect& r, double radius));
 
 308     %Rename(DrawRoundedRectanglePointSize, void, DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius));
 
 313         "Draws a circle with the given center point and radius.  The current
 
 314 pen is used for the outline and the current brush for filling the
 
 317 :see: `DrawEllipse`");
 
 318     void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
 
 319     %Rename(DrawCirclePoint, void, DrawCircle(const wxPoint& pt, wxCoord radius));
 
 324         "Draws an ellipse contained in the specified rectangle. The current pen
 
 325 is used for the outline and the current brush for filling the shape.", "
 
 327 :see: `DrawCircle`");
 
 328     void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
 
 329     %Rename(DrawEllipseRect, void, DrawEllipse(const wxRect& rect));
 
 330     %Rename(DrawEllipsePointSize, void, DrawEllipse(const wxPoint& pt, const wxSize& sz));
 
 335         "Draw an icon on the display (does nothing if the device context is
 
 336 PostScript). This can be the simplest way of drawing bitmaps on a
 
 338     void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
 
 339     %Rename(DrawIconPoint, void, DrawIcon(const wxIcon& icon, const wxPoint& pt));
 
 344         "Draw a bitmap on the device context at the specified point. If
 
 345 *transparent* is true and the bitmap has a transparency mask, (or
 
 346 alpha channel on the platforms that support it) then the bitmap will
 
 347 be drawn transparently.", "
 
 349 When drawing a mono-bitmap, the current text foreground colour will be
 
 350 used to draw the foreground of the bitmap (all bits set to 1), and the
 
 351 current text background colour to draw the background (all bits set to
 
 354 :see: `SetTextForeground`, `SetTextBackground` and `wx.MemoryDC`");
 
 355     void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = false);
 
 356     %Rename(DrawBitmapPoint, void, DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, bool useMask = false));
 
 361         "Draws a text string at the specified point, using the current text
 
 362 font, and the current text foreground and background colours.
 
 364 The coordinates refer to the top-left corner of the rectangle bounding
 
 365 the string. See `wx.DC.GetTextExtent` for how to get the dimensions of
 
 366 a text string, which can be used to position the text more precisely,
 
 367 (you will need to use a real DC with GetTextExtent as wx.PseudoDC does
 
 370 **NOTE**: under wxGTK the current logical function is used by this
 
 371 function but it is ignored by wxMSW. Thus, you should avoid using
 
 372 logical functions with this function in portable programs.", "
 
 374 :see: `DrawRotatedText`");
 
 375     void DrawText(const wxString& text, wxCoord x, wxCoord y);
 
 376     %Rename(DrawTextPoint, void, DrawText(const wxString& text, const wxPoint& pt));
 
 381         "Draws the text rotated by *angle* degrees, if supported by the platform.
 
 383 **NOTE**: Under Win9x only TrueType fonts can be drawn by this
 
 384 function. In particular, a font different from ``wx.NORMAL_FONT``
 
 385 should be used as the it is not normally a TrueType
 
 386 font. ``wx.SWISS_FONT`` is an example of a font which is.","
 
 389     void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
 
 390     %Rename(DrawRotatedTextPoint, void, DrawRotatedText(const wxString& text, const wxPoint& pt, double angle));
 
 394 //        bool , Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
 
 395 //                    wxDC *source, wxCoord xsrc, wxCoord ysrc,
 
 396 //                    int rop = wxCOPY, bool useMask = false,
 
 397 //                    wxCoord xsrcMask = -1, wxCoord ysrcMask = -1),
 
 398 //        "Copy from a source DC to this DC.  Parameters specify the destination
 
 399 //coordinates, size of area to copy, source DC, source coordinates,
 
 400 //logical function, whether to use a bitmap mask, and mask source
 
 403 //    :param xdest:       Destination device context x position.
 
 404 //    :param ydest:       Destination device context y position.
 
 405 //    :param width:       Width of source area to be copied.
 
 406 //    :param height:      Height of source area to be copied.
 
 407 //    :param source:      Source device context.
 
 408 //    :param xsrc:        Source device context x position.
 
 409 //    :param ysrc:        Source device context y position.
 
 410 //    :param rop:         Logical function to use: see `SetLogicalFunction`.
 
 411 //    :param useMask:     If true, Blit does a transparent blit using the mask
 
 412 //                        that is associated with the bitmap selected into the
 
 413 //                        source device context.
 
 414 //    :param xsrcMask:    Source x position on the mask. If both xsrcMask and
 
 415 //                        ysrcMask are -1, xsrc and ysrc will be assumed for
 
 416 //                        the mask source position.
 
 417 //    :param ysrcMask:    Source y position on the mask. 
 
 421 //        bool , Blit(const wxPoint& destPt, const wxSize& sz,
 
 422 //                    wxDC *source, const wxPoint& srcPt,
 
 423 //                    int rop = wxCOPY, bool useMask = false,
 
 424 //                    const wxPoint& srcPtMask = wxDefaultPosition),
 
 425 //        "Copy from a source DC to this DC.  Parameters specify the destination
 
 426 //coordinates, size of area to copy, source DC, source coordinates,
 
 427 //logical function, whether to use a bitmap mask, and mask source
 
 430 //    :param destPt:      Destination device context position.
 
 431 //    :param sz:          Size of source area to be copied.
 
 432 //    :param source:      Source device context.
 
 433 //    :param srcPt:       Source device context position.
 
 434 //    :param rop:         Logical function to use: see `SetLogicalFunction`.
 
 435 //    :param useMask:     If true, Blit does a transparent blit using the mask
 
 436 //                        that is associated with the bitmap selected into the
 
 437 //                        source device context.
 
 438 //    :param srcPtMask:   Source position on the mask. 
 
 444         void , DrawLines(int points, wxPoint* points_array,
 
 445                          wxCoord xoffset = 0, wxCoord yoffset = 0),
 
 446         "DrawLines(self, List points, int xoffset=0, int yoffset=0)",
 
 447         "Draws lines using a sequence of `wx.Point` objects, adding the
 
 448 optional offset coordinate. The current pen is used for drawing the
 
 453         void , DrawPolygon(int points, wxPoint* points_array,
 
 454                      wxCoord xoffset = 0, wxCoord yoffset = 0,
 
 455                            int fillStyle = wxODDEVEN_RULE),
 
 456         "DrawPolygon(self, List points, int xoffset=0, int yoffset=0,
 
 457     int fillStyle=ODDEVEN_RULE)",
 
 458         "Draws a filled polygon using a sequence of `wx.Point` objects, adding
 
 459 the optional offset coordinate.  The last argument specifies the fill
 
 460 rule: ``wx.ODDEVEN_RULE`` (the default) or ``wx.WINDING_RULE``.
 
 462 The current pen is used for drawing the outline, and the current brush
 
 463 for filling the shape. Using a transparent brush suppresses
 
 464 filling. Note that wxWidgets automatically closes the first and last
 
 468     // TODO:  Figure out a good typemap for this...
 
 469     //        Convert the first 3 args from a sequence of sequences?
 
 470 //     void DrawPolyPolygon(int n, int count[], wxPoint points[],
 
 471 //                           wxCoord xoffset = 0, wxCoord yoffset = 0,
 
 472 //                           int fillStyle = wxODDEVEN_RULE);
 
 476         void , DrawLabel(const wxString& text, const wxRect& rect,
 
 477                          int alignment = wxALIGN_LEFT | wxALIGN_TOP,
 
 478                          int indexAccel = -1),
 
 479         "Draw *text* within the specified rectangle, abiding by the alignment
 
 480 flags.  Will additionally emphasize the character at *indexAccel* if
 
 483 :see: `DrawImageLabel`");
 
 486         void, DrawLabel(const wxString& text,
 
 487                               const wxBitmap& image,
 
 489                               int alignment = wxALIGN_LEFT | wxALIGN_TOP,
 
 490                               int indexAccel = -1),
 
 491        "Draw *text* and an image (which may be ``wx.NullBitmap`` to skip
 
 492 drawing it) within the specified rectangle, abiding by the alignment
 
 493 flags.  Will additionally emphasize the character at *indexAccel* if
 
 494 it is not -1.", "", DrawImageLabel);
 
 498         void , DrawSpline(int points, wxPoint* points_array),
 
 499         "DrawSpline(self, List points)",
 
 500         "Draws a spline between all given control points, (a list of `wx.Point`
 
 501 objects) using the current pen. The spline is drawn using a series of
 
 502 lines, using an algorithm taken from the X drawing program 'XFIG'.", "");
 
 506         virtual void , Clear(),
 
 507         "Clears the device context using the current background brush.", "");
 
 510     // set objects to use for drawing
 
 511     // ------------------------------
 
 514         virtual void , SetFont(const wxFont& font),
 
 515         "Sets the current font for the DC. It must be a valid font, in
 
 516 particular you should not pass ``wx.NullFont`` to this method.","
 
 521         virtual void , SetPen(const wxPen& pen),
 
 522         "Sets the current pen for the DC.
 
 524 If the argument is ``wx.NullPen``, the current pen is selected out of the
 
 525 device context, and the original pen restored.", "
 
 530         virtual void , SetBrush(const wxBrush& brush),
 
 531         "Sets the current brush for the DC.
 
 533 If the argument is ``wx.NullBrush``, the current brush is selected out
 
 534 of the device context, and the original brush restored, allowing the
 
 535 current brush to be destroyed safely.","
 
 540         virtual void , SetBackground(const wxBrush& brush),
 
 541         "Sets the current background brush for the DC.", "");
 
 544         virtual void , SetBackgroundMode(int mode),
 
 545         "*mode* may be one of ``wx.SOLID`` and ``wx.TRANSPARENT``. This setting
 
 546 determines whether text will be drawn with a background colour or
 
 550         virtual void , SetPalette(const wxPalette& palette),
 
 551         "If this is a window DC or memory DC, assigns the given palette to the
 
 552 window or bitmap associated with the DC. If the argument is
 
 553 ``wx.NullPalette``, the current palette is selected out of the device
 
 554 context, and the original palette restored.", "
 
 556 :see: `wx.Palette`");
 
 560         virtual void , SetTextForeground(const wxColour& colour),
 
 561         "Sets the current text foreground colour for the DC.", "");
 
 564         virtual void , SetTextBackground(const wxColour& colour),
 
 565         "Sets the current text background colour for the DC.", "");
 
 568         virtual void , SetLogicalFunction(int function),
 
 569         "Sets the current logical function for the device context. This
 
 570 determines how a source pixel (from a pen or brush colour, combines
 
 571 with a destination pixel in the current device context.
 
 573 The possible values and their meaning in terms of source and
 
 574 destination pixel values are as follows:
 
 576     ================       ==========================
 
 578     wx.AND_INVERT          (NOT src) AND dst
 
 579     wx.AND_REVERSE         src AND (NOT dst)
 
 582     wx.EQUIV               (NOT src) XOR dst
 
 584     wx.NAND                (NOT src) OR (NOT dst)
 
 585     wx.NOR                 (NOT src) AND (NOT dst)
 
 588     wx.OR_INVERT           (NOT src) OR dst
 
 589     wx.OR_REVERSE          src OR (NOT dst)
 
 591     wx.SRC_INVERT          NOT src
 
 593     ================       ==========================
 
 595 The default is wx.COPY, which simply draws with the current
 
 596 colour. The others combine the current colour and the background using
 
 597 a logical operation. wx.INVERT is commonly used for drawing rubber
 
 598 bands or moving outlines, since drawing twice reverts to the original
 
 603     %property(IdBounds, GetIdBounds, SetIdBounds, doc="See `GetIdBounds` and `SetIdBounds`");
 
 604     %property(Len, GetLen, doc="See `GetLen`");