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 //---------------------------------------------------------------------------
27 #if !wxUSE_GRAPHICS_CONTEXT
28 // C++ stub classes for platforms that don't have wxGraphicsContext yet.
34 wxPyBlock_t blocked = wxPyBeginBlockThreads();
35 PyErr_SetString(PyExc_NotImplementedError,
36 "wxGraphicsPath is not available on this platform.");
37 wxPyEndBlockThreads(blocked);
39 virtual ~wxGraphicsPath() {}
41 void MoveToPoint( wxDouble, wxDouble ) {}
42 void AddLineToPoint( wxDouble, wxDouble ) {}
43 void AddCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, wxDouble ) {}
44 void CloseSubpath() {}
45 void GetCurrentPoint( wxDouble&, wxDouble&) {}
46 void AddArc( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, bool ) {}
48 void AddQuadCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble ) {}
49 void AddRectangle( wxDouble, wxDouble, wxDouble, wxDouble ) {}
50 void AddCircle( wxDouble, wxDouble, wxDouble ) {}
51 void AddArcToPoint( wxDouble, wxDouble , wxDouble, wxDouble, wxDouble ) {}
53 wxPoint2DDouble GetCurrentPoint() { return wxPoint2DDouble(0,0); }
54 void MoveToPoint( const wxPoint2DDouble& ) {}
55 void AddLineToPoint( const wxPoint2DDouble&) {}
56 void AddCurveToPoint( const wxPoint2DDouble&, const wxPoint2DDouble&, const wxPoint2DDouble&) {}
57 void AddArc( const wxPoint2DDouble&, wxDouble, wxDouble, wxDouble, bool) {}
61 class wxGraphicsContext
65 wxPyBlock_t blocked = wxPyBeginBlockThreads();
66 PyErr_SetString(PyExc_NotImplementedError,
67 "wxGraphicsContext is not available on this platform.");
68 wxPyEndBlockThreads(blocked);
70 virtual ~wxGraphicsContext() {}
72 static wxGraphicsContext* Create( const wxWindowDC&) {
73 wxPyBlock_t blocked = wxPyBeginBlockThreads();
74 PyErr_SetString(PyExc_NotImplementedError,
75 "wxGraphicsPath is not available on this platform.");
76 wxPyEndBlockThreads(blocked);
80 wxGraphicsPath * CreatePath() {}
83 void Clip( const wxRegion & ) {}
84 void Translate( wxDouble , wxDouble ) {}
85 void Scale( wxDouble , wxDouble ) {}
86 void Rotate( wxDouble ) {}
87 void SetPen( const wxPen & ) {}
88 void SetBrush( const wxBrush & ) {}
89 void SetLinearGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble ,
90 const wxColour&, const wxColour&) {}
91 void SetRadialGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ,
92 const wxColour &, const wxColour &) {}
93 void SetFont( const wxFont & ) {}
94 void SetTextColor( const wxColour & ) {}
95 void StrokePath( const wxGraphicsPath * ) {}
96 void FillPath( const wxGraphicsPath *, int ) {}
97 void DrawPath( const wxGraphicsPath *, int ) {}
98 void DrawText( const wxString &, wxDouble , wxDouble ) {}
99 void DrawText( const wxString &, wxDouble , wxDouble , wxDouble ) {}
100 void GetTextExtent( const wxString &, wxDouble *, wxDouble *,
101 wxDouble *, wxDouble * ) const {}
102 void GetPartialTextExtents(const wxString& , wxArrayDouble& ) const {}
103 void DrawBitmap( const wxBitmap &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
104 void DrawIcon( const wxIcon &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
105 void StrokeLine( wxDouble , wxDouble , wxDouble , wxDouble ) {}
106 void StrokeLines( size_t , const wxPoint2DDouble *) {}
107 void StrokeLines( size_t , const wxPoint2DDouble *, const wxPoint2DDouble *) {}
108 void DrawLines( size_t , const wxPoint2DDouble *, int ) {}
109 void DrawRectangle( wxDouble , wxDouble , wxDouble , wxDouble ) {}
110 void DrawEllipse( wxDouble , wxDouble, wxDouble , wxDouble) {}
111 void DrawRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
115 class wxGCDC: public wxWindowDC
118 wxGCDC(const wxWindowDC&) {
119 wxPyBlock_t blocked = wxPyBeginBlockThreads();
120 PyErr_SetString(PyExc_NotImplementedError,
121 "wxGCDC is not available on this platform.");
122 wxPyEndBlockThreads(blocked);
126 wxPyBlock_t blocked = wxPyBeginBlockThreads();
127 PyErr_SetString(PyExc_NotImplementedError,
128 "wxGCDC is not available on this platform.");
129 wxPyEndBlockThreads(blocked);
134 wxGraphicsContext* GetGraphicContext() { return NULL; }
140 //---------------------------------------------------------------------------
141 //---------------------------------------------------------------------------
143 MustHaveApp(wxGraphicsPath);
144 MustHaveApp(wxGraphicsContext);
147 //#define wxDouble double
148 typedef double wxDouble;
151 // TODO: Decide which of the overloaded methods should use the primary names
156 //wxGraphicsPath(); *** This class is an ABC, so we can't allow instances to be created directly
157 virtual ~wxGraphicsPath();
161 virtual void , MoveToPoint( wxDouble x, wxDouble y ),
162 "Begins a new subpath at (x,y)", "");
163 // void MoveToPoint( const wxPoint2D& p);
167 virtual void , AddLineToPoint( wxDouble x, wxDouble y ),
168 "Adds a straight line from the current point to (x,y) ", "");
169 // void AddLineToPoint( const wxPoint2D& p);
173 virtual void , AddCurveToPoint( wxDouble cx1, wxDouble cy1,
174 wxDouble cx2, wxDouble cy2,
175 wxDouble x, wxDouble y ),
176 "Adds a cubic Bezier curve from the current point, using two control
177 points and an end point", "");
178 // void AddCurveToPoint( const wxPoint2D& c1, const wxPoint2D& c2, const wxPoint2D& e);
182 virtual void , CloseSubpath(),
183 "closes the current sub-path", "");
186 //virtual void , GetCurrentPoint( wxDouble& x, wxDouble&y),
188 wxPoint2D , GetCurrentPoint(),
189 "Gets the last point of the current path, (0,0) if not yet set", "");
193 virtual void , AddArc( wxDouble x, wxDouble y, wxDouble r,
194 wxDouble startAngle, wxDouble endAngle, bool clockwise ),
195 "Adds an arc of a circle centering at (x,y) with radius (r) from
196 startAngle to endAngle", "");
197 // void AddArc( const wxPoint2D& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
201 virtual void , AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ),
202 "Adds a quadratic Bezier curve from the current point, using a control
203 point and an end point", "");
207 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
208 "Appends a rectangle as a new closed subpath", "");
212 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
213 "Appends an ellipsis as a new closed subpath fitting the passed rectangle", "");
217 virtual void , AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ,
218 "Draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1)
219 to (x2,y2), also a straight line from (current) to (x1,y1)", "");
224 //---------------------------------------------------------------------------
227 class wxGraphicsContext
230 // wxGraphicsContext() This is also an ABC, use Create to make an instance...
231 virtual ~wxGraphicsContext();
233 static wxGraphicsContext* Create( const wxWindowDC& dc);
235 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
237 virtual wxGraphicsPath * , CreatePath(),
241 // push the current state of the context, ie the transformation matrix on a stack
243 virtual void , PushState(),
247 // pops a stored state from the stack
249 virtual void , PopState(),
253 // clips drawings to the region
255 virtual void , Clip( const wxRegion ®ion ),
265 virtual void , Translate( wxDouble dx , wxDouble dy ),
271 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
277 virtual void , Rotate( wxDouble angle ),
287 virtual void , SetPen( const wxPen &pen ),
291 // sets the brush for filling
293 virtual void , SetBrush( const wxBrush &brush ),
297 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
299 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
300 const wxColour&c1, const wxColour&c2),
304 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
305 // with radius r and color cColor
307 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
309 const wxColour &oColor, const wxColour &cColor),
315 virtual void , SetFont( const wxFont &font ),
319 // sets the text color
321 virtual void , SetTextColor( const wxColour &col ),
325 // strokes along a path with the current pen
327 virtual void , StrokePath( const wxGraphicsPath *path ),
331 // fills a path with the current brush
333 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
337 // draws a path by first filling and then stroking
339 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
348 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
353 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
358 virtual void , GetTextExtent( const wxString &text,
359 wxDouble *OUTPUT /*width*/,
360 wxDouble *OUTPUT /*height*/,
361 wxDouble *OUTPUT /*descent*/,
362 wxDouble *OUTPUT /*externalLeading*/ ) const ,
367 virtual void , GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const,
376 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
381 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
386 // convenience methods
389 // strokes a single line
391 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
395 // stroke lines connecting each of the points
397 virtual void , StrokeLines( size_t n, const wxPoint2D *points),
401 // stroke disconnected lines from begin to end points
403 virtual void , StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints),
409 virtual void , DrawLines( size_t n, const wxPoint2D *points, int fillStyle = wxWINDING_RULE ),
415 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
421 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
425 // draws a rounded rectangle
427 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
434 //---------------------------------------------------------------------------
437 class wxGCDC: public wxDC
440 wxGCDC(const wxWindowDC& dc);
444 wxGraphicsContext* GetGraphicContext();
450 //---------------------------------------------------------------------------