]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_graphics.i
UpdatePulse --> Pulse
[wxWidgets.git] / wxPython / src / _graphics.i
CommitLineData
6d61d718
RD
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
281c54cc
RD
23// Turn off the aquisition of the Global Interpreter Lock for the classes and
24// functions in this file
25%threadWrapperOff
26
6d61d718
RD
27//---------------------------------------------------------------------------
28
29
30%{
31#if !wxUSE_GRAPHICS_CONTEXT
32// C++ stub classes for platforms that don't have wxGraphicsContext yet.
33
34class wxGraphicsPath
35{
36public :
37 wxGraphicsPath() {
38 wxPyBlock_t blocked = wxPyBeginBlockThreads();
39 PyErr_SetString(PyExc_NotImplementedError,
40 "wxGraphicsPath is not available on this platform.");
41 wxPyEndBlockThreads(blocked);
42 }
43 virtual ~wxGraphicsPath() {}
44
45 void MoveToPoint( wxDouble, wxDouble ) {}
46 void AddLineToPoint( wxDouble, wxDouble ) {}
47 void AddCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, wxDouble ) {}
48 void CloseSubpath() {}
49 void GetCurrentPoint( wxDouble&, wxDouble&) {}
50 void AddArc( wxDouble, wxDouble, wxDouble, wxDouble, wxDouble, bool ) {}
51
52 void AddQuadCurveToPoint( wxDouble, wxDouble, wxDouble, wxDouble ) {}
53 void AddRectangle( wxDouble, wxDouble, wxDouble, wxDouble ) {}
54 void AddCircle( wxDouble, wxDouble, wxDouble ) {}
55 void AddArcToPoint( wxDouble, wxDouble , wxDouble, wxDouble, wxDouble ) {}
56
57 wxPoint2DDouble GetCurrentPoint() { return wxPoint2DDouble(0,0); }
58 void MoveToPoint( const wxPoint2DDouble& ) {}
59 void AddLineToPoint( const wxPoint2DDouble&) {}
60 void AddCurveToPoint( const wxPoint2DDouble&, const wxPoint2DDouble&, const wxPoint2DDouble&) {}
61 void AddArc( const wxPoint2DDouble&, wxDouble, wxDouble, wxDouble, bool) {}
62};
63
64
65class wxGraphicsContext
66{
67public:
68 wxGraphicsContext() {
69 wxPyBlock_t blocked = wxPyBeginBlockThreads();
70 PyErr_SetString(PyExc_NotImplementedError,
71 "wxGraphicsContext is not available on this platform.");
72 wxPyEndBlockThreads(blocked);
73 }
74 virtual ~wxGraphicsContext() {}
75
76 static wxGraphicsContext* Create( const wxWindowDC&) {
77 wxPyBlock_t blocked = wxPyBeginBlockThreads();
78 PyErr_SetString(PyExc_NotImplementedError,
79 "wxGraphicsPath is not available on this platform.");
80 wxPyEndBlockThreads(blocked);
81 return NULL;
82 }
b876c1e4
RD
83
84 static wxGraphicsContext* CreateFromNative( void * ) {
85 wxPyBlock_t blocked = wxPyBeginBlockThreads();
86 PyErr_SetString(PyExc_NotImplementedError,
87 "wxGraphicsContext is not available on this platform.");
88 wxPyEndBlockThreads(blocked);
89 return NULL;
90 }
91
050441c8 92 wxGraphicsPath * CreatePath() { return NULL; }
6d61d718
RD
93 void PushState() {}
94 void PopState() {}
95 void Clip( const wxRegion & ) {}
b876c1e4
RD
96 void Clip( wxDouble, wxDouble, wxDouble, wxDouble ) {}
97 void ResetClip() {}
98 void * GetNativeContext() { return NULL; }
6d61d718
RD
99 void Translate( wxDouble , wxDouble ) {}
100 void Scale( wxDouble , wxDouble ) {}
101 void Rotate( wxDouble ) {}
102 void SetPen( const wxPen & ) {}
103 void SetBrush( const wxBrush & ) {}
104 void SetLinearGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble ,
105 const wxColour&, const wxColour&) {}
106 void SetRadialGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ,
107 const wxColour &, const wxColour &) {}
108 void SetFont( const wxFont & ) {}
109 void SetTextColor( const wxColour & ) {}
110 void StrokePath( const wxGraphicsPath * ) {}
111 void FillPath( const wxGraphicsPath *, int ) {}
112 void DrawPath( const wxGraphicsPath *, int ) {}
113 void DrawText( const wxString &, wxDouble , wxDouble ) {}
114 void DrawText( const wxString &, wxDouble , wxDouble , wxDouble ) {}
115 void GetTextExtent( const wxString &, wxDouble *, wxDouble *,
116 wxDouble *, wxDouble * ) const {}
117 void GetPartialTextExtents(const wxString& , wxArrayDouble& ) const {}
118 void DrawBitmap( const wxBitmap &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
119 void DrawIcon( const wxIcon &, wxDouble , wxDouble , wxDouble , wxDouble ) {}
120 void StrokeLine( wxDouble , wxDouble , wxDouble , wxDouble ) {}
121 void StrokeLines( size_t , const wxPoint2DDouble *) {}
122 void StrokeLines( size_t , const wxPoint2DDouble *, const wxPoint2DDouble *) {}
123 void DrawLines( size_t , const wxPoint2DDouble *, int ) {}
124 void DrawRectangle( wxDouble , wxDouble , wxDouble , wxDouble ) {}
125 void DrawEllipse( wxDouble , wxDouble, wxDouble , wxDouble) {}
126 void DrawRoundedRectangle( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ) {}
127};
128
129
130class wxGCDC: public wxWindowDC
131{
132public:
133 wxGCDC(const wxWindowDC&) {
134 wxPyBlock_t blocked = wxPyBeginBlockThreads();
135 PyErr_SetString(PyExc_NotImplementedError,
136 "wxGCDC is not available on this platform.");
137 wxPyEndBlockThreads(blocked);
138 }
139
140 wxGCDC() {
141 wxPyBlock_t blocked = wxPyBeginBlockThreads();
142 PyErr_SetString(PyExc_NotImplementedError,
143 "wxGCDC is not available on this platform.");
144 wxPyEndBlockThreads(blocked);
145 }
146
147 virtual ~wxGCDC() {}
148
b876c1e4
RD
149 wxGraphicsContext* GetGraphicsContext() { return NULL; }
150 void SetGraphicsContext( wxGraphicsContext* ) {}
6d61d718
RD
151};
152
153#endif
154%}
155
156//---------------------------------------------------------------------------
157//---------------------------------------------------------------------------
158
281c54cc
RD
159
160%typemap(in) (size_t points, wxPoint2D* points_array ) {
161 $2 = wxPoint2D_LIST_helper($input, &$1);
162 if ($2 == NULL) SWIG_fail;
163}
164%typemap(freearg) (size_t points, wxPoint2D* points_array ) {
165 if ($2) delete [] $2;
166}
167
168
169
6d61d718
RD
170MustHaveApp(wxGraphicsPath);
171MustHaveApp(wxGraphicsContext);
172MustHaveApp(wxGCDC);
173
174//#define wxDouble double
175typedef double wxDouble;
176
177
178// TODO: Decide which of the overloaded methods should use the primary names
179
180class wxGraphicsPath
181{
182public :
183 //wxGraphicsPath(); *** This class is an ABC, so we can't allow instances to be created directly
184 virtual ~wxGraphicsPath();
185
186
187 DocDeclStr(
188 virtual void , MoveToPoint( wxDouble x, wxDouble y ),
189 "Begins a new subpath at (x,y)", "");
190// void MoveToPoint( const wxPoint2D& p);
191
192
193 DocDeclStr(
194 virtual void , AddLineToPoint( wxDouble x, wxDouble y ),
195 "Adds a straight line from the current point to (x,y) ", "");
196// void AddLineToPoint( const wxPoint2D& p);
197
198
199 DocDeclStr(
200 virtual void , AddCurveToPoint( wxDouble cx1, wxDouble cy1,
201 wxDouble cx2, wxDouble cy2,
202 wxDouble x, wxDouble y ),
203 "Adds a cubic Bezier curve from the current point, using two control
204points and an end point", "");
205// void AddCurveToPoint( const wxPoint2D& c1, const wxPoint2D& c2, const wxPoint2D& e);
206
207
208 DocDeclStr(
209 virtual void , CloseSubpath(),
210 "closes the current sub-path", "");
211
212
213 //virtual void , GetCurrentPoint( wxDouble& x, wxDouble&y),
214 DocDeclStr(
215 wxPoint2D , GetCurrentPoint(),
216 "Gets the last point of the current path, (0,0) if not yet set", "");
217
218
219 DocDeclStr(
220 virtual void , AddArc( wxDouble x, wxDouble y, wxDouble r,
221 wxDouble startAngle, wxDouble endAngle, bool clockwise ),
222 "Adds an arc of a circle centering at (x,y) with radius (r) from
223startAngle to endAngle", "");
224// void AddArc( const wxPoint2D& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
225
226
227 DocDeclStr(
228 virtual void , AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ),
229 "Adds a quadratic Bezier curve from the current point, using a control
230point and an end point", "");
231
232
233 DocDeclStr(
234 virtual void , AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
235 "Appends a rectangle as a new closed subpath", "");
236
237
238 DocDeclStr(
239 virtual void , AddCircle( wxDouble x, wxDouble y, wxDouble r ),
281c54cc 240 "Appends a circle as a new closed subpath with the given radius.", "");
6d61d718
RD
241
242
243 DocDeclStr(
244 virtual void , AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ,
245 "Draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1)
246to (x2,y2), also a straight line from (current) to (x1,y1)", "");
247
248
249};
250
8292b82b
RD
251//---------------------------------------------------------------------------
252
253/*
254class wxGraphicsMatrix
255{
256public :
257 wxGraphicsMatrix() {}
258
259 virtual ~wxGraphicsMatrix() {}
260
261 wxGraphicsMatrix* Concat( const wxGraphicsMatrix *t ) const;
262
263 // returns the inverse matrix
264 wxGraphicsMatrix* Invert() const;
265
266 // returns true if the elements of the transformation matrix are equal ?
267 bool operator==(const wxGraphicsMatrix& t) const;
268
269 // return true if this is the identity matrix
270 bool IsIdentity();
271
272 //
273 // transformation
274 //
275
276 // translate
277 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
278
279 // scale
280 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
281
282 // rotate (radians)
283 virtual void Rotate( wxDouble angle ) = 0;
284} ;
285*/
286
287
6d61d718
RD
288//---------------------------------------------------------------------------
289
290
291class wxGraphicsContext
292{
293public:
294 // wxGraphicsContext() This is also an ABC, use Create to make an instance...
295 virtual ~wxGraphicsContext();
8292b82b
RD
296
297 %nokwargs Create;
298 %pythonAppend Create( const wxWindowDC& dc)
0e4e6012 299 "val.__dc = args[0] # save a ref so the other dc will not be deleted before self";
6d61d718 300 static wxGraphicsContext* Create( const wxWindowDC& dc);
8292b82b
RD
301
302 static wxGraphicsContext* Create( wxWindow* window ) ;
303
304 static wxGraphicsContext* CreateFromNative( void * context ) ;
305
6d61d718
RD
306
307 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
308 DocDeclStr(
309 virtual wxGraphicsPath * , CreatePath(),
310 "", "");
311
8292b82b
RD
312 /*
313 // create a 'native' matrix corresponding to these values
314 virtual wxGraphicsMatrix* CreateMatrix( wxDouble a=1.0, wxDouble b=0.0,
315 wxDouble c=0.0, wxDouble d=1.0,
316 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
317 */
6d61d718 318
8292b82b 319
6d61d718
RD
320 // push the current state of the context, ie the transformation matrix on a stack
321 DocDeclStr(
322 virtual void , PushState(),
323 "", "");
324
325
326 // pops a stored state from the stack
327 DocDeclStr(
328 virtual void , PopState(),
329 "", "");
330
331
332 // clips drawings to the region
8292b82b 333 DocDeclStrName(
6d61d718 334 virtual void , Clip( const wxRegion &region ),
8292b82b
RD
335 "", "",
336 ClipRegion);
337
338 // clips drawings to the rect
339 DocDeclStr(
340 virtual void , Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
341 "", "");
342
343
344 // resets the clipping to original extent
345 DocDeclStr(
346 virtual void , ResetClip(),
6d61d718
RD
347 "", "");
348
349
8292b82b
RD
350 // returns the native context
351 DocDeclStr(
352 virtual void * , GetNativeContext(),
353 "", "");
354
355
356
6d61d718 357 //
8292b82b 358 // transformation: changes the current transformation matrix CTM of the context
6d61d718
RD
359 //
360
361 // translate
362 DocDeclStr(
363 virtual void , Translate( wxDouble dx , wxDouble dy ),
364 "", "");
365
366
367 // scale
368 DocDeclStr(
369 virtual void , Scale( wxDouble xScale , wxDouble yScale ),
370 "", "");
371
372
373 // rotate (radians)
374 DocDeclStr(
375 virtual void , Rotate( wxDouble angle ),
376 "", "");
377
378
379 //
380 // setting the paint
381 //
382
383 // sets the pan
384 DocDeclStr(
385 virtual void , SetPen( const wxPen &pen ),
386 "", "");
387
388
389 // sets the brush for filling
390 DocDeclStr(
391 virtual void , SetBrush( const wxBrush &brush ),
392 "", "");
393
394
395 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
396 DocDeclStr(
397 virtual void , SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
398 const wxColour&c1, const wxColour&c2),
399 "", "");
400
401
402 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
403 // with radius r and color cColor
404 DocDeclStr(
405 virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
406 wxDouble radius,
407 const wxColour &oColor, const wxColour &cColor),
408 "", "");
409
410
411 // sets the font
412 DocDeclStr(
413 virtual void , SetFont( const wxFont &font ),
414 "", "");
415
416
417 // sets the text color
418 DocDeclStr(
419 virtual void , SetTextColor( const wxColour &col ),
420 "", "");
421
422
423 // strokes along a path with the current pen
424 DocDeclStr(
425 virtual void , StrokePath( const wxGraphicsPath *path ),
426 "", "");
427
428
429 // fills a path with the current brush
430 DocDeclStr(
431 virtual void , FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
432 "", "");
433
434
435 // draws a path by first filling and then stroking
436 DocDeclStr(
437 virtual void , DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ),
438 "", "");
439
440
441 //
442 // text
443 //
444
445 DocDeclStr(
446 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y ),
447 "", "");
448
449
281c54cc 450 DocDeclStrName(
6d61d718 451 virtual void , DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ),
281c54cc
RD
452 "", "",
453 DrawRotatedText);
6d61d718
RD
454
455
281c54cc 456 DocDeclAStr(
6d61d718
RD
457 virtual void , GetTextExtent( const wxString &text,
458 wxDouble *OUTPUT /*width*/,
459 wxDouble *OUTPUT /*height*/,
460 wxDouble *OUTPUT /*descent*/,
461 wxDouble *OUTPUT /*externalLeading*/ ) const ,
281c54cc 462 "GetTextExtend(self, text) --> (width, height, descent, externalLeading)",
6d61d718
RD
463 "", "");
464
465
281c54cc
RD
466 %extend {
467 DocAStr(GetPartialTextExtents,
468 "GetPartialTextExtents(self, text) -> [widths]",
469 "", "");
470 wxArrayDouble GetPartialTextExtents(const wxString& text) {
471 wxArrayDouble widths;
472 self->GetPartialTextExtents(text, widths);
473 return widths;
474 }
475 }
6d61d718
RD
476
477
478 //
479 // image support
480 //
481
482 DocDeclStr(
483 virtual void , DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
484 "", "");
485
486
487 DocDeclStr(
488 virtual void , DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ),
489 "", "");
490
491
492 //
493 // convenience methods
494 //
495
496 // strokes a single line
497 DocDeclStr(
498 virtual void , StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2),
499 "", "");
6d61d718 500
281c54cc 501
6d61d718 502 // stroke lines connecting each of the points
281c54cc
RD
503 DocDeclAStr(
504 virtual void , StrokeLines( size_t points, const wxPoint2D *points_array),
505 "StrokeLines(self, List points)",
6d61d718
RD
506 "", "");
507
508
281c54cc
RD
509// // stroke disconnected lines from begin to end points
510// virtual void StrokeLines( size_t n, const wxPoint2D *beginPoints, const wxPoint2D *endPoints);
511
281c54cc 512 %extend {
aa43bcc7 513 void StrokeLineSegements(PyObject* beginPoints, PyObject* endPoints)
281c54cc
RD
514 {
515 size_t c1, c2, count;
516 wxPoint2D* beginP = wxPoint2D_LIST_helper(beginPoints, &c1);
517 wxPoint2D* endP = wxPoint2D_LIST_helper(endPoints, &c2);
518
519 if ( beginP != NULL && endP != NULL )
520 {
521 count = wxMin(c1, c2);
522 self->StrokeLines(count, beginP, endP);
523 }
524 delete [] beginP;
525 delete [] endP;
526 }
527 }
6d61d718
RD
528
529 // draws a polygon
530 DocDeclStr(
281c54cc 531 virtual void , DrawLines( size_t points, const wxPoint2D *points_array, int fillStyle = wxWINDING_RULE ),
6d61d718
RD
532 "", "");
533
534
535 // draws a polygon
536 DocDeclStr(
537 virtual void , DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
538 "", "");
539
540
541 // draws an ellipse
542 DocDeclStr(
543 virtual void , DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h),
544 "", "");
545
546
547 // draws a rounded rectangle
548 DocDeclStr(
549 virtual void , DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius),
550 "", "");
551
6d61d718
RD
552};
553
554
555//---------------------------------------------------------------------------
556
6240681f
RD
557%{
558#include "wx/dcgraph.h"
559%}
6d61d718
RD
560
561class wxGCDC: public wxDC
562{
563public:
0e4e6012
RD
564 %pythonAppend wxGCDC
565 "self.__dc = args[0] # save a ref so the other dc will not be deleted before self";
6d61d718
RD
566 wxGCDC(const wxWindowDC& dc);
567 //wxGCDC();
568 virtual ~wxGCDC();
569
8292b82b
RD
570 wxGraphicsContext* GetGraphicsContext();
571 virtual void SetGraphicsContext( wxGraphicsContext* ctx );
572
573 %property(GraphicsContext, GetGraphicsContext, SetGraphicsContext);
6d61d718
RD
574};
575
576
281c54cc 577//---------------------------------------------------------------------------
6d61d718 578
281c54cc
RD
579// Turn GIL acquisition back on.
580%threadWrapperOn
6d61d718 581