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 DrawRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
259 virtual void DrawEllipse( wxDouble , wxDouble , wxDouble , wxDouble ) {}
260 virtual void DrawRoundedRectangle( wxDouble wxDouble , wxDouble , wxDouble , wxDouble ) {}
261 virtual bool ShouldOffset() const { return false; }
265 class wxGraphicsRenderer : public wxObject
268 wxGraphicsRenderer() {
269 PyErr_SetString(PyExc_NotImplementedError,
270 "wx.GraphicsRenderer is not available on this platform.");
273 virtual ~wxGraphicsRenderer() {}
275 static wxGraphicsRenderer* GetDefaultRenderer() {
276 PyErr_SetString(PyExc_NotImplementedError,
277 "wx.GraphicsRenderer is not available on this platform.");
281 virtual wxGraphicsContext * CreateContext( const wxWindowDC& ) { return NULL; }
282 virtual wxGraphicsContext * CreateContextFromNativeContext( void * ) { return NULL; }
283 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * ) { return NULL; }
284 virtual wxGraphicsContext * CreateContext( wxWindow* ) { return NULL; }
285 virtual wxGraphicsContext * CreateMeasuringContext() { return NULL; }
287 virtual wxGraphicsPath CreatePath() { return wxNullGraphicsPath; }
289 virtual wxGraphicsMatrix CreateMatrix( wxDouble , wxDouble , wxDouble , wxDouble ,
290 wxDouble , wxDouble ) { return wxNullGraphicsMatrix; }
292 virtual wxGraphicsPen CreatePen(const wxPen& ) { return wxNullGraphicsPen; }
293 virtual wxGraphicsBrush CreateBrush(const wxBrush& ) { return wxNullGraphicsBrush; }
294 virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble , wxDouble , wxDouble , wxDouble ,
295 const wxColour&, const wxColour&) { return wxNullGraphicsBrush; }
296 virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ,
297 const wxColour &, const wxColour &) { return wxNullGraphicsBrush; }
298 virtual wxGraphicsFont CreateFont( const wxFont & , const wxColour & ) { return wxNullGraphicsFont; }
303 class wxGCDC: public wxWindowDC
306 wxGCDC(const wxWindowDC&) {
307 wxPyBlock_t blocked = wxPyBeginBlockThreads();
308 PyErr_SetString(PyExc_NotImplementedError,
309 "wxGCDC is not available on this platform.");
310 wxPyEndBlockThreads(blocked);
313 wxGCDC(const wxWindow*) {
314 wxPyBlock_t blocked = wxPyBeginBlockThreads();
315 PyErr_SetString(PyExc_NotImplementedError,
316 "wxGCDC is not available on this platform.");
317 wxPyEndBlockThreads(blocked);
321 wxPyBlock_t blocked = wxPyBeginBlockThreads();
322 PyErr_SetString(PyExc_NotImplementedError,
323 "wxGCDC is not available on this platform.");
324 wxPyEndBlockThreads(blocked);
329 wxGraphicsContext* GetGraphicsContext() { return NULL; }
330 void SetGraphicsContext( wxGraphicsContext* ) {}
336 //---------------------------------------------------------------------------
337 //---------------------------------------------------------------------------
340 %typemap(in) (size_t points, wxPoint2D* points_array ) {
341 $2 = wxPoint2D_LIST_helper($input, &$1);
342 if ($2 == NULL) SWIG_fail;
344 %typemap(freearg) (size_t points, wxPoint2D* points_array ) {
345 if ($2) delete [] $2;
350 MustHaveApp(wxGraphicsPath);
351 MustHaveApp(wxGraphicsContext);
354 typedef double wxDouble;
357 //---------------------------------------------------------------------------
360 DocStr(wxGraphicsObject,
361 "This class is the superclass of native graphics objects like pens
362 etc. It provides the internal reference counting. It is not to be
363 instantiated by user code.", "");
364 class wxGraphicsObject : public wxObject
367 wxGraphicsObject( wxGraphicsRenderer* renderer = NULL );
368 virtual ~wxGraphicsObject();
371 bool , IsNull() const ,
372 "Is this object valid (false) or still empty (true)?", "");
375 wxGraphicsRenderer* , GetRenderer() const,
376 "Returns the renderer that was used to create this instance, or
377 ``None`` if it has not been initialized yet.", "");
382 DocStr(wxGraphicsPen,
383 "A wx.GraphicsPen is a native representation of a pen. It is used for
384 stroking a path on a `wx.GraphicsContext`. The contents are specific and
385 private to the respective renderer. The only way to get a valid instance
386 is via a CreatePen call on the graphics context or the renderer
388 class wxGraphicsPen : public wxGraphicsObject
392 virtual ~wxGraphicsPen();
395 DocStr(wxGraphicsBrush,
396 "A wx.GraphicsBrush is a native representation of a brush. It is used
397 for filling a path on a `wx.GraphicsContext`. The contents are
398 specific and private to the respective renderer. The only way to get a
399 valid instance is via a Create...Brush call on the graphics context or
400 the renderer instance.", "");
401 class wxGraphicsBrush : public wxGraphicsObject
405 virtual ~wxGraphicsBrush();
409 DocStr(wxGraphicsFont,
410 "A `wx.GraphicsFont` is a native representation of a font (including
411 text colour). The contents are specific an private to the respective
412 renderer. The only way to get a valid instance is via a CreateFont
413 call on the graphics context or the renderer instance.", "");
414 class wxGraphicsFont : public wxGraphicsObject
418 virtual ~wxGraphicsFont();
422 //---------------------------------------------------------------------------
424 DocStr(wxGraphicsMatrix,
425 "A wx.GraphicsMatrix is a native representation of an affine
426 matrix. The contents are specific an private to the respective
427 renderer. The only way to get a valid instance is via a CreateMatrix
428 call on the graphics context or the renderer instance.", "");
429 class wxGraphicsMatrix : public wxGraphicsObject
433 virtual ~wxGraphicsMatrix();
436 virtual void , Concat( const wxGraphicsMatrix& t ),
437 "Concatenates the passed in matrix to the current matrix.", "");
441 // "Copy the passed in matrix to this one.", "");
442 // void Copy( const wxGraphicsMatrix& t ) {
449 virtual void , Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
450 wxDouble tx=0.0, wxDouble ty=0.0),
451 "Sets the matrix to the specified values (default values are the
452 identity matrix.)", "");
456 virtual void , Get(wxDouble* OUTPUT, wxDouble* OUTPUT, wxDouble* OUTPUT,
457 wxDouble* OUTPUT, wxDouble* OUTPUT, wxDouble* OUTPUT),
458 "Get(self) --> (a, b, c, d, tx, ty)",
459 "Gets the component values of the matrix and returns them as a tuple.", "");
463 virtual void , Invert(),
464 "Inverts the matrix.", "");
468 virtual bool , IsEqual( const wxGraphicsMatrix& t) const,
469 "Returns ``True`` if the elements of the transformation matrix are
474 virtual bool , IsIdentity() const,
475 "Returns ``True`` if this is the identity matrix", "");
479 virtual void , Translate( wxDouble dx , wxDouble dy ),
480 "Add a translation to this matrix.", "");
484 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
485 "Scales this matrix.", "");
489 virtual void , Rotate( wxDouble angle ),
490 "Rotates this matrix. The angle should be specified in radians.", "");
494 virtual void , TransformPoint( wxDouble *INOUT, wxDouble *INOUT ) const,
495 "TransformPoint(self, x, y) --> (x, y)",
496 "Applies this matrix to a point, returns the resulting point values", "");
500 virtual void , TransformDistance( wxDouble *INOUT, wxDouble *INOUT ) const,
501 "TransformDistance(self, dx, dy) --> (dx, dy)",
502 "Applies this matrix to a distance (ie. performs all transforms except
507 virtual void * , GetNativeMatrix() const,
508 "Returns the native representation of the matrix. For CoreGraphics this
509 is a CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for
510 Cairo a cairo_matrix_t pointer. NOTE: For wxPython we still need a
511 way to make this value usable.", "");
514 //---------------------------------------------------------------------------
516 class wxGraphicsPath : public wxGraphicsObject
520 virtual ~wxGraphicsPath();
523 %nokwargs MoveToPoint;
525 "Begins a new subpath at the specified point.", "");
526 virtual void MoveToPoint( wxDouble x, wxDouble y );
527 void MoveToPoint( const wxPoint2D& p);
530 %nokwargs AddLineToPoint;
531 DocStr(AddLineToPoint,
532 "Adds a straight line from the current point to the specified point.", "");
533 virtual void AddLineToPoint( wxDouble x, wxDouble y );
534 void AddLineToPoint( const wxPoint2D& p);
537 %nokwargs AddCurveToPoint;
538 DocStr(AddCurveToPoint,
539 "Adds a cubic Bezier curve from the current point, using two control
540 points and an end point", "");
541 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1,
542 wxDouble cx2, wxDouble cy2,
543 wxDouble x, wxDouble y );
544 void AddCurveToPoint( const wxPoint2D& c1, const wxPoint2D& c2, const wxPoint2D& e);
549 virtual void , AddPath( const wxGraphicsPath& path ),
550 "Adds another path", "");
554 virtual void , CloseSubpath(),
555 "Closes the current sub-path.", "");
559 wxPoint2D , GetCurrentPoint() const,
560 "Gets the last point of the current path, (0,0) if not yet set", "");
565 "Adds an arc of a circle centering at (x,y) with radius (r) from
566 startAngle to endAngle", "");
567 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r,
568 wxDouble startAngle, wxDouble endAngle, bool clockwise=true );
569 void AddArc( const wxPoint2D& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise=true);
573 virtual void , AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ),
574 "Adds a quadratic Bezier curve from the current point, using a control
575 point and an end point", "");
579 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
580 "Appends a rectangle as a new closed subpath.", "");
584 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
585 "Appends a circle around (x,y) with radius r as a new closed subpath.", "");
589 virtual void , AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ,
590 "Appends an arc to two tangents connecting (current) to (x1,y1) and
591 (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)", "");
595 virtual void , AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
596 "Appends an ellipse fitting into the passed in rectangle.", "");
600 virtual void , AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
601 "Appends a rounded rectangle.", "");
605 virtual void * , GetNativePath() const,
606 "Returns the native path (CGPathRef for Core Graphics, Path pointer for
607 GDIPlus and a cairo_path_t pointer for cairo). NOTE: For wxPython we
608 still need a way to make this value usable.", "");
612 virtual void , UnGetNativePath(void *p) const,
613 "Gives back the native path returned by GetNativePath() because there
614 might be some deallocations necessary (eg on cairo the native path
615 returned by GetNativePath is newly allocated each time).", "");
619 virtual void , Transform( const wxGraphicsMatrix& matrix ),
620 "Transforms each point of this path by the matrix", "");
624 wxRect2D , GetBox() const,
625 "Gets the bounding box enclosing all points (possibly including control
631 "Returns ``True`` if the point is within the path.", "");
632 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE) const;
633 bool Contains( const wxPoint2D& c, int fillStyle = wxODDEVEN_RULE) const;
638 //---------------------------------------------------------------------------
641 const wxGraphicsPen wxNullGraphicsPen;
642 const wxGraphicsBrush wxNullGraphicsBrush;
643 const wxGraphicsFont wxNullGraphicsFont;
644 const wxGraphicsMatrix wxNullGraphicsMatrix;
645 const wxGraphicsPath wxNullGraphicsPath;
648 //---------------------------------------------------------------------------
650 DocStr(wxGraphicsContext,
651 "A `wx.GraphicsContext` instance is the object that is drawn upon. It is
652 created by a renderer using the CreateContext calls, this can be done
653 either directly using a renderer instance, or indirectly using the
654 static convenience CreateXXX functions of wx.GraphicsContext that
655 always delegate the task to the default renderer.", "");
657 class wxGraphicsContext : public wxGraphicsObject
660 //wxGraphicsContext(); This is an ABC, use Create to make an instance...
661 virtual ~wxGraphicsContext();
666 "val.__dc = args[0] # save a ref so the dc will not be deleted before self";
668 "Creates a wx.GraphicsContext either from a window or a DC.", "");
669 static wxGraphicsContext* Create( const wxWindowDC& dc);
670 static wxGraphicsContext* Create( wxWindow* window ) ;
673 static wxGraphicsContext* , Create(),
674 "Create a lightwieght context that can be used for measuring text only.", "",
675 CreateMeasuringContext);
677 %newobject CreateFromNative;
679 static wxGraphicsContext* , CreateFromNative( void * context ) ,
680 "Creates a wx.GraphicsContext from a native context. This native
681 context must be eg a CGContextRef for Core Graphics, a Graphics
682 pointer for GDIPlus or a cairo_t pointer for Cairo.", "");
685 %newobject CreateFromNative;
687 static wxGraphicsContext* , CreateFromNativeWindow( void * window ) ,
688 "Creates a wx.GraphicsContext from a native window.", "");
693 virtual wxGraphicsPath , CreatePath(),
694 "Creates a native graphics path which is initially empty.", "");
698 virtual wxGraphicsPen , CreatePen(const wxPen& pen),
699 "Creates a native pen from a `wx.Pen`.", "");
703 virtual wxGraphicsBrush , CreateBrush(const wxBrush& brush ),
704 "Creates a native brush from a `wx.Brush`.", "");
708 virtual wxGraphicsBrush ,
709 CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
710 const wxColour& c1, const wxColour& c2),
711 "Creates a native brush, having a linear gradient, starting at (x1,y1)
712 with color c1 to (x2,y2) with color c2.", "");
716 virtual wxGraphicsBrush ,
717 CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
718 const wxColour &oColor, const wxColour &cColor),
719 "Creates a native brush, having a radial gradient originating at point
720 (xo,yc) with color oColour and ends on a circle around (xc,yc) with
721 radius r and color cColour.", "");
725 virtual wxGraphicsFont , CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ),
726 "Creates a native graphics font from a `wx.Font` and a text colour.", "");
730 virtual wxGraphicsMatrix , CreateMatrix( wxDouble a=1.0, wxDouble b=0.0,
731 wxDouble c=0.0, wxDouble d=1.0,
732 wxDouble tx=0.0, wxDouble ty=0.0),
733 "Creates a native affine transformation matrix from the passed in
734 values. The defaults result in an identity matrix.", "");
739 virtual void , PushState(),
740 "Push the current state of the context, (ie the transformation matrix)
745 virtual void , PopState(),
746 "Pops a stored state from the stack", "");
750 virtual void , Clip( const wxRegion ®ion ),
751 "Clips drawings to the region, combined to current clipping region.", "",
756 virtual void , Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
757 "Clips drawings to the rectangle.", "");
761 virtual void , ResetClip(),
762 "Resets the clipping to original shape.", "");
766 virtual void * , GetNativeContext(),
767 "Returns the native context (CGContextRef for Core Graphics, Graphics
768 pointer for GDIPlus and cairo_t pointer for cairo).", "");
772 virtual int , GetLogicalFunction() const,
773 "Returns the current logical function.", "");
777 virtual bool , SetLogicalFunction(int function) ,
778 "Sets the current logical function, returns ``True`` if it supported", "");
782 virtual void , Translate( wxDouble dx , wxDouble dy ),
783 "Translates the current transformation matrix.", "");
787 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
788 "Scale the current transformation matrix of the context.", "");
792 virtual void , Rotate( wxDouble angle ),
793 "Rotate the current transformation matrix of the context. ``angle`` is
794 specified in radians.", "");
798 virtual void , ConcatTransform( const wxGraphicsMatrix& matrix ),
799 "Concatenates the passed in transform with the current transform of
804 virtual void , SetTransform( const wxGraphicsMatrix& matrix ),
805 "Sets the current transform of this context.", "");
809 virtual wxGraphicsMatrix , GetTransform() const,
810 "Gets the current transformation matrix of this context.", "");
815 DocStr(SetPen, "Sets the stroke pen", "");
817 virtual void SetPen( const wxGraphicsPen& pen );
818 void SetPen( const wxPen& pen );
821 DocStr(SetBrush, "Sets the brush for filling", "");
823 virtual void SetBrush( const wxGraphicsBrush& brush );
824 void SetBrush( const wxBrush& brush );
827 DocStr(SetFont, "Sets the font", "");
829 virtual void SetFont( const wxGraphicsFont& font );
830 void SetFont( const wxFont& font, const wxColour& colour = *wxBLACK);
835 virtual void , StrokePath( const wxGraphicsPath& path ),
836 "Strokes along a path with the current pen.", "");
840 virtual void , FillPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ),
841 "Fills a path with the current brush.", "");
845 virtual void , DrawPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ),
846 "Draws the path by first filling and then stroking.", "");
851 "Draws a text string at the defined position.", "");
852 void DrawText( const wxString &str, wxDouble x, wxDouble y,
853 const wxGraphicsBrush& backgroundBrush = wxNullGraphicsBrush )
855 if ( !backgroundBrush.IsNull() )
856 self->DrawText(str, x, y, backgroundBrush);
858 self->DrawText(str, x, y);
861 DocStr(DrawRotatedText,
862 "Draws a text string at the defined position, at the specified angle,
863 which is given in radians.", "");
864 void DrawRotatedText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle,
865 const wxGraphicsBrush& backgroundBrush = wxNullGraphicsBrush )
867 if ( !backgroundBrush.IsNull() )
868 self->DrawText(str, x, y, angle, backgroundBrush);
870 self->DrawText(str, x, y, angle);
877 virtual void , GetTextExtent( const wxString &text,
878 wxDouble *OUTPUT /*width*/,
879 wxDouble *OUTPUT /*height*/,
880 wxDouble *OUTPUT /*descent*/,
881 wxDouble *OUTPUT /*externalLeading*/ ) const ,
882 "GetFullTextExtent(self, text) --> (width, height, descent, externalLeading)",
883 "Gets the dimensions of the string using the currently selected
884 font. ``text`` is the string to measure, ``w`` and ``h`` are the total
885 width and height respectively, ``descent`` is the dimension from the
886 baseline of the font to the bottom of the descender, and
887 ``externalLeading`` is any extra vertical space added to the font by
888 the font designer (usually is zero).", "",
892 DocAStr(GetTextExtent,
893 "GetTextExtent(self, text) --> (width, height)",
894 "Gets the dimensions of the string using the currently selected
895 font. ``text`` is the string to measure, ``w`` and ``h`` are the total
896 width and height respectively.", "");
898 PyObject* GetTextExtent( const wxString &text )
900 wxDouble width = 0.0,
902 self->GetTextExtent(text, &width, &height, NULL, NULL);
903 // thread wrapers are turned off for this .i file, so no need to acquire GIL...
904 PyObject* rv = PyTuple_New(2);
905 PyTuple_SET_ITEM(rv, 0, PyFloat_FromDouble(width));
906 PyTuple_SET_ITEM(rv, 1, PyFloat_FromDouble(height));
913 DocAStr(GetPartialTextExtents,
914 "GetPartialTextExtents(self, text) -> [widths]",
915 "Returns a list of widths from the beginning of ``text`` to the
916 coresponding character in ``text``.", "");
917 wxArrayDouble GetPartialTextExtents(const wxString& text) {
918 wxArrayDouble widths;
919 self->GetPartialTextExtents(text, widths);
926 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
927 "Draws the bitmap. In case of a mono bitmap, this is treated as a mask
928 and the current brush is used for filling.", "");
932 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
933 "Draws the icon.", "");
938 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
939 "Strokes a single line.", "");
943 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
944 "StrokeLines(self, List points)",
945 "Stroke lines connecting each of the points", "");
949 DocStr(StrokeLineSegements,
950 "Stroke disconnected lines from begin to end points", "");
951 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
953 size_t c1, c2, count;
954 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
955 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
957 if ( beginP != NULL && endP != NULL )
959 count = wxMin(c1, c2);
960 self->StrokeLines(count, beginP, endP);
969 virtual void , DrawLines( size_t points, const wxPoint2D *points_array,
970 int fillStyle = wxODDEVEN_RULE ),
971 "Draws a polygon.", "");
975 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
976 "Draws a rectangle.", "");
980 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
981 "Draws an ellipse.", "");
985 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
986 "Draws a rounded rectangle", "");
991 virtual bool , ShouldOffset() const,
992 "helper to determine if a 0.5 offset should be applied for the drawing operation", "");
997 //---------------------------------------------------------------------------
999 class wxGraphicsRenderer : public wxObject
1002 // wxGraphicsRenderer(); This is an ABC, use GetDefaultRenderer
1004 virtual ~wxGraphicsRenderer();
1006 // %newobject GetDefaultRenderer; ???
1007 static wxGraphicsRenderer* GetDefaultRenderer();
1009 %nokwargs CreateContext;
1010 %newobject CreateContext;
1011 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) ;
1012 virtual wxGraphicsContext * CreateContext( wxWindow* window );
1014 // create a context that can be used for measuring texts only, no drawing allowed
1015 virtual wxGraphicsContext * CreateMeasuringContext();
1017 %newobject CreateContextFromNativeContext;
1018 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context );
1020 %newobject CreateContextFromNativeWindow;
1021 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window );
1024 virtual wxGraphicsPath CreatePath();
1026 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
1027 wxDouble tx=0.0, wxDouble ty=0.0);
1029 virtual wxGraphicsPen CreatePen(const wxPen& pen) ;
1031 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) ;
1033 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
1034 const wxColour&c1, const wxColour&c2);
1036 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
1037 const wxColour &oColor, const wxColour &cColor);
1039 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK );
1045 //---------------------------------------------------------------------------
1048 #include "wx/dcgraph.h"
1051 class wxGCDC: public wxDC
1055 %pythonAppend wxGCDC
1056 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
1057 wxGCDC(const wxWindowDC& dc);
1058 wxGCDC(wxWindow* window);
1062 wxGraphicsContext* GetGraphicsContext();
1063 virtual void SetGraphicsContext( wxGraphicsContext* ctx );
1065 %property(GraphicsContext, GetGraphicsContext, SetGraphicsContext);
1069 //---------------------------------------------------------------------------
1071 // Turn GIL acquisition back on.