]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_graphics.i
use the right number in the tarball filename
[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 // Turn off the aquisition of the Global Interpreter Lock for the classes and
24 // functions in this file
25 %threadWrapperOff
26
27 //---------------------------------------------------------------------------
28
29
30 %{
31 #if !wxUSE_GRAPHICS_CONTEXT
32 // C++ stub classes for platforms that don't have wxGraphicsContext yet.
33
34 class wxGraphicsPath
35 {
36 public :
37 wxGraphicsPath() {
38 wxPyBlock_t blocked = wxPyBeginBlockThreads();
39 PyErr_SetString(PyExc_NotImplementedError,
40 "wxGraphicsPath is not available on this platform.");
41 wxPyEndBlockThreads(blocked);
42 }
43 virtual ~wxGraphicsPath() {}
44
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 ) {}
51
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 ) {}
56
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) {}
62 };
63
64
65 class wxGraphicsContext
66 {
67 public:
68 wxGraphicsContext() {
69 wxPyBlock_t blocked = wxPyBeginBlockThreads();
70 PyErr_SetString(PyExc_NotImplementedError,
71 "wxGraphicsContext is not available on this platform.");
72 wxPyEndBlockThreads(blocked);
73 }
74 virtual ~wxGraphicsContext() {}
75
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);
81 return NULL;
82 }
83
84 wxGraphicsPath * CreatePath() { return NULL; }
85 void PushState() {}
86 void PopState() {}
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 ) {}
116 };
117
118
119 class wxGCDC: public wxWindowDC
120 {
121 public:
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);
127 }
128
129 wxGCDC() {
130 wxPyBlock_t blocked = wxPyBeginBlockThreads();
131 PyErr_SetString(PyExc_NotImplementedError,
132 "wxGCDC is not available on this platform.");
133 wxPyEndBlockThreads(blocked);
134 }
135
136 virtual ~wxGCDC() {}
137
138 wxGraphicsContext* GetGraphicContext() { return NULL; }
139 };
140
141 #endif
142 %}
143
144 //---------------------------------------------------------------------------
145 //---------------------------------------------------------------------------
146
147
148 %typemap(in) (size_t points, wxPoint2D* points_array ) {
149 $2 = wxPoint2D_LIST_helper($input, &$1);
150 if ($2 == NULL) SWIG_fail;
151 }
152 %typemap(freearg) (size_t points, wxPoint2D* points_array ) {
153 if ($2) delete [] $2;
154 }
155
156
157
158 MustHaveApp(wxGraphicsPath);
159 MustHaveApp(wxGraphicsContext);
160 MustHaveApp(wxGCDC);
161
162 //#define wxDouble double
163 typedef double wxDouble;
164
165
166 // TODO: Decide which of the overloaded methods should use the primary names
167
168 class wxGraphicsPath
169 {
170 public :
171 //wxGraphicsPath(); *** This class is an ABC, so we can't allow instances to be created directly
172 virtual ~wxGraphicsPath();
173
174
175 DocDeclStr(
176 virtual void , MoveToPoint( wxDouble x, wxDouble y ),
177 "Begins a new subpath at (x,y)", "");
178 // void MoveToPoint( const wxPoint2D& p);
179
180
181 DocDeclStr(
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);
185
186
187 DocDeclStr(
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);
194
195
196 DocDeclStr(
197 virtual void , CloseSubpath(),
198 "closes the current sub-path", "");
199
200
201 //virtual void , GetCurrentPoint( wxDouble& x, wxDouble&y),
202 DocDeclStr(
203 wxPoint2D , GetCurrentPoint(),
204 "Gets the last point of the current path, (0,0) if not yet set", "");
205
206
207 DocDeclStr(
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);
213
214
215 DocDeclStr(
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", "");
219
220
221 DocDeclStr(
222 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
223 "Appends a rectangle as a new closed subpath", "");
224
225
226 DocDeclStr(
227 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
228 "Appends a circle as a new closed subpath with the given radius.", "");
229
230
231 DocDeclStr(
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)", "");
235
236
237 };
238
239 //---------------------------------------------------------------------------
240
241
242 class wxGraphicsContext
243 {
244 public:
245 // wxGraphicsContext() This is also an ABC, use Create to make an instance...
246 virtual ~wxGraphicsContext();
247
248 %pythonAppend Create
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);
251
252 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
253 DocDeclStr(
254 virtual wxGraphicsPath * , CreatePath(),
255 "", "");
256
257
258 // push the current state of the context, ie the transformation matrix on a stack
259 DocDeclStr(
260 virtual void , PushState(),
261 "", "");
262
263
264 // pops a stored state from the stack
265 DocDeclStr(
266 virtual void , PopState(),
267 "", "");
268
269
270 // clips drawings to the region
271 DocDeclStr(
272 virtual void , Clip( const wxRegion &region ),
273 "", "");
274
275
276 //
277 // transformation
278 //
279
280 // translate
281 DocDeclStr(
282 virtual void , Translate( wxDouble dx , wxDouble dy ),
283 "", "");
284
285
286 // scale
287 DocDeclStr(
288 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
289 "", "");
290
291
292 // rotate (radians)
293 DocDeclStr(
294 virtual void , Rotate( wxDouble angle ),
295 "", "");
296
297
298 //
299 // setting the paint
300 //
301
302 // sets the pan
303 DocDeclStr(
304 virtual void , SetPen( const wxPen &pen ),
305 "", "");
306
307
308 // sets the brush for filling
309 DocDeclStr(
310 virtual void , SetBrush( const wxBrush &brush ),
311 "", "");
312
313
314 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
315 DocDeclStr(
316 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
317 const wxColour&c1, const wxColour&c2),
318 "", "");
319
320
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
323 DocDeclStr(
324 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
325 wxDouble radius,
326 const wxColour &oColor, const wxColour &cColor),
327 "", "");
328
329
330 // sets the font
331 DocDeclStr(
332 virtual void , SetFont( const wxFont &font ),
333 "", "");
334
335
336 // sets the text color
337 DocDeclStr(
338 virtual void , SetTextColor( const wxColour &col ),
339 "", "");
340
341
342 // strokes along a path with the current pen
343 DocDeclStr(
344 virtual void , StrokePath( const wxGraphicsPath *path ),
345 "", "");
346
347
348 // fills a path with the current brush
349 DocDeclStr(
350 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
351 "", "");
352
353
354 // draws a path by first filling and then stroking
355 DocDeclStr(
356 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
357 "", "");
358
359
360 //
361 // text
362 //
363
364 DocDeclStr(
365 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
366 "", "");
367
368
369 DocDeclStrName(
370 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
371 "", "",
372 DrawRotatedText);
373
374
375 DocDeclAStr(
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)",
382 "", "");
383
384
385 %extend {
386 DocAStr(GetPartialTextExtents,
387 "GetPartialTextExtents(self, text) -> [widths]",
388 "", "");
389 wxArrayDouble GetPartialTextExtents(const wxString& text) {
390 wxArrayDouble widths;
391 self->GetPartialTextExtents(text, widths);
392 return widths;
393 }
394 }
395
396
397 //
398 // image support
399 //
400
401 DocDeclStr(
402 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
403 "", "");
404
405
406 DocDeclStr(
407 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
408 "", "");
409
410
411 //
412 // convenience methods
413 //
414
415 // strokes a single line
416 DocDeclStr(
417 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
418 "", "");
419
420
421 // stroke lines connecting each of the points
422 DocDeclAStr(
423 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
424 "StrokeLines(self, List points)",
425 "", "");
426
427
428 // // stroke disconnected lines from begin to end points
429 // virtual void StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints);
430
431 %extend {
432 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
433 {
434 size_t c1, c2, count;
435 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
436 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
437
438 if ( beginP != NULL && endP != NULL )
439 {
440 count = wxMin(c1, c2);
441 self->StrokeLines(count, beginP, endP);
442 }
443 delete [] beginP;
444 delete [] endP;
445 }
446 }
447
448 // draws a polygon
449 DocDeclStr(
450 virtual void , DrawLines( size_t points, const wxPoint2D *points_array, int fillStyle = wxWINDING_RULE ),
451 "", "");
452
453
454 // draws a polygon
455 DocDeclStr(
456 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
457 "", "");
458
459
460 // draws an ellipse
461 DocDeclStr(
462 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
463 "", "");
464
465
466 // draws a rounded rectangle
467 DocDeclStr(
468 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
469 "", "");
470
471 };
472
473
474 //---------------------------------------------------------------------------
475
476
477 class wxGCDC: public wxDC
478 {
479 public:
480 %pythonAppend wxGCDC
481 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
482 wxGCDC(const wxWindowDC& dc);
483 //wxGCDC();
484 virtual ~wxGCDC();
485
486 wxGraphicsContext* GetGraphicContext();
487 };
488
489
490 //---------------------------------------------------------------------------
491
492 // Turn GIL acquisition back on.
493 %threadWrapperOn
494