]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _dc.i | |
3 | // Purpose: SWIG interface defs for wxDC and releated classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 7-July-1997 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
4942342c | 16 | |
d14a1e28 RD |
17 | //--------------------------------------------------------------------------- |
18 | ||
19 | %{ | |
20 | #include "wx/wxPython/pydrawxxx.h" | |
21 | %} | |
22 | ||
23 | // TODO: 1. wrappers for wxDrawObject and wxDC::DrawObject | |
24 | ||
25 | ||
26 | //--------------------------------------------------------------------------- | |
27 | ||
28 | %typemap(in) (int points, wxPoint* points_array ) { | |
29 | $2 = wxPoint_LIST_helper($input, &$1); | |
30 | if ($2 == NULL) SWIG_fail; | |
31 | } | |
32 | %typemap(freearg) (int points, wxPoint* points_array ) { | |
33 | if ($2) delete [] $2; | |
34 | } | |
35 | ||
36 | ||
37 | //--------------------------------------------------------------------------- | |
38 | %newgroup; | |
39 | ||
40 | ||
70794ec5 RD |
41 | DocStr(wxDC, |
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. | |
48 | ||
49 | Derived types of wxDC have documentation for specific features only, | |
50 | so refer to this section for most device context information. | |
51 | ||
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.", ""); | |
55 | ||
d14a1e28 RD |
56 | class wxDC : public wxObject { |
57 | public: | |
58 | // wxDC(); **** abstract base class, can't instantiate. | |
59 | ~wxDC(); | |
60 | ||
61 | ||
22b549f2 RD |
62 | %pythoncode { |
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 | |
67 | } | |
70794ec5 | 68 | |
70794ec5 | 69 | |
22b549f2 | 70 | |
70794ec5 | 71 | // TODO virtual void DrawObject(wxDrawObject* drawobject); |
d14a1e28 RD |
72 | |
73 | ||
70794ec5 RD |
74 | DocStr( |
75 | FloodFill, | |
76 | "Flood fills the device context starting from the given point, using | |
77 | the current brush colour, and using a style: | |
d14a1e28 | 78 | |
70794ec5 RD |
79 | - **wxFLOOD_SURFACE**: the flooding occurs until a colour other than |
80 | the given colour is encountered. | |
d14a1e28 | 81 | |
70794ec5 RD |
82 | - **wxFLOOD_BORDER**: the area to be flooded is bounded by the given |
83 | colour. | |
d14a1e28 | 84 | |
70794ec5 | 85 | Returns False if the operation failed. |
d14a1e28 | 86 | |
70794ec5 RD |
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.", ""); | |
d14a1e28 | 90 | bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE); |
1b8c7ba6 | 91 | %Rename(FloodFillPoint, bool, FloodFill(const wxPoint& pt, const wxColour& col, int style = wxFLOOD_SURFACE)); |
dce2bd22 | 92 | |
ddbb966d RD |
93 | // fill the area specified by rect with a radial gradient, starting from |
94 | // initialColour in the centre of the cercle and fading to destColour. | |
95 | ||
96 | DocDeclStr( | |
97 | void , GradientFillConcentric(const wxRect& rect, | |
98 | const wxColour& initialColour, | |
99 | const wxColour& destColour, | |
100 | const wxPoint& circleCenter), | |
101 | "Fill the area specified by rect with a radial gradient, starting from | |
102 | initialColour in the center of the circle and fading to destColour on | |
103 | the outside of the circle. The circleCenter argument is the relative | |
104 | coordinants of the center of the circle in the specified rect. | |
105 | ||
106 | Note: Currently this function is very slow, don't use it for real-time | |
107 | drawing.", ""); | |
108 | ||
109 | ||
110 | DocDeclStr( | |
111 | void , GradientFillLinear(const wxRect& rect, | |
112 | const wxColour& initialColour, | |
113 | const wxColour& destColour, | |
114 | wxDirection nDirection = wxEAST), | |
115 | "Fill the area specified by rect with a linear gradient, starting from | |
116 | initialColour and eventually fading to destColour. The nDirection | |
117 | parameter specifies the direction of the colour change, default is to | |
118 | use initialColour on the left part of the rectangle and destColour on | |
119 | the right side.", ""); | |
120 | ||
121 | ||
70794ec5 RD |
122 | |
123 | DocStr( | |
124 | GetPixel, | |
125 | "Gets the colour at the specified location on the DC.",""); | |
d14a1e28 RD |
126 | %extend { |
127 | wxColour GetPixel(wxCoord x, wxCoord y) { | |
128 | wxColour col; | |
129 | self->GetPixel(x, y, &col); | |
130 | return col; | |
131 | } | |
dce2bd22 RD |
132 | wxColour GetPixelPoint(const wxPoint& pt) { |
133 | wxColour col; | |
134 | self->GetPixel(pt, &col); | |
135 | return col; | |
136 | } | |
d14a1e28 | 137 | } |
70794ec5 | 138 | |
dce2bd22 | 139 | |
70794ec5 RD |
140 | DocStr( |
141 | DrawLine, | |
142 | "Draws a line from the first point to the second. The current pen is | |
143 | used for drawing the line. Note that the second point is *not* part of | |
144 | the line and is not drawn by this function (this is consistent with | |
145 | the behaviour of many other toolkits).", ""); | |
d14a1e28 | 146 | void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); |
1b8c7ba6 | 147 | %Rename(DrawLinePoint, void, DrawLine(const wxPoint& pt1, const wxPoint& pt2)); |
dce2bd22 | 148 | |
70794ec5 RD |
149 | |
150 | DocStr( | |
151 | CrossHair, | |
152 | "Displays a cross hair using the current pen. This is a vertical and | |
153 | horizontal line the height and width of the window, centred on the | |
154 | given point.", ""); | |
d14a1e28 | 155 | void CrossHair(wxCoord x, wxCoord y); |
1b8c7ba6 | 156 | %Rename(CrossHairPoint, void, CrossHair(const wxPoint& pt)); |
dce2bd22 | 157 | |
70794ec5 RD |
158 | |
159 | DocStr( | |
160 | DrawArc, | |
161 | "Draws an arc of a circle, centred on the *center* point (xc, yc), from | |
162 | the first point to the second. The current pen is used for the outline | |
163 | and the current brush for filling the shape. | |
164 | ||
165 | The arc is drawn in an anticlockwise direction from the start point to | |
166 | the end point.", ""); | |
d14a1e28 | 167 | void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc); |
1b8c7ba6 | 168 | %Rename(DrawArcPoint, void, DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& center)); |
dce2bd22 | 169 | |
70794ec5 RD |
170 | |
171 | DocStr( | |
172 | DrawCheckMark, | |
173 | "Draws a check mark inside the given rectangle.", ""); | |
d14a1e28 | 174 | void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
1b8c7ba6 | 175 | %Rename(DrawCheckMarkRect, void, DrawCheckMark(const wxRect& rect)); |
dce2bd22 | 176 | |
70794ec5 RD |
177 | DocStr( |
178 | DrawEllipticArc, | |
179 | "Draws an arc of an ellipse, with the given rectangle defining the | |
180 | bounds of the ellipse. The current pen is used for drawing the arc and | |
181 | the current brush is used for drawing the pie. | |
182 | ||
183 | The *start* and *end* parameters specify the start and end of the arc | |
184 | relative to the three-o'clock position from the center of the | |
185 | rectangle. Angles are specified in degrees (360 is a complete | |
186 | circle). Positive values mean counter-clockwise motion. If start is | |
187 | equal to end, a complete ellipse will be drawn.", ""); | |
188 | void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double start, double end); | |
1b8c7ba6 | 189 | %Rename(DrawEllipticArcPointSize, void, DrawEllipticArc(const wxPoint& pt, const wxSize& sz, double start, double end)); |
70794ec5 | 190 | |
dce2bd22 | 191 | |
70794ec5 RD |
192 | DocStr( |
193 | DrawPoint, | |
194 | "Draws a point using the current pen.", ""); | |
d14a1e28 | 195 | void DrawPoint(wxCoord x, wxCoord y); |
1b8c7ba6 | 196 | %Rename(DrawPointPoint, void, DrawPoint(const wxPoint& pt)); |
dce2bd22 | 197 | |
70794ec5 RD |
198 | |
199 | DocStr( | |
200 | DrawRectangle, | |
201 | "Draws a rectangle with the given top left corner, and with the given | |
202 | size. The current pen is used for the outline and the current brush | |
203 | for filling the shape.", ""); | |
d14a1e28 | 204 | void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
1b8c7ba6 RD |
205 | %Rename(DrawRectangleRect,void, DrawRectangle(const wxRect& rect)); |
206 | %Rename(DrawRectanglePointSize, void, DrawRectangle(const wxPoint& pt, const wxSize& sz)); | |
dce2bd22 | 207 | |
70794ec5 RD |
208 | |
209 | DocStr( | |
210 | DrawRoundedRectangle, | |
211 | "Draws a rectangle with the given top left corner, and with the given | |
212 | size. The corners are quarter-circles using the given radius. The | |
213 | current pen is used for the outline and the current brush for filling | |
214 | the shape. | |
215 | ||
216 | If radius is positive, the value is assumed to be the radius of the | |
217 | rounded corner. If radius is negative, the absolute value is assumed | |
218 | to be the proportion of the smallest dimension of the rectangle. This | |
219 | means that the corner can be a sensible size relative to the size of | |
220 | the rectangle, and also avoids the strange effects X produces when the | |
221 | corners are too big for the rectangle.", ""); | |
d14a1e28 | 222 | void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius); |
1b8c7ba6 RD |
223 | %Rename(DrawRoundedRectangleRect, void, DrawRoundedRectangle(const wxRect& r, double radius)); |
224 | %Rename(DrawRoundedRectanglePointSize, void, DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius)); | |
dce2bd22 | 225 | |
70794ec5 RD |
226 | |
227 | DocStr( | |
228 | DrawCircle, | |
229 | "Draws a circle with the given center point and radius. The current | |
230 | pen is used for the outline and the current brush for filling the | |
231 | shape.", " | |
232 | ||
233 | :see: `DrawEllipse`"); | |
d14a1e28 | 234 | void DrawCircle(wxCoord x, wxCoord y, wxCoord radius); |
1b8c7ba6 | 235 | %Rename(DrawCirclePoint, void, DrawCircle(const wxPoint& pt, wxCoord radius)); |
dce2bd22 | 236 | |
70794ec5 RD |
237 | |
238 | DocStr( | |
239 | DrawEllipse, | |
240 | "Draws an ellipse contained in the specified rectangle. The current pen | |
241 | is used for the outline and the current brush for filling the shape.", " | |
242 | ||
243 | :see: `DrawCircle`"); | |
d14a1e28 | 244 | void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); |
1b8c7ba6 RD |
245 | %Rename(DrawEllipseRect, void, DrawEllipse(const wxRect& rect)); |
246 | %Rename(DrawEllipsePointSize, void, DrawEllipse(const wxPoint& pt, const wxSize& sz)); | |
dce2bd22 | 247 | |
70794ec5 RD |
248 | |
249 | DocStr( | |
250 | DrawIcon, | |
251 | "Draw an icon on the display (does nothing if the device context is | |
252 | PostScript). This can be the simplest way of drawing bitmaps on a | |
253 | window.", ""); | |
d14a1e28 | 254 | void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); |
1b8c7ba6 | 255 | %Rename(DrawIconPoint, void, DrawIcon(const wxIcon& icon, const wxPoint& pt)); |
dce2bd22 | 256 | |
d14a1e28 | 257 | |
70794ec5 RD |
258 | DocStr( |
259 | DrawBitmap, | |
260 | "Draw a bitmap on the device context at the specified point. If | |
261 | *transparent* is true and the bitmap has a transparency mask, (or | |
262 | alpha channel on the platforms that support it) then the bitmap will | |
263 | be drawn transparently.", " | |
4942342c | 264 | |
70794ec5 RD |
265 | When drawing a mono-bitmap, the current text foreground colour will be |
266 | used to draw the foreground of the bitmap (all bits set to 1), and the | |
267 | current text background colour to draw the background (all bits set to | |
268 | 0). | |
d14a1e28 | 269 | |
70794ec5 | 270 | :see: `SetTextForeground`, `SetTextBackground` and `wx.MemoryDC`"); |
a72f4631 | 271 | void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = false); |
1b8c7ba6 | 272 | %Rename(DrawBitmapPoint, void, DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, bool useMask = false)); |
d14a1e28 | 273 | |
d14a1e28 | 274 | |
70794ec5 RD |
275 | DocStr( |
276 | DrawText, | |
277 | "Draws a text string at the specified point, using the current text | |
278 | font, and the current text foreground and background colours. | |
d14a1e28 | 279 | |
70794ec5 RD |
280 | The coordinates refer to the top-left corner of the rectangle bounding |
281 | the string. See `GetTextExtent` for how to get the dimensions of a | |
282 | text string, which can be used to position the text more precisely. | |
d14a1e28 | 283 | |
70794ec5 RD |
284 | **NOTE**: under wxGTK the current logical function is used by this |
285 | function but it is ignored by wxMSW. Thus, you should avoid using | |
286 | logical functions with this function in portable programs.", " | |
d14a1e28 | 287 | |
70794ec5 RD |
288 | :see: `DrawRotatedText`"); |
289 | void DrawText(const wxString& text, wxCoord x, wxCoord y); | |
1b8c7ba6 | 290 | %Rename(DrawTextPoint, void, DrawText(const wxString& text, const wxPoint& pt)); |
d14a1e28 | 291 | |
d14a1e28 | 292 | |
70794ec5 RD |
293 | DocStr( |
294 | DrawRotatedText, | |
295 | "Draws the text rotated by *angle* degrees, if supported by the platform. | |
d14a1e28 | 296 | |
70794ec5 RD |
297 | **NOTE**: Under Win9x only TrueType fonts can be drawn by this |
298 | function. In particular, a font different from ``wx.NORMAL_FONT`` | |
299 | should be used as the it is not normally a TrueType | |
300 | font. ``wx.SWISS_FONT`` is an example of a font which is."," | |
d14a1e28 | 301 | |
70794ec5 RD |
302 | :see: `DrawText`"); |
303 | void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle); | |
1b8c7ba6 | 304 | %Rename(DrawRotatedTextPoint, void, DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)); |
d14a1e28 | 305 | |
d14a1e28 | 306 | |
70794ec5 RD |
307 | DocDeclStr( |
308 | bool , Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
309 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
a72f4631 | 310 | int rop = wxCOPY, bool useMask = false, |
70794ec5 RD |
311 | wxCoord xsrcMask = -1, wxCoord ysrcMask = -1), |
312 | "Copy from a source DC to this DC. Parameters specify the destination | |
313 | coordinates, size of area to copy, source DC, source coordinates, | |
314 | logical function, whether to use a bitmap mask, and mask source | |
315 | position.", " | |
316 | ||
317 | :param xdest: Destination device context x position. | |
318 | :param ydest: Destination device context y position. | |
319 | :param width: Width of source area to be copied. | |
320 | :param height: Height of source area to be copied. | |
321 | :param source: Source device context. | |
322 | :param xsrc: Source device context x position. | |
323 | :param ysrc: Source device context y position. | |
324 | :param rop: Logical function to use: see `SetLogicalFunction`. | |
325 | :param useMask: If true, Blit does a transparent blit using the mask | |
326 | that is associated with the bitmap selected into the | |
327 | source device context. | |
328 | :param xsrcMask: Source x position on the mask. If both xsrcMask and | |
329 | ysrcMask are -1, xsrc and ysrc will be assumed for | |
330 | the mask source position. | |
331 | :param ysrcMask: Source y position on the mask. | |
332 | "); | |
333 | ||
334 | DocDeclStrName( | |
335 | bool , Blit(const wxPoint& destPt, const wxSize& sz, | |
336 | wxDC *source, const wxPoint& srcPt, | |
a72f4631 | 337 | int rop = wxCOPY, bool useMask = false, |
70794ec5 RD |
338 | const wxPoint& srcPtMask = wxDefaultPosition), |
339 | "Copy from a source DC to this DC. Parameters specify the destination | |
340 | coordinates, size of area to copy, source DC, source coordinates, | |
341 | logical function, whether to use a bitmap mask, and mask source | |
342 | position.", " | |
343 | ||
344 | :param destPt: Destination device context position. | |
345 | :param sz: Size of source area to be copied. | |
346 | :param source: Source device context. | |
347 | :param srcPt: Source device context position. | |
348 | :param rop: Logical function to use: see `SetLogicalFunction`. | |
349 | :param useMask: If true, Blit does a transparent blit using the mask | |
350 | that is associated with the bitmap selected into the | |
351 | source device context. | |
352 | :param srcPtMask: Source position on the mask. | |
353 | ", | |
354 | BlitPointSize); | |
8f514ab4 RD |
355 | |
356 | ||
357 | DocDeclStr( | |
358 | wxBitmap , GetAsBitmap(const wxRect *subrect = NULL) const, | |
359 | "", ""); | |
360 | ||
70794ec5 | 361 | |
d14a1e28 | 362 | |
70794ec5 RD |
363 | DocStr( |
364 | SetClippingRegion, | |
365 | "Sets the clipping region for this device context to the intersection | |
366 | of the given region described by the parameters of this method and the | |
367 | previously set clipping region. You should call `DestroyClippingRegion` | |
368 | if you want to set the clipping region exactly to the region | |
369 | specified. | |
4942342c | 370 | |
70794ec5 RD |
371 | The clipping region is an area to which drawing is |
372 | restricted. Possible uses for the clipping region are for clipping | |
373 | text or for speeding up window redraws when only a known area of the | |
374 | screen is damaged.", " | |
d14a1e28 | 375 | |
70794ec5 RD |
376 | :see: `DestroyClippingRegion`, `wx.Region`"); |
377 | void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
1b8c7ba6 RD |
378 | %Rename(SetClippingRegionPointSize, void, SetClippingRegion(const wxPoint& pt, const wxSize& sz)); |
379 | %Rename(SetClippingRegionAsRegion, void, SetClippingRegion(const wxRegion& region)); | |
380 | %Rename(SetClippingRect, void, SetClippingRegion(const wxRect& rect)); | |
d7403ad2 | 381 | |
4942342c | 382 | |
70794ec5 RD |
383 | |
384 | DocDeclAStr( | |
385 | void , DrawLines(int points, wxPoint* points_array, | |
386 | wxCoord xoffset = 0, wxCoord yoffset = 0), | |
387 | "DrawLines(self, List points, int xoffset=0, int yoffset=0)", | |
388 | "Draws lines using a sequence of `wx.Point` objects, adding the | |
389 | optional offset coordinate. The current pen is used for drawing the | |
390 | lines.", ""); | |
391 | ||
d14a1e28 | 392 | |
70794ec5 RD |
393 | DocDeclAStr( |
394 | void , DrawPolygon(int points, wxPoint* points_array, | |
d14a1e28 | 395 | wxCoord xoffset = 0, wxCoord yoffset = 0, |
70794ec5 RD |
396 | int fillStyle = wxODDEVEN_RULE), |
397 | "DrawPolygon(self, List points, int xoffset=0, int yoffset=0, | |
398 | int fillStyle=ODDEVEN_RULE)", | |
399 | "Draws a filled polygon using a sequence of `wx.Point` objects, adding | |
400 | the optional offset coordinate. The last argument specifies the fill | |
401 | rule: ``wx.ODDEVEN_RULE`` (the default) or ``wx.WINDING_RULE``. | |
402 | ||
403 | The current pen is used for drawing the outline, and the current brush | |
404 | for filling the shape. Using a transparent brush suppresses | |
405 | filling. Note that wxWidgets automatically closes the first and last | |
406 | points.", ""); | |
407 | ||
d14a1e28 | 408 | |
86aafce3 RD |
409 | // TODO: Figure out a good typemap for this... |
410 | // Convert the first 3 args from a sequence of sequences? | |
411 | // void DrawPolyPolygon(int n, int count[], wxPoint points[], | |
412 | // wxCoord xoffset = 0, wxCoord yoffset = 0, | |
413 | // int fillStyle = wxODDEVEN_RULE); | |
d14a1e28 | 414 | |
86aafce3 | 415 | |
70794ec5 RD |
416 | DocDeclStr( |
417 | void , DrawLabel(const wxString& text, const wxRect& rect, | |
418 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
419 | int indexAccel = -1), | |
420 | "Draw *text* within the specified rectangle, abiding by the alignment | |
421 | flags. Will additionally emphasize the character at *indexAccel* if | |
422 | it is not -1.", " | |
423 | ||
424 | :see: `DrawImageLabel`"); | |
425 | ||
426 | ||
d14a1e28 | 427 | %extend { |
70794ec5 RD |
428 | DocStr(DrawImageLabel, |
429 | "Draw *text* and an image (which may be ``wx.NullBitmap`` to skip | |
430 | drawing it) within the specified rectangle, abiding by the alignment | |
431 | flags. Will additionally emphasize the character at *indexAccel* if | |
432 | it is not -1. Returns the bounding rectangle.", ""); | |
d14a1e28 RD |
433 | wxRect DrawImageLabel(const wxString& text, |
434 | const wxBitmap& image, | |
435 | const wxRect& rect, | |
436 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
437 | int indexAccel = -1) { | |
438 | wxRect rv; | |
439 | self->DrawLabel(text, image, rect, alignment, indexAccel, &rv); | |
440 | return rv; | |
441 | } | |
442 | } | |
443 | ||
444 | ||
445 | ||
70794ec5 RD |
446 | DocDeclAStr( |
447 | void , DrawSpline(int points, wxPoint* points_array), | |
448 | "DrawSpline(self, List points)", | |
449 | "Draws a spline between all given control points, (a list of `wx.Point` | |
450 | objects) using the current pen. The spline is drawn using a series of | |
451 | lines, using an algorithm taken from the X drawing program 'XFIG'.", ""); | |
452 | ||
d14a1e28 RD |
453 | |
454 | ||
4942342c | 455 | |
d14a1e28 RD |
456 | // global DC operations |
457 | // -------------------- | |
458 | ||
70794ec5 RD |
459 | DocDeclStr( |
460 | virtual void , Clear(), | |
461 | "Clears the device context using the current background brush.", ""); | |
462 | ||
d14a1e28 | 463 | |
70794ec5 RD |
464 | DocDeclStr( |
465 | virtual bool , StartDoc(const wxString& message), | |
466 | "Starts a document (only relevant when outputting to a | |
467 | printer). *Message* is a message to show whilst printing.", ""); | |
468 | ||
469 | DocDeclStr( | |
470 | virtual void , EndDoc(), | |
471 | "Ends a document (only relevant when outputting to a printer).", ""); | |
472 | ||
d14a1e28 | 473 | |
70794ec5 RD |
474 | DocDeclStr( |
475 | virtual void , StartPage(), | |
476 | "Starts a document page (only relevant when outputting to a printer).", ""); | |
477 | ||
478 | DocDeclStr( | |
479 | virtual void , EndPage(), | |
480 | "Ends a document page (only relevant when outputting to a printer).", ""); | |
481 | ||
d14a1e28 | 482 | |
4942342c | 483 | |
d14a1e28 RD |
484 | // set objects to use for drawing |
485 | // ------------------------------ | |
486 | ||
70794ec5 RD |
487 | DocDeclStr( |
488 | virtual void , SetFont(const wxFont& font), | |
489 | "Sets the current font for the DC. It must be a valid font, in | |
490 | particular you should not pass ``wx.NullFont`` to this method."," | |
d14a1e28 | 491 | |
70794ec5 RD |
492 | :see: `wx.Font`"); |
493 | ||
494 | DocDeclStr( | |
495 | virtual void , SetPen(const wxPen& pen), | |
496 | "Sets the current pen for the DC. | |
4942342c | 497 | |
70794ec5 RD |
498 | If the argument is ``wx.NullPen``, the current pen is selected out of the |
499 | device context, and the original pen restored.", " | |
d14a1e28 | 500 | |
70794ec5 RD |
501 | :see: `wx.Pen`"); |
502 | ||
503 | DocDeclStr( | |
504 | virtual void , SetBrush(const wxBrush& brush), | |
505 | "Sets the current brush for the DC. | |
506 | ||
507 | If the argument is ``wx.NullBrush``, the current brush is selected out | |
508 | of the device context, and the original brush restored, allowing the | |
509 | current brush to be destroyed safely."," | |
510 | ||
511 | :see: `wx.Brush`"); | |
512 | ||
513 | DocDeclStr( | |
514 | virtual void , SetBackground(const wxBrush& brush), | |
515 | "Sets the current background brush for the DC.", ""); | |
516 | ||
517 | DocDeclStr( | |
518 | virtual void , SetBackgroundMode(int mode), | |
519 | "*mode* may be one of ``wx.SOLID`` and ``wx.TRANSPARENT``. This setting | |
520 | determines whether text will be drawn with a background colour or | |
521 | not.", ""); | |
522 | ||
523 | DocDeclStr( | |
524 | virtual void , SetPalette(const wxPalette& palette), | |
525 | "If this is a window DC or memory DC, assigns the given palette to the | |
526 | window or bitmap associated with the DC. If the argument is | |
527 | ``wx.NullPalette``, the current palette is selected out of the device | |
528 | context, and the original palette restored.", " | |
529 | ||
530 | :see: `wx.Palette`"); | |
531 | ||
532 | ||
533 | ||
534 | DocDeclStr( | |
535 | virtual void , DestroyClippingRegion(), | |
536 | "Destroys the current clipping region so that none of the DC is | |
537 | clipped.", " | |
538 | ||
539 | :see: `SetClippingRegion`"); | |
540 | ||
541 | ||
542 | DocDeclAStr( | |
322913ce | 543 | void, GetClippingBox(wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT) const, |
70794ec5 RD |
544 | "GetClippingBox() -> (x, y, width, height)", |
545 | "Gets the rectangle surrounding the current clipping region.", ""); | |
4942342c | 546 | |
d14a1e28 | 547 | %extend { |
70794ec5 RD |
548 | DocStr( |
549 | GetClippingRect, | |
550 | "Gets the rectangle surrounding the current clipping region.", ""); | |
d14a1e28 RD |
551 | wxRect GetClippingRect() { |
552 | wxRect rect; | |
553 | self->GetClippingBox(rect); | |
554 | return rect; | |
555 | } | |
556 | } | |
d14a1e28 | 557 | |
4942342c RD |
558 | |
559 | ||
d14a1e28 RD |
560 | // text extent |
561 | // ----------- | |
562 | ||
70794ec5 RD |
563 | DocDeclStr( |
564 | virtual wxCoord , GetCharHeight() const, | |
565 | "Gets the character height of the currently set font.", ""); | |
566 | ||
567 | DocDeclStr( | |
568 | virtual wxCoord , GetCharWidth() const, | |
569 | "Gets the average character width of the currently set font.", ""); | |
570 | ||
d14a1e28 | 571 | |
d14a1e28 | 572 | |
322913ce RD |
573 | DocDeclAStr( |
574 | void, GetTextExtent(const wxString& string, wxCoord *OUTPUT, wxCoord *OUTPUT), | |
575 | "GetTextExtent(wxString string) -> (width, height)", | |
d07d2bc9 RD |
576 | "Get the width and height of the text using the current font. Only |
577 | works for single line strings.", ""); | |
578 | ||
322913ce RD |
579 | DocDeclAStrName( |
580 | void, GetTextExtent(const wxString& string, | |
4942342c | 581 | wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord* OUTPUT, |
322913ce RD |
582 | wxFont* font = NULL), |
583 | "GetFullTextExtent(wxString string, Font font=None) ->\n (width, height, descent, externalLeading)", | |
d07d2bc9 RD |
584 | "Get the width, height, decent and leading of the text using the |
585 | current or specified font. Only works for single line strings.", "", | |
322913ce RD |
586 | GetFullTextExtent); |
587 | ||
4942342c | 588 | |
322913ce RD |
589 | // works for single as well as multi-line strings |
590 | DocDeclAStr( | |
591 | void, GetMultiLineTextExtent(const wxString& text, | |
592 | wxCoord *OUTPUT, wxCoord *OUTPUT, wxCoord *OUTPUT, | |
593 | wxFont *font = NULL), | |
25e29eb2 | 594 | "GetMultiLineTextExtent(wxString string, Font font=None) ->\n (width, height, lineHeight)", |
67cb8b47 | 595 | "Get the width, height, and line height of the text using the |
d07d2bc9 RD |
596 | current or specified font. Works for single as well as multi-line |
597 | strings.", ""); | |
322913ce | 598 | |
746ee6b8 RD |
599 | |
600 | %extend { | |
70794ec5 RD |
601 | DocAStr(GetPartialTextExtents, |
602 | "GetPartialTextExtents(self, text) -> [widths]", | |
603 | "Returns a list of integers such that each value is the distance in | |
604 | pixels from the begining of text to the coresponding character of | |
605 | *text*. The generic version simply builds a running total of the widths | |
606 | of each character using GetTextExtent, however if the various | |
607 | platforms have a native API function that is faster or more accurate | |
43e8916f | 608 | than the generic implementation then it will be used instead.", ""); |
746ee6b8 RD |
609 | wxArrayInt GetPartialTextExtents(const wxString& text) { |
610 | wxArrayInt widths; | |
611 | self->GetPartialTextExtents(text, widths); | |
612 | return widths; | |
613 | } | |
614 | } | |
615 | ||
d14a1e28 RD |
616 | |
617 | // size and resolution | |
618 | // ------------------- | |
619 | ||
70794ec5 RD |
620 | DocStr( |
621 | GetSize, | |
622 | "This gets the horizontal and vertical resolution in device units. It | |
623 | can be used to scale graphics to fit the page. For example, if *maxX* | |
624 | and *maxY* represent the maximum horizontal and vertical 'pixel' values | |
625 | used in your application, the following code will scale the graphic to | |
626 | fit on the printer page:: | |
627 | ||
628 | w, h = dc.GetSize() | |
629 | scaleX = maxX*1.0 / w | |
630 | scaleY = maxY*1.0 / h | |
631 | dc.SetUserScale(min(scaleX,scaleY),min(scaleX,scaleY)) | |
632 | ", ""); | |
d14a1e28 | 633 | wxSize GetSize(); |
322913ce RD |
634 | DocDeclAName( |
635 | void, GetSize( int *OUTPUT, int *OUTPUT ), | |
636 | "GetSizeTuple() -> (width, height)", | |
637 | GetSizeTuple); | |
4942342c | 638 | |
d14a1e28 | 639 | |
d07d2bc9 | 640 | DocStr(GetSizeMM, "Get the DC size in milimeters.", ""); |
d14a1e28 | 641 | wxSize GetSizeMM() const; |
322913ce RD |
642 | DocDeclAName( |
643 | void, GetSizeMM( int *OUTPUT, int *OUTPUT ) const, | |
644 | "GetSizeMMTuple() -> (width, height)", | |
645 | GetSizeMMTuple); | |
4942342c RD |
646 | |
647 | ||
d14a1e28 RD |
648 | |
649 | // coordinates conversions | |
650 | // ----------------------- | |
651 | ||
70794ec5 RD |
652 | DocDeclStr( |
653 | wxCoord , DeviceToLogicalX(wxCoord x) const, | |
654 | "Convert device X coordinate to logical coordinate, using the current | |
655 | mapping mode.", ""); | |
656 | ||
657 | DocDeclStr( | |
658 | wxCoord , DeviceToLogicalY(wxCoord y) const, | |
659 | "Converts device Y coordinate to logical coordinate, using the current | |
660 | mapping mode.", ""); | |
661 | ||
662 | DocDeclStr( | |
663 | wxCoord , DeviceToLogicalXRel(wxCoord x) const, | |
664 | "Convert device X coordinate to relative logical coordinate, using the | |
665 | current mapping mode but ignoring the x axis orientation. Use this | |
666 | function for converting a width, for example.", ""); | |
667 | ||
668 | DocDeclStr( | |
669 | wxCoord , DeviceToLogicalYRel(wxCoord y) const, | |
670 | "Convert device Y coordinate to relative logical coordinate, using the | |
671 | current mapping mode but ignoring the y axis orientation. Use this | |
672 | function for converting a height, for example.", ""); | |
673 | ||
674 | DocDeclStr( | |
675 | wxCoord , LogicalToDeviceX(wxCoord x) const, | |
676 | "Converts logical X coordinate to device coordinate, using the current | |
677 | mapping mode.", ""); | |
678 | ||
679 | DocDeclStr( | |
680 | wxCoord , LogicalToDeviceY(wxCoord y) const, | |
681 | "Converts logical Y coordinate to device coordinate, using the current | |
682 | mapping mode.", ""); | |
683 | ||
684 | DocDeclStr( | |
685 | wxCoord , LogicalToDeviceXRel(wxCoord x) const, | |
686 | "Converts logical X coordinate to relative device coordinate, using the | |
687 | current mapping mode but ignoring the x axis orientation. Use this for | |
688 | converting a width, for example.", ""); | |
689 | ||
690 | DocDeclStr( | |
691 | wxCoord , LogicalToDeviceYRel(wxCoord y) const, | |
692 | "Converts logical Y coordinate to relative device coordinate, using the | |
693 | current mapping mode but ignoring the y axis orientation. Use this for | |
694 | converting a height, for example.", ""); | |
695 | ||
d14a1e28 | 696 | |
70794ec5 | 697 | |
d14a1e28 RD |
698 | // query DC capabilities |
699 | // --------------------- | |
700 | ||
701 | virtual bool CanDrawBitmap() const; | |
702 | virtual bool CanGetTextExtent() const; | |
703 | ||
d14a1e28 | 704 | |
70794ec5 RD |
705 | DocDeclStr( |
706 | virtual int , GetDepth() const, | |
707 | "Returns the colour depth of the DC.", ""); | |
708 | ||
d14a1e28 | 709 | |
70794ec5 RD |
710 | DocDeclStr( |
711 | virtual wxSize , GetPPI() const, | |
361b8ff7 | 712 | "Resolution in pixels per inch", ""); |
70794ec5 | 713 | |
d14a1e28 | 714 | |
70794ec5 | 715 | DocDeclStr( |
6c2dd16f | 716 | virtual bool , IsOk() const, |
70794ec5 | 717 | "Returns true if the DC is ok to use.", ""); |
6c2dd16f | 718 | %pythoncode { Ok = IsOk } |
70794ec5 | 719 | |
4942342c | 720 | |
d14a1e28 | 721 | |
70794ec5 RD |
722 | DocDeclStr( |
723 | int , GetBackgroundMode() const, | |
724 | "Returns the current background mode, either ``wx.SOLID`` or | |
725 | ``wx.TRANSPARENT``."," | |
d14a1e28 | 726 | |
70794ec5 RD |
727 | :see: `SetBackgroundMode`"); |
728 | ||
729 | DocDeclStr( | |
730 | const wxBrush& , GetBackground() const, | |
731 | "Gets the brush used for painting the background."," | |
d14a1e28 | 732 | |
70794ec5 RD |
733 | :see: `SetBackground`"); |
734 | ||
735 | DocDeclStr( | |
736 | const wxBrush& , GetBrush() const, | |
737 | "Gets the current brush", ""); | |
738 | ||
739 | DocDeclStr( | |
740 | const wxFont& , GetFont() const, | |
741 | "Gets the current font", ""); | |
742 | ||
743 | DocDeclStr( | |
744 | const wxPen& , GetPen() const, | |
745 | "Gets the current pen", ""); | |
746 | ||
747 | DocDeclStr( | |
748 | const wxColour& , GetTextBackground() const, | |
749 | "Gets the current text background colour", ""); | |
750 | ||
751 | DocDeclStr( | |
752 | const wxColour& , GetTextForeground() const, | |
753 | "Gets the current text foreground colour", ""); | |
754 | ||
d14a1e28 | 755 | |
70794ec5 RD |
756 | DocDeclStr( |
757 | virtual void , SetTextForeground(const wxColour& colour), | |
758 | "Sets the current text foreground colour for the DC.", ""); | |
759 | ||
760 | DocDeclStr( | |
761 | virtual void , SetTextBackground(const wxColour& colour), | |
762 | "Sets the current text background colour for the DC.", ""); | |
763 | ||
4942342c | 764 | |
70794ec5 RD |
765 | DocDeclStr( |
766 | int , GetMapMode() const, | |
767 | "Gets the current *mapping mode* for the device context ", ""); | |
768 | ||
769 | DocDeclStr( | |
770 | virtual void , SetMapMode(int mode), | |
771 | "The *mapping mode* of the device context defines the unit of | |
772 | measurement used to convert logical units to device units. The | |
773 | mapping mode can be one of the following: | |
774 | ||
775 | ================ ============================================= | |
776 | wx.MM_TWIPS Each logical unit is 1/20 of a point, or 1/1440 | |
777 | of an inch. | |
778 | wx.MM_POINTS Each logical unit is a point, or 1/72 of an inch. | |
779 | wx.MM_METRIC Each logical unit is 1 mm. | |
780 | wx.MM_LOMETRIC Each logical unit is 1/10 of a mm. | |
781 | wx.MM_TEXT Each logical unit is 1 pixel. | |
782 | ================ ============================================= | |
783 | "," | |
784 | Note that in X, text drawing isn't handled consistently with the | |
785 | mapping mode; a font is always specified in point size. However, | |
786 | setting the user scale (see `SetUserScale`) scales the text | |
787 | appropriately. In Windows, scalable TrueType fonts are always used; in | |
788 | X, results depend on availability of fonts, but usually a reasonable | |
789 | match is found. | |
790 | ||
791 | The coordinate origin is always at the top left of the screen/printer. | |
792 | ||
793 | Drawing to a Windows printer device context uses the current mapping | |
794 | mode, but mapping mode is currently ignored for PostScript output. | |
795 | "); | |
796 | ||
797 | ||
798 | ||
799 | DocDeclAStr( | |
322913ce | 800 | virtual void, GetUserScale(double *OUTPUT, double *OUTPUT) const, |
70794ec5 RD |
801 | "GetUserScale(self) -> (xScale, yScale)", |
802 | "Gets the current user scale factor (set by `SetUserScale`).", ""); | |
4942342c | 803 | |
70794ec5 RD |
804 | DocDeclStr( |
805 | virtual void , SetUserScale(double x, double y), | |
806 | "Sets the user scaling factor, useful for applications which require | |
807 | 'zooming'.", ""); | |
808 | ||
d14a1e28 | 809 | |
4942342c | 810 | |
322913ce RD |
811 | DocDeclA( |
812 | virtual void, GetLogicalScale(double *OUTPUT, double *OUTPUT), | |
813 | "GetLogicalScale() -> (xScale, yScale)"); | |
814 | ||
d14a1e28 RD |
815 | virtual void SetLogicalScale(double x, double y); |
816 | ||
322913ce | 817 | |
d14a1e28 | 818 | wxPoint GetLogicalOrigin() const; |
322913ce RD |
819 | DocDeclAName( |
820 | void, GetLogicalOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const, | |
821 | "GetLogicalOriginTuple() -> (x,y)", | |
822 | GetLogicalOriginTuple); | |
4942342c | 823 | |
d14a1e28 | 824 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); |
d7403ad2 RD |
825 | %extend { |
826 | void SetLogicalOriginPoint(const wxPoint& point) { | |
827 | self->SetLogicalOrigin(point.x, point.y); | |
828 | } | |
829 | } | |
d14a1e28 | 830 | |
d7403ad2 | 831 | |
d14a1e28 | 832 | wxPoint GetDeviceOrigin() const; |
322913ce RD |
833 | DocDeclAName( |
834 | void, GetDeviceOrigin(wxCoord *OUTPUT, wxCoord *OUTPUT) const, | |
835 | "GetDeviceOriginTuple() -> (x,y)", | |
836 | GetDeviceOriginTuple); | |
4942342c | 837 | |
d14a1e28 | 838 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); |
d7403ad2 RD |
839 | %extend { |
840 | void SetDeviceOriginPoint(const wxPoint& point) { | |
841 | self->SetDeviceOrigin(point.x, point.y); | |
842 | } | |
843 | } | |
d14a1e28 | 844 | |
70794ec5 RD |
845 | DocDeclStr( |
846 | virtual void , SetAxisOrientation(bool xLeftRight, bool yBottomUp), | |
847 | "Sets the x and y axis orientation (i.e., the direction from lowest to | |
848 | highest values on the axis). The default orientation is the natural | |
849 | orientation, e.g. x axis from left to right and y axis from bottom up.", ""); | |
3350d652 | 850 | |
d14a1e28 | 851 | |
70794ec5 RD |
852 | DocDeclStr( |
853 | int , GetLogicalFunction() const, | |
854 | "Gets the current logical function (set by `SetLogicalFunction`).", ""); | |
855 | ||
856 | DocDeclStr( | |
857 | virtual void , SetLogicalFunction(int function), | |
858 | "Sets the current logical function for the device context. This | |
859 | determines how a source pixel (from a pen or brush colour, or source | |
860 | device context if using `Blit`) combines with a destination pixel in | |
861 | the current device context. | |
862 | ||
863 | The possible values and their meaning in terms of source and | |
864 | destination pixel values are as follows: | |
865 | ||
866 | ================ ========================== | |
867 | wx.AND src AND dst | |
868 | wx.AND_INVERT (NOT src) AND dst | |
869 | wx.AND_REVERSE src AND (NOT dst) | |
870 | wx.CLEAR 0 | |
871 | wx.COPY src | |
872 | wx.EQUIV (NOT src) XOR dst | |
873 | wx.INVERT NOT dst | |
874 | wx.NAND (NOT src) OR (NOT dst) | |
875 | wx.NOR (NOT src) AND (NOT dst) | |
876 | wx.NO_OP dst | |
877 | wx.OR src OR dst | |
878 | wx.OR_INVERT (NOT src) OR dst | |
879 | wx.OR_REVERSE src OR (NOT dst) | |
880 | wx.SET 1 | |
881 | wx.SRC_INVERT NOT src | |
882 | wx.XOR src XOR dst | |
883 | ================ ========================== | |
884 | ||
885 | The default is wx.COPY, which simply draws with the current | |
886 | colour. The others combine the current colour and the background using | |
887 | a logical operation. wx.INVERT is commonly used for drawing rubber | |
888 | bands or moving outlines, since drawing twice reverts to the original | |
889 | colour. | |
890 | ", ""); | |
891 | ||
d14a1e28 | 892 | |
25e29eb2 RD |
893 | DocDeclStr( |
894 | void , ComputeScaleAndOrigin(), | |
895 | "Performs all necessary computations for given platform and context | |
896 | type after each change of scale and origin parameters. Usually called | |
897 | automatically internally after such changes. | |
898 | ", ""); | |
3350d652 RD |
899 | |
900 | ||
901 | ||
49e6b3c3 RD |
902 | // DocDeclStr( |
903 | // virtual void , SetOptimization(bool optimize), | |
904 | // "If *optimize* is true this function sets optimization mode on. This | |
905 | // currently means that under X, the device context will not try to set a | |
906 | // pen or brush property if it is known to be set already. This approach | |
907 | // can fall down if non-wxWidgets code is using the same device context | |
908 | // or window, for example when the window is a panel on which the | |
909 | // windowing system draws panel items. The wxWidgets device context | |
910 | // 'memory' will now be out of step with reality. | |
911 | ||
912 | // Setting optimization off, drawing, then setting it back on again, is a | |
913 | // trick that must occasionally be employed.", ""); | |
914 | ||
915 | // DocDeclStr( | |
916 | // virtual bool , GetOptimization(), | |
917 | // "Returns true if device context optimization is on. See | |
918 | // `SetOptimization` for details.", ""); | |
919 | ||
920 | %pythoncode { | |
921 | def SetOptimization(self, optimize): | |
922 | pass | |
923 | def GetOptimization(self): | |
924 | return False | |
925 | ||
926 | SetOptimization = wx._deprecated(SetOptimization) | |
927 | GetOptimization = wx._deprecated(GetOptimization) | |
928 | } | |
70794ec5 | 929 | |
70794ec5 | 930 | |
d14a1e28 RD |
931 | // bounding box |
932 | // ------------ | |
933 | ||
70794ec5 RD |
934 | DocDeclStr( |
935 | virtual void , CalcBoundingBox(wxCoord x, wxCoord y), | |
936 | "Adds the specified point to the bounding box which can be retrieved | |
937 | with `MinX`, `MaxX` and `MinY`, `MaxY` or `GetBoundingBox` functions.", ""); | |
938 | ||
d7403ad2 | 939 | %extend { |
70794ec5 RD |
940 | DocStr(CalcBoundingBoxPoint, |
941 | "Adds the specified point to the bounding box which can be retrieved | |
942 | with `MinX`, `MaxX` and `MinY`, `MaxY` or `GetBoundingBox` functions.",""); | |
d7403ad2 RD |
943 | void CalcBoundingBoxPoint(const wxPoint& point) { |
944 | self->CalcBoundingBox(point.x, point.y); | |
945 | } | |
946 | } | |
947 | ||
70794ec5 RD |
948 | DocDeclStr( |
949 | void , ResetBoundingBox(), | |
950 | "Resets the bounding box: after a call to this function, the bounding | |
951 | box doesn't contain anything.", ""); | |
952 | ||
d14a1e28 RD |
953 | |
954 | // Get the final bounding box of the PostScript or Metafile picture. | |
70794ec5 RD |
955 | DocDeclStr( |
956 | wxCoord , MinX() const, | |
957 | "Gets the minimum horizontal extent used in drawing commands so far.", ""); | |
958 | ||
959 | DocDeclStr( | |
960 | wxCoord , MaxX() const, | |
961 | "Gets the maximum horizontal extent used in drawing commands so far.", ""); | |
962 | ||
963 | DocDeclStr( | |
964 | wxCoord , MinY() const, | |
965 | "Gets the minimum vertical extent used in drawing commands so far.", ""); | |
966 | ||
967 | DocDeclStr( | |
968 | wxCoord , MaxY() const, | |
969 | "Gets the maximum vertical extent used in drawing commands so far.", ""); | |
970 | ||
d14a1e28 RD |
971 | |
972 | ||
70794ec5 RD |
973 | DocAStr(GetBoundingBox, |
974 | "GetBoundingBox() -> (x1,y1, x2,y2)", | |
975 | "Returns the min and max points used in drawing commands so far.", ""); | |
d14a1e28 RD |
976 | %extend { |
977 | void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT); | |
978 | // See below for implementation | |
4942342c | 979 | } |
70794ec5 | 980 | |
6c2dd16f | 981 | %pythoncode { def __nonzero__(self): return self.IsOk() }; |
d14a1e28 RD |
982 | |
983 | ||
8adc9d9d RD |
984 | // RTL related functions |
985 | // --------------------- | |
986 | ||
987 | DocDeclStr( | |
988 | virtual wxLayoutDirection , GetLayoutDirection() const, | |
989 | "Get the layout direction (LTR or RTL)_ for this dc. On platforms | |
990 | where RTL layout is supported, the return value will either be | |
991 | ``wx.Layout_LeftToRight`` or ``wx.Layout_RightToLeft``. | |
992 | ``wx.Layout_Default`` is returned if layout direction is not | |
993 | supported.", ""); | |
994 | ||
995 | DocDeclStr( | |
996 | virtual void , SetLayoutDirection(wxLayoutDirection dir), | |
997 | "Change the layout direction for this dc.", ""); | |
998 | ||
999 | ||
1000 | ||
1001 | ||
96fc3ef4 RD |
1002 | #ifdef __WXMSW__ |
1003 | long GetHDC(); | |
1004 | #endif | |
1005 | ||
d14a1e28 RD |
1006 | |
1007 | %extend { // See drawlist.cpp for impplementaion of these... | |
1008 | PyObject* _DrawPointList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
1009 | { | |
1010 | return wxPyDrawXXXList(*self, wxPyDrawXXXPoint, pyCoords, pyPens, pyBrushes); | |
1011 | } | |
1012 | ||
1013 | PyObject* _DrawLineList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
1014 | { | |
1015 | return wxPyDrawXXXList(*self, wxPyDrawXXXLine, pyCoords, pyPens, pyBrushes); | |
1016 | } | |
1017 | ||
1018 | PyObject* _DrawRectangleList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
1019 | { | |
1020 | return wxPyDrawXXXList(*self, wxPyDrawXXXRectangle, pyCoords, pyPens, pyBrushes); | |
1021 | } | |
1022 | ||
1023 | PyObject* _DrawEllipseList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
1024 | { | |
1025 | return wxPyDrawXXXList(*self, wxPyDrawXXXEllipse, pyCoords, pyPens, pyBrushes); | |
1026 | } | |
1027 | ||
1028 | PyObject* _DrawPolygonList(PyObject* pyCoords, PyObject* pyPens, PyObject* pyBrushes) | |
1029 | { | |
1030 | return wxPyDrawXXXList(*self, wxPyDrawXXXPolygon, pyCoords, pyPens, pyBrushes); | |
1031 | } | |
1032 | ||
1033 | PyObject* _DrawTextList(PyObject* textList, PyObject* pyPoints, | |
1034 | PyObject* foregroundList, PyObject* backgroundList) { | |
1035 | return wxPyDrawTextList(*self, textList, pyPoints, foregroundList, backgroundList); | |
1036 | } | |
1037 | } | |
1038 | ||
1039 | %pythoncode { | |
1040 | def DrawPointList(self, points, pens=None): | |
70794ec5 RD |
1041 | """ |
1042 | Draw a list of points as quickly as possible. | |
1043 | ||
1044 | :param points: A sequence of 2-element sequences representing | |
1045 | each point to draw, (x,y). | |
1046 | :param pens: If None, then the current pen is used. If a | |
1047 | single pen then it will be used for all points. If | |
1048 | a list of pens then there should be one for each point | |
1049 | in points. | |
1050 | """ | |
d14a1e28 RD |
1051 | if pens is None: |
1052 | pens = [] | |
1053 | elif isinstance(pens, wx.Pen): | |
1054 | pens = [pens] | |
1055 | elif len(pens) != len(points): | |
1056 | raise ValueError('points and pens must have same length') | |
1057 | return self._DrawPointList(points, pens, []) | |
1058 | ||
1059 | ||
1060 | def DrawLineList(self, lines, pens=None): | |
70794ec5 RD |
1061 | """ |
1062 | Draw a list of lines as quickly as possible. | |
1063 | ||
1064 | :param lines: A sequence of 4-element sequences representing | |
1065 | each line to draw, (x1,y1, x2,y2). | |
1066 | :param pens: If None, then the current pen is used. If a | |
1067 | single pen then it will be used for all lines. If | |
1068 | a list of pens then there should be one for each line | |
1069 | in lines. | |
1070 | """ | |
d14a1e28 RD |
1071 | if pens is None: |
1072 | pens = [] | |
1073 | elif isinstance(pens, wx.Pen): | |
1074 | pens = [pens] | |
1075 | elif len(pens) != len(lines): | |
1076 | raise ValueError('lines and pens must have same length') | |
1077 | return self._DrawLineList(lines, pens, []) | |
1078 | ||
1079 | ||
1080 | def DrawRectangleList(self, rectangles, pens=None, brushes=None): | |
70794ec5 RD |
1081 | """ |
1082 | Draw a list of rectangles as quickly as possible. | |
1083 | ||
1084 | :param rectangles: A sequence of 4-element sequences representing | |
1085 | each rectangle to draw, (x,y, w,h). | |
1086 | :param pens: If None, then the current pen is used. If a | |
1087 | single pen then it will be used for all rectangles. | |
1088 | If a list of pens then there should be one for each | |
1089 | rectangle in rectangles. | |
1090 | :param brushes: A brush or brushes to be used to fill the rectagles, | |
1091 | with similar semantics as the pens parameter. | |
1092 | """ | |
d14a1e28 RD |
1093 | if pens is None: |
1094 | pens = [] | |
1095 | elif isinstance(pens, wx.Pen): | |
1096 | pens = [pens] | |
1097 | elif len(pens) != len(rectangles): | |
1098 | raise ValueError('rectangles and pens must have same length') | |
1099 | if brushes is None: | |
1100 | brushes = [] | |
1101 | elif isinstance(brushes, wx.Brush): | |
1102 | brushes = [brushes] | |
1103 | elif len(brushes) != len(rectangles): | |
1104 | raise ValueError('rectangles and brushes must have same length') | |
1105 | return self._DrawRectangleList(rectangles, pens, brushes) | |
1106 | ||
1107 | ||
1108 | def DrawEllipseList(self, ellipses, pens=None, brushes=None): | |
70794ec5 RD |
1109 | """ |
1110 | Draw a list of ellipses as quickly as possible. | |
1111 | ||
1112 | :param ellipses: A sequence of 4-element sequences representing | |
1113 | each ellipse to draw, (x,y, w,h). | |
1114 | :param pens: If None, then the current pen is used. If a | |
1115 | single pen then it will be used for all ellipses. | |
1116 | If a list of pens then there should be one for each | |
1117 | ellipse in ellipses. | |
1118 | :param brushes: A brush or brushes to be used to fill the ellipses, | |
1119 | with similar semantics as the pens parameter. | |
1120 | """ | |
d14a1e28 RD |
1121 | if pens is None: |
1122 | pens = [] | |
1123 | elif isinstance(pens, wx.Pen): | |
1124 | pens = [pens] | |
1125 | elif len(pens) != len(ellipses): | |
1126 | raise ValueError('ellipses and pens must have same length') | |
1127 | if brushes is None: | |
1128 | brushes = [] | |
1129 | elif isinstance(brushes, wx.Brush): | |
1130 | brushes = [brushes] | |
1131 | elif len(brushes) != len(ellipses): | |
1132 | raise ValueError('ellipses and brushes must have same length') | |
1133 | return self._DrawEllipseList(ellipses, pens, brushes) | |
1134 | ||
1135 | ||
1136 | def DrawPolygonList(self, polygons, pens=None, brushes=None): | |
70794ec5 RD |
1137 | """ |
1138 | Draw a list of polygons, each of which is a list of points. | |
1139 | ||
1140 | :param polygons: A sequence of sequences of sequences. | |
1141 | [[(x1,y1),(x2,y2),(x3,y3)...], | |
1142 | [(x1,y1),(x2,y2),(x3,y3)...]] | |
1143 | ||
1144 | :param pens: If None, then the current pen is used. If a | |
1145 | single pen then it will be used for all polygons. | |
1146 | If a list of pens then there should be one for each | |
1147 | polygon. | |
1148 | :param brushes: A brush or brushes to be used to fill the polygons, | |
1149 | with similar semantics as the pens parameter. | |
1150 | """ | |
d14a1e28 RD |
1151 | if pens is None: |
1152 | pens = [] | |
1153 | elif isinstance(pens, wx.Pen): | |
1154 | pens = [pens] | |
1155 | elif len(pens) != len(polygons): | |
1156 | raise ValueError('polygons and pens must have same length') | |
1157 | if brushes is None: | |
1158 | brushes = [] | |
1159 | elif isinstance(brushes, wx.Brush): | |
1160 | brushes = [brushes] | |
1161 | elif len(brushes) != len(polygons): | |
1162 | raise ValueError('polygons and brushes must have same length') | |
1163 | return self._DrawPolygonList(polygons, pens, brushes) | |
1164 | ||
1165 | ||
70794ec5 RD |
1166 | def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None): |
1167 | """ | |
1168 | Draw a list of strings using a list of coordinants for positioning each string. | |
1169 | ||
1170 | :param textList: A list of strings | |
1171 | :param coords: A list of (x,y) positions | |
1172 | :param foregrounds: A list of `wx.Colour` objects to use for the | |
1173 | foregrounds of the strings. | |
1174 | :param backgrounds: A list of `wx.Colour` objects to use for the | |
1175 | backgrounds of the strings. | |
1176 | ||
1177 | NOTE: Make sure you set Background mode to wx.Solid (DC.SetBackgroundMode) | |
1178 | If you want backgrounds to do anything. | |
1179 | """ | |
d14a1e28 RD |
1180 | if type(textList) == type(''): |
1181 | textList = [textList] | |
1182 | elif len(textList) != len(coords): | |
1183 | raise ValueError('textlist and coords must have same length') | |
1184 | if foregrounds is None: | |
1185 | foregrounds = [] | |
fd3f2efe | 1186 | elif isinstance(foregrounds, wx.Colour): |
d14a1e28 RD |
1187 | foregrounds = [foregrounds] |
1188 | elif len(foregrounds) != len(coords): | |
1189 | raise ValueError('foregrounds and coords must have same length') | |
1190 | if backgrounds is None: | |
1191 | backgrounds = [] | |
fd3f2efe | 1192 | elif isinstance(backgrounds, wx.Colour): |
d14a1e28 RD |
1193 | backgrounds = [backgrounds] |
1194 | elif len(backgrounds) != len(coords): | |
1195 | raise ValueError('backgrounds and coords must have same length') | |
1196 | return self._DrawTextList(textList, coords, foregrounds, backgrounds) | |
1197 | } | |
1198 | ||
0eae5d09 RD |
1199 | %property(Background, GetBackground, SetBackground, doc="See `GetBackground` and `SetBackground`"); |
1200 | %property(BackgroundMode, GetBackgroundMode, SetBackgroundMode, doc="See `GetBackgroundMode` and `SetBackgroundMode`"); | |
1201 | %property(BoundingBox, GetBoundingBox, doc="See `GetBoundingBox`"); | |
1202 | %property(Brush, GetBrush, SetBrush, doc="See `GetBrush` and `SetBrush`"); | |
1203 | %property(CharHeight, GetCharHeight, doc="See `GetCharHeight`"); | |
1204 | %property(CharWidth, GetCharWidth, doc="See `GetCharWidth`"); | |
1205 | %property(ClippingBox, GetClippingBox, doc="See `GetClippingBox`"); | |
1206 | %property(ClippingRect, GetClippingRect, SetClippingRect, doc="See `GetClippingRect` and `SetClippingRect`"); | |
1207 | %property(Depth, GetDepth, doc="See `GetDepth`"); | |
1208 | %property(DeviceOrigin, GetDeviceOrigin, SetDeviceOrigin, doc="See `GetDeviceOrigin` and `SetDeviceOrigin`"); | |
1209 | %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`"); | |
1210 | %property(FullTextExtent, GetFullTextExtent, doc="See `GetFullTextExtent`"); | |
1211 | %property(LogicalFunction, GetLogicalFunction, SetLogicalFunction, doc="See `GetLogicalFunction` and `SetLogicalFunction`"); | |
1212 | %property(LogicalOrigin, GetLogicalOrigin, SetLogicalOrigin, doc="See `GetLogicalOrigin` and `SetLogicalOrigin`"); | |
1213 | %property(LogicalScale, GetLogicalScale, SetLogicalScale, doc="See `GetLogicalScale` and `SetLogicalScale`"); | |
1214 | %property(MapMode, GetMapMode, SetMapMode, doc="See `GetMapMode` and `SetMapMode`"); | |
1215 | %property(MultiLineTextExtent, GetMultiLineTextExtent, doc="See `GetMultiLineTextExtent`"); | |
1216 | %property(Optimization, GetOptimization, SetOptimization, doc="See `GetOptimization` and `SetOptimization`"); | |
1217 | %property(PPI, GetPPI, doc="See `GetPPI`"); | |
1218 | %property(PartialTextExtents, GetPartialTextExtents, doc="See `GetPartialTextExtents`"); | |
1219 | %property(Pen, GetPen, SetPen, doc="See `GetPen` and `SetPen`"); | |
1220 | %property(Pixel, GetPixel, doc="See `GetPixel`"); | |
1221 | %property(PixelPoint, GetPixelPoint, doc="See `GetPixelPoint`"); | |
1222 | %property(Size, GetSize, doc="See `GetSize`"); | |
1223 | %property(SizeMM, GetSizeMM, doc="See `GetSizeMM`"); | |
1224 | %property(TextBackground, GetTextBackground, SetTextBackground, doc="See `GetTextBackground` and `SetTextBackground`"); | |
1225 | %property(TextExtent, GetTextExtent, doc="See `GetTextExtent`"); | |
1226 | %property(TextForeground, GetTextForeground, SetTextForeground, doc="See `GetTextForeground` and `SetTextForeground`"); | |
1227 | %property(UserScale, GetUserScale, SetUserScale, doc="See `GetUserScale` and `SetUserScale`"); | |
8adc9d9d RD |
1228 | |
1229 | %property(LayoutDirection, GetLayoutDirection, SetLayoutDirection); | |
d14a1e28 RD |
1230 | }; |
1231 | ||
1232 | ||
1233 | ||
1234 | %{ | |
1235 | static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) { | |
1236 | *x1 = dc->MinX(); | |
1237 | *y1 = dc->MinY(); | |
1238 | *x2 = dc->MaxX(); | |
1239 | *y2 = dc->MaxY(); | |
1240 | } | |
1241 | %} | |
1242 | ||
1243 | ||
ad55c49e RD |
1244 | //--------------------------------------------------------------------------- |
1245 | %newgroup | |
1246 | ||
1247 | DocStr(wxDCTextColourChanger, | |
1248 | "wx.DCTextColourChanger can be used to temporarily change the DC text | |
1249 | colour and restore it automatically when the object goes out of scope", ""); | |
1250 | ||
1251 | class wxDCTextColourChanger | |
1252 | { | |
1253 | public: | |
1254 | wxDCTextColourChanger(wxDC& dc, const wxColour& col); | |
1255 | ~wxDCTextColourChanger(); | |
1256 | }; | |
1257 | ||
1258 | ||
1259 | DocStr(wxDCPenChanger, | |
1260 | "wx.DCPenChanger can be used to temporarily change the DC pen and | |
1261 | restore it automatically when the object goes out of scope", ""); | |
1262 | ||
1263 | class wxDCPenChanger | |
1264 | { | |
1265 | public: | |
1266 | wxDCPenChanger(wxDC& dc, const wxPen& pen); | |
1267 | ~wxDCPenChanger(); | |
1268 | }; | |
1269 | ||
1270 | ||
1271 | ||
1272 | DocStr(wxDCBrushChanger, | |
1273 | "wx.DCBrushChanger can be used to temporarily change the DC brush and | |
1274 | restore it automatically when the object goes out of scope", ""); | |
1275 | ||
1276 | class wxDCBrushChanger | |
1277 | { | |
1278 | public: | |
1279 | wxDCBrushChanger(wxDC& dc, const wxBrush& brush); | |
1280 | ~wxDCBrushChanger(); | |
1281 | }; | |
1282 | ||
1283 | ||
1284 | DocStr(wxDCClipper, | |
1285 | "wx.wxDCClipper sets the DC's clipping region when it is constructed, | |
1286 | and then automatically destroys the clipping region when the clipper | |
1287 | goes out of scope.", ""); | |
1288 | ||
1289 | class wxDCClipper | |
1290 | { | |
1291 | public: | |
1292 | %nokwargs wxDCClipper; | |
1293 | wxDCClipper(wxDC& dc, const wxRegion& r); | |
1294 | wxDCClipper(wxDC& dc, const wxRect& r); | |
1295 | wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h); | |
1296 | ~wxDCClipper(); | |
1297 | }; | |
1298 | ||
1299 | ||
1300 | ||
1301 | ||
d14a1e28 RD |
1302 | //--------------------------------------------------------------------------- |
1303 | %newgroup | |
1304 | ||
ab1f7d2a RD |
1305 | MustHaveApp(wxMemoryDC); |
1306 | ||
70794ec5 RD |
1307 | DocStr(wxMemoryDC, |
1308 | "A memory device context provides a means to draw graphics onto a | |
1309 | bitmap. A bitmap must be selected into the new memory DC before it may | |
1310 | be used for anything. Typical usage is as follows:: | |
1311 | ||
1312 | dc = wx.MemoryDC() | |
1313 | dc.SelectObject(bitmap) | |
96285a18 | 1314 | # draw on the dc using any of the Draw methods |
70794ec5 RD |
1315 | dc.SelectObject(wx.NullBitmap) |
1316 | # the bitmap now contains wahtever was drawn upon it | |
1317 | ||
1318 | Note that the memory DC *must* be deleted (or the bitmap selected out | |
1319 | of it) before a bitmap can be reselected into another memory DC. | |
1320 | ", ""); | |
1321 | ||
d14a1e28 RD |
1322 | class wxMemoryDC : public wxDC { |
1323 | public: | |
70794ec5 | 1324 | DocCtorStr( |
8f514ab4 | 1325 | wxMemoryDC(wxBitmap& bitmap = wxNullBitmap), |
70794ec5 RD |
1326 | "Constructs a new memory device context. |
1327 | ||
1328 | Use the Ok member to test whether the constructor was successful in | |
96285a18 RD |
1329 | creating a usable device context. If a bitmap is not given to this |
1330 | constructor then don't forget to select a bitmap into the DC before | |
1331 | drawing on it.", " | |
4942342c | 1332 | |
70794ec5 RD |
1333 | :see: `MemoryDCFromDC`"); |
1334 | ||
1335 | DocCtorStrName( | |
1336 | wxMemoryDC(wxDC* oldDC), | |
1337 | "Creates a DC that is compatible with the oldDC.", "", | |
1338 | MemoryDCFromDC); | |
1339 | ||
1340 | ||
1341 | DocDeclStr( | |
8f514ab4 | 1342 | void , SelectObject(wxBitmap& bitmap), |
70794ec5 RD |
1343 | "Selects the bitmap into the device context, to use as the memory |
1344 | bitmap. Selecting the bitmap into a memory DC allows you to draw into | |
1345 | the DC, and therefore the bitmap, and also to use Blit to copy the | |
1346 | bitmap to a window. | |
1347 | ||
1348 | If the argument is wx.NullBitmap (or some other uninitialised | |
1349 | `wx.Bitmap`) the current bitmap is selected out of the device context, | |
1350 | and the original bitmap restored, allowing the current bitmap to be | |
1351 | destroyed safely.", ""); | |
8f514ab4 RD |
1352 | |
1353 | ||
1354 | DocDeclStr( | |
1355 | void , SelectObjectAsSource(const wxBitmap& bmp), | |
1356 | "", ""); | |
1357 | ||
70794ec5 | 1358 | |
d14a1e28 RD |
1359 | }; |
1360 | ||
72156afe RD |
1361 | //--------------------------------------------------------------------------- |
1362 | %newgroup | |
1363 | ||
1364 | MustHaveApp(wxScreenDC); | |
1365 | ||
1366 | DocStr(wxScreenDC, | |
1367 | "A wxScreenDC can be used to paint anywhere on the screen. This should | |
1368 | normally be constructed as a temporary stack object; don't store a | |
1369 | wxScreenDC object. | |
1370 | ", ""); | |
1371 | class wxScreenDC : public wxDC { | |
1372 | public: | |
1373 | wxScreenDC(); | |
1374 | ||
1375 | DocDeclStrName( | |
1376 | bool , StartDrawingOnTop(wxWindow* window), | |
1377 | "Specify that the area of the screen to be drawn upon coincides with | |
1378 | the given window. | |
1379 | ||
1380 | :see: `EndDrawingOnTop`", "", | |
1381 | StartDrawingOnTopWin); | |
1382 | ||
1383 | ||
1384 | DocDeclStr( | |
1385 | bool , StartDrawingOnTop(wxRect* rect = NULL), | |
1386 | "Specify that the area is the given rectangle, or the whole screen if | |
1387 | ``None`` is passed. | |
1388 | ||
1389 | :see: `EndDrawingOnTop`", ""); | |
1390 | ||
1391 | ||
1392 | DocDeclStr( | |
1393 | bool , EndDrawingOnTop(), | |
1394 | "Use this in conjunction with `StartDrawingOnTop` or | |
1395 | `StartDrawingOnTopWin` to ensure that drawing to the screen occurs on | |
1396 | top of existing windows. Without this, some window systems (such as X) | |
1397 | only allow drawing to take place underneath other windows. | |
1398 | ||
1399 | You might use this pair of functions when implementing a drag feature, | |
1400 | for example as in the `wx.SplitterWindow` implementation. | |
1401 | ||
1402 | These functions are probably obsolete since the X implementations | |
1403 | allow drawing directly on the screen now. However, the fact that this | |
1404 | function allows the screen to be refreshed afterwards may be useful | |
1405 | to some applications.", ""); | |
1406 | ||
1407 | }; | |
1408 | ||
1409 | //--------------------------------------------------------------------------- | |
1410 | %newgroup | |
1411 | ||
1412 | MustHaveApp(wxWindowDC); | |
1413 | ||
1414 | DocStr(wxWindowDC, | |
1415 | "A wx.WindowDC must be constructed if an application wishes to paint on | |
1416 | the whole area of a window (client and decorations). This should | |
1417 | normally be constructed as a temporary stack object; don't store a | |
1418 | wx.WindowDC object.",""); | |
1419 | class wxWindowDC : public wxDC { | |
1420 | public: | |
1421 | DocCtorStr( | |
1422 | wxWindowDC(wxWindow* win), | |
1423 | "Constructor. Pass the window on which you wish to paint.",""); | |
1424 | }; | |
1425 | ||
1426 | //--------------------------------------------------------------------------- | |
1427 | %newgroup | |
1428 | ||
1429 | MustHaveApp(wxClientDC); | |
1430 | ||
1431 | DocStr(wxClientDC, | |
1432 | "A wx.ClientDC must be constructed if an application wishes to paint on | |
1433 | the client area of a window from outside an EVT_PAINT event. This should | |
1434 | normally be constructed as a temporary stack object; don't store a | |
1435 | wx.ClientDC object long term. | |
1436 | ||
1437 | To draw on a window from within an EVT_PAINT handler, construct a | |
1438 | `wx.PaintDC` object. | |
1439 | ||
1440 | To draw on the whole window including decorations, construct a | |
1441 | `wx.WindowDC` object (Windows only). | |
1442 | ", ""); | |
1443 | class wxClientDC : public wxWindowDC { | |
1444 | public: | |
1445 | DocCtorStr( | |
1446 | wxClientDC(wxWindow* win), | |
1447 | "Constructor. Pass the window on which you wish to paint.", ""); | |
1448 | }; | |
1449 | ||
1450 | //--------------------------------------------------------------------------- | |
1451 | %newgroup | |
1452 | ||
1453 | MustHaveApp(wxPaintDC); | |
1454 | ||
1455 | DocStr(wxPaintDC, | |
1456 | "A wx.PaintDC must be constructed if an application wishes to paint on | |
1457 | the client area of a window from within an EVT_PAINT event | |
1458 | handler. This should normally be constructed as a temporary stack | |
1459 | object; don't store a wx.PaintDC object. If you have an EVT_PAINT | |
1460 | handler, you **must** create a wx.PaintDC object within it even if you | |
1461 | don't actually use it. | |
1462 | ||
1463 | Using wx.PaintDC within EVT_PAINT handlers is important because it | |
1464 | automatically sets the clipping area to the damaged area of the | |
1465 | window. Attempts to draw outside this area do not appear. | |
1466 | ||
1467 | To draw on a window from outside EVT_PAINT handlers, construct a | |
1468 | `wx.ClientDC` object. | |
1469 | ",""); | |
1470 | class wxPaintDC : public wxClientDC { | |
1471 | public: | |
1472 | DocCtorStr( | |
1473 | wxPaintDC(wxWindow* win), | |
1474 | "Constructor. Pass the window on which you wish to paint.", ""); | |
1475 | }; | |
1476 | ||
1477 | ||
1478 | ||
d14a1e28 RD |
1479 | //--------------------------------------------------------------------------- |
1480 | %newgroup | |
1481 | ||
b159c5c4 | 1482 | |
ef22e3d3 | 1483 | %{ |
ef22e3d3 | 1484 | #include <wx/dcbuffer.h> |
ef22e3d3 RD |
1485 | %} |
1486 | ||
67a5217c RD |
1487 | enum { |
1488 | wxBUFFER_VIRTUAL_AREA, | |
1489 | wxBUFFER_CLIENT_AREA | |
1490 | }; | |
ef22e3d3 | 1491 | |
ab1f7d2a RD |
1492 | MustHaveApp(wxBufferedDC); |
1493 | ||
70794ec5 RD |
1494 | DocStr(wxBufferedDC, |
1495 | "This simple class provides a simple way to avoid flicker: when drawing | |
1496 | on it, everything is in fact first drawn on an in-memory buffer (a | |
1497 | `wx.Bitmap`) and then copied to the screen only once, when this object | |
0a012f77 RD |
1498 | is destroyed. You can either provide a buffer bitmap yourself, and |
1499 | reuse it the next time something needs painted, or you can let the | |
1500 | buffered DC create and provide a buffer bitmap itself. | |
70794ec5 | 1501 | |
0a012f77 | 1502 | Buffered DCs can be used in the same way as any other device context. |
6a223074 RD |
1503 | wx.BufferedDC itself typically replaces `wx.ClientDC`, if you want to |
1504 | use it in your EVT_PAINT handler, you should look at | |
0a012f77 RD |
1505 | `wx.BufferedPaintDC`. You can also use a wx.BufferedDC without |
1506 | providing a target DC. In this case the operations done on the dc | |
1507 | will only be written to the buffer bitmap and *not* to any window, so | |
1508 | you will want to have provided the buffer bitmap and then reuse it | |
1509 | when it needs painted to the window. | |
6a223074 RD |
1510 | |
1511 | Please note that GTK+ 2.0 and OS X provide double buffering themselves | |
0a012f77 RD |
1512 | natively. You may want to use `wx.Window.IsDoubleBuffered` to |
1513 | determine whether you need to use buffering or not, or use | |
1514 | `wx.AutoBufferedPaintDC` to avoid needless double buffering on systems | |
1515 | that already do it automatically. | |
1516 | ||
1517 | ||
70794ec5 RD |
1518 | ", ""); |
1519 | ||
96285a18 | 1520 | class wxBufferedDC : public wxMemoryDC |
d14a1e28 RD |
1521 | { |
1522 | public: | |
e608d228 | 1523 | %pythonAppend wxBufferedDC |
70794ec5 | 1524 | "self.__dc = args[0] # save a ref so the other dc will not be deleted before self"; |
1b8c7ba6 | 1525 | |
b159c5c4 | 1526 | %nokwargs wxBufferedDC; |
d14a1e28 | 1527 | |
70794ec5 RD |
1528 | DocStr( |
1529 | wxBufferedDC, | |
1530 | "Constructs a buffered DC.", " | |
1531 | ||
1532 | :param dc: The underlying DC: everything drawn to this object will | |
1533 | be flushed to this DC when this object is destroyed. You may | |
1534 | pass ``None`` in order to just initialize the buffer, and not | |
1535 | flush it. | |
1536 | ||
1537 | :param buffer: If a `wx.Size` object is passed as the 2nd arg then | |
1538 | it is the size of the bitmap that will be created internally | |
1539 | and used for an implicit buffer. If the 2nd arg is a | |
1540 | `wx.Bitmap` then it is the explicit buffer that will be | |
1541 | used. Using an explicit buffer is the most efficient solution | |
1542 | as the bitmap doesn't have to be recreated each time but it | |
1543 | also requires more memory as the bitmap is never freed. The | |
1544 | bitmap should have appropriate size, anything drawn outside of | |
4a065572 RD |
1545 | its bounds is clipped. If wx.NullBitmap is used then a new |
1546 | buffer will be allocated that is the same size as the dc. | |
b159c5c4 | 1547 | |
67a5217c RD |
1548 | :param style: The style parameter indicates whether the supplied buffer is |
1549 | intended to cover the entire virtual size of a `wx.ScrolledWindow` or | |
1550 | if it only covers the client area. Acceptable values are | |
1551 | ``wx.BUFFER_VIRTUAL_AREA`` and ``wx.BUFFER_CLIENT_AREA``. | |
1552 | ||
1553 | "); | |
4a065572 | 1554 | wxBufferedDC( wxDC* dc, |
d9b33d70 | 1555 | wxBitmap& buffer=wxNullBitmap, |
4a065572 RD |
1556 | int style = wxBUFFER_CLIENT_AREA ); |
1557 | wxBufferedDC( wxDC* dc, | |
1558 | const wxSize& area, | |
1559 | int style = wxBUFFER_CLIENT_AREA ); | |
96285a18 RD |
1560 | // wxBufferedDC(wxWindow* win, |
1561 | // wxDC *dc, | |
1562 | // const wxSize &area, | |
1563 | // int style = wxBUFFER_CLIENT_AREA); | |
9a3dccf6 | 1564 | |
7a0b15e9 | 1565 | |
70794ec5 RD |
1566 | DocCtorStr( |
1567 | ~wxBufferedDC(), | |
1568 | "Copies everything drawn on the DC so far to the underlying DC | |
1569 | associated with this object, if any.", ""); | |
1570 | ||
4a065572 | 1571 | |
70794ec5 RD |
1572 | DocDeclStr( |
1573 | void , UnMask(), | |
1574 | "Blits the buffer to the dc, and detaches the dc from the buffer (so it | |
1575 | can be effectively used once only). This is usually only called in | |
1576 | the destructor.", ""); | |
d9b33d70 RD |
1577 | |
1578 | // Set and get the style | |
1579 | void SetStyle(int style); | |
1580 | int GetStyle() const; | |
d14a1e28 RD |
1581 | }; |
1582 | ||
1583 | ||
7a0b15e9 | 1584 | |
70794ec5 | 1585 | |
ab1f7d2a | 1586 | MustHaveApp(wxBufferedPaintDC); |
7a0b15e9 | 1587 | |
70794ec5 RD |
1588 | DocStr(wxBufferedPaintDC, |
1589 | "This is a subclass of `wx.BufferedDC` which can be used inside of an | |
1590 | EVT_PAINT event handler. Just create an object of this class instead | |
1591 | of `wx.PaintDC` and that's all you have to do to (mostly) avoid | |
1592 | flicker. The only thing to watch out for is that if you are using this | |
1593 | class together with `wx.ScrolledWindow`, you probably do **not** want | |
1594 | to call `wx.Window.PrepareDC` on it as it already does this internally | |
1595 | for the real underlying `wx.PaintDC`. | |
1596 | ||
1597 | If your window is already fully buffered in a `wx.Bitmap` then your | |
1598 | EVT_PAINT handler can be as simple as just creating a | |
1599 | ``wx.BufferedPaintDC`` as it will `Blit` the buffer to the window | |
1600 | automatically when it is destroyed. For example:: | |
1601 | ||
1602 | def OnPaint(self, event): | |
1603 | dc = wx.BufferedPaintDC(self, self.buffer) | |
1604 | ||
1605 | ||
1606 | ", ""); | |
1607 | ||
d14a1e28 RD |
1608 | class wxBufferedPaintDC : public wxBufferedDC |
1609 | { | |
1610 | public: | |
b159c5c4 | 1611 | |
70794ec5 | 1612 | DocCtorStr( |
67a5217c | 1613 | wxBufferedPaintDC( wxWindow *window, |
d9b33d70 | 1614 | wxBitmap &buffer = wxNullBitmap, |
67a5217c | 1615 | int style = wxBUFFER_CLIENT_AREA), |
70794ec5 RD |
1616 | "Create a buffered paint DC. As with `wx.BufferedDC`, you may either |
1617 | provide the bitmap to be used for buffering or let this object create | |
1618 | one internally (in the latter case, the size of the client part of the | |
9a3dccf6 | 1619 | window is automatically used).", ""); |
b159c5c4 | 1620 | |
d14a1e28 RD |
1621 | }; |
1622 | ||
d14a1e28 RD |
1623 | //--------------------------------------------------------------------------- |
1624 | %newgroup | |
1625 | ||
72156afe RD |
1626 | // Epydoc doesn't like this for some strange reason... |
1627 | // %pythoncode { | |
1628 | // if 'wxMac' in wx.PlatformInfo or 'gtk2' in wx.PlatformInfo: | |
1629 | // _AutoBufferedPaintDCBase = PaintDC | |
1630 | // else: | |
1631 | // _AutoBufferedPaintDCBase = BufferedPaintDC | |
1632 | ||
1633 | // class AutoBufferedPaintDC(_AutoBufferedPaintDCBase): | |
1634 | // """ | |
1635 | // If the current platform double buffers by default then this DC is the | |
1636 | // same as a plain `wx.PaintDC`, otherwise it is a `wx.BufferedPaintDC`. | |
205d49f7 | 1637 | |
72156afe RD |
1638 | // :see: `wx.AutoBufferedPaintDCFactory` |
1639 | // """ | |
1640 | // def __init__(self, window): | |
1641 | // _AutoBufferedPaintDCBase.__init__(self, window) | |
1642 | // } | |
205d49f7 | 1643 | |
ab1f7d2a | 1644 | |
72156afe RD |
1645 | DocStr(wxAutoBufferedPaintDC, |
1646 | "If the current platform double buffers by default then this DC is the | |
1647 | same as a plain `wx.PaintDC`, otherwise it is a `wx.BufferedPaintDC`. | |
70794ec5 | 1648 | |
72156afe | 1649 | :see: `wx.AutoBufferedPaintDCFactory` |
70794ec5 | 1650 | ", ""); |
70794ec5 | 1651 | |
72156afe RD |
1652 | class wxAutoBufferedPaintDC: public wxDC |
1653 | { | |
d14a1e28 | 1654 | public: |
72156afe | 1655 | wxAutoBufferedPaintDC(wxWindow* win); |
d14a1e28 RD |
1656 | }; |
1657 | ||
9a3dccf6 | 1658 | |
96285a18 RD |
1659 | %newobject wxAutoBufferedPaintDCFactory; |
1660 | DocDeclStr( | |
1661 | wxDC* , wxAutoBufferedPaintDCFactory(wxWindow* window), | |
1662 | "Checks if the window is natively double buffered and will return a | |
72156afe RD |
1663 | `wx.PaintDC` if it is, a `wx.BufferedPaintDC` otherwise. The advantage of |
1664 | this function over `wx.AutoBufferedPaintDC` is that this function will check | |
1665 | if the the specified window has double-buffering enabled rather than just | |
1666 | going by platform defaults.", ""); | |
96285a18 RD |
1667 | |
1668 | ||
1669 | ||
d14a1e28 RD |
1670 | //--------------------------------------------------------------------------- |
1671 | %newgroup | |
1672 | ||
ab1f7d2a RD |
1673 | MustHaveApp(wxMirrorDC); |
1674 | ||
70794ec5 RD |
1675 | DocStr(wxMirrorDC, |
1676 | "wx.MirrorDC is a simple wrapper class which is always associated with a | |
1677 | real `wx.DC` object and either forwards all of its operations to it | |
1678 | without changes (no mirroring takes place) or exchanges x and y | |
1679 | coordinates which makes it possible to reuse the same code to draw a | |
1680 | figure and its mirror -- i.e. reflection related to the diagonal line | |
1681 | x == y.", ""); | |
d14a1e28 RD |
1682 | class wxMirrorDC : public wxDC |
1683 | { | |
1684 | public: | |
70794ec5 RD |
1685 | DocCtorStr( |
1686 | wxMirrorDC(wxDC& dc, bool mirror), | |
1687 | "Creates a mirrored DC associated with the real *dc*. Everything drawn | |
1688 | on the wx.MirrorDC will appear on the *dc*, and will be mirrored if | |
1689 | *mirror* is True.",""); | |
d14a1e28 RD |
1690 | }; |
1691 | ||
1692 | //--------------------------------------------------------------------------- | |
1693 | %newgroup | |
1694 | ||
1695 | %{ | |
1696 | #include <wx/dcps.h> | |
1697 | %} | |
1698 | ||
ab1f7d2a RD |
1699 | MustHaveApp(wxPostScriptDC); |
1700 | ||
70794ec5 RD |
1701 | DocStr(wxPostScriptDC, |
1702 | "This is a `wx.DC` that can write to PostScript files on any platform.",""); | |
1703 | ||
d14a1e28 RD |
1704 | class wxPostScriptDC : public wxDC { |
1705 | public: | |
70794ec5 RD |
1706 | DocCtorStr( |
1707 | wxPostScriptDC(const wxPrintData& printData), | |
1708 | "Constructs a PostScript printer device context from a `wx.PrintData` | |
1709 | object.", ""); | |
d14a1e28 RD |
1710 | |
1711 | wxPrintData& GetPrintData(); | |
1712 | void SetPrintData(const wxPrintData& data); | |
1713 | ||
70794ec5 RD |
1714 | DocDeclStr( |
1715 | static void , SetResolution(int ppi), | |
1716 | "Set resolution (in pixels per inch) that will be used in PostScript | |
1717 | output. Default is 720ppi.", ""); | |
1718 | ||
1719 | DocDeclStr( | |
1720 | static int , GetResolution(), | |
1721 | "Return resolution used in PostScript output.", ""); | |
7012bb9f RD |
1722 | |
1723 | %property(PrintData, GetPrintData, SetPrintData, doc="See `GetPrintData` and `SetPrintData`"); | |
d14a1e28 RD |
1724 | }; |
1725 | ||
1726 | //--------------------------------------------------------------------------- | |
1727 | %newgroup | |
1728 | ||
1729 | ||
ab1f7d2a RD |
1730 | MustHaveApp(wxMetaFile); |
1731 | MustHaveApp(wxMetaFileDC); | |
1732 | ||
1733 | ||
da457c1b | 1734 | #if defined(__WXMSW__) || defined(__WXMAC__) |
d14a1e28 RD |
1735 | |
1736 | %{ | |
1737 | #include <wx/metafile.h> | |
1738 | %} | |
1739 | ||
1740 | class wxMetaFile : public wxObject { | |
1741 | public: | |
1742 | wxMetaFile(const wxString& filename = wxPyEmptyString); | |
1743 | ~wxMetaFile(); | |
1744 | ||
6c2dd16f RD |
1745 | bool IsOk(); |
1746 | %pythoncode { Ok = IsOk } | |
d14a1e28 RD |
1747 | bool SetClipboard(int width = 0, int height = 0); |
1748 | ||
1749 | wxSize GetSize(); | |
1750 | int GetWidth(); | |
1751 | int GetHeight(); | |
1752 | ||
da457c1b | 1753 | #ifdef __WXMSW__ |
d14a1e28 | 1754 | const wxString& GetFileName() const; |
da457c1b RD |
1755 | #endif |
1756 | ||
6c2dd16f | 1757 | %pythoncode { def __nonzero__(self): return self.IsOk() } |
d14a1e28 RD |
1758 | }; |
1759 | ||
1760 | // bool wxMakeMetaFilePlaceable(const wxString& filename, | |
1761 | // int minX, int minY, int maxX, int maxY, float scale=1.0); | |
1762 | ||
1763 | ||
1764 | class wxMetaFileDC : public wxDC { | |
1765 | public: | |
1766 | wxMetaFileDC(const wxString& filename = wxPyEmptyString, | |
1767 | int width = 0, int height = 0, | |
1768 | const wxString& description = wxPyEmptyString); | |
1769 | wxMetaFile* Close(); | |
1770 | }; | |
1771 | ||
1772 | ||
1773 | ||
1774 | #else // Make some dummies for the other platforms | |
1775 | ||
1776 | %{ | |
1777 | class wxMetaFile : public wxObject { | |
1778 | public: | |
1779 | wxMetaFile(const wxString&) | |
81cfe5e1 | 1780 | { wxPyRaiseNotImplemented(); } |
d14a1e28 RD |
1781 | }; |
1782 | ||
1783 | class wxMetaFileDC : public wxClientDC { | |
1784 | public: | |
1785 | wxMetaFileDC(const wxString&, int, int, const wxString&) | |
81cfe5e1 | 1786 | { wxPyRaiseNotImplemented(); } |
d14a1e28 RD |
1787 | }; |
1788 | ||
1789 | %} | |
1790 | ||
1791 | class wxMetaFile : public wxObject { | |
1792 | public: | |
1793 | wxMetaFile(const wxString& filename = wxPyEmptyString); | |
1794 | }; | |
1795 | ||
1796 | class wxMetaFileDC : public wxDC { | |
1797 | public: | |
1798 | wxMetaFileDC(const wxString& filename = wxPyEmptyString, | |
1799 | int width = 0, int height = 0, | |
1800 | const wxString& description = wxPyEmptyString); | |
1801 | }; | |
1802 | ||
1803 | ||
1804 | #endif | |
1805 | ||
1806 | ||
1807 | //--------------------------------------------------------------------------- | |
1808 | ||
ab1f7d2a RD |
1809 | MustHaveApp(wxPrinterDC); |
1810 | ||
d14a1e28 RD |
1811 | #if defined(__WXMSW__) || defined(__WXMAC__) |
1812 | ||
1813 | class wxPrinterDC : public wxDC { | |
1814 | public: | |
1815 | wxPrinterDC(const wxPrintData& printData); | |
d14a1e28 RD |
1816 | }; |
1817 | ||
1818 | #else | |
1819 | %{ | |
1820 | class wxPrinterDC : public wxClientDC { | |
1821 | public: | |
1822 | wxPrinterDC(const wxPrintData&) | |
81cfe5e1 | 1823 | { wxPyRaiseNotImplemented(); } |
4942342c | 1824 | |
d14a1e28 RD |
1825 | }; |
1826 | %} | |
4942342c | 1827 | |
d14a1e28 RD |
1828 | class wxPrinterDC : public wxDC { |
1829 | public: | |
1830 | wxPrinterDC(const wxPrintData& printData); | |
d14a1e28 RD |
1831 | }; |
1832 | #endif | |
1833 | ||
4942342c RD |
1834 | //--------------------------------------------------------------------------- |
1835 | //--------------------------------------------------------------------------- |