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