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