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() { return NULL; }
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();
234 "val.__dc = args[0] # save a ref so the other dc will not be deleted before self";
235 static wxGraphicsContext* Create( const wxWindowDC& dc);
237 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
239 virtual wxGraphicsPath * , CreatePath(),
243 // push the current state of the context, ie the transformation matrix on a stack
245 virtual void , PushState(),
249 // pops a stored state from the stack
251 virtual void , PopState(),
255 // clips drawings to the region
257 virtual void , Clip( const wxRegion ®ion ),
267 virtual void , Translate( wxDouble dx , wxDouble dy ),
273 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
279 virtual void , Rotate( wxDouble angle ),
289 virtual void , SetPen( const wxPen &pen ),
293 // sets the brush for filling
295 virtual void , SetBrush( const wxBrush &brush ),
299 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
301 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
302 const wxColour&c1, const wxColour&c2),
306 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
307 // with radius r and color cColor
309 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
311 const wxColour &oColor, const wxColour &cColor),
317 virtual void , SetFont( const wxFont &font ),
321 // sets the text color
323 virtual void , SetTextColor( const wxColour &col ),
327 // strokes along a path with the current pen
329 virtual void , StrokePath( const wxGraphicsPath *path ),
333 // fills a path with the current brush
335 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
339 // draws a path by first filling and then stroking
341 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
350 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
355 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
360 virtual void , GetTextExtent( const wxString &text,
361 wxDouble *OUTPUT /*width*/,
362 wxDouble *OUTPUT /*height*/,
363 wxDouble *OUTPUT /*descent*/,
364 wxDouble *OUTPUT /*externalLeading*/ ) const ,
369 virtual void , GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const,
378 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
383 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
388 // convenience methods
391 // strokes a single line
393 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
397 // stroke lines connecting each of the points
399 virtual void , StrokeLines( size_t n, const wxPoint2D *points),
403 // stroke disconnected lines from begin to end points
405 virtual void , StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints),
411 virtual void , DrawLines( size_t n, const wxPoint2D *points, int fillStyle = wxWINDING_RULE ),
417 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
423 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
427 // draws a rounded rectangle
429 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
436 //---------------------------------------------------------------------------
439 class wxGCDC: public wxDC
443 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
444 wxGCDC(const wxWindowDC& dc);
448 wxGraphicsContext* GetGraphicContext();
454 //---------------------------------------------------------------------------