]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_graphics.i
Update ReST docs
[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 wxGraphicsMatrix
243 {
244 public :
245 wxGraphicsMatrix() {}
246
247 virtual ~wxGraphicsMatrix() {}
248
249 wxGraphicsMatrix* Concat( const wxGraphicsMatrix *t ) const;
250
251 // returns the inverse matrix
252 wxGraphicsMatrix* Invert() const;
253
254 // returns true if the elements of the transformation matrix are equal ?
255 bool operator==(const wxGraphicsMatrix& t) const;
256
257 // return true if this is the identity matrix
258 bool IsIdentity();
259
260 //
261 // transformation
262 //
263
264 // translate
265 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
266
267 // scale
268 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
269
270 // rotate (radians)
271 virtual void Rotate( wxDouble angle ) = 0;
272 } ;
273 */
274
275
276 //---------------------------------------------------------------------------
277
278
279 class wxGraphicsContext
280 {
281 public:
282 // wxGraphicsContext() This is also an ABC, use Create to make an instance...
283 virtual ~wxGraphicsContext();
284
285 %nokwargs Create;
286 %pythonAppend Create( const wxWindowDC& dc)
287 "val.__dc = args[0] # save a ref so the other dc will not be deleted before self";
288 static wxGraphicsContext* Create( const wxWindowDC& dc);
289
290 static wxGraphicsContext* Create( wxWindow* window ) ;
291
292 static wxGraphicsContext* CreateFromNative( void * context ) ;
293
294
295 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
296 DocDeclStr(
297 virtual wxGraphicsPath * , CreatePath(),
298 "", "");
299
300 /*
301 // create a 'native' matrix corresponding to these values
302 virtual wxGraphicsMatrix* CreateMatrix( wxDouble a=1.0, wxDouble b=0.0,
303 wxDouble c=0.0, wxDouble d=1.0,
304 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
305 */
306
307
308 // push the current state of the context, ie the transformation matrix on a stack
309 DocDeclStr(
310 virtual void , PushState(),
311 "", "");
312
313
314 // pops a stored state from the stack
315 DocDeclStr(
316 virtual void , PopState(),
317 "", "");
318
319
320 // clips drawings to the region
321 DocDeclStrName(
322 virtual void , Clip( const wxRegion &region ),
323 "", "",
324 ClipRegion);
325
326 // clips drawings to the rect
327 DocDeclStr(
328 virtual void , Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
329 "", "");
330
331
332 // resets the clipping to original extent
333 DocDeclStr(
334 virtual void , ResetClip(),
335 "", "");
336
337
338 // returns the native context
339 DocDeclStr(
340 virtual void * , GetNativeContext(),
341 "", "");
342
343
344
345 //
346 // transformation: changes the current transformation matrix CTM of the context
347 //
348
349 // translate
350 DocDeclStr(
351 virtual void , Translate( wxDouble dx , wxDouble dy ),
352 "", "");
353
354
355 // scale
356 DocDeclStr(
357 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
358 "", "");
359
360
361 // rotate (radians)
362 DocDeclStr(
363 virtual void , Rotate( wxDouble angle ),
364 "", "");
365
366
367 //
368 // setting the paint
369 //
370
371 // sets the pan
372 DocDeclStr(
373 virtual void , SetPen( const wxPen &pen ),
374 "", "");
375
376
377 // sets the brush for filling
378 DocDeclStr(
379 virtual void , SetBrush( const wxBrush &brush ),
380 "", "");
381
382
383 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
384 DocDeclStr(
385 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
386 const wxColour&c1, const wxColour&c2),
387 "", "");
388
389
390 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
391 // with radius r and color cColor
392 DocDeclStr(
393 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
394 wxDouble radius,
395 const wxColour &oColor, const wxColour &cColor),
396 "", "");
397
398
399 // sets the font
400 DocDeclStr(
401 virtual void , SetFont( const wxFont &font ),
402 "", "");
403
404
405 // sets the text color
406 DocDeclStr(
407 virtual void , SetTextColor( const wxColour &col ),
408 "", "");
409
410
411 // strokes along a path with the current pen
412 DocDeclStr(
413 virtual void , StrokePath( const wxGraphicsPath *path ),
414 "", "");
415
416
417 // fills a path with the current brush
418 DocDeclStr(
419 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
420 "", "");
421
422
423 // draws a path by first filling and then stroking
424 DocDeclStr(
425 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
426 "", "");
427
428
429 //
430 // text
431 //
432
433 DocDeclStr(
434 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
435 "", "");
436
437
438 DocDeclStrName(
439 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
440 "", "",
441 DrawRotatedText);
442
443
444 DocDeclAStr(
445 virtual void , GetTextExtent( const wxString &text,
446 wxDouble *OUTPUT /*width*/,
447 wxDouble *OUTPUT /*height*/,
448 wxDouble *OUTPUT /*descent*/,
449 wxDouble *OUTPUT /*externalLeading*/ ) const ,
450 "GetTextExtend(self, text) --> (width, height, descent, externalLeading)",
451 "", "");
452
453
454 %extend {
455 DocAStr(GetPartialTextExtents,
456 "GetPartialTextExtents(self, text) -> [widths]",
457 "", "");
458 wxArrayDouble GetPartialTextExtents(const wxString& text) {
459 wxArrayDouble widths;
460 self->GetPartialTextExtents(text, widths);
461 return widths;
462 }
463 }
464
465
466 //
467 // image support
468 //
469
470 DocDeclStr(
471 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
472 "", "");
473
474
475 DocDeclStr(
476 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
477 "", "");
478
479
480 //
481 // convenience methods
482 //
483
484 // strokes a single line
485 DocDeclStr(
486 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
487 "", "");
488
489
490 // stroke lines connecting each of the points
491 DocDeclAStr(
492 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
493 "StrokeLines(self, List points)",
494 "", "");
495
496
497 // // stroke disconnected lines from begin to end points
498 // virtual void StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints);
499
500 %extend {
501 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
502 {
503 size_t c1, c2, count;
504 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
505 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
506
507 if ( beginP != NULL && endP != NULL )
508 {
509 count = wxMin(c1, c2);
510 self->StrokeLines(count, beginP, endP);
511 }
512 delete [] beginP;
513 delete [] endP;
514 }
515 }
516
517 // draws a polygon
518 DocDeclStr(
519 virtual void , DrawLines( size_t points, const wxPoint2D *points_array, int fillStyle = wxWINDING_RULE ),
520 "", "");
521
522
523 // draws a polygon
524 DocDeclStr(
525 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
526 "", "");
527
528
529 // draws an ellipse
530 DocDeclStr(
531 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
532 "", "");
533
534
535 // draws a rounded rectangle
536 DocDeclStr(
537 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
538 "", "");
539
540 };
541
542
543 //---------------------------------------------------------------------------
544
545 %{
546 #include "wx/dcgraph.h"
547 %}
548
549 class wxGCDC: public wxDC
550 {
551 public:
552 %pythonAppend wxGCDC
553 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
554 wxGCDC(const wxWindowDC& dc);
555 //wxGCDC();
556 virtual ~wxGCDC();
557
558 wxGraphicsContext* GetGraphicsContext();
559 virtual void SetGraphicsContext( wxGraphicsContext* ctx );
560
561 %property(GraphicsContext, GetGraphicsContext, SetGraphicsContext);
562 };
563
564
565 //---------------------------------------------------------------------------
566
567 // Turn GIL acquisition back on.
568 %threadWrapperOn
569