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