Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / XS / GraphicsContext.xs
1 #############################################################################
2 ## Name:        XS/GraphicsContext.xs
3 ## Purpose:     XS for Wx::GraphicsContext
4 ## Author:      Klaas Hartmann
5 ## Modified by:
6 ## Created:     29/06/2007
7 ## RCS-ID:      $Id: GraphicsContext.xs 2523 2009-02-04 23:50:57Z mbarbon $
8 ## Copyright:   (c) 2007, 2009 Klaas Hartmann
9 ## Licence:     This program is free software; you can redistribute it and/or
10 ##              modify it under the same terms as Perl itself
11 #############################################################################
12
13 #if wxUSE_GRAPHICS_CONTEXT
14
15 #include <wx/graphics.h>
16 #include <wx/window.h>
17 #include "cpp/streams.h"
18 #include "cpp/overload.h"
19
20 MODULE=Wx PACKAGE=Wx::GraphicsContext
21
22 void
23 Create ( ... )
24   PPCODE:
25     BEGIN_OVERLOAD()
26         MATCH_REDISP_FUNCTION(wxPliOvl_wwin, Wx::GraphicsContext::createFromWindow)
27         MATCH_REDISP_FUNCTION(wxPliOvl_wdc, Wx::GraphicsContext::createFromDC)
28     END_OVERLOAD( "Wx::GraphicsContext::Create" )
29
30 wxGraphicsContext* 
31 createFromWindow ( window )
32     wxWindow* window
33   CODE:
34     RETVAL = wxGraphicsContext::Create( window );
35   OUTPUT: RETVAL
36
37 wxGraphicsContext* 
38 createFromDC (dc )
39     wxWindowDC* dc
40   CODE:
41     RETVAL = wxGraphicsContext::Create(*dc);
42   OUTPUT: RETVAL
43
44 wxGraphicsPen*  
45 wxGraphicsContext::CreatePen ( pen )
46     wxPen* pen
47   CODE:
48     RETVAL = new wxGraphicsPen( THIS->CreatePen(*pen) );
49   OUTPUT: RETVAL
50
51 wxGraphicsBrush*
52 wxGraphicsContext::CreateBrush ( brush )
53     wxBrush* brush
54   CODE:
55     RETVAL = new wxGraphicsBrush( THIS->CreateBrush(*brush) );
56   OUTPUT: RETVAL
57
58 wxGraphicsBrush*
59 wxGraphicsContext::CreateRadialGradientBrush (xo,yo,xc,yc,radius,oColor, cColor)
60     wxDouble xo
61     wxDouble yo
62     wxDouble xc
63     wxDouble yc
64     wxDouble radius
65     wxColour* oColor
66     wxColour* cColor
67   CODE:
68     RETVAL = new wxGraphicsBrush( THIS->CreateRadialGradientBrush(xo,yo,xc,yc,radius,*oColor,*cColor) );
69   OUTPUT: RETVAL
70
71 wxGraphicsBrush*
72 wxGraphicsContext::CreateLinearGradientBrush (x1,y1,x2,y2,c1,c2)
73     wxDouble x1
74     wxDouble y1
75     wxDouble x2
76     wxDouble y2
77     wxColour* c1
78     wxColour* c2
79   CODE:
80     RETVAL = new wxGraphicsBrush( THIS->CreateLinearGradientBrush(x1,y1,x2,y2,*c1,*c2) );
81   OUTPUT: RETVAL
82
83 wxGraphicsFont* 
84 wxGraphicsContext::CreateFont (font, col = (wxColour*)wxBLACK )
85     wxFont* font
86     wxColour* col
87   CODE:
88     RETVAL = new wxGraphicsFont( THIS->CreateFont(*font, *col) );
89   OUTPUT: RETVAL
90
91 wxGraphicsMatrix* 
92 wxGraphicsContext::CreateMatrix ( a = 1.0, b = 0.0, c = 0.0, d = 1.0, tx = 0.0, ty = 0.0)
93     wxDouble a
94     wxDouble b
95     wxDouble c
96     wxDouble d
97     wxDouble tx
98     wxDouble ty
99   CODE:
100     RETVAL = new wxGraphicsMatrix( THIS->CreateMatrix(a,b,c,d,tx,ty) );
101   OUTPUT: RETVAL
102
103 wxGraphicsPath* 
104 wxGraphicsContext::CreatePath ()
105   CODE:
106       RETVAL = new wxGraphicsPath( THIS->CreatePath() );
107   OUTPUT: RETVAL
108
109 # DECLARE_OVERLOAD( wrgn, Wx::Region )
110
111 void
112 Clip ( ... )
113   PPCODE:
114     BEGIN_OVERLOAD()
115         MATCH_REDISP(wxPliOvl_n_n_n_n, ClipXYWH)
116         MATCH_REDISP(wxPliOvl_wrgn, ClipRegion)
117     END_OVERLOAD( "Wx::GraphicsContext::Clip" )
118
119 void
120 wxGraphicsContext::ClipXYWH (x, y, w, h)
121     wxDouble x
122     wxDouble y
123     wxDouble w
124     wxDouble h
125   CODE:
126     THIS->Clip (x, y, w, h);
127
128 void
129 wxGraphicsContext::ClipRegion (region)
130     wxRegion* region
131   CODE:
132     THIS->Clip (*region);
133
134 void
135 wxGraphicsContext::ResetClip ()
136
137 void 
138 wxGraphicsContext::DrawBitmap (bitmap, x, y, w, h)
139     wxBitmap* bitmap
140     wxDouble x
141     wxDouble y
142     wxDouble w
143     wxDouble h
144   CODE:
145     THIS->DrawBitmap( *bitmap, x, y, w, h );
146
147 void 
148 wxGraphicsContext::DrawEllipse(x, y, w, h)
149     wxDouble x
150     wxDouble y
151     wxDouble w
152     wxDouble h
153
154 void 
155 wxGraphicsContext::DrawIcon(icon, x, y, w, h)
156     wxIcon* icon
157     wxDouble x
158     wxDouble y
159     wxDouble w
160     wxDouble h
161   CODE:
162     THIS->DrawIcon( *icon, x, y, w, h );
163
164 void
165 wxGraphicsContext::DrawLines ( points, fillStyle = wxODDEVEN_RULE )
166     SV* points
167     wxPolygonFillMode fillStyle
168   CODE:
169     wxPliArrayGuard<wxPoint2DDouble> newPoints;
170     int n = wxPli_av_2_point2ddoublearray(aTHX_ points, newPoints.lvalue());
171     THIS->DrawLines(n,newPoints);
172
173 void 
174 wxGraphicsContext::DrawPath (path, fillStyle = wxODDEVEN_RULE)
175     wxGraphicsPath *path
176     wxPolygonFillMode fillStyle
177   CODE:
178     THIS->DrawPath( *path, fillStyle );
179
180 void 
181 wxGraphicsContext::DrawRectangle (x, y, w, h)
182     wxDouble x
183     wxDouble y
184     wxDouble w
185     wxDouble h
186
187 void 
188 wxGraphicsContext::DrawRoundedRectangle (x, y, w, h, radius)
189     wxDouble x
190     wxDouble y
191     wxDouble w
192     wxDouble h
193     wxDouble radius
194
195 void
196 wxGraphicsContext::DrawText ( ... )
197   PPCODE:
198     BEGIN_OVERLOAD()
199       MATCH_REDISP(wxPliOvl_s_n_n_n, DrawTextAngle)
200       MATCH_REDISP(wxPliOvl_s_n_n, DrawTextNoAngle)
201     END_OVERLOAD( "Wx::GraphicsContext::DrawText" )
202
203 void
204 wxGraphicsContext::DrawTextAngle ( string, x, y, angle )
205     wxString string
206     wxDouble x
207     wxDouble y
208     wxDouble angle
209   CODE:
210     THIS->DrawText(string,x,y,angle);
211
212 void
213 wxGraphicsContext::DrawTextNoAngle ( string, x, y )
214     wxString string
215     wxDouble x
216     wxDouble y
217   CODE:
218     THIS->DrawText(string,x,y);
219
220 void
221 wxGraphicsContext::FillPath (path, fillStyle = wxODDEVEN_RULE)
222     wxGraphicsPath *path
223     wxPolygonFillMode fillStyle
224   CODE:
225     THIS->FillPath ( *path, fillStyle );
226
227 void
228 wxGraphicsContext::StrokePath ( path )
229     wxGraphicsPath *path;
230   CODE:
231     THIS->StrokePath ( *path );
232
233 ## Adapted from wxDC
234
235 void
236 wxGraphicsContext::GetTextExtent( string )
237     wxString string
238   PREINIT:
239     wxDouble x, y, descent, externalLeading;
240   PPCODE:
241     THIS->GetTextExtent( string, &x, &y, &descent, &externalLeading);
242     EXTEND( SP, 4 );
243     PUSHs( sv_2mortal( newSVnv( x ) ) );
244     PUSHs( sv_2mortal( newSVnv( y ) ) );
245     PUSHs( sv_2mortal( newSVnv( descent ) ) );
246     PUSHs( sv_2mortal( newSVnv( externalLeading ) ) );
247
248  # Adapted from wxDC
249
250 void
251 wxGraphicsContext::GetPartialTextExtents( string )
252     wxString string
253   PREINIT:
254     wxArrayDouble widths;
255   PPCODE:
256     THIS->GetPartialTextExtents( string, widths );
257     PUTBACK;
258     wxPli_doublearray_push( aTHX_ widths );
259     SPAGAIN;
260
261 void
262 wxGraphicsContext::Rotate ( angle )
263     wxDouble angle
264
265 void
266 wxGraphicsContext::Scale ( x, y )
267     wxDouble x
268     wxDouble y
269
270 void 
271 wxGraphicsContext::Translate ( x, y )
272     wxDouble x
273     wxDouble y
274
275 wxGraphicsMatrix*
276 wxGraphicsContext::GetTransform ()
277   CODE:
278     RETVAL = new wxGraphicsMatrix( THIS->GetTransform() );
279   OUTPUT: RETVAL
280
281 void 
282 wxGraphicsContext::SetTransform (matrix)
283     wxGraphicsMatrix* matrix
284   CODE:
285     THIS->SetTransform(*matrix);
286
287 void
288 wxGraphicsContext::ConcatTransform (matrix)
289     wxGraphicsMatrix* matrix
290   CODE:
291     THIS->ConcatTransform(*matrix);
292
293 # DECLARE_OVERLOAD( wbru, Wx::Brush )
294 # DECLARE_OVERLOAD( wgbr, Wx::GraphicsBrush )
295 # DECLARE_OVERLOAD( wfon, Wx::Font )
296 # DECLARE_OVERLOAD( wgfo, Wx::GraphicsFont )
297 # DECLARE_OVERLOAD( wpen, Wx::Pen )
298 # DECLARE_OVERLOAD( wgpe, Wx::GraphicsPen )
299 # DECLARE_OVERLOAD( wcol, Wx::Colour )
300
301 void
302 SetBrush ( ... )
303   PPCODE:
304     BEGIN_OVERLOAD()
305         MATCH_REDISP(wxPliOvl_wbru, SetBrushBrush)
306         MATCH_REDISP(wxPliOvl_wgbr, SetBrushGraphics)
307     END_OVERLOAD( "Wx::GraphicsContext::SetBrush" )
308
309 void
310 wxGraphicsContext::SetBrushBrush (brush)
311     wxBrush* brush
312   CODE:
313     THIS->SetBrush( *brush );
314
315 void
316 wxGraphicsContext::SetBrushGraphics (brush)
317     wxGraphicsBrush* brush
318   CODE:
319     THIS->SetBrush( *brush );
320
321 void
322 SetFont ( ... )
323   PPCODE:
324     BEGIN_OVERLOAD()
325         MATCH_REDISP(wxPliOvl_wfon_wcol, SetFontFont)
326         MATCH_REDISP(wxPliOvl_wgfo, SetFontGraphics)
327     END_OVERLOAD( "Wx::GraphicsContext::SetFont" )
328
329 void 
330 wxGraphicsContext::SetFontFont (font, colour)
331     wxFont* font
332     wxColour* colour
333   CODE:
334     THIS->SetFont(*font, *colour);
335
336 void 
337 wxGraphicsContext::SetFontGraphics (font)
338     wxGraphicsFont* font
339   CODE:
340     THIS->SetFont(*font);
341
342 void
343 SetPen ( ... )
344   PPCODE:
345     BEGIN_OVERLOAD()
346         MATCH_REDISP(wxPliOvl_wpen, SetPenPen)
347         MATCH_REDISP(wxPliOvl_wgpe, SetPenGraphics)
348     END_OVERLOAD( "Wx::GraphicsContext::SetPen" )
349
350 void
351 wxGraphicsContext::SetPenPen (pen)
352     wxPen* pen
353   CODE:
354     THIS->SetPen( *pen );
355
356 void
357 wxGraphicsContext::SetPenGraphics (pen)
358     wxGraphicsPen* pen
359   CODE:
360     THIS->SetPen( *pen );
361
362 void
363 wxGraphicsContext::StrokeLine (x1,y1,x2,y2)
364     wxDouble x1
365     wxDouble y1
366     wxDouble x2
367     wxDouble y2
368
369 ##Used wpoi's for overload checking as opposed to arr's 
370 ##We want array references (which wpoi matches) but arr
371 ##causes some problems...
372
373 void
374 wxGraphicsContext::StrokeLines ( ... )
375   PPCODE:
376     BEGIN_OVERLOAD()
377         MATCH_REDISP(wxPliOvl_wpoi_wpoi, StrokeLinesTwo)
378         MATCH_REDISP(wxPliOvl_wpoi, StrokeLinesOne)
379     END_OVERLOAD( "Wx::GraphicsContext::StrokeLines" )
380
381
382 void
383 wxGraphicsContext::StrokeLinesOne ( points )
384     SV* points
385   CODE:
386     wxPliArrayGuard<wxPoint2DDouble> points2d;
387     int n = wxPli_av_2_point2ddoublearray(aTHX_ points, points2d.lvalue());
388     THIS->StrokeLines(n,points2d);
389
390
391 void
392 wxGraphicsContext::StrokeLinesTwo ( beginPoints, endPoints )
393     SV* beginPoints
394     SV* endPoints
395   CODE:
396     wxPliArrayGuard<wxPoint2DDouble> beginPoints2d, endPoints2d;
397     int n1 = wxPli_av_2_point2ddoublearray(aTHX_ beginPoints, beginPoints2d.lvalue());
398     int n2 = wxPli_av_2_point2ddoublearray(aTHX_ endPoints, endPoints2d.lvalue());
399     THIS->StrokeLines(wxMin(n1, n2), beginPoints2d, endPoints2d);
400
401 #endif