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 wxGraphicsContext
245 // wxGraphicsContext() This is also an ABC, use Create to make an instance...
246 virtual ~wxGraphicsContext();
249 "val.__dc = args[0] # save a ref so the other dc will not be deleted before self";
250 static wxGraphicsContext* Create( const wxWindowDC& dc);
252 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
254 virtual wxGraphicsPath * , CreatePath(),
258 // push the current state of the context, ie the transformation matrix on a stack
260 virtual void , PushState(),
264 // pops a stored state from the stack
266 virtual void , PopState(),
270 // clips drawings to the region
272 virtual void , Clip( const wxRegion ®ion ),
282 virtual void , Translate( wxDouble dx , wxDouble dy ),
288 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
294 virtual void , Rotate( wxDouble angle ),
304 virtual void , SetPen( const wxPen &pen ),
308 // sets the brush for filling
310 virtual void , SetBrush( const wxBrush &brush ),
314 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
316 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
317 const wxColour&c1, const wxColour&c2),
321 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
322 // with radius r and color cColor
324 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
326 const wxColour &oColor, const wxColour &cColor),
332 virtual void , SetFont( const wxFont &font ),
336 // sets the text color
338 virtual void , SetTextColor( const wxColour &col ),
342 // strokes along a path with the current pen
344 virtual void , StrokePath( const wxGraphicsPath *path ),
348 // fills a path with the current brush
350 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
354 // draws a path by first filling and then stroking
356 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
365 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
370 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
376 virtual void , GetTextExtent( const wxString &text,
377 wxDouble *OUTPUT /*width*/,
378 wxDouble *OUTPUT /*height*/,
379 wxDouble *OUTPUT /*descent*/,
380 wxDouble *OUTPUT /*externalLeading*/ ) const ,
381 "GetTextExtend(self, text) --> (width, height, descent, externalLeading)",
386 DocAStr(GetPartialTextExtents,
387 "GetPartialTextExtents(self, text) -> [widths]",
389 wxArrayDouble GetPartialTextExtents(const wxString& text) {
390 wxArrayDouble widths;
391 self->GetPartialTextExtents(text, widths);
402 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
407 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
412 // convenience methods
415 // strokes a single line
417 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
421 // stroke lines connecting each of the points
423 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
424 "StrokeLines(self, List points)",
428 // // stroke disconnected lines from begin to end points
429 // virtual void StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints);
432 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
434 size_t c1, c2, count;
435 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
436 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
438 if ( beginP != NULL && endP != NULL )
440 count = wxMin(c1, c2);
441 self->StrokeLines(count, beginP, endP);
450 virtual void , DrawLines( size_t points, const wxPoint2D *points_array, int fillStyle = wxWINDING_RULE ),
456 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
462 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
466 // draws a rounded rectangle
468 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
474 //---------------------------------------------------------------------------
477 class wxGCDC: public wxDC
481 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
482 wxGCDC(const wxWindowDC& dc);
486 wxGraphicsContext* GetGraphicContext();
490 //---------------------------------------------------------------------------
492 // Turn GIL acquisition back on.