]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_graphics.i
848dc43bde468bfbe44dd20b238358ad1b4e8047
[wxWidgets.git] / wxPython / src / _graphics.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _graphics.i
3 // Purpose: Wrapper definitions for wx.GraphicsPath, wx.GraphicsContext
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 2-Oct-2006
8 // RCS-ID: $Id$
9 // Copyright: (c) 2006 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 %newgroup
18
19 %{
20 #include <wx/graphics.h>
21 %}
22
23 //---------------------------------------------------------------------------
24
25
26 %{
27 #if !wxUSE_GRAPHICS_CONTEXT
28 // C++ stub classes for platforms that don't have wxGraphicsContext yet.
29
30 class wxGraphicsPath
31 {
32 public :
33 wxGraphicsPath() {
34 wxPyBlock_t blocked = wxPyBeginBlockThreads();
35 PyErr_SetString(PyExc_NotImplementedError,
36 "wxGraphicsPath is not available on this platform.");
37 wxPyEndBlockThreads(blocked);
38 }
39 virtual ~wxGraphicsPath() {}
40
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 ) {}
47
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 ) {}
52
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) {}
58 };
59
60
61 class wxGraphicsContext
62 {
63 public:
64 wxGraphicsContext() {
65 wxPyBlock_t blocked = wxPyBeginBlockThreads();
66 PyErr_SetString(PyExc_NotImplementedError,
67 "wxGraphicsContext is not available on this platform.");
68 wxPyEndBlockThreads(blocked);
69 }
70 virtual ~wxGraphicsContext() {}
71
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);
77 return NULL;
78 }
79
80 wxGraphicsPath * CreatePath() {}
81 void PushState() {}
82 void PopState() {}
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 ) {}
112 };
113
114
115 class wxGCDC: public wxWindowDC
116 {
117 public:
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);
123 }
124
125 wxGCDC() {
126 wxPyBlock_t blocked = wxPyBeginBlockThreads();
127 PyErr_SetString(PyExc_NotImplementedError,
128 "wxGCDC is not available on this platform.");
129 wxPyEndBlockThreads(blocked);
130 }
131
132 virtual ~wxGCDC() {}
133
134 wxGraphicsContext* GetGraphicContext() { return NULL; }
135 };
136
137 #endif
138 %}
139
140 //---------------------------------------------------------------------------
141 //---------------------------------------------------------------------------
142
143 MustHaveApp(wxGraphicsPath);
144 MustHaveApp(wxGraphicsContext);
145 MustHaveApp(wxGCDC);
146
147 //#define wxDouble double
148 typedef double wxDouble;
149
150
151 // TODO: Decide which of the overloaded methods should use the primary names
152
153 class wxGraphicsPath
154 {
155 public :
156 //wxGraphicsPath(); *** This class is an ABC, so we can't allow instances to be created directly
157 virtual ~wxGraphicsPath();
158
159
160 DocDeclStr(
161 virtual void , MoveToPoint( wxDouble x, wxDouble y ),
162 "Begins a new subpath at (x,y)", "");
163 // void MoveToPoint( const wxPoint2D& p);
164
165
166 DocDeclStr(
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);
170
171
172 DocDeclStr(
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);
179
180
181 DocDeclStr(
182 virtual void , CloseSubpath(),
183 "closes the current sub-path", "");
184
185
186 //virtual void , GetCurrentPoint( wxDouble& x, wxDouble&y),
187 DocDeclStr(
188 wxPoint2D , GetCurrentPoint(),
189 "Gets the last point of the current path, (0,0) if not yet set", "");
190
191
192 DocDeclStr(
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);
198
199
200 DocDeclStr(
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", "");
204
205
206 DocDeclStr(
207 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
208 "Appends a rectangle as a new closed subpath", "");
209
210
211 DocDeclStr(
212 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
213 "Appends an ellipsis as a new closed subpath fitting the passed rectangle", "");
214
215
216 DocDeclStr(
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)", "");
220
221
222 };
223
224 //---------------------------------------------------------------------------
225
226
227 class wxGraphicsContext
228 {
229 public:
230 // wxGraphicsContext() This is also an ABC, use Create to make an instance...
231 virtual ~wxGraphicsContext();
232
233 static wxGraphicsContext* Create( const wxWindowDC& dc);
234
235 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
236 DocDeclStr(
237 virtual wxGraphicsPath * , CreatePath(),
238 "", "");
239
240
241 // push the current state of the context, ie the transformation matrix on a stack
242 DocDeclStr(
243 virtual void , PushState(),
244 "", "");
245
246
247 // pops a stored state from the stack
248 DocDeclStr(
249 virtual void , PopState(),
250 "", "");
251
252
253 // clips drawings to the region
254 DocDeclStr(
255 virtual void , Clip( const wxRegion &region ),
256 "", "");
257
258
259 //
260 // transformation
261 //
262
263 // translate
264 DocDeclStr(
265 virtual void , Translate( wxDouble dx , wxDouble dy ),
266 "", "");
267
268
269 // scale
270 DocDeclStr(
271 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
272 "", "");
273
274
275 // rotate (radians)
276 DocDeclStr(
277 virtual void , Rotate( wxDouble angle ),
278 "", "");
279
280
281 //
282 // setting the paint
283 //
284
285 // sets the pan
286 DocDeclStr(
287 virtual void , SetPen( const wxPen &pen ),
288 "", "");
289
290
291 // sets the brush for filling
292 DocDeclStr(
293 virtual void , SetBrush( const wxBrush &brush ),
294 "", "");
295
296
297 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
298 DocDeclStr(
299 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
300 const wxColour&c1, const wxColour&c2),
301 "", "");
302
303
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
306 DocDeclStr(
307 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
308 wxDouble radius,
309 const wxColour &oColor, const wxColour &cColor),
310 "", "");
311
312
313 // sets the font
314 DocDeclStr(
315 virtual void , SetFont( const wxFont &font ),
316 "", "");
317
318
319 // sets the text color
320 DocDeclStr(
321 virtual void , SetTextColor( const wxColour &col ),
322 "", "");
323
324
325 // strokes along a path with the current pen
326 DocDeclStr(
327 virtual void , StrokePath( const wxGraphicsPath *path ),
328 "", "");
329
330
331 // fills a path with the current brush
332 DocDeclStr(
333 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
334 "", "");
335
336
337 // draws a path by first filling and then stroking
338 DocDeclStr(
339 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
340 "", "");
341
342
343 //
344 // text
345 //
346
347 DocDeclStr(
348 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
349 "", "");
350
351
352 DocDeclStr(
353 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
354 "", "");
355
356
357 DocDeclStr(
358 virtual void , GetTextExtent( const wxString &text,
359 wxDouble *OUTPUT /*width*/,
360 wxDouble *OUTPUT /*height*/,
361 wxDouble *OUTPUT /*descent*/,
362 wxDouble *OUTPUT /*externalLeading*/ ) const ,
363 "", "");
364
365
366 DocDeclStr(
367 virtual void , GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const,
368 "", "");
369
370
371 //
372 // image support
373 //
374
375 DocDeclStr(
376 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
377 "", "");
378
379
380 DocDeclStr(
381 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
382 "", "");
383
384
385 //
386 // convenience methods
387 //
388
389 // strokes a single line
390 DocDeclStr(
391 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
392 "", "");
393
394
395 // stroke lines connecting each of the points
396 DocDeclStr(
397 virtual void , StrokeLines( size_t n, const wxPoint2D *points),
398 "", "");
399
400
401 // stroke disconnected lines from begin to end points
402 DocDeclStr(
403 virtual void , StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints),
404 "", "");
405
406
407 // draws a polygon
408 DocDeclStr(
409 virtual void , DrawLines( size_t n, const wxPoint2D *points, int fillStyle = wxWINDING_RULE ),
410 "", "");
411
412
413 // draws a polygon
414 DocDeclStr(
415 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
416 "", "");
417
418
419 // draws an ellipse
420 DocDeclStr(
421 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
422 "", "");
423
424
425 // draws a rounded rectangle
426 DocDeclStr(
427 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
428 "", "");
429
430
431 };
432
433
434 //---------------------------------------------------------------------------
435
436
437 class wxGCDC: public wxDC
438 {
439 public:
440 wxGCDC(const wxWindowDC& dc);
441 //wxGCDC();
442 virtual ~wxGCDC();
443
444 wxGraphicsContext* GetGraphicContext();
445 };
446
447
448
449
450 //---------------------------------------------------------------------------