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
27 //---------------------------------------------------------------------------
31 #if !wxUSE_GRAPHICS_CONTEXT
32 // C++ stub classes for platforms that don't have wxGraphicsContext yet.
38 wxPyBlock_t blocked = wxPyBeginBlockThreads();
39 PyErr_SetString(PyExc_NotImplementedError,
40 "wxGraphicsPath is not available on this platform.");
41 wxPyEndBlockThreads(blocked);
43 virtual ~wxGraphicsPath() {}
45 void MoveToPoint( wxDouble, wxDouble ) {}
46 void AddLineToPoint( wxDouble, wxDouble ) {}
47 void AddCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, wxDouble ) {}
48 void CloseSubpath() {}
49 void GetCurrentPoint( wxDouble&, wxDouble&) {}
50 void AddArc( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, bool ) {}
52 void AddQuadCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble ) {}
53 void AddRectangle( wxDouble, wxDouble, wxDouble, wxDouble ) {}
54 void AddCircle( wxDouble, wxDouble, wxDouble ) {}
55 void AddArcToPoint( wxDouble, wxDouble , wxDouble, wxDouble, wxDouble ) {}
57 wxPoint2DDouble GetCurrentPoint() { return wxPoint2DDouble(0,0); }
58 void MoveToPoint( const wxPoint2DDouble& ) {}
59 void AddLineToPoint( const wxPoint2DDouble&) {}
60 void AddCurveToPoint( const wxPoint2DDouble&, const wxPoint2DDouble&, const wxPoint2DDouble&) {}
61 void AddArc( const wxPoint2DDouble&, wxDouble, wxDouble, wxDouble, bool) {}
65 class wxGraphicsContext
69 wxPyBlock_t blocked = wxPyBeginBlockThreads();
70 PyErr_SetString(PyExc_NotImplementedError,
71 "wxGraphicsContext is not available on this platform.");
72 wxPyEndBlockThreads(blocked);
74 virtual ~wxGraphicsContext() {}
76 static wxGraphicsContext* Create( const wxWindowDC&) {
77 wxPyBlock_t blocked = wxPyBeginBlockThreads();
78 PyErr_SetString(PyExc_NotImplementedError,
79 "wxGraphicsPath is not available on this platform.");
80 wxPyEndBlockThreads(blocked);
84 wxGraphicsPath * CreatePath() { return NULL; }
87 void Clip( const wxRegion & ) {}
88 void Translate( wxDouble , wxDouble ) {}
89 void Scale( wxDouble , wxDouble ) {}
90 void Rotate( wxDouble ) {}
91 void SetPen( const wxPen & ) {}
92 void SetBrush( const wxBrush & ) {}
93 void SetLinearGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble ,
94 const wxColour&, const wxColour&) {}
95 void SetRadialGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ,
96 const wxColour &, const wxColour &) {}
97 void SetFont( const wxFont & ) {}
98 void SetTextColor( const wxColour & ) {}
99 void StrokePath( const wxGraphicsPath * ) {}
100 void FillPath( const wxGraphicsPath *, int ) {}
101 void DrawPath( const wxGraphicsPath *, int ) {}
102 void DrawText( const wxString &, wxDouble , wxDouble ) {}
103 void DrawText( const wxString &, wxDouble , wxDouble , wxDouble ) {}
104 void GetTextExtent( const wxString &, wxDouble *, wxDouble *,
105 wxDouble *, wxDouble * ) const {}
106 void GetPartialTextExtents(const wxString& , wxArrayDouble& ) const {}
107 void DrawBitmap( const wxBitmap &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
108 void DrawIcon( const wxIcon &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
109 void StrokeLine( wxDouble , wxDouble , wxDouble , wxDouble ) {}
110 void StrokeLines( size_t , const wxPoint2DDouble *) {}
111 void StrokeLines( size_t , const wxPoint2DDouble *, const wxPoint2DDouble *) {}
112 void DrawLines( size_t , const wxPoint2DDouble *, int ) {}
113 void DrawRectangle( wxDouble , wxDouble , wxDouble , wxDouble ) {}
114 void DrawEllipse( wxDouble , wxDouble, wxDouble , wxDouble) {}
115 void DrawRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
119 class wxGCDC: public wxWindowDC
122 wxGCDC(const wxWindowDC&) {
123 wxPyBlock_t blocked = wxPyBeginBlockThreads();
124 PyErr_SetString(PyExc_NotImplementedError,
125 "wxGCDC is not available on this platform.");
126 wxPyEndBlockThreads(blocked);
130 wxPyBlock_t blocked = wxPyBeginBlockThreads();
131 PyErr_SetString(PyExc_NotImplementedError,
132 "wxGCDC is not available on this platform.");
133 wxPyEndBlockThreads(blocked);
138 wxGraphicsContext* GetGraphicContext() { return NULL; }
144 //---------------------------------------------------------------------------
145 //---------------------------------------------------------------------------
148 %typemap(in) (size_t points, wxPoint2D* points_array ) {
149 $2 = wxPoint2D_LIST_helper($input, &$1);
150 if ($2 == NULL) SWIG_fail;
152 %typemap(freearg) (size_t points, wxPoint2D* points_array ) {
153 if ($2) delete [] $2;
158 MustHaveApp(wxGraphicsPath);
159 MustHaveApp(wxGraphicsContext);
162 //#define wxDouble double
163 typedef double wxDouble;
166 // TODO: Decide which of the overloaded methods should use the primary names
171 //wxGraphicsPath(); *** This class is an ABC, so we can't allow instances to be created directly
172 virtual ~wxGraphicsPath();
176 virtual void , MoveToPoint( wxDouble x, wxDouble y ),
177 "Begins a new subpath at (x,y)", "");
178 // void MoveToPoint( const wxPoint2D& p);
182 virtual void , AddLineToPoint( wxDouble x, wxDouble y ),
183 "Adds a straight line from the current point to (x,y) ", "");
184 // void AddLineToPoint( const wxPoint2D& p);
188 virtual void , AddCurveToPoint( wxDouble cx1, wxDouble cy1,
189 wxDouble cx2, wxDouble cy2,
190 wxDouble x, wxDouble y ),
191 "Adds a cubic Bezier curve from the current point, using two control
192 points and an end point", "");
193 // void AddCurveToPoint( const wxPoint2D& c1, const wxPoint2D& c2, const wxPoint2D& e);
197 virtual void , CloseSubpath(),
198 "closes the current sub-path", "");
201 //virtual void , GetCurrentPoint( wxDouble& x, wxDouble&y),
203 wxPoint2D , GetCurrentPoint(),
204 "Gets the last point of the current path, (0,0) if not yet set", "");
208 virtual void , AddArc( wxDouble x, wxDouble y, wxDouble r,
209 wxDouble startAngle, wxDouble endAngle, bool clockwise ),
210 "Adds an arc of a circle centering at (x,y) with radius (r) from
211 startAngle to endAngle", "");
212 // void AddArc( const wxPoint2D& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
216 virtual void , AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ),
217 "Adds a quadratic Bezier curve from the current point, using a control
218 point and an end point", "");
222 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
223 "Appends a rectangle as a new closed subpath", "");
227 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
228 "Appends a circle as a new closed subpath with the given radius.", "");
232 virtual void , AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ,
233 "Draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1)
234 to (x2,y2), also a straight line from (current) to (x1,y1)", "");
239 //---------------------------------------------------------------------------
242 class wxGraphicsMatrix
245 wxGraphicsMatrix() {}
247 virtual ~wxGraphicsMatrix() {}
249 wxGraphicsMatrix* Concat( const wxGraphicsMatrix *t ) const;
251 // returns the inverse matrix
252 wxGraphicsMatrix* Invert() const;
254 // returns true if the elements of the transformation matrix are equal ?
255 bool operator==(const wxGraphicsMatrix& t) const;
257 // return true if this is the identity matrix
265 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
268 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
271 virtual void Rotate( wxDouble angle ) = 0;
276 //---------------------------------------------------------------------------
279 class wxGraphicsContext
282 // wxGraphicsContext() This is also an ABC, use Create to make an instance...
283 virtual ~wxGraphicsContext();
286 %pythonAppend Create( const wxWindowDC& dc)
287 "val.__dc = args[0] # save a ref so the other dc will not be deleted before self";
288 static wxGraphicsContext* Create( const wxWindowDC& dc);
290 static wxGraphicsContext* Create( wxWindow* window ) ;
292 static wxGraphicsContext* CreateFromNative( void * context ) ;
295 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
297 virtual wxGraphicsPath * , CreatePath(),
301 // create a 'native' matrix corresponding to these values
302 virtual wxGraphicsMatrix* CreateMatrix( wxDouble a=1.0, wxDouble b=0.0,
303 wxDouble c=0.0, wxDouble d=1.0,
304 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
308 // push the current state of the context, ie the transformation matrix on a stack
310 virtual void , PushState(),
314 // pops a stored state from the stack
316 virtual void , PopState(),
320 // clips drawings to the region
322 virtual void , Clip( const wxRegion ®ion ),
326 // clips drawings to the rect
328 virtual void , Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
332 // resets the clipping to original extent
334 virtual void , ResetClip(),
338 // returns the native context
340 virtual void * , GetNativeContext(),
346 // transformation: changes the current transformation matrix CTM of the context
351 virtual void , Translate( wxDouble dx , wxDouble dy ),
357 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
363 virtual void , Rotate( wxDouble angle ),
373 virtual void , SetPen( const wxPen &pen ),
377 // sets the brush for filling
379 virtual void , SetBrush( const wxBrush &brush ),
383 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
385 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
386 const wxColour&c1, const wxColour&c2),
390 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
391 // with radius r and color cColor
393 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
395 const wxColour &oColor, const wxColour &cColor),
401 virtual void , SetFont( const wxFont &font ),
405 // sets the text color
407 virtual void , SetTextColor( const wxColour &col ),
411 // strokes along a path with the current pen
413 virtual void , StrokePath( const wxGraphicsPath *path ),
417 // fills a path with the current brush
419 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
423 // draws a path by first filling and then stroking
425 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
434 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
439 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
445 virtual void , GetTextExtent( const wxString &text,
446 wxDouble *OUTPUT /*width*/,
447 wxDouble *OUTPUT /*height*/,
448 wxDouble *OUTPUT /*descent*/,
449 wxDouble *OUTPUT /*externalLeading*/ ) const ,
450 "GetTextExtend(self, text) --> (width, height, descent, externalLeading)",
455 DocAStr(GetPartialTextExtents,
456 "GetPartialTextExtents(self, text) -> [widths]",
458 wxArrayDouble GetPartialTextExtents(const wxString& text) {
459 wxArrayDouble widths;
460 self->GetPartialTextExtents(text, widths);
471 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
476 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
481 // convenience methods
484 // strokes a single line
486 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
490 // stroke lines connecting each of the points
492 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
493 "StrokeLines(self, List points)",
497 // // stroke disconnected lines from begin to end points
498 // virtual void StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints);
501 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
503 size_t c1, c2, count;
504 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
505 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
507 if ( beginP != NULL && endP != NULL )
509 count = wxMin(c1, c2);
510 self->StrokeLines(count, beginP, endP);
519 virtual void , DrawLines( size_t points, const wxPoint2D *points_array, int fillStyle = wxWINDING_RULE ),
525 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
531 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
535 // draws a rounded rectangle
537 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
543 //---------------------------------------------------------------------------
546 #include "wx/dcgraph.h"
549 class wxGCDC: public wxDC
553 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
554 wxGCDC(const wxWindowDC& dc);
558 wxGraphicsContext* GetGraphicsContext();
559 virtual void SetGraphicsContext( wxGraphicsContext* ctx );
561 %property(GraphicsContext, GetGraphicsContext, SetGraphicsContext);
565 //---------------------------------------------------------------------------
567 // Turn GIL acquisition back on.