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 static wxGraphicsContext* CreateFromNative( void * ) {
85 wxPyBlock_t blocked = wxPyBeginBlockThreads();
86 PyErr_SetString(PyExc_NotImplementedError,
87 "wxGraphicsContext is not available on this platform.");
88 wxPyEndBlockThreads(blocked);
92 wxGraphicsPath * CreatePath() { return NULL; }
95 void Clip( const wxRegion & ) {}
96 void Clip( wxDouble, wxDouble, wxDouble, wxDouble ) {}
98 void * GetNativeContext() { return NULL; }
99 void Translate( wxDouble , wxDouble ) {}
100 void Scale( wxDouble , wxDouble ) {}
101 void Rotate( wxDouble ) {}
102 void SetPen( const wxPen & ) {}
103 void SetBrush( const wxBrush & ) {}
104 void SetLinearGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble ,
105 const wxColour&, const wxColour&) {}
106 void SetRadialGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ,
107 const wxColour &, const wxColour &) {}
108 void SetFont( const wxFont & ) {}
109 void SetTextColor( const wxColour & ) {}
110 void StrokePath( const wxGraphicsPath * ) {}
111 void FillPath( const wxGraphicsPath *, int ) {}
112 void DrawPath( const wxGraphicsPath *, int ) {}
113 void DrawText( const wxString &, wxDouble , wxDouble ) {}
114 void DrawText( const wxString &, wxDouble , wxDouble , wxDouble ) {}
115 void GetTextExtent( const wxString &, wxDouble *, wxDouble *,
116 wxDouble *, wxDouble * ) const {}
117 void GetPartialTextExtents(const wxString& , wxArrayDouble& ) const {}
118 void DrawBitmap( const wxBitmap &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
119 void DrawIcon( const wxIcon &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
120 void StrokeLine( wxDouble , wxDouble , wxDouble , wxDouble ) {}
121 void StrokeLines( size_t , const wxPoint2DDouble *) {}
122 void StrokeLines( size_t , const wxPoint2DDouble *, const wxPoint2DDouble *) {}
123 void DrawLines( size_t , const wxPoint2DDouble *, int ) {}
124 void DrawRectangle( wxDouble , wxDouble , wxDouble , wxDouble ) {}
125 void DrawEllipse( wxDouble , wxDouble, wxDouble , wxDouble) {}
126 void DrawRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
130 class wxGCDC: public wxWindowDC
133 wxGCDC(const wxWindowDC&) {
134 wxPyBlock_t blocked = wxPyBeginBlockThreads();
135 PyErr_SetString(PyExc_NotImplementedError,
136 "wxGCDC is not available on this platform.");
137 wxPyEndBlockThreads(blocked);
141 wxPyBlock_t blocked = wxPyBeginBlockThreads();
142 PyErr_SetString(PyExc_NotImplementedError,
143 "wxGCDC is not available on this platform.");
144 wxPyEndBlockThreads(blocked);
149 wxGraphicsContext* GetGraphicsContext() { return NULL; }
150 void SetGraphicsContext( wxGraphicsContext* ) {}
156 //---------------------------------------------------------------------------
157 //---------------------------------------------------------------------------
160 %typemap(in) (size_t points, wxPoint2D* points_array ) {
161 $2 = wxPoint2D_LIST_helper($input, &$1);
162 if ($2 == NULL) SWIG_fail;
164 %typemap(freearg) (size_t points, wxPoint2D* points_array ) {
165 if ($2) delete [] $2;
170 MustHaveApp(wxGraphicsPath);
171 MustHaveApp(wxGraphicsContext);
174 //#define wxDouble double
175 typedef double wxDouble;
178 // TODO: Decide which of the overloaded methods should use the primary names
183 //wxGraphicsPath(); *** This class is an ABC, so we can't allow instances to be created directly
184 virtual ~wxGraphicsPath();
188 virtual void , MoveToPoint( wxDouble x, wxDouble y ),
189 "Begins a new subpath at (x,y)", "");
190 // void MoveToPoint( const wxPoint2D& p);
194 virtual void , AddLineToPoint( wxDouble x, wxDouble y ),
195 "Adds a straight line from the current point to (x,y) ", "");
196 // void AddLineToPoint( const wxPoint2D& p);
200 virtual void , AddCurveToPoint( wxDouble cx1, wxDouble cy1,
201 wxDouble cx2, wxDouble cy2,
202 wxDouble x, wxDouble y ),
203 "Adds a cubic Bezier curve from the current point, using two control
204 points and an end point", "");
205 // void AddCurveToPoint( const wxPoint2D& c1, const wxPoint2D& c2, const wxPoint2D& e);
209 virtual void , CloseSubpath(),
210 "closes the current sub-path", "");
213 //virtual void , GetCurrentPoint( wxDouble& x, wxDouble&y),
215 wxPoint2D , GetCurrentPoint(),
216 "Gets the last point of the current path, (0,0) if not yet set", "");
220 virtual void , AddArc( wxDouble x, wxDouble y, wxDouble r,
221 wxDouble startAngle, wxDouble endAngle, bool clockwise ),
222 "Adds an arc of a circle centering at (x,y) with radius (r) from
223 startAngle to endAngle", "");
224 // void AddArc( const wxPoint2D& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
228 virtual void , AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ),
229 "Adds a quadratic Bezier curve from the current point, using a control
230 point and an end point", "");
234 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
235 "Appends a rectangle as a new closed subpath", "");
239 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
240 "Appends a circle as a new closed subpath with the given radius.", "");
244 virtual void , AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ,
245 "Draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1)
246 to (x2,y2), also a straight line from (current) to (x1,y1)", "");
251 //---------------------------------------------------------------------------
254 class wxGraphicsMatrix
257 wxGraphicsMatrix() {}
259 virtual ~wxGraphicsMatrix() {}
261 wxGraphicsMatrix* Concat( const wxGraphicsMatrix *t ) const;
263 // returns the inverse matrix
264 wxGraphicsMatrix* Invert() const;
266 // returns true if the elements of the transformation matrix are equal ?
267 bool operator==(const wxGraphicsMatrix& t) const;
269 // return true if this is the identity matrix
277 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
280 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
283 virtual void Rotate( wxDouble angle ) = 0;
288 //---------------------------------------------------------------------------
291 class wxGraphicsContext
294 // wxGraphicsContext() This is also an ABC, use Create to make an instance...
295 virtual ~wxGraphicsContext();
298 %pythonAppend Create( const wxWindowDC& dc)
299 "val.__dc = args[0] # save a ref so the other dc will not be deleted before self";
300 static wxGraphicsContext* Create( const wxWindowDC& dc);
302 static wxGraphicsContext* Create( wxWindow* window ) ;
304 static wxGraphicsContext* CreateFromNative( void * context ) ;
307 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
309 virtual wxGraphicsPath * , CreatePath(),
313 // create a 'native' matrix corresponding to these values
314 virtual wxGraphicsMatrix* CreateMatrix( wxDouble a=1.0, wxDouble b=0.0,
315 wxDouble c=0.0, wxDouble d=1.0,
316 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
320 // push the current state of the context, ie the transformation matrix on a stack
322 virtual void , PushState(),
326 // pops a stored state from the stack
328 virtual void , PopState(),
332 // clips drawings to the region
334 virtual void , Clip( const wxRegion ®ion ),
338 // clips drawings to the rect
340 virtual void , Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
344 // resets the clipping to original extent
346 virtual void , ResetClip(),
350 // returns the native context
352 virtual void * , GetNativeContext(),
358 // transformation: changes the current transformation matrix CTM of the context
363 virtual void , Translate( wxDouble dx , wxDouble dy ),
369 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
375 virtual void , Rotate( wxDouble angle ),
385 virtual void , SetPen( const wxPen &pen ),
389 // sets the brush for filling
391 virtual void , SetBrush( const wxBrush &brush ),
395 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
397 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
398 const wxColour&c1, const wxColour&c2),
402 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
403 // with radius r and color cColor
405 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
407 const wxColour &oColor, const wxColour &cColor),
413 virtual void , SetFont( const wxFont &font ),
417 // sets the text color
419 virtual void , SetTextColor( const wxColour &col ),
423 // strokes along a path with the current pen
425 virtual void , StrokePath( const wxGraphicsPath *path ),
429 // fills a path with the current brush
431 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
435 // draws a path by first filling and then stroking
437 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
446 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
451 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
457 virtual void , GetTextExtent( const wxString &text,
458 wxDouble *OUTPUT /*width*/,
459 wxDouble *OUTPUT /*height*/,
460 wxDouble *OUTPUT /*descent*/,
461 wxDouble *OUTPUT /*externalLeading*/ ) const ,
462 "GetTextExtend(self, text) --> (width, height, descent, externalLeading)",
467 DocAStr(GetPartialTextExtents,
468 "GetPartialTextExtents(self, text) -> [widths]",
470 wxArrayDouble GetPartialTextExtents(const wxString& text) {
471 wxArrayDouble widths;
472 self->GetPartialTextExtents(text, widths);
483 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
488 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
493 // convenience methods
496 // strokes a single line
498 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
502 // stroke lines connecting each of the points
504 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
505 "StrokeLines(self, List points)",
509 // // stroke disconnected lines from begin to end points
510 // virtual void StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints);
513 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
515 size_t c1, c2, count;
516 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
517 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
519 if ( beginP != NULL && endP != NULL )
521 count = wxMin(c1, c2);
522 self->StrokeLines(count, beginP, endP);
531 virtual void , DrawLines( size_t points, const wxPoint2D *points_array, int fillStyle = wxWINDING_RULE ),
537 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
543 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
547 // draws a rounded rectangle
549 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
555 //---------------------------------------------------------------------------
558 #include "wx/dcgraph.h"
561 class wxGCDC: public wxDC
565 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
566 wxGCDC(const wxWindowDC& dc);
570 wxGraphicsContext* GetGraphicsContext();
571 virtual void SetGraphicsContext( wxGraphicsContext* ctx );
573 %property(GraphicsContext, GetGraphicsContext, SetGraphicsContext);
577 //---------------------------------------------------------------------------
579 // Turn GIL acquisition back on.