]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_graphics.i
fixed wxVsnprintf() to write as much as it can if the output buffer is too short
[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 %{
32 #if !wxUSE_GRAPHICS_CONTEXT
33 // C++ stub classes for platforms or build configurations that don't have
34 // wxGraphicsContext yet.
35
36 class wxGraphicsRenderer;
37 class wxGraphicsMatrix;
38
39
40 class wxGraphicsObject : public wxObject
41 {
42 public :
43 wxGraphicsObject() {}
44 wxGraphicsObject( wxGraphicsRenderer* ) {
45 PyErr_SetString(PyExc_NotImplementedError,
46 "wx.GraphicsObject is not available on this platform.");
47 }
48 wxGraphicsObject( const wxGraphicsObject& ) {}
49 virtual ~wxGraphicsObject() {}
50 bool IsNull() const { return false; }
51 wxGraphicsRenderer* GetRenderer() const { return NULL; }
52 } ;
53
54
55
56 class wxGraphicsPen : public wxGraphicsObject
57 {
58 public:
59 wxGraphicsPen() {}
60 virtual ~wxGraphicsPen() {}
61 } ;
62 wxGraphicsPen wxNullGraphicsPen;
63
64
65
66 class wxGraphicsBrush : public wxGraphicsObject
67 {
68 public :
69 wxGraphicsBrush() {}
70 virtual ~wxGraphicsBrush() {}
71 } ;
72 wxGraphicsBrush wxNullGraphicsBrush;
73
74
75
76 class wxGraphicsFont : public wxGraphicsObject
77 {
78 public :
79 wxGraphicsFont() {}
80 virtual ~wxGraphicsFont() {}
81 } ;
82 wxGraphicsFont wxNullGraphicsFont;
83
84
85
86 class wxGraphicsPath : public wxGraphicsObject
87 {
88 public :
89 wxGraphicsPath() { }
90 wxGraphicsPath(wxGraphicsRenderer* ) {
91 PyErr_SetString(PyExc_NotImplementedError,
92 "wx.GraphicsPath is not available on this platform.");
93 }
94 virtual ~wxGraphicsPath() {}
95
96 void MoveToPoint( wxDouble, wxDouble ) {}
97 void MoveToPoint( const wxPoint2DDouble& ) {}
98 void AddLineToPoint( wxDouble, wxDouble ) {}
99 void AddLineToPoint( const wxPoint2DDouble& ) {}
100 void AddCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, wxDouble ) {}
101 void AddCurveToPoint( const wxPoint2DDouble&, const wxPoint2DDouble&, const wxPoint2DDouble&) {}
102 void AddPath( const wxGraphicsPath& ) {}
103 void CloseSubpath() {}
104 void GetCurrentPoint( wxDouble&, wxDouble&) const {}
105 wxPoint2DDouble GetCurrentPoint() const { return wxPoint2D(0,0); }
106 void AddArc( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, bool ) {}
107 void AddArc( const wxPoint2DDouble& , wxDouble, wxDouble , wxDouble , bool ) {}
108
109 void AddQuadCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble ) {}
110 void AddRectangle( wxDouble, wxDouble, wxDouble, wxDouble ) {}
111 void AddCircle( wxDouble, wxDouble, wxDouble ) {}
112 void AddArcToPoint( wxDouble, wxDouble , wxDouble, wxDouble, wxDouble ) {}
113
114 void AddEllipse( wxDouble , wxDouble , wxDouble , wxDouble ) {}
115 void AddRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
116 void * GetNativePath() const { return NULL; }
117 void UnGetNativePath(void *) const {}
118 void Transform( const wxGraphicsMatrix& ) {}
119 void GetBox(wxDouble *, wxDouble *, wxDouble *, wxDouble *) const {}
120 wxRect2D GetBox() const { return wxRect2D(0,0,0,0); }
121
122 bool Contains( wxDouble , wxDouble , int ) const { return false; }
123 bool Contains( const wxPoint2DDouble& , int ) const { return false; }
124 };
125 wxGraphicsPath wxNullGraphicsPath;
126
127
128 class wxGraphicsMatrix : public wxGraphicsObject
129 {
130 public :
131 wxGraphicsMatrix() { }
132 wxGraphicsMatrix(wxGraphicsRenderer* ) {
133 PyErr_SetString(PyExc_NotImplementedError,
134 "wx.GraphicsMatrix is not available on this platform.");
135 }
136 virtual ~wxGraphicsMatrix() {}
137 virtual void Concat( const wxGraphicsMatrix & ) {}
138 virtual void Copy( const wxGraphicsMatrix & ) {}
139 virtual void Set(wxDouble , wxDouble , wxDouble , wxDouble ,
140 wxDouble , wxDouble ) {}
141 virtual void Get(wxDouble*, wxDouble*, wxDouble*,
142 wxDouble*, wxDouble*, wxDouble*) {}
143 virtual void Invert() {}
144 virtual bool IsEqual( const wxGraphicsMatrix& t) const { return false; }
145 virtual bool IsIdentity() const { return false; }
146 virtual void Translate( wxDouble , wxDouble ) {}
147 virtual void Scale( wxDouble , wxDouble ) {}
148 virtual void Rotate( wxDouble ) {}
149 virtual void TransformPoint( wxDouble *, wxDouble * ) const {}
150 virtual void TransformDistance( wxDouble *, wxDouble * ) const {}
151 virtual void * GetNativeMatrix() const { return NULL; }
152 };
153 wxGraphicsMatrix wxNullGraphicsMatrix;
154
155
156 class wxGraphicsContext : public wxGraphicsObject
157 {
158 public:
159
160 wxGraphicsContext(wxGraphicsRenderer* ) {
161 PyErr_SetString(PyExc_NotImplementedError,
162 "wx.GraphicsContext is not available on this platform.");
163 }
164
165 virtual ~wxGraphicsContext() {}
166
167 static wxGraphicsContext* Create() {
168 PyErr_SetString(PyExc_NotImplementedError,
169 "wx.GraphicsContext is not available on this platform.");
170 return NULL;
171 }
172 static wxGraphicsContext* Create( const wxWindowDC& ) {
173 PyErr_SetString(PyExc_NotImplementedError,
174 "wx.GraphicsContext is not available on this platform.");
175 return NULL;
176 }
177
178 static wxGraphicsContext* CreateFromNative( void * ) {
179 PyErr_SetString(PyExc_NotImplementedError,
180 "wx.GraphicsContext is not available on this platform.");
181 return NULL;
182 }
183
184 static wxGraphicsContext* CreateFromNativeWindow( void * ) {
185 PyErr_SetString(PyExc_NotImplementedError,
186 "wx.GraphicsContext is not available on this platform.");
187 return NULL;
188 }
189
190 static wxGraphicsContext* Create( wxWindow* ) {
191 PyErr_SetString(PyExc_NotImplementedError,
192 "wx.GraphicsContext is not available on this platform.");
193 return NULL;
194 }
195
196 wxGraphicsPath CreatePath() { return wxNullGraphicsPath; }
197
198 virtual wxGraphicsPen CreatePen(const wxPen& ) { return wxNullGraphicsPen; }
199
200 virtual wxGraphicsBrush CreateBrush(const wxBrush& ) { return wxNullGraphicsBrush; }
201
202 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble ,
203 const wxColour&, const wxColour&) { return wxNullGraphicsBrush; }
204
205 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo,
206 wxDouble xc, wxDouble yc, wxDouble radius,
207 const wxColour &oColor, const wxColour &cColor) { return wxNullGraphicsBrush; }
208
209 virtual wxGraphicsFont CreateFont( const wxFont &, const wxColour & ) { return wxNullGraphicsFont; }
210
211 virtual wxGraphicsMatrix CreateMatrix( wxDouble, wxDouble, wxDouble, wxDouble,
212 wxDouble, wxDouble) { return wxNullGraphicsMatrix; }
213
214 virtual void PushState() {}
215 virtual void PopState() {}
216 virtual void Clip( const wxRegion & ) {}
217 virtual void Clip( wxDouble , wxDouble , wxDouble , wxDouble ) {}
218 virtual void ResetClip() {}
219 virtual void * GetNativeContext() { return NULL; }
220 virtual int GetLogicalFunction() const { return 0; }
221 virtual bool SetLogicalFunction(int ) {}
222 virtual void Translate( wxDouble , wxDouble ) {}
223 virtual void Scale( wxDouble , wxDouble ) {}
224 virtual void Rotate( wxDouble ) {}
225 virtual void ConcatTransform( const wxGraphicsMatrix& ) {}
226 virtual void SetTransform( const wxGraphicsMatrix& ) {}
227 virtual wxGraphicsMatrix GetTransform() const { return wxNullGraphicsMatrix; }
228
229 virtual void SetPen( const wxGraphicsPen& ) {}
230 void SetPen( const wxPen& ) {}
231
232 virtual void SetBrush( const wxGraphicsBrush& ) {}
233 void SetBrush( const wxBrush& ) {}
234
235 virtual void SetFont( const wxGraphicsFont& ) {}
236 void SetFont( const wxFont&, const wxColour& ) {}
237
238 virtual void StrokePath( const wxGraphicsPath & ) {}
239 virtual void FillPath( const wxGraphicsPath &, int ) {}
240 virtual void DrawPath( const wxGraphicsPath &, int ) {}
241
242 virtual void DrawText( const wxString &, wxDouble , wxDouble ) {}
243 virtual void DrawText( const wxString &, wxDouble , wxDouble , wxDouble ) {}
244 virtual void DrawText( const wxString &, wxDouble , wxDouble , wxGraphicsBrush ) {}
245 virtual void DrawText( const wxString &, wxDouble , wxDouble , wxDouble , wxGraphicsBrush ) {}
246 virtual void GetTextExtent( const wxString &, wxDouble *, wxDouble *,
247 wxDouble *, wxDouble * ) const {}
248 virtual void GetPartialTextExtents(const wxString& , wxArrayDouble& ) const {}
249
250 virtual void DrawBitmap( const wxBitmap &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
251 virtual void DrawIcon( const wxIcon &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
252
253 virtual void StrokeLine( wxDouble , wxDouble , wxDouble , wxDouble ) {}
254 virtual void StrokeLines( size_t , const wxPoint2DDouble *) {}
255 virtual void StrokeLines( size_t , const wxPoint2DDouble *, const wxPoint2DDouble *) {}
256 virtual void DrawLines( size_t , const wxPoint2DDouble *, int ) {}
257 virtual void DrawRectangle( wxDouble , wxDouble , wxDouble , wxDouble ) {}
258 virtual void DrawEllipse( wxDouble , wxDouble , wxDouble , wxDouble ) {}
259 virtual void DrawRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
260 virtual bool ShouldOffset() const { return false; }
261 };
262
263
264 class wxGraphicsRenderer : public wxObject
265 {
266 public :
267 wxGraphicsRenderer() {
268 PyErr_SetString(PyExc_NotImplementedError,
269 "wx.GraphicsRenderer is not available on this platform.");
270 }
271
272 virtual ~wxGraphicsRenderer() {}
273
274 static wxGraphicsRenderer* GetDefaultRenderer() {
275 PyErr_SetString(PyExc_NotImplementedError,
276 "wx.GraphicsRenderer is not available on this platform.");
277 return NULL;
278 }
279
280 virtual wxGraphicsContext * CreateContext( const wxWindowDC& ) { return NULL; }
281 virtual wxGraphicsContext * CreateContextFromNativeContext( void * ) { return NULL; }
282 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * ) { return NULL; }
283 virtual wxGraphicsContext * CreateContext( wxWindow* ) { return NULL; }
284 virtual wxGraphicsContext * CreateMeasuringContext() { return NULL; }
285
286 virtual wxGraphicsPath CreatePath() { return wxNullGraphicsPath; }
287
288 virtual wxGraphicsMatrix CreateMatrix( wxDouble , wxDouble , wxDouble , wxDouble ,
289 wxDouble , wxDouble ) { return wxNullGraphicsMatrix; }
290
291 virtual wxGraphicsPen CreatePen(const wxPen& ) { return wxNullGraphicsPen; }
292 virtual wxGraphicsBrush CreateBrush(const wxBrush& ) { return wxNullGraphicsBrush; }
293 virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble , wxDouble , wxDouble , wxDouble ,
294 const wxColour&, const wxColour&) { return wxNullGraphicsBrush; }
295 virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ,
296 const wxColour &, const wxColour &) { return wxNullGraphicsBrush; }
297 virtual wxGraphicsFont CreateFont( const wxFont & , const wxColour & ) { return wxNullGraphicsFont; }
298 };
299
300
301
302 class wxGCDC: public wxWindowDC
303 {
304 public:
305 wxGCDC(const wxWindowDC&) {
306 wxPyBlock_t blocked = wxPyBeginBlockThreads();
307 PyErr_SetString(PyExc_NotImplementedError,
308 "wxGCDC is not available on this platform.");
309 wxPyEndBlockThreads(blocked);
310 }
311
312 wxGCDC(const wxWindow*) {
313 wxPyBlock_t blocked = wxPyBeginBlockThreads();
314 PyErr_SetString(PyExc_NotImplementedError,
315 "wxGCDC is not available on this platform.");
316 wxPyEndBlockThreads(blocked);
317 }
318
319 wxGCDC() {
320 wxPyBlock_t blocked = wxPyBeginBlockThreads();
321 PyErr_SetString(PyExc_NotImplementedError,
322 "wxGCDC is not available on this platform.");
323 wxPyEndBlockThreads(blocked);
324 }
325
326 virtual ~wxGCDC() {}
327
328 wxGraphicsContext* GetGraphicsContext() { return NULL; }
329 void SetGraphicsContext( wxGraphicsContext* ) {}
330 };
331
332 #endif
333 %}
334
335 //---------------------------------------------------------------------------
336 //---------------------------------------------------------------------------
337
338
339 %typemap(in) (size_t points, wxPoint2D* points_array ) {
340 $2 = wxPoint2D_LIST_helper($input, &$1);
341 if ($2 == NULL) SWIG_fail;
342 }
343 %typemap(freearg) (size_t points, wxPoint2D* points_array ) {
344 if ($2) delete [] $2;
345 }
346
347
348
349 MustHaveApp(wxGraphicsPath);
350 MustHaveApp(wxGraphicsContext);
351 MustHaveApp(wxGCDC);
352
353 //---------------------------------------------------------------------------
354
355
356 DocStr(wxGraphicsObject,
357 "This class is the superclass of native graphics objects like pens
358 etc. It provides the internal reference counting. It is not to be
359 instantiated by user code.", "");
360 class wxGraphicsObject : public wxObject
361 {
362 public :
363 wxGraphicsObject( wxGraphicsRenderer* renderer = NULL );
364 virtual ~wxGraphicsObject();
365
366 DocDeclStr(
367 bool , IsNull() const ,
368 "Is this object valid (false) or still empty (true)?", "");
369
370 DocDeclStr(
371 wxGraphicsRenderer* , GetRenderer() const,
372 "Returns the renderer that was used to create this instance, or
373 ``None`` if it has not been initialized yet.", "");
374
375 };
376
377
378 DocStr(wxGraphicsPen,
379 "A wx.GraphicsPen is a native representation of a pen. It is used for
380 stroking a path on a `wx.GraphicsContext`. The contents are specific and
381 private to the respective renderer. The only way to get a valid instance
382 is via a CreatePen call on the graphics context or the renderer
383 instance.", "");
384 class wxGraphicsPen : public wxGraphicsObject
385 {
386 public :
387 wxGraphicsPen();
388 virtual ~wxGraphicsPen();
389 };
390
391 DocStr(wxGraphicsBrush,
392 "A wx.GraphicsBrush is a native representation of a brush. It is used
393 for filling a path on a `wx.GraphicsContext`. The contents are
394 specific and private to the respective renderer. The only way to get a
395 valid instance is via a Create...Brush call on the graphics context or
396 the renderer instance.", "");
397 class wxGraphicsBrush : public wxGraphicsObject
398 {
399 public :
400 wxGraphicsBrush();
401 virtual ~wxGraphicsBrush();
402 };
403
404
405 DocStr(wxGraphicsFont,
406 "A `wx.GraphicsFont` is a native representation of a font (including
407 text colour). The contents are specific an private to the respective
408 renderer. The only way to get a valid instance is via a CreateFont
409 call on the graphics context or the renderer instance.", "");
410 class wxGraphicsFont : public wxGraphicsObject
411 {
412 public :
413 wxGraphicsFont();
414 virtual ~wxGraphicsFont();
415 };
416
417
418 //---------------------------------------------------------------------------
419
420 DocStr(wxGraphicsMatrix,
421 "A wx.GraphicsMatrix is a native representation of an affine
422 matrix. The contents are specific and private to the respective
423 renderer. The only way to get a valid instance is via a CreateMatrix
424 call on the graphics context or the renderer instance.", "");
425 class wxGraphicsMatrix : public wxGraphicsObject
426 {
427 public :
428 // wxGraphicsMatrix();
429 virtual ~wxGraphicsMatrix();
430
431 DocDeclStr(
432 virtual void , Concat( const wxGraphicsMatrix& t ),
433 "Concatenates the passed in matrix to the current matrix.", "");
434
435
436 DocDeclStr(
437 virtual void , Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
438 wxDouble tx=0.0, wxDouble ty=0.0),
439 "Sets the matrix to the specified values (default values are the
440 identity matrix.)", "");
441
442
443 DocDeclAStr(
444 virtual void , Get(wxDouble* OUTPUT, wxDouble* OUTPUT, wxDouble* OUTPUT,
445 wxDouble* OUTPUT, wxDouble* OUTPUT, wxDouble* OUTPUT),
446 "Get(self) --> (a, b, c, d, tx, ty)",
447 "Gets the component values of the matrix and returns them as a tuple.", "");
448
449
450 DocDeclStr(
451 virtual void , Invert(),
452 "Inverts the matrix.", "");
453
454
455 DocDeclStr(
456 virtual bool , IsEqual( const wxGraphicsMatrix& t) const,
457 "Returns ``True`` if the elements of the transformation matrix are
458 equal", "");
459
460
461 DocDeclStr(
462 virtual bool , IsIdentity() const,
463 "Returns ``True`` if this is the identity matrix", "");
464
465
466 DocDeclStr(
467 virtual void , Translate( wxDouble dx , wxDouble dy ),
468 "Add a translation to this matrix.", "");
469
470
471 DocDeclStr(
472 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
473 "Scales this matrix.", "");
474
475
476 DocDeclStr(
477 virtual void , Rotate( wxDouble angle ),
478 "Rotates this matrix. The angle should be specified in radians.", "");
479
480
481 DocDeclAStr(
482 virtual void , TransformPoint( wxDouble *INOUT, wxDouble *INOUT ) const,
483 "TransformPoint(self, x, y) --> (x, y)",
484 "Applies this matrix to a point, returns the resulting point values", "");
485
486
487 DocDeclAStr(
488 virtual void , TransformDistance( wxDouble *INOUT, wxDouble *INOUT ) const,
489 "TransformDistance(self, dx, dy) --> (dx, dy)",
490 "Applies this matrix to a distance (ie. performs all transforms except
491 translations)", "");
492
493
494 DocDeclStr(
495 virtual void * , GetNativeMatrix() const,
496 "Returns the native representation of the matrix. For CoreGraphics this
497 is a CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for
498 Cairo a cairo_matrix_t pointer. NOTE: For wxPython we still need a
499 way to make this value usable.", "");
500 };
501
502 //---------------------------------------------------------------------------
503
504 class wxGraphicsPath : public wxGraphicsObject
505 {
506 public :
507 // wxGraphicsPath();
508 virtual ~wxGraphicsPath();
509
510
511 %nokwargs MoveToPoint;
512 DocStr(MoveToPoint,
513 "Begins a new subpath at the specified point.", "");
514 virtual void MoveToPoint( wxDouble x, wxDouble y );
515 void MoveToPoint( const wxPoint2D& p);
516
517
518 %nokwargs AddLineToPoint;
519 DocStr(AddLineToPoint,
520 "Adds a straight line from the current point to the specified point.", "");
521 virtual void AddLineToPoint( wxDouble x, wxDouble y );
522 void AddLineToPoint( const wxPoint2D& p);
523
524
525 %nokwargs AddCurveToPoint;
526 DocStr(AddCurveToPoint,
527 "Adds a cubic Bezier curve from the current point, using two control
528 points and an end point", "");
529 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1,
530 wxDouble cx2, wxDouble cy2,
531 wxDouble x, wxDouble y );
532 void AddCurveToPoint( const wxPoint2D& c1, const wxPoint2D& c2, const wxPoint2D& e);
533
534
535
536 DocDeclStr(
537 virtual void , AddPath( const wxGraphicsPath& path ),
538 "Adds another path", "");
539
540
541 DocDeclStr(
542 virtual void , CloseSubpath(),
543 "Closes the current sub-path.", "");
544
545
546 DocDeclStr(
547 wxPoint2D , GetCurrentPoint() const,
548 "Gets the last point of the current path, (0,0) if not yet set", "");
549
550
551 %nokwargs AddArc;
552 DocStr(AddArc,
553 "Adds an arc of a circle centering at (x,y) with radius (r) from
554 startAngle to endAngle", "");
555 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r,
556 wxDouble startAngle, wxDouble endAngle, bool clockwise=true );
557 void AddArc( const wxPoint2D& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise=true);
558
559
560 DocDeclStr(
561 virtual void , AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ),
562 "Adds a quadratic Bezier curve from the current point, using a control
563 point and an end point", "");
564
565
566 DocDeclStr(
567 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
568 "Appends a rectangle as a new closed subpath.", "");
569
570
571 DocDeclStr(
572 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
573 "Appends a circle around (x,y) with radius r as a new closed subpath.", "");
574
575
576 DocDeclStr(
577 virtual void , AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ,
578 "Appends an arc to two tangents connecting (current) to (x1,y1) and
579 (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)", "");
580
581
582 DocDeclStr(
583 virtual void , AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
584 "Appends an ellipse fitting into the passed in rectangle.", "");
585
586
587 DocDeclStr(
588 virtual void , AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
589 "Appends a rounded rectangle.", "");
590
591
592 DocDeclStr(
593 virtual void * , GetNativePath() const,
594 "Returns the native path (CGPathRef for Core Graphics, Path pointer for
595 GDIPlus and a cairo_path_t pointer for cairo). NOTE: For wxPython we
596 still need a way to make this value usable.", "");
597
598
599 DocDeclStr(
600 virtual void , UnGetNativePath(void *p) const,
601 "Gives back the native path returned by GetNativePath() because there
602 might be some deallocations necessary (eg on cairo the native path
603 returned by GetNativePath is newly allocated each time).", "");
604
605
606 DocDeclStr(
607 virtual void , Transform( const wxGraphicsMatrix& matrix ),
608 "Transforms each point of this path by the matrix", "");
609
610
611 DocDeclStr(
612 wxRect2D , GetBox() const,
613 "Gets the bounding box enclosing all points (possibly including control
614 points)", "");
615
616
617 %nokwargs Contains;
618 DocStr(Contains,
619 "Returns ``True`` if the point is within the path.", "");
620 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE) const;
621 bool Contains( const wxPoint2D& c, int fillStyle = wxODDEVEN_RULE) const;
622
623 };
624
625
626 //---------------------------------------------------------------------------
627
628 %immutable;
629 const wxGraphicsPen wxNullGraphicsPen;
630 const wxGraphicsBrush wxNullGraphicsBrush;
631 const wxGraphicsFont wxNullGraphicsFont;
632 const wxGraphicsMatrix wxNullGraphicsMatrix;
633 const wxGraphicsPath wxNullGraphicsPath;
634 %mutable;
635
636 //---------------------------------------------------------------------------
637
638 DocStr(wxGraphicsContext,
639 "A `wx.GraphicsContext` instance is the object that is drawn upon. It is
640 created by a renderer using the CreateContext calls, this can be done
641 either directly using a renderer instance, or indirectly using the
642 static convenience CreateXXX functions of wx.GraphicsContext that
643 always delegate the task to the default renderer.", "");
644
645 class wxGraphicsContext : public wxGraphicsObject
646 {
647 public:
648 //wxGraphicsContext(); This is an ABC, use Create to make an instance...
649 virtual ~wxGraphicsContext();
650
651 %newobject Create;
652 %nokwargs Create;
653 %pythonAppend Create
654 "val.__dc = args[0] # save a ref so the dc will not be deleted before self";
655 DocStr(Create,
656 "Creates a wx.GraphicsContext either from a window or a DC.", "");
657 static wxGraphicsContext* Create( const wxWindowDC& dc);
658 static wxGraphicsContext* Create( wxWindow* window ) ;
659
660 DocDeclStrName(
661 static wxGraphicsContext* , Create(),
662 "Create a lightwieght context that can be used for measuring text only.", "",
663 CreateMeasuringContext);
664
665 %newobject CreateFromNative;
666 DocDeclStr(
667 static wxGraphicsContext* , CreateFromNative( void * context ) ,
668 "Creates a wx.GraphicsContext from a native context. This native
669 context must be eg a CGContextRef for Core Graphics, a Graphics
670 pointer for GDIPlus or a cairo_t pointer for Cairo. NOTE: For
671 wxPython we still need a way to make this value usable.", "");
672
673
674 %newobject CreateFromNative;
675 DocDeclStr(
676 static wxGraphicsContext* , CreateFromNativeWindow( void * window ) ,
677 "Creates a wx.GraphicsContext from a native window. NOTE: For wxPython
678 we still need a way to make this value usable.", "");
679
680
681
682 DocDeclStr(
683 virtual wxGraphicsPath , CreatePath(),
684 "Creates a native graphics path which is initially empty.", "");
685
686
687 DocDeclStr(
688 virtual wxGraphicsPen , CreatePen(const wxPen& pen),
689 "Creates a native pen from a `wx.Pen`.", "");
690
691
692 DocDeclStr(
693 virtual wxGraphicsBrush , CreateBrush(const wxBrush& brush ),
694 "Creates a native brush from a `wx.Brush`.", "");
695
696
697 DocDeclStr(
698 virtual wxGraphicsBrush ,
699 CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
700 const wxColour& c1, const wxColour& c2),
701 "Creates a native brush, having a linear gradient, starting at (x1,y1)
702 with color c1 to (x2,y2) with color c2.", "");
703
704
705 DocDeclStr(
706 virtual wxGraphicsBrush ,
707 CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
708 const wxColour &oColor, const wxColour &cColor),
709 "Creates a native brush, having a radial gradient originating at point
710 (xo,yc) with color oColour and ends on a circle around (xc,yc) with
711 radius r and color cColour.", "");
712
713
714 DocDeclStr(
715 virtual wxGraphicsFont , CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ),
716 "Creates a native graphics font from a `wx.Font` and a text colour.", "");
717
718
719 DocDeclStr(
720 virtual wxGraphicsMatrix , CreateMatrix( wxDouble a=1.0, wxDouble b=0.0,
721 wxDouble c=0.0, wxDouble d=1.0,
722 wxDouble tx=0.0, wxDouble ty=0.0),
723 "Creates a native affine transformation matrix from the passed in
724 values. The defaults result in an identity matrix.", "");
725
726
727
728 DocDeclStr(
729 virtual void , PushState(),
730 "Push the current state of the context, (ie the transformation matrix)
731 on a stack", "");
732
733
734 DocDeclStr(
735 virtual void , PopState(),
736 "Pops a stored state from the stack", "");
737
738
739 DocDeclStrName(
740 virtual void , Clip( const wxRegion &region ),
741 "Clips drawings to the region, combined to current clipping region.", "",
742 ClipRegion);
743
744
745 DocDeclStr(
746 virtual void , Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
747 "Clips drawings to the rectangle.", "");
748
749
750 DocDeclStr(
751 virtual void , ResetClip(),
752 "Resets the clipping to original shape.", "");
753
754
755 DocDeclStr(
756 virtual void * , GetNativeContext(),
757 "Returns the native context (CGContextRef for Core Graphics, Graphics
758 pointer for GDIPlus and cairo_t pointer for cairo).", "");
759
760
761 DocDeclStr(
762 virtual int , GetLogicalFunction() const,
763 "Returns the current logical function.", "");
764
765
766 DocDeclStr(
767 virtual bool , SetLogicalFunction(int function) ,
768 "Sets the current logical function, returns ``True`` if it supported", "");
769
770
771 DocDeclStr(
772 virtual void , Translate( wxDouble dx , wxDouble dy ),
773 "Translates the current transformation matrix.", "");
774
775
776 DocDeclStr(
777 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
778 "Scale the current transformation matrix of the context.", "");
779
780
781 DocDeclStr(
782 virtual void , Rotate( wxDouble angle ),
783 "Rotate the current transformation matrix of the context. ``angle`` is
784 specified in radians.", "");
785
786
787 DocDeclStr(
788 virtual void , ConcatTransform( const wxGraphicsMatrix& matrix ),
789 "Concatenates the passed in transform with the current transform of
790 this context.", "");
791
792
793 DocDeclStr(
794 virtual void , SetTransform( const wxGraphicsMatrix& matrix ),
795 "Sets the current transform of this context.", "");
796
797
798 DocDeclStr(
799 virtual wxGraphicsMatrix , GetTransform() const,
800 "Gets the current transformation matrix of this context.", "");
801
802
803
804 DocStr(SetPen, "Sets the stroke pen", "");
805 %nokwargs SetPen;
806 virtual void SetPen( const wxGraphicsPen& pen );
807 void SetPen( const wxPen& pen );
808
809
810 DocStr(SetBrush, "Sets the brush for filling", "");
811 %nokwargs SetBrush;
812 virtual void SetBrush( const wxGraphicsBrush& brush );
813 void SetBrush( const wxBrush& brush );
814
815
816 DocStr(SetFont, "Sets the font", "");
817 %nokwargs SetFont;
818 virtual void SetFont( const wxGraphicsFont& font );
819 void SetFont( const wxFont& font, const wxColour& colour = *wxBLACK);
820
821
822
823 DocDeclStr(
824 virtual void , StrokePath( const wxGraphicsPath& path ),
825 "Strokes along a path with the current pen.", "");
826
827
828 DocDeclStr(
829 virtual void , FillPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ),
830 "Fills a path with the current brush.", "");
831
832
833 DocDeclStr(
834 virtual void , DrawPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ),
835 "Draws the path by first filling and then stroking.", "");
836
837
838 %extend {
839 DocStr(DrawText,
840 "Draws a text string at the defined position.", "");
841 void DrawText( const wxString &str, wxDouble x, wxDouble y,
842 const wxGraphicsBrush& backgroundBrush = wxNullGraphicsBrush )
843 {
844 if ( !backgroundBrush.IsNull() )
845 self->DrawText(str, x, y, backgroundBrush);
846 else
847 self->DrawText(str, x, y);
848 }
849
850 DocStr(DrawRotatedText,
851 "Draws a text string at the defined position, at the specified angle,
852 which is given in radians.", "");
853 void DrawRotatedText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle,
854 const wxGraphicsBrush& backgroundBrush = wxNullGraphicsBrush )
855 {
856 if ( !backgroundBrush.IsNull() )
857 self->DrawText(str, x, y, angle, backgroundBrush);
858 else
859 self->DrawText(str, x, y, angle);
860 }
861 }
862
863
864
865 DocDeclAStrName(
866 virtual void , GetTextExtent( const wxString &text,
867 wxDouble *OUTPUT /*width*/,
868 wxDouble *OUTPUT /*height*/,
869 wxDouble *OUTPUT /*descent*/,
870 wxDouble *OUTPUT /*externalLeading*/ ) const ,
871 "GetFullTextExtent(self, text) --> (width, height, descent, externalLeading)",
872 "Gets the dimensions of the string using the currently selected
873 font. ``text`` is the string to measure, ``w`` and ``h`` are the total
874 width and height respectively, ``descent`` is the dimension from the
875 baseline of the font to the bottom of the descender, and
876 ``externalLeading`` is any extra vertical space added to the font by
877 the font designer (usually is zero).", "",
878 GetFullTextExtent);
879
880 %extend {
881 DocAStr(GetTextExtent,
882 "GetTextExtent(self, text) --> (width, height)",
883 "Gets the dimensions of the string using the currently selected
884 font. ``text`` is the string to measure, ``w`` and ``h`` are the total
885 width and height respectively.", "");
886
887 PyObject* GetTextExtent( const wxString &text )
888 {
889 wxDouble width = 0.0,
890 height = 0.0;
891 self->GetTextExtent(text, &width, &height, NULL, NULL);
892 // thread wrapers are turned off for this .i file, so no need to acquire GIL...
893 PyObject* rv = PyTuple_New(2);
894 PyTuple_SET_ITEM(rv, 0, PyFloat_FromDouble(width));
895 PyTuple_SET_ITEM(rv, 1, PyFloat_FromDouble(height));
896 return rv;
897 }
898 }
899
900
901 %extend {
902 DocAStr(GetPartialTextExtents,
903 "GetPartialTextExtents(self, text) -> [widths]",
904 "Returns a list of widths from the beginning of ``text`` to the
905 coresponding character in ``text``.", "");
906 wxArrayDouble GetPartialTextExtents(const wxString& text) {
907 wxArrayDouble widths;
908 self->GetPartialTextExtents(text, widths);
909 return widths;
910 }
911 }
912
913
914 DocDeclStr(
915 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
916 "Draws the bitmap. In case of a mono bitmap, this is treated as a mask
917 and the current brush is used for filling.", "");
918
919
920 DocDeclStr(
921 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
922 "Draws the icon.", "");
923
924
925
926 DocDeclStr(
927 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
928 "Strokes a single line.", "");
929
930
931 DocDeclAStr(
932 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
933 "StrokeLines(self, List points)",
934 "Stroke lines connecting each of the points", "");
935
936
937 %extend {
938 DocAStr(StrokeLineSegements,
939 "StrokeLineSegments(self, List beginPoints, List endPoints)",
940 "Stroke disconnected lines from begin to end points", "");
941 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
942 {
943 size_t c1, c2, count;
944 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
945 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
946
947 if ( beginP != NULL && endP != NULL )
948 {
949 count = wxMin(c1, c2);
950 self->StrokeLines(count, beginP, endP);
951 }
952 delete [] beginP;
953 delete [] endP;
954 }
955 }
956
957
958 DocDeclStr(
959 virtual void , DrawLines( size_t points, const wxPoint2D *points_array,
960 int fillStyle = wxODDEVEN_RULE ),
961 "Draws a polygon.", "");
962
963
964 DocDeclStr(
965 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
966 "Draws a rectangle.", "");
967
968
969 DocDeclStr(
970 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
971 "Draws an ellipse.", "");
972
973
974 DocDeclStr(
975 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
976 "Draws a rounded rectangle", "");
977
978
979
980 DocDeclStr(
981 virtual bool , ShouldOffset() const,
982 "helper to determine if a 0.5 offset should be applied for the drawing operation", "");
983
984 };
985
986
987 //---------------------------------------------------------------------------
988
989 class wxGraphicsRenderer : public wxObject
990 {
991 public :
992 // wxGraphicsRenderer(); This is an ABC, use GetDefaultRenderer
993
994 virtual ~wxGraphicsRenderer();
995
996 // %newobject GetDefaultRenderer; ???
997 static wxGraphicsRenderer* GetDefaultRenderer();
998
999 %nokwargs CreateContext;
1000 %newobject CreateContext;
1001 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) ;
1002 virtual wxGraphicsContext * CreateContext( wxWindow* window );
1003
1004 // create a context that can be used for measuring texts only, no drawing allowed
1005 virtual wxGraphicsContext * CreateMeasuringContext();
1006
1007 %newobject CreateContextFromNativeContext;
1008 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context );
1009
1010 %newobject CreateContextFromNativeWindow;
1011 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window );
1012
1013
1014 virtual wxGraphicsPath CreatePath();
1015
1016 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
1017 wxDouble tx=0.0, wxDouble ty=0.0);
1018
1019 virtual wxGraphicsPen CreatePen(const wxPen& pen) ;
1020
1021 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) ;
1022
1023 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
1024 const wxColour&c1, const wxColour&c2);
1025
1026 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
1027 const wxColour &oColor, const wxColour &cColor);
1028
1029 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK );
1030
1031 };
1032
1033
1034
1035 //---------------------------------------------------------------------------
1036
1037 %{
1038 #include "wx/dcgraph.h"
1039 %}
1040
1041 class wxGCDC: public wxDC
1042 {
1043 public:
1044 %nokwargs wxGCDC;
1045 %pythonAppend wxGCDC
1046 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
1047 wxGCDC(const wxWindowDC& dc);
1048 wxGCDC(wxWindow* window);
1049 //wxGCDC();
1050 virtual ~wxGCDC();
1051
1052 wxGraphicsContext* GetGraphicsContext();
1053 virtual void SetGraphicsContext( wxGraphicsContext* ctx );
1054
1055 %property(GraphicsContext, GetGraphicsContext, SetGraphicsContext);
1056 };
1057
1058
1059 //---------------------------------------------------------------------------
1060
1061 // Turn GIL acquisition back on.
1062 %threadWrapperOn
1063