1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Wrapper definitions for wx.GraphicsPath, wx.GraphicsContext
9 // Copyright: (c) 2006 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
20 #include <wx/graphics.h>
23 // Turn off the aquisition of the Global Interpreter Lock for the classes and
24 // functions in this file
28 //---------------------------------------------------------------------------
29 //---------------------------------------------------------------------------
32 #if !wxUSE_GRAPHICS_CONTEXT
33 // C++ stub classes for platforms or build configurations that don't have
34 // wxGraphicsContext yet.
36 class wxGraphicsRenderer;
37 class wxGraphicsMatrix;
40 class wxGraphicsObject : public wxObject
44 wxGraphicsObject( wxGraphicsRenderer* ) {
45 PyErr_SetString(PyExc_NotImplementedError,
46 "wx.GraphicsObject is not available on this platform.");
48 wxGraphicsObject( const wxGraphicsObject& ) {}
49 virtual ~wxGraphicsObject() {}
50 bool IsNull() const { return false; }
51 wxGraphicsRenderer* GetRenderer() const { return NULL; }
56 class wxGraphicsPen : public wxGraphicsObject
60 virtual ~wxGraphicsPen() {}
62 wxGraphicsPen wxNullGraphicsPen;
66 class wxGraphicsBrush : public wxGraphicsObject
70 virtual ~wxGraphicsBrush() {}
72 wxGraphicsBrush wxNullGraphicsBrush;
76 class wxGraphicsFont : public wxGraphicsObject
80 virtual ~wxGraphicsFont() {}
82 wxGraphicsFont wxNullGraphicsFont;
86 class wxGraphicsPath : public wxGraphicsObject
90 wxGraphicsPath(wxGraphicsRenderer* ) {
91 PyErr_SetString(PyExc_NotImplementedError,
92 "wx.GraphicsPath is not available on this platform.");
94 virtual ~wxGraphicsPath() {}
96 void MoveToPoint( wxDouble, wxDouble ) {}
97 void MoveToPoint( const wxPoint2DDouble& ) {}
98 void AddLineToPoint( wxDouble, wxDouble ) {}
99 void AddLineToPoint( const wxPoint2DDouble& ) {}
100 void AddCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, wxDouble ) {}
101 void AddCurveToPoint( const wxPoint2DDouble&, const wxPoint2DDouble&, const wxPoint2DDouble&) {}
102 void AddPath( const wxGraphicsPath& ) {}
103 void CloseSubpath() {}
104 void GetCurrentPoint( wxDouble&, wxDouble&) const {}
105 wxPoint2DDouble GetCurrentPoint() const { return wxPoint2D(0,0); }
106 void AddArc( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, bool ) {}
107 void AddArc( const wxPoint2DDouble& , wxDouble, wxDouble , wxDouble , bool ) {}
109 void AddQuadCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble ) {}
110 void AddRectangle( wxDouble, wxDouble, wxDouble, wxDouble ) {}
111 void AddCircle( wxDouble, wxDouble, wxDouble ) {}
112 void AddArcToPoint( wxDouble, wxDouble , wxDouble, wxDouble, wxDouble ) {}
114 void AddEllipse( wxDouble , wxDouble , wxDouble , wxDouble ) {}
115 void AddRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
116 void * GetNativePath() const { return NULL; }
117 void UnGetNativePath(void *) const {}
118 void Transform( const wxGraphicsMatrix& ) {}
119 void GetBox(wxDouble *, wxDouble *, wxDouble *, wxDouble *) const {}
120 wxRect2D GetBox() const { return wxRect2D(0,0,0,0); }
122 bool Contains( wxDouble , wxDouble , int ) const { return false; }
123 bool Contains( const wxPoint2DDouble& , int ) const { return false; }
125 wxGraphicsPath wxNullGraphicsPath;
128 class wxGraphicsMatrix : public wxGraphicsObject
131 wxGraphicsMatrix() { }
132 wxGraphicsMatrix(wxGraphicsRenderer* ) {
133 PyErr_SetString(PyExc_NotImplementedError,
134 "wx.GraphicsMatrix is not available on this platform.");
136 virtual ~wxGraphicsMatrix() {}
137 virtual void Concat( const wxGraphicsMatrix & ) {}
138 virtual void Copy( const wxGraphicsMatrix & ) {}
139 virtual void Set(wxDouble , wxDouble , wxDouble , wxDouble ,
140 wxDouble , wxDouble ) {}
141 virtual void Get(wxDouble*, wxDouble*, wxDouble*,
142 wxDouble*, wxDouble*, wxDouble*) {}
143 virtual void Invert() {}
144 virtual bool IsEqual( const wxGraphicsMatrix& t) const { return false; }
145 virtual bool IsIdentity() const { return false; }
146 virtual void Translate( wxDouble , wxDouble ) {}
147 virtual void Scale( wxDouble , wxDouble ) {}
148 virtual void Rotate( wxDouble ) {}
149 virtual void TransformPoint( wxDouble *, wxDouble * ) const {}
150 virtual void TransformDistance( wxDouble *, wxDouble * ) const {}
151 virtual void * GetNativeMatrix() const { return NULL; }
153 wxGraphicsMatrix wxNullGraphicsMatrix;
156 class wxGraphicsContext : public wxGraphicsObject
160 wxGraphicsContext(wxGraphicsRenderer* ) {
161 PyErr_SetString(PyExc_NotImplementedError,
162 "wx.GraphicsContext is not available on this platform.");
165 virtual ~wxGraphicsContext() {}
167 static wxGraphicsContext* Create() {
168 PyErr_SetString(PyExc_NotImplementedError,
169 "wx.GraphicsContext is not available on this platform.");
172 static wxGraphicsContext* Create( const wxWindowDC& ) {
173 PyErr_SetString(PyExc_NotImplementedError,
174 "wx.GraphicsContext is not available on this platform.");
178 static wxGraphicsContext* CreateFromNative( void * ) {
179 PyErr_SetString(PyExc_NotImplementedError,
180 "wx.GraphicsContext is not available on this platform.");
184 static wxGraphicsContext* CreateFromNativeWindow( void * ) {
185 PyErr_SetString(PyExc_NotImplementedError,
186 "wx.GraphicsContext is not available on this platform.");
190 static wxGraphicsContext* Create( wxWindow* ) {
191 PyErr_SetString(PyExc_NotImplementedError,
192 "wx.GraphicsContext is not available on this platform.");
196 wxGraphicsPath CreatePath() { return wxNullGraphicsPath; }
198 virtual wxGraphicsPen CreatePen(const wxPen& ) { return wxNullGraphicsPen; }
200 virtual wxGraphicsBrush CreateBrush(const wxBrush& ) { return wxNullGraphicsBrush; }
202 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble ,
203 const wxColour&, const wxColour&) { return wxNullGraphicsBrush; }
205 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo,
206 wxDouble xc, wxDouble yc, wxDouble radius,
207 const wxColour &oColor, const wxColour &cColor) { return wxNullGraphicsBrush; }
209 virtual wxGraphicsFont CreateFont( const wxFont &, const wxColour & ) { return wxNullGraphicsFont; }
211 virtual wxGraphicsMatrix CreateMatrix( wxDouble, wxDouble, wxDouble, wxDouble,
212 wxDouble, wxDouble) { return wxNullGraphicsMatrix; }
214 virtual void PushState() {}
215 virtual void PopState() {}
216 virtual void Clip( const wxRegion & ) {}
217 virtual void Clip( wxDouble , wxDouble , wxDouble , wxDouble ) {}
218 virtual void ResetClip() {}
219 virtual void * GetNativeContext() { return NULL; }
220 virtual int GetLogicalFunction() const { return 0; }
221 virtual bool SetLogicalFunction(int ) {}
222 virtual void Translate( wxDouble , wxDouble ) {}
223 virtual void Scale( wxDouble , wxDouble ) {}
224 virtual void Rotate( wxDouble ) {}
225 virtual void ConcatTransform( const wxGraphicsMatrix& ) {}
226 virtual void SetTransform( const wxGraphicsMatrix& ) {}
227 virtual wxGraphicsMatrix GetTransform() const { return wxNullGraphicsMatrix; }
229 virtual void SetPen( const wxGraphicsPen& ) {}
230 void SetPen( const wxPen& ) {}
232 virtual void SetBrush( const wxGraphicsBrush& ) {}
233 void SetBrush( const wxBrush& ) {}
235 virtual void SetFont( const wxGraphicsFont& ) {}
236 void SetFont( const wxFont&, const wxColour& ) {}
238 virtual void StrokePath( const wxGraphicsPath & ) {}
239 virtual void FillPath( const wxGraphicsPath &, int ) {}
240 virtual void DrawPath( const wxGraphicsPath &, int ) {}
242 virtual void DrawText( const wxString &, wxDouble , wxDouble ) {}
243 virtual void DrawText( const wxString &, wxDouble , wxDouble , wxDouble ) {}
244 virtual void DrawText( const wxString &, wxDouble , wxDouble , wxGraphicsBrush ) {}
245 virtual void DrawText( const wxString &, wxDouble , wxDouble , wxDouble , wxGraphicsBrush ) {}
246 virtual void GetTextExtent( const wxString &, wxDouble *, wxDouble *,
247 wxDouble *, wxDouble * ) const {}
248 virtual void GetPartialTextExtents(const wxString& , wxArrayDouble& ) const {}
250 virtual void DrawBitmap( const wxBitmap &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
251 virtual void DrawIcon( const wxIcon &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
253 virtual void StrokeLine( wxDouble , wxDouble , wxDouble , wxDouble ) {}
254 virtual void StrokeLines( size_t , const wxPoint2DDouble *) {}
255 virtual void StrokeLines( size_t , const wxPoint2DDouble *, const wxPoint2DDouble *) {}
256 virtual void DrawLines( size_t , const wxPoint2DDouble *, int ) {}
257 virtual void DrawRectangle( wxDouble , wxDouble , wxDouble , wxDouble ) {}
258 virtual void DrawEllipse( wxDouble , wxDouble , wxDouble , wxDouble ) {}
259 virtual void DrawRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
260 virtual bool ShouldOffset() const { return false; }
264 class wxGraphicsRenderer : public wxObject
267 wxGraphicsRenderer() {
268 PyErr_SetString(PyExc_NotImplementedError,
269 "wx.GraphicsRenderer is not available on this platform.");
272 virtual ~wxGraphicsRenderer() {}
274 static wxGraphicsRenderer* GetDefaultRenderer() {
275 PyErr_SetString(PyExc_NotImplementedError,
276 "wx.GraphicsRenderer is not available on this platform.");
280 virtual wxGraphicsContext * CreateContext( const wxWindowDC& ) { return NULL; }
281 virtual wxGraphicsContext * CreateContextFromNativeContext( void * ) { return NULL; }
282 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * ) { return NULL; }
283 virtual wxGraphicsContext * CreateContext( wxWindow* ) { return NULL; }
284 virtual wxGraphicsContext * CreateMeasuringContext() { return NULL; }
286 virtual wxGraphicsPath CreatePath() { return wxNullGraphicsPath; }
288 virtual wxGraphicsMatrix CreateMatrix( wxDouble , wxDouble , wxDouble , wxDouble ,
289 wxDouble , wxDouble ) { return wxNullGraphicsMatrix; }
291 virtual wxGraphicsPen CreatePen(const wxPen& ) { return wxNullGraphicsPen; }
292 virtual wxGraphicsBrush CreateBrush(const wxBrush& ) { return wxNullGraphicsBrush; }
293 virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble , wxDouble , wxDouble , wxDouble ,
294 const wxColour&, const wxColour&) { return wxNullGraphicsBrush; }
295 virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ,
296 const wxColour &, const wxColour &) { return wxNullGraphicsBrush; }
297 virtual wxGraphicsFont CreateFont( const wxFont & , const wxColour & ) { return wxNullGraphicsFont; }
302 class wxGCDC: public wxWindowDC
305 wxGCDC(const wxWindowDC&) {
306 wxPyBlock_t blocked = wxPyBeginBlockThreads();
307 PyErr_SetString(PyExc_NotImplementedError,
308 "wxGCDC is not available on this platform.");
309 wxPyEndBlockThreads(blocked);
312 wxGCDC(const wxWindow*) {
313 wxPyBlock_t blocked = wxPyBeginBlockThreads();
314 PyErr_SetString(PyExc_NotImplementedError,
315 "wxGCDC is not available on this platform.");
316 wxPyEndBlockThreads(blocked);
320 wxPyBlock_t blocked = wxPyBeginBlockThreads();
321 PyErr_SetString(PyExc_NotImplementedError,
322 "wxGCDC is not available on this platform.");
323 wxPyEndBlockThreads(blocked);
328 wxGraphicsContext* GetGraphicsContext() { return NULL; }
329 void SetGraphicsContext( wxGraphicsContext* ) {}
335 //---------------------------------------------------------------------------
336 //---------------------------------------------------------------------------
339 %typemap(in) (size_t points, wxPoint2D* points_array ) {
340 $2 = wxPoint2D_LIST_helper($input, &$1);
341 if ($2 == NULL) SWIG_fail;
343 %typemap(freearg) (size_t points, wxPoint2D* points_array ) {
344 if ($2) delete [] $2;
349 MustHaveApp(wxGraphicsPath);
350 MustHaveApp(wxGraphicsContext);
353 typedef double wxDouble;
356 //---------------------------------------------------------------------------
359 DocStr(wxGraphicsObject,
360 "This class is the superclass of native graphics objects like pens
361 etc. It provides the internal reference counting. It is not to be
362 instantiated by user code.", "");
363 class wxGraphicsObject : public wxObject
366 wxGraphicsObject( wxGraphicsRenderer* renderer = NULL );
367 virtual ~wxGraphicsObject();
370 bool , IsNull() const ,
371 "Is this object valid (false) or still empty (true)?", "");
374 wxGraphicsRenderer* , GetRenderer() const,
375 "Returns the renderer that was used to create this instance, or
376 ``None`` if it has not been initialized yet.", "");
381 DocStr(wxGraphicsPen,
382 "A wx.GraphicsPen is a native representation of a pen. It is used for
383 stroking a path on a `wx.GraphicsContext`. The contents are specific and
384 private to the respective renderer. The only way to get a valid instance
385 is via a CreatePen call on the graphics context or the renderer
387 class wxGraphicsPen : public wxGraphicsObject
391 virtual ~wxGraphicsPen();
394 DocStr(wxGraphicsBrush,
395 "A wx.GraphicsBrush is a native representation of a brush. It is used
396 for filling a path on a `wx.GraphicsContext`. The contents are
397 specific and private to the respective renderer. The only way to get a
398 valid instance is via a Create...Brush call on the graphics context or
399 the renderer instance.", "");
400 class wxGraphicsBrush : public wxGraphicsObject
404 virtual ~wxGraphicsBrush();
408 DocStr(wxGraphicsFont,
409 "A `wx.GraphicsFont` is a native representation of a font (including
410 text colour). The contents are specific an private to the respective
411 renderer. The only way to get a valid instance is via a CreateFont
412 call on the graphics context or the renderer instance.", "");
413 class wxGraphicsFont : public wxGraphicsObject
417 virtual ~wxGraphicsFont();
421 //---------------------------------------------------------------------------
423 DocStr(wxGraphicsMatrix,
424 "A wx.GraphicsMatrix is a native representation of an affine
425 matrix. The contents are specific and private to the respective
426 renderer. The only way to get a valid instance is via a CreateMatrix
427 call on the graphics context or the renderer instance.", "");
428 class wxGraphicsMatrix : public wxGraphicsObject
431 // wxGraphicsMatrix();
432 virtual ~wxGraphicsMatrix();
435 virtual void , Concat( const wxGraphicsMatrix& t ),
436 "Concatenates the passed in matrix to the current matrix.", "");
440 virtual void , Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
441 wxDouble tx=0.0, wxDouble ty=0.0),
442 "Sets the matrix to the specified values (default values are the
443 identity matrix.)", "");
447 virtual void , Get(wxDouble* OUTPUT, wxDouble* OUTPUT, wxDouble* OUTPUT,
448 wxDouble* OUTPUT, wxDouble* OUTPUT, wxDouble* OUTPUT),
449 "Get(self) --> (a, b, c, d, tx, ty)",
450 "Gets the component values of the matrix and returns them as a tuple.", "");
454 virtual void , Invert(),
455 "Inverts the matrix.", "");
459 virtual bool , IsEqual( const wxGraphicsMatrix& t) const,
460 "Returns ``True`` if the elements of the transformation matrix are
465 virtual bool , IsIdentity() const,
466 "Returns ``True`` if this is the identity matrix", "");
470 virtual void , Translate( wxDouble dx , wxDouble dy ),
471 "Add a translation to this matrix.", "");
475 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
476 "Scales this matrix.", "");
480 virtual void , Rotate( wxDouble angle ),
481 "Rotates this matrix. The angle should be specified in radians.", "");
485 virtual void , TransformPoint( wxDouble *INOUT, wxDouble *INOUT ) const,
486 "TransformPoint(self, x, y) --> (x, y)",
487 "Applies this matrix to a point, returns the resulting point values", "");
491 virtual void , TransformDistance( wxDouble *INOUT, wxDouble *INOUT ) const,
492 "TransformDistance(self, dx, dy) --> (dx, dy)",
493 "Applies this matrix to a distance (ie. performs all transforms except
498 virtual void * , GetNativeMatrix() const,
499 "Returns the native representation of the matrix. For CoreGraphics this
500 is a CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for
501 Cairo a cairo_matrix_t pointer. NOTE: For wxPython we still need a
502 way to make this value usable.", "");
505 //---------------------------------------------------------------------------
507 class wxGraphicsPath : public wxGraphicsObject
511 virtual ~wxGraphicsPath();
514 %nokwargs MoveToPoint;
516 "Begins a new subpath at the specified point.", "");
517 virtual void MoveToPoint( wxDouble x, wxDouble y );
518 void MoveToPoint( const wxPoint2D& p);
521 %nokwargs AddLineToPoint;
522 DocStr(AddLineToPoint,
523 "Adds a straight line from the current point to the specified point.", "");
524 virtual void AddLineToPoint( wxDouble x, wxDouble y );
525 void AddLineToPoint( const wxPoint2D& p);
528 %nokwargs AddCurveToPoint;
529 DocStr(AddCurveToPoint,
530 "Adds a cubic Bezier curve from the current point, using two control
531 points and an end point", "");
532 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1,
533 wxDouble cx2, wxDouble cy2,
534 wxDouble x, wxDouble y );
535 void AddCurveToPoint( const wxPoint2D& c1, const wxPoint2D& c2, const wxPoint2D& e);
540 virtual void , AddPath( const wxGraphicsPath& path ),
541 "Adds another path", "");
545 virtual void , CloseSubpath(),
546 "Closes the current sub-path.", "");
550 wxPoint2D , GetCurrentPoint() const,
551 "Gets the last point of the current path, (0,0) if not yet set", "");
556 "Adds an arc of a circle centering at (x,y) with radius (r) from
557 startAngle to endAngle", "");
558 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r,
559 wxDouble startAngle, wxDouble endAngle, bool clockwise=true );
560 void AddArc( const wxPoint2D& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise=true);
564 virtual void , AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ),
565 "Adds a quadratic Bezier curve from the current point, using a control
566 point and an end point", "");
570 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
571 "Appends a rectangle as a new closed subpath.", "");
575 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
576 "Appends a circle around (x,y) with radius r as a new closed subpath.", "");
580 virtual void , AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ,
581 "Appends an arc to two tangents connecting (current) to (x1,y1) and
582 (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)", "");
586 virtual void , AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
587 "Appends an ellipse fitting into the passed in rectangle.", "");
591 virtual void , AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
592 "Appends a rounded rectangle.", "");
596 virtual void * , GetNativePath() const,
597 "Returns the native path (CGPathRef for Core Graphics, Path pointer for
598 GDIPlus and a cairo_path_t pointer for cairo). NOTE: For wxPython we
599 still need a way to make this value usable.", "");
603 virtual void , UnGetNativePath(void *p) const,
604 "Gives back the native path returned by GetNativePath() because there
605 might be some deallocations necessary (eg on cairo the native path
606 returned by GetNativePath is newly allocated each time).", "");
610 virtual void , Transform( const wxGraphicsMatrix& matrix ),
611 "Transforms each point of this path by the matrix", "");
615 wxRect2D , GetBox() const,
616 "Gets the bounding box enclosing all points (possibly including control
622 "Returns ``True`` if the point is within the path.", "");
623 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE) const;
624 bool Contains( const wxPoint2D& c, int fillStyle = wxODDEVEN_RULE) const;
629 //---------------------------------------------------------------------------
632 const wxGraphicsPen wxNullGraphicsPen;
633 const wxGraphicsBrush wxNullGraphicsBrush;
634 const wxGraphicsFont wxNullGraphicsFont;
635 const wxGraphicsMatrix wxNullGraphicsMatrix;
636 const wxGraphicsPath wxNullGraphicsPath;
639 //---------------------------------------------------------------------------
641 DocStr(wxGraphicsContext,
642 "A `wx.GraphicsContext` instance is the object that is drawn upon. It is
643 created by a renderer using the CreateContext calls, this can be done
644 either directly using a renderer instance, or indirectly using the
645 static convenience CreateXXX functions of wx.GraphicsContext that
646 always delegate the task to the default renderer.", "");
648 class wxGraphicsContext : public wxGraphicsObject
651 //wxGraphicsContext(); This is an ABC, use Create to make an instance...
652 virtual ~wxGraphicsContext();
657 "val.__dc = args[0] # save a ref so the dc will not be deleted before self";
659 "Creates a wx.GraphicsContext either from a window or a DC.", "");
660 static wxGraphicsContext* Create( const wxWindowDC& dc);
661 static wxGraphicsContext* Create( wxWindow* window ) ;
664 static wxGraphicsContext* , Create(),
665 "Create a lightwieght context that can be used for measuring text only.", "",
666 CreateMeasuringContext);
668 %newobject CreateFromNative;
670 static wxGraphicsContext* , CreateFromNative( void * context ) ,
671 "Creates a wx.GraphicsContext from a native context. This native
672 context must be eg a CGContextRef for Core Graphics, a Graphics
673 pointer for GDIPlus or a cairo_t pointer for Cairo.", "");
676 %newobject CreateFromNative;
678 static wxGraphicsContext* , CreateFromNativeWindow( void * window ) ,
679 "Creates a wx.GraphicsContext from a native window.", "");
684 virtual wxGraphicsPath , CreatePath(),
685 "Creates a native graphics path which is initially empty.", "");
689 virtual wxGraphicsPen , CreatePen(const wxPen& pen),
690 "Creates a native pen from a `wx.Pen`.", "");
694 virtual wxGraphicsBrush , CreateBrush(const wxBrush& brush ),
695 "Creates a native brush from a `wx.Brush`.", "");
699 virtual wxGraphicsBrush ,
700 CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
701 const wxColour& c1, const wxColour& c2),
702 "Creates a native brush, having a linear gradient, starting at (x1,y1)
703 with color c1 to (x2,y2) with color c2.", "");
707 virtual wxGraphicsBrush ,
708 CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
709 const wxColour &oColor, const wxColour &cColor),
710 "Creates a native brush, having a radial gradient originating at point
711 (xo,yc) with color oColour and ends on a circle around (xc,yc) with
712 radius r and color cColour.", "");
716 virtual wxGraphicsFont , CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ),
717 "Creates a native graphics font from a `wx.Font` and a text colour.", "");
721 virtual wxGraphicsMatrix , CreateMatrix( wxDouble a=1.0, wxDouble b=0.0,
722 wxDouble c=0.0, wxDouble d=1.0,
723 wxDouble tx=0.0, wxDouble ty=0.0),
724 "Creates a native affine transformation matrix from the passed in
725 values. The defaults result in an identity matrix.", "");
730 virtual void , PushState(),
731 "Push the current state of the context, (ie the transformation matrix)
736 virtual void , PopState(),
737 "Pops a stored state from the stack", "");
741 virtual void , Clip( const wxRegion ®ion ),
742 "Clips drawings to the region, combined to current clipping region.", "",
747 virtual void , Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
748 "Clips drawings to the rectangle.", "");
752 virtual void , ResetClip(),
753 "Resets the clipping to original shape.", "");
757 virtual void * , GetNativeContext(),
758 "Returns the native context (CGContextRef for Core Graphics, Graphics
759 pointer for GDIPlus and cairo_t pointer for cairo).", "");
763 virtual int , GetLogicalFunction() const,
764 "Returns the current logical function.", "");
768 virtual bool , SetLogicalFunction(int function) ,
769 "Sets the current logical function, returns ``True`` if it supported", "");
773 virtual void , Translate( wxDouble dx , wxDouble dy ),
774 "Translates the current transformation matrix.", "");
778 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
779 "Scale the current transformation matrix of the context.", "");
783 virtual void , Rotate( wxDouble angle ),
784 "Rotate the current transformation matrix of the context. ``angle`` is
785 specified in radians.", "");
789 virtual void , ConcatTransform( const wxGraphicsMatrix& matrix ),
790 "Concatenates the passed in transform with the current transform of
795 virtual void , SetTransform( const wxGraphicsMatrix& matrix ),
796 "Sets the current transform of this context.", "");
800 virtual wxGraphicsMatrix , GetTransform() const,
801 "Gets the current transformation matrix of this context.", "");
806 DocStr(SetPen, "Sets the stroke pen", "");
808 virtual void SetPen( const wxGraphicsPen& pen );
809 void SetPen( const wxPen& pen );
812 DocStr(SetBrush, "Sets the brush for filling", "");
814 virtual void SetBrush( const wxGraphicsBrush& brush );
815 void SetBrush( const wxBrush& brush );
818 DocStr(SetFont, "Sets the font", "");
820 virtual void SetFont( const wxGraphicsFont& font );
821 void SetFont( const wxFont& font, const wxColour& colour = *wxBLACK);
826 virtual void , StrokePath( const wxGraphicsPath& path ),
827 "Strokes along a path with the current pen.", "");
831 virtual void , FillPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ),
832 "Fills a path with the current brush.", "");
836 virtual void , DrawPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ),
837 "Draws the path by first filling and then stroking.", "");
842 "Draws a text string at the defined position.", "");
843 void DrawText( const wxString &str, wxDouble x, wxDouble y,
844 const wxGraphicsBrush& backgroundBrush = wxNullGraphicsBrush )
846 if ( !backgroundBrush.IsNull() )
847 self->DrawText(str, x, y, backgroundBrush);
849 self->DrawText(str, x, y);
852 DocStr(DrawRotatedText,
853 "Draws a text string at the defined position, at the specified angle,
854 which is given in radians.", "");
855 void DrawRotatedText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle,
856 const wxGraphicsBrush& backgroundBrush = wxNullGraphicsBrush )
858 if ( !backgroundBrush.IsNull() )
859 self->DrawText(str, x, y, angle, backgroundBrush);
861 self->DrawText(str, x, y, angle);
868 virtual void , GetTextExtent( const wxString &text,
869 wxDouble *OUTPUT /*width*/,
870 wxDouble *OUTPUT /*height*/,
871 wxDouble *OUTPUT /*descent*/,
872 wxDouble *OUTPUT /*externalLeading*/ ) const ,
873 "GetFullTextExtent(self, text) --> (width, height, descent, externalLeading)",
874 "Gets the dimensions of the string using the currently selected
875 font. ``text`` is the string to measure, ``w`` and ``h`` are the total
876 width and height respectively, ``descent`` is the dimension from the
877 baseline of the font to the bottom of the descender, and
878 ``externalLeading`` is any extra vertical space added to the font by
879 the font designer (usually is zero).", "",
883 DocAStr(GetTextExtent,
884 "GetTextExtent(self, text) --> (width, height)",
885 "Gets the dimensions of the string using the currently selected
886 font. ``text`` is the string to measure, ``w`` and ``h`` are the total
887 width and height respectively.", "");
889 PyObject* GetTextExtent( const wxString &text )
891 wxDouble width = 0.0,
893 self->GetTextExtent(text, &width, &height, NULL, NULL);
894 // thread wrapers are turned off for this .i file, so no need to acquire GIL...
895 PyObject* rv = PyTuple_New(2);
896 PyTuple_SET_ITEM(rv, 0, PyFloat_FromDouble(width));
897 PyTuple_SET_ITEM(rv, 1, PyFloat_FromDouble(height));
904 DocAStr(GetPartialTextExtents,
905 "GetPartialTextExtents(self, text) -> [widths]",
906 "Returns a list of widths from the beginning of ``text`` to the
907 coresponding character in ``text``.", "");
908 wxArrayDouble GetPartialTextExtents(const wxString& text) {
909 wxArrayDouble widths;
910 self->GetPartialTextExtents(text, widths);
917 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
918 "Draws the bitmap. In case of a mono bitmap, this is treated as a mask
919 and the current brush is used for filling.", "");
923 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
924 "Draws the icon.", "");
929 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
930 "Strokes a single line.", "");
934 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
935 "StrokeLines(self, List points)",
936 "Stroke lines connecting each of the points", "");
940 DocStr(StrokeLineSegements,
941 "Stroke disconnected lines from begin to end points", "");
942 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
944 size_t c1, c2, count;
945 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
946 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
948 if ( beginP != NULL && endP != NULL )
950 count = wxMin(c1, c2);
951 self->StrokeLines(count, beginP, endP);
960 virtual void , DrawLines( size_t points, const wxPoint2D *points_array,
961 int fillStyle = wxODDEVEN_RULE ),
962 "Draws a polygon.", "");
966 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
967 "Draws a rectangle.", "");
971 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
972 "Draws an ellipse.", "");
976 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
977 "Draws a rounded rectangle", "");
982 virtual bool , ShouldOffset() const,
983 "helper to determine if a 0.5 offset should be applied for the drawing operation", "");
988 //---------------------------------------------------------------------------
990 class wxGraphicsRenderer : public wxObject
993 // wxGraphicsRenderer(); This is an ABC, use GetDefaultRenderer
995 virtual ~wxGraphicsRenderer();
997 // %newobject GetDefaultRenderer; ???
998 static wxGraphicsRenderer* GetDefaultRenderer();
1000 %nokwargs CreateContext;
1001 %newobject CreateContext;
1002 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) ;
1003 virtual wxGraphicsContext * CreateContext( wxWindow* window );
1005 // create a context that can be used for measuring texts only, no drawing allowed
1006 virtual wxGraphicsContext * CreateMeasuringContext();
1008 %newobject CreateContextFromNativeContext;
1009 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context );
1011 %newobject CreateContextFromNativeWindow;
1012 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window );
1015 virtual wxGraphicsPath CreatePath();
1017 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
1018 wxDouble tx=0.0, wxDouble ty=0.0);
1020 virtual wxGraphicsPen CreatePen(const wxPen& pen) ;
1022 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) ;
1024 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
1025 const wxColour&c1, const wxColour&c2);
1027 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
1028 const wxColour &oColor, const wxColour &cColor);
1030 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK );
1036 //---------------------------------------------------------------------------
1039 #include "wx/dcgraph.h"
1042 class wxGCDC: public wxDC
1046 %pythonAppend wxGCDC
1047 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
1048 wxGCDC(const wxWindowDC& dc);
1049 wxGCDC(wxWindow* window);
1053 wxGraphicsContext* GetGraphicsContext();
1054 virtual void SetGraphicsContext( wxGraphicsContext* ctx );
1056 %property(GraphicsContext, GetGraphicsContext, SetGraphicsContext);
1060 //---------------------------------------------------------------------------
1062 // Turn GIL acquisition back on.