]> git.saurik.com Git - wxWidgets.git/blob - src/msw/graphics.cpp
Add wxArchiveFSHandler.
[wxWidgets.git] / src / msw / graphics.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/graphics.cpp
3 // Purpose: wxGCDC class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 2006-09-30
7 // RCS-ID: $Id$
8 // Copyright: (c) 2006 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/dc.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/msw/wrapcdlg.h"
22 #include "wx/image.h"
23 #include "wx/window.h"
24 #include "wx/dc.h"
25 #include "wx/utils.h"
26 #include "wx/dialog.h"
27 #include "wx/app.h"
28 #include "wx/bitmap.h"
29 #include "wx/dcmemory.h"
30 #include "wx/log.h"
31 #include "wx/icon.h"
32 #include "wx/dcprint.h"
33 #include "wx/module.h"
34 #endif
35
36 #include "wx/graphics.h"
37
38 #if wxUSE_GRAPHICS_CONTEXT
39
40 #include <vector>
41
42 using namespace std;
43
44 //-----------------------------------------------------------------------------
45 // constants
46 //-----------------------------------------------------------------------------
47
48 const double RAD2DEG = 180.0 / M_PI;
49
50 //-----------------------------------------------------------------------------
51 // Local functions
52 //-----------------------------------------------------------------------------
53
54 static inline double dmin(double a, double b) { return a < b ? a : b; }
55 static inline double dmax(double a, double b) { return a > b ? a : b; }
56
57 static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
58 static inline double RadToDeg(double deg) { return (deg * 180.0) / M_PI; }
59
60 //-----------------------------------------------------------------------------
61 // device context implementation
62 //
63 // more and more of the dc functionality should be implemented by calling
64 // the appropricate wxGDIPlusContext, but we will have to do that step by step
65 // also coordinate conversions should be moved to native matrix ops
66 //-----------------------------------------------------------------------------
67
68 // we always stock two context states, one at entry, to be able to preserve the
69 // state we were called with, the other one after changing to HI Graphics orientation
70 // (this one is used for getting back clippings etc)
71
72 //-----------------------------------------------------------------------------
73 // wxGraphicsPath implementation
74 //-----------------------------------------------------------------------------
75
76 #include "wx/msw/private.h" // needs to be before #include <commdlg.h>
77
78 #if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__)
79 #include <commdlg.h>
80 #endif
81
82 // TODO remove this dependency (gdiplus needs the macros)
83
84 #ifndef max
85 #define max(a,b) (((a) > (b)) ? (a) : (b))
86 #endif
87
88 #ifndef min
89 #define min(a,b) (((a) < (b)) ? (a) : (b))
90 #endif
91
92 #include "gdiplus.h"
93 using namespace Gdiplus;
94
95 class WXDLLIMPEXP_CORE wxGDIPlusPath : public wxGraphicsPath
96 {
97 public :
98 wxGDIPlusPath();
99 wxGDIPlusPath(wxGraphicsRenderer* renderer, GraphicsPath* path = NULL);
100 ~wxGDIPlusPath();
101
102 virtual wxGraphicsPath *Clone() const;
103
104 //
105 // These are the path primitives from which everything else can be constructed
106 //
107
108 // begins a new subpath at (x,y)
109 virtual void MoveToPoint( wxDouble x, wxDouble y );
110
111 // adds a straight line from the current point to (x,y)
112 virtual void AddLineToPoint( wxDouble x, wxDouble y );
113
114 // adds a cubic Bezier curve from the current point, using two control points and an end point
115 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y );
116
117
118 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
119 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) ;
120
121 // gets the last point of the current path, (0,0) if not yet set
122 virtual void GetCurrentPoint( wxDouble& x, wxDouble&y) ;
123
124 // adds another path
125 virtual void AddPath( const wxGraphicsPath* path );
126
127 // closes the current sub-path
128 virtual void CloseSubpath();
129
130 //
131 // These are convenience functions which - if not available natively will be assembled
132 // using the primitives from above
133 //
134
135 // appends a rectangle as a new closed subpath
136 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ;
137 /*
138
139 // appends an ellipsis as a new closed subpath fitting the passed rectangle
140 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
141
142 // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
143 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
144 */
145
146 // returns the native path
147 virtual void * GetNativePath() const { return m_path; }
148
149 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
150 virtual void UnGetNativePath(void * WXUNUSED(path)) {}
151
152 // transforms each point of this path by the matrix
153 virtual void Transform( wxGraphicsMatrix* matrix ) ;
154
155 // gets the bounding box enclosing all points (possibly including control points)
156 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) ;
157
158 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxWINDING_RULE) ;
159
160 private :
161 GraphicsPath* m_path;
162 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusPath)
163 };
164
165 class WXDLLIMPEXP_CORE wxGDIPlusMatrix : public wxGraphicsMatrix
166 {
167 public :
168 wxGDIPlusMatrix() ;
169
170 wxGDIPlusMatrix(wxGraphicsRenderer* renderer, Matrix* matrix = NULL ) ;
171 virtual ~wxGDIPlusMatrix() ;
172
173 virtual wxGraphicsMatrix *Clone() const ;
174
175 // concatenates the matrix
176 virtual void Concat( const wxGraphicsMatrix *t );
177
178 // copies the passed in matrix
179 virtual void Copy( const wxGraphicsMatrix *t );
180
181 // sets the matrix to the respective values
182 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
183 wxDouble tx=0.0, wxDouble ty=0.0);
184
185 // makes this the inverse matrix
186 virtual void Invert();
187
188 // returns true if the elements of the transformation matrix are equal ?
189 virtual bool IsEqual( const wxGraphicsMatrix* t) const ;
190
191 // return true if this is the identity matrix
192 virtual bool IsIdentity();
193
194 //
195 // transformation
196 //
197
198 // add the translation to this matrix
199 virtual void Translate( wxDouble dx , wxDouble dy );
200
201 // add the scale to this matrix
202 virtual void Scale( wxDouble xScale , wxDouble yScale );
203
204 // add the rotation to this matrix (radians)
205 virtual void Rotate( wxDouble angle );
206
207 //
208 // apply the transforms
209 //
210
211 // applies that matrix to the point
212 virtual void TransformPoint( wxDouble *x, wxDouble *y );
213
214 // applies the matrix except for translations
215 virtual void TransformDistance( wxDouble *dx, wxDouble *dy );
216
217 // returns the native representation
218 virtual void * GetNativeMatrix() const;
219 private:
220 Matrix* m_matrix ;
221
222 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusMatrix)
223 } ;
224
225 class WXDLLIMPEXP_CORE wxGDIPlusPenData : public wxGraphicsObjectRefData
226 {
227 public:
228 wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen );
229 ~wxGDIPlusPenData();
230
231 void Init();
232
233 virtual wxDouble GetWidth() { return m_width; }
234 virtual Pen* GetGDIPlusPen() { return m_pen; }
235
236 protected :
237 Pen* m_pen;
238 Image* m_penImage;
239 Brush* m_penBrush;
240
241 wxDouble m_width;
242 };
243
244 class WXDLLIMPEXP_CORE wxGDIPlusBrushData : public wxGraphicsObjectRefData
245 {
246 public:
247 wxGDIPlusBrushData( wxGraphicsRenderer* renderer );
248 wxGDIPlusBrushData( wxGraphicsRenderer* renderer, const wxBrush &brush );
249 ~wxGDIPlusBrushData ();
250
251 void CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
252 const wxColour&c1, const wxColour&c2 );
253 void CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
254 const wxColour &oColor, const wxColour &cColor );
255 virtual Brush* GetGDIPlusBrush() { return m_brush; }
256
257 protected:
258 virtual void Init();
259
260 private :
261 Brush* m_brush;
262 Image* m_brushImage;
263 GraphicsPath* m_brushPath;
264 };
265
266 class WXDLLIMPEXP_CORE wxGDIPlusFontData : public wxGraphicsObjectRefData
267 {
268 public:
269 wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col );
270 ~wxGDIPlusFontData();
271
272 virtual Brush* GetGDIPlusBrush() { return m_textBrush; }
273 virtual Font* GetGDIPlusFont() { return m_font; }
274 private :
275 Brush* m_textBrush;
276 Font* m_font;
277 };
278
279 class WXDLLIMPEXP_CORE wxGDIPlusContext : public wxGraphicsContext
280 {
281 public:
282 wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc );
283 wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd );
284 wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr);
285 wxGDIPlusContext();
286
287 virtual ~wxGDIPlusContext();
288
289 virtual void Clip( const wxRegion &region );
290 // clips drawings to the rect
291 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
292
293 // resets the clipping to original extent
294 virtual void ResetClip();
295
296 virtual void * GetNativeContext();
297
298 virtual void StrokePath( const wxGraphicsPath *p );
299 virtual void FillPath( const wxGraphicsPath *p , int fillStyle = wxWINDING_RULE );
300
301 virtual void Translate( wxDouble dx , wxDouble dy );
302 virtual void Scale( wxDouble xScale , wxDouble yScale );
303 virtual void Rotate( wxDouble angle );
304
305 // concatenates this transform with the current transform of this context
306 virtual void ConcatTransform( const wxGraphicsMatrix* matrix );
307
308 // sets the transform of this context
309 virtual void SetTransform( const wxGraphicsMatrix* matrix );
310
311 // gets the matrix of this context
312 virtual void GetTransform( wxGraphicsMatrix* matrix );
313
314 virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
315 virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
316 virtual void PushState();
317 virtual void PopState();
318
319 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y);
320 virtual void GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height,
321 wxDouble *descent, wxDouble *externalLeading ) const;
322 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const;
323
324 private:
325 void Init();
326 void SetDefaults();
327
328 Graphics* m_context;
329 vector<GraphicsState> m_stateStack;
330 GraphicsState m_state1;
331 GraphicsState m_state2;
332
333 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext)
334 };
335
336 //-----------------------------------------------------------------------------
337 // wxGDIPlusPen implementation
338 //-----------------------------------------------------------------------------
339
340 wxGDIPlusPenData::~wxGDIPlusPenData()
341 {
342 delete m_pen;
343 delete m_penImage;
344 delete m_penBrush;
345 }
346
347 void wxGDIPlusPenData::Init()
348 {
349 m_pen = NULL ;
350 m_penImage = NULL;
351 m_penBrush = NULL;
352 }
353
354 wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
355 : wxGraphicsObjectRefData(renderer)
356 {
357 Init();
358 m_width = pen.GetWidth();
359 if (m_width <= 0.0)
360 m_width = 0.1;
361
362 m_pen = new Pen(Color( pen.GetColour().Alpha() , pen.GetColour().Red() ,
363 pen.GetColour().Green() , pen.GetColour().Blue() ), m_width );
364
365 LineCap cap;
366 switch ( pen.GetCap() )
367 {
368 case wxCAP_ROUND :
369 cap = LineCapRound;
370 break;
371
372 case wxCAP_PROJECTING :
373 cap = LineCapSquare;
374 break;
375
376 case wxCAP_BUTT :
377 cap = LineCapFlat; // TODO verify
378 break;
379
380 default :
381 cap = LineCapFlat;
382 break;
383 }
384 m_pen->SetLineCap(cap,cap, DashCapFlat);
385
386 LineJoin join;
387 switch ( pen.GetJoin() )
388 {
389 case wxJOIN_BEVEL :
390 join = LineJoinBevel;
391 break;
392
393 case wxJOIN_MITER :
394 join = LineJoinMiter;
395 break;
396
397 case wxJOIN_ROUND :
398 join = LineJoinRound;
399 break;
400
401 default :
402 join = LineJoinMiter;
403 break;
404 }
405
406 m_pen->SetLineJoin(join);
407
408 m_pen->SetDashStyle(DashStyleSolid);
409
410 DashStyle dashStyle = DashStyleSolid;
411 switch ( pen.GetStyle() )
412 {
413 case wxSOLID :
414 break;
415
416 case wxDOT :
417 dashStyle = DashStyleDot;
418 break;
419
420 case wxLONG_DASH :
421 dashStyle = DashStyleDash; // TODO verify
422 break;
423
424 case wxSHORT_DASH :
425 dashStyle = DashStyleDash;
426 break;
427
428 case wxDOT_DASH :
429 dashStyle = DashStyleDashDot;
430 break;
431 case wxUSER_DASH :
432 {
433 dashStyle = DashStyleCustom;
434 wxDash *dashes;
435 int count = pen.GetDashes( &dashes );
436 if ((dashes != NULL) && (count > 0))
437 {
438 REAL *userLengths = new REAL[count];
439 for ( int i = 0; i < count; ++i )
440 {
441 userLengths[i] = dashes[i];
442 }
443 m_pen->SetDashPattern( userLengths, count);
444 delete[] userLengths;
445 }
446 }
447 break;
448 case wxSTIPPLE :
449 {
450 wxBitmap* bmp = pen.GetStipple();
451 if ( bmp && bmp->Ok() )
452 {
453 m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
454 m_penBrush = new TextureBrush(m_penImage);
455 m_pen->SetBrush( m_penBrush );
456 }
457
458 }
459 break;
460 default :
461 if ( pen.GetStyle() >= wxFIRST_HATCH && pen.GetStyle() <= wxLAST_HATCH )
462 {
463 HatchStyle style = HatchStyleHorizontal;
464 switch( pen.GetStyle() )
465 {
466 case wxBDIAGONAL_HATCH :
467 style = HatchStyleBackwardDiagonal;
468 break ;
469 case wxCROSSDIAG_HATCH :
470 style = HatchStyleDiagonalCross;
471 break ;
472 case wxFDIAGONAL_HATCH :
473 style = HatchStyleForwardDiagonal;
474 break ;
475 case wxCROSS_HATCH :
476 style = HatchStyleCross;
477 break ;
478 case wxHORIZONTAL_HATCH :
479 style = HatchStyleHorizontal;
480 break ;
481 case wxVERTICAL_HATCH :
482 style = HatchStyleVertical;
483 break ;
484
485 }
486 m_penBrush = new HatchBrush(style,Color( pen.GetColour().Alpha() , pen.GetColour().Red() ,
487 pen.GetColour().Green() , pen.GetColour().Blue() ), Color::Transparent );
488 m_pen->SetBrush( m_penBrush );
489 }
490 break;
491 }
492 if ( dashStyle != DashStyleSolid )
493 m_pen->SetDashStyle(dashStyle);
494 }
495
496 //-----------------------------------------------------------------------------
497 // wxGDIPlusBrush implementation
498 //-----------------------------------------------------------------------------
499
500 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer )
501 : wxGraphicsObjectRefData(renderer)
502 {
503 Init();
504 }
505
506 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer , const wxBrush &brush )
507 : wxGraphicsObjectRefData(renderer)
508 {
509 Init();
510 if ( brush.GetStyle() == wxSOLID)
511 {
512 m_brush = new SolidBrush( Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
513 brush.GetColour().Green() , brush.GetColour().Blue() ) );
514 }
515 else if ( brush.IsHatch() )
516 {
517 HatchStyle style = HatchStyleHorizontal;
518 switch( brush.GetStyle() )
519 {
520 case wxBDIAGONAL_HATCH :
521 style = HatchStyleBackwardDiagonal;
522 break ;
523 case wxCROSSDIAG_HATCH :
524 style = HatchStyleDiagonalCross;
525 break ;
526 case wxFDIAGONAL_HATCH :
527 style = HatchStyleForwardDiagonal;
528 break ;
529 case wxCROSS_HATCH :
530 style = HatchStyleCross;
531 break ;
532 case wxHORIZONTAL_HATCH :
533 style = HatchStyleHorizontal;
534 break ;
535 case wxVERTICAL_HATCH :
536 style = HatchStyleVertical;
537 break ;
538
539 }
540 m_brush = new HatchBrush(style,Color( brush.GetColour().Alpha() , brush.GetColour().Red() ,
541 brush.GetColour().Green() , brush.GetColour().Blue() ), Color::Transparent );
542 }
543 else
544 {
545 wxBitmap* bmp = brush.GetStipple();
546 if ( bmp && bmp->Ok() )
547 {
548 wxDELETE( m_brushImage );
549 m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
550 m_brush = new TextureBrush(m_brushImage);
551 }
552 }
553 }
554
555 wxGDIPlusBrushData::~wxGDIPlusBrushData()
556 {
557 delete m_brush;
558 delete m_brushImage;
559 delete m_brushPath;
560 };
561
562 void wxGDIPlusBrushData::Init()
563 {
564 m_brush = NULL;
565 m_brushImage= NULL;
566 m_brushPath= NULL;
567 }
568
569 void wxGDIPlusBrushData::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxColour&c1, const wxColour&c2)
570 {
571 m_brush = new LinearGradientBrush( PointF( x1,y1) , PointF( x2,y2),
572 Color( c1.Alpha(), c1.Red(),c1.Green() , c1.Blue() ),
573 Color( c2.Alpha(), c2.Red(),c2.Green() , c2.Blue() ));
574 }
575
576 void wxGDIPlusBrushData::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
577 const wxColour &oColor, const wxColour &cColor)
578 {
579 // Create a path that consists of a single circle.
580 m_brushPath = new GraphicsPath();
581 m_brushPath->AddEllipse( (REAL)(xc-radius), (REAL)(yc-radius), (REAL)(2*radius), (REAL)(2*radius));
582
583 PathGradientBrush *b = new PathGradientBrush(m_brushPath);
584 m_brush = b;
585 b->SetCenterPoint( PointF(xo,yo));
586 b->SetCenterColor(Color( oColor.Alpha(), oColor.Red(),oColor.Green() , oColor.Blue() ));
587
588 Color colors[] = {Color( cColor.Alpha(), cColor.Red(),cColor.Green() , cColor.Blue() )};
589 int count = 1;
590 b->SetSurroundColors(colors, &count);
591 }
592
593 //-----------------------------------------------------------------------------
594 // wxGDIPlusFont implementation
595 //-----------------------------------------------------------------------------
596
597 wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font,
598 const wxColour& col ) : wxGraphicsObjectRefData( renderer )
599 {
600 m_textBrush = NULL;
601 m_font = NULL;
602
603 wxWCharBuffer s = font.GetFaceName().wc_str( *wxConvUI );
604 int size = font.GetPointSize();
605 int style = FontStyleRegular;
606 if ( font.GetStyle() == wxFONTSTYLE_ITALIC )
607 style |= FontStyleItalic;
608 if ( font.GetUnderlined() )
609 style |= FontStyleUnderline;
610 if ( font.GetWeight() == wxFONTWEIGHT_BOLD )
611 style |= FontStyleBold;
612 m_font = new Font( s , size , style );
613 m_textBrush = new SolidBrush( Color( col.Alpha() , col.Red() ,
614 col.Green() , col.Blue() ));
615 }
616
617 wxGDIPlusFontData::~wxGDIPlusFontData()
618 {
619 delete m_textBrush;
620 delete m_font;
621 }
622
623 //-----------------------------------------------------------------------------
624 // wxGDIPlusPath implementation
625 //-----------------------------------------------------------------------------
626
627 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusPath,wxGraphicsPath)
628
629 wxGDIPlusPath::wxGDIPlusPath(wxGraphicsRenderer* renderer, GraphicsPath* path ) : wxGraphicsPath(renderer)
630 {
631 if ( path )
632 m_path = path;
633 else
634 m_path = new GraphicsPath();
635 }
636
637 wxGDIPlusPath::wxGDIPlusPath() : wxGraphicsPath(NULL)
638 {
639 wxLogDebug(wxT("Illegal Constructor called"));
640 }
641
642
643 wxGDIPlusPath::~wxGDIPlusPath()
644 {
645 delete m_path;
646 }
647
648 wxGraphicsPath* wxGDIPlusPath::Clone() const
649 {
650 return new wxGDIPlusPath( GetRenderer() , m_path->Clone());
651 }
652
653
654
655 //
656 // The Primitives
657 //
658
659 void wxGDIPlusPath::MoveToPoint( wxDouble x , wxDouble y )
660 {
661 m_path->StartFigure();
662 m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y);
663 }
664
665 void wxGDIPlusPath::AddLineToPoint( wxDouble x , wxDouble y )
666 {
667 m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y);
668 }
669
670 void wxGDIPlusPath::CloseSubpath()
671 {
672 m_path->CloseFigure();
673 }
674
675 void wxGDIPlusPath::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y )
676 {
677 PointF c1(cx1,cy1);
678 PointF c2(cx2,cy2);
679 PointF end(x,y);
680 PointF start;
681 m_path->GetLastPoint(&start);
682 m_path->AddBezier(start,c1,c2,end);
683 }
684
685 // gets the last point of the current path, (0,0) if not yet set
686 void wxGDIPlusPath::GetCurrentPoint( wxDouble& x, wxDouble&y)
687 {
688 PointF start;
689 m_path->GetLastPoint(&start);
690 x = start.X ;
691 y = start.Y ;
692 }
693
694 void wxGDIPlusPath::AddArc( wxDouble x, wxDouble y, wxDouble r, double startAngle, double endAngle, bool clockwise )
695 {
696 double sweepAngle = endAngle - startAngle ;
697 if( abs(sweepAngle) >= 2*M_PI)
698 {
699 sweepAngle = 2 * M_PI;
700 }
701 else
702 {
703 if ( clockwise )
704 {
705 if( sweepAngle < 0 )
706 sweepAngle += 2 * M_PI;
707 }
708 else
709 {
710 if( sweepAngle > 0 )
711 sweepAngle -= 2 * M_PI;
712
713 }
714 }
715 m_path->AddArc((REAL) (x-r),(REAL) (y-r),(REAL) (2*r),(REAL) (2*r),RadToDeg(startAngle),RadToDeg(sweepAngle));
716 }
717
718 void wxGDIPlusPath::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
719 {
720 m_path->AddRectangle(RectF(x,y,w,h));
721 }
722
723 void wxGDIPlusPath::AddPath( const wxGraphicsPath* path )
724 {
725 m_path->AddPath( (GraphicsPath*) path->GetNativePath(), FALSE);
726 }
727
728
729 // transforms each point of this path by the matrix
730 void wxGDIPlusPath::Transform( wxGraphicsMatrix* matrix )
731 {
732 m_path->Transform( (Matrix*) matrix->GetNativeMatrix() );
733 }
734
735 // gets the bounding box enclosing all points (possibly including control points)
736 void wxGDIPlusPath::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)
737 {
738 RectF bounds;
739 m_path->GetBounds( &bounds, NULL, NULL) ;
740 *x = bounds.X;
741 *y = bounds.Y;
742 *w = bounds.Width;
743 *h = bounds.Height;
744 }
745
746 bool wxGDIPlusPath::Contains( wxDouble x, wxDouble y, int fillStyle )
747 {
748 m_path->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding);
749 return m_path->IsVisible( (FLOAT) x,(FLOAT) y) == TRUE ;
750 }
751
752 //-----------------------------------------------------------------------------
753 // wxGDIPlusMatrix implementation
754 //-----------------------------------------------------------------------------
755
756 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusMatrix,wxGraphicsMatrix)
757
758 wxGDIPlusMatrix::wxGDIPlusMatrix() : wxGraphicsMatrix(NULL)
759 {
760 wxLogDebug(wxT("Illegal Constructor called"));
761 }
762
763 wxGDIPlusMatrix::wxGDIPlusMatrix(wxGraphicsRenderer* renderer, Matrix* matrix )
764 : wxGraphicsMatrix(renderer)
765 {
766 if ( matrix )
767 m_matrix = matrix ;
768 else
769 m_matrix = new Matrix();
770 }
771
772 wxGDIPlusMatrix::~wxGDIPlusMatrix()
773 {
774 delete m_matrix;
775 }
776
777 wxGraphicsMatrix *wxGDIPlusMatrix::Clone() const
778 {
779 return new wxGDIPlusMatrix( GetRenderer(), m_matrix->Clone());
780 }
781
782 // concatenates the matrix
783 void wxGDIPlusMatrix::Concat( const wxGraphicsMatrix *t )
784 {
785 m_matrix->Multiply( (Matrix*) t->GetNativeMatrix());
786 }
787
788 // copies the passed in matrix
789 void wxGDIPlusMatrix::Copy( const wxGraphicsMatrix *t )
790 {
791 delete m_matrix;
792 m_matrix = ((Matrix*) t->GetNativeMatrix())->Clone();
793 }
794
795 // sets the matrix to the respective values
796 void wxGDIPlusMatrix::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
797 wxDouble tx, wxDouble ty)
798 {
799 m_matrix->SetElements(a,b,c,d,tx,ty);
800 }
801
802 // makes this the inverse matrix
803 void wxGDIPlusMatrix::Invert()
804 {
805 m_matrix->Invert();
806 }
807
808 // returns true if the elements of the transformation matrix are equal ?
809 bool wxGDIPlusMatrix::IsEqual( const wxGraphicsMatrix* t) const
810 {
811 return m_matrix->Equals((Matrix*) t->GetNativeMatrix())== TRUE ;
812 }
813
814 // return true if this is the identity matrix
815 bool wxGDIPlusMatrix::IsIdentity()
816 {
817 return m_matrix->IsIdentity() == TRUE ;
818 }
819
820 //
821 // transformation
822 //
823
824 // add the translation to this matrix
825 void wxGDIPlusMatrix::Translate( wxDouble dx , wxDouble dy )
826 {
827 m_matrix->Translate(dx,dy);
828 }
829
830 // add the scale to this matrix
831 void wxGDIPlusMatrix::Scale( wxDouble xScale , wxDouble yScale )
832 {
833 m_matrix->Scale(xScale,yScale);
834 }
835
836 // add the rotation to this matrix (radians)
837 void wxGDIPlusMatrix::Rotate( wxDouble angle )
838 {
839 m_matrix->Rotate( angle );
840 }
841
842 //
843 // apply the transforms
844 //
845
846 // applies that matrix to the point
847 void wxGDIPlusMatrix::TransformPoint( wxDouble *x, wxDouble *y )
848 {
849 PointF pt(*x,*y);
850 m_matrix->TransformPoints(&pt);
851 *x = pt.X;
852 *y = pt.Y;
853 }
854
855 // applies the matrix except for translations
856 void wxGDIPlusMatrix::TransformDistance( wxDouble *dx, wxDouble *dy )
857 {
858 PointF pt(*dx,*dy);
859 m_matrix->TransformVectors(&pt);
860 *dx = pt.X;
861 *dy = pt.Y;
862 }
863
864 // returns the native representation
865 void * wxGDIPlusMatrix::GetNativeMatrix() const
866 {
867 return m_matrix;
868 }
869
870 //-----------------------------------------------------------------------------
871 // wxGDIPlusContext implementation
872 //-----------------------------------------------------------------------------
873
874 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusContext,wxGraphicsContext)
875
876 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc )
877 : wxGraphicsContext(renderer)
878 {
879 Init();
880 m_context = new Graphics( hdc);
881 SetDefaults();
882 }
883
884 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd )
885 : wxGraphicsContext(renderer)
886 {
887 Init();
888 m_context = new Graphics( hwnd);
889 SetDefaults();
890 }
891
892 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr )
893 : wxGraphicsContext(renderer)
894 {
895 Init();
896 m_context = gr;
897 SetDefaults();
898 }
899
900 wxGDIPlusContext::wxGDIPlusContext() : wxGraphicsContext(NULL)
901 {
902 Init();
903 }
904
905 void wxGDIPlusContext::Init()
906 {
907 m_context = NULL;
908 m_state1 = 0;
909 m_state2= 0;
910 }
911
912 void wxGDIPlusContext::SetDefaults()
913 {
914 m_context->SetSmoothingMode(SmoothingModeHighQuality);
915 m_state1 = m_context->Save();
916 m_state2 = m_context->Save();
917 }
918
919 wxGDIPlusContext::~wxGDIPlusContext()
920 {
921 if ( m_context )
922 {
923 m_context->Restore( m_state2 );
924 m_context->Restore( m_state1 );
925 delete m_context;
926 }
927 }
928
929
930 void wxGDIPlusContext::Clip( const wxRegion &region )
931 {
932 m_context->SetClip((HRGN)region.GetHRGN(),CombineModeIntersect);
933 }
934
935 void wxGDIPlusContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
936 {
937 m_context->SetClip(RectF(x,y,w,h),CombineModeIntersect);
938 }
939
940 void wxGDIPlusContext::ResetClip()
941 {
942 m_context->ResetClip();
943 }
944
945 void wxGDIPlusContext::StrokePath( const wxGraphicsPath *path )
946 {
947 if ( !m_pen.IsNull() )
948 {
949 m_context->DrawPath( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath*) path->GetNativePath() );
950 }
951 }
952
953 void wxGDIPlusContext::FillPath( const wxGraphicsPath *path , int fillStyle )
954 {
955 if ( !m_brush.IsNull() )
956 {
957 ((GraphicsPath*) path->GetNativePath())->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding);
958 m_context->FillPath( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() ,
959 (GraphicsPath*) path->GetNativePath());
960 }
961 }
962
963 void wxGDIPlusContext::Rotate( wxDouble angle )
964 {
965 m_context->RotateTransform( RadToDeg(angle) );
966 }
967
968 void wxGDIPlusContext::Translate( wxDouble dx , wxDouble dy )
969 {
970 m_context->TranslateTransform( dx , dy );
971 }
972
973 void wxGDIPlusContext::Scale( wxDouble xScale , wxDouble yScale )
974 {
975 m_context->ScaleTransform(xScale,yScale);
976 }
977
978 void wxGDIPlusContext::PushState()
979 {
980 GraphicsState state = m_context->Save();
981 m_stateStack.push_back(state);
982 }
983
984 void wxGDIPlusContext::PopState()
985 {
986 GraphicsState state = m_stateStack.back();
987 m_stateStack.pop_back();
988 m_context->Restore(state);
989 }
990
991 // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the
992 // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied
993 // bytes as parameter
994
995 void wxGDIPlusContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
996 {
997 Bitmap* image = NULL;
998 Bitmap* helper = NULL;
999 if ( bmp.GetMask() )
1000 {
1001 Bitmap interim((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE()) ;
1002
1003 size_t width = interim.GetWidth();
1004 size_t height = interim.GetHeight();
1005 Rect bounds(0,0,width,height);
1006
1007 image = new Bitmap(width,height,PixelFormat32bppPARGB) ;
1008
1009 Bitmap interimMask((HBITMAP)bmp.GetMask()->GetMaskBitmap(),NULL);
1010 wxASSERT(interimMask.GetPixelFormat() == PixelFormat1bppIndexed);
1011
1012 BitmapData dataMask ;
1013 interimMask.LockBits(&bounds,ImageLockModeRead,
1014 interimMask.GetPixelFormat(),&dataMask);
1015
1016
1017 BitmapData imageData ;
1018 image->LockBits(&bounds,ImageLockModeWrite, PixelFormat32bppPARGB, &imageData);
1019
1020 BYTE maskPattern = 0 ;
1021 BYTE maskByte = 0;
1022 size_t maskIndex ;
1023
1024 for ( size_t y = 0 ; y < height ; ++y)
1025 {
1026 maskIndex = 0 ;
1027 for( size_t x = 0 ; x < width; ++x)
1028 {
1029 if ( x % 8 == 0)
1030 {
1031 maskPattern = 0x80;
1032 maskByte = *((BYTE*)dataMask.Scan0 + dataMask.Stride*y + maskIndex);
1033 maskIndex++;
1034 }
1035 else
1036 maskPattern = maskPattern >> 1;
1037
1038 ARGB *dest = (ARGB*)((BYTE*)imageData.Scan0 + imageData.Stride*y + x*4);
1039 if ( (maskByte & maskPattern) == 0 )
1040 *dest = 0x00000000;
1041 else
1042 {
1043 Color c ;
1044 interim.GetPixel(x,y,&c) ;
1045 *dest = (c.GetValue() | Color::AlphaMask);
1046 }
1047 }
1048 }
1049
1050 image->UnlockBits(&imageData);
1051
1052 interimMask.UnlockBits(&dataMask);
1053 interim.UnlockBits(&dataMask);
1054 }
1055 else
1056 {
1057 image = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE());
1058 if ( GetPixelFormatSize(image->GetPixelFormat()) == 32 )
1059 {
1060 size_t width = image->GetWidth();
1061 size_t height = image->GetHeight();
1062 Rect bounds(0,0,width,height);
1063 BitmapData data ;
1064
1065 helper = image ;
1066 image = NULL ;
1067 helper->LockBits(&bounds, ImageLockModeRead,
1068 helper->GetPixelFormat(),&data);
1069
1070 image = new Bitmap(data.Width, data.Height, data.Stride,
1071 PixelFormat32bppARGB , (BYTE*) data.Scan0);
1072
1073 helper->UnlockBits(&data);
1074 }
1075 }
1076 if ( image )
1077 m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ;
1078 delete image ;
1079 delete helper ;
1080 }
1081
1082 void wxGDIPlusContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1083 {
1084 HICON hIcon = (HICON)icon.GetHICON();
1085 ICONINFO iconInfo ;
1086 // IconInfo creates the bitmaps for color and mask, we must dispose of them after use
1087 if (!GetIconInfo(hIcon,&iconInfo))
1088 return;
1089
1090 BITMAP iconBmpData ;
1091 GetObject(iconInfo.hbmColor,sizeof(BITMAP),&iconBmpData);
1092 Bitmap interim(iconInfo.hbmColor,NULL);
1093
1094 Bitmap* image = NULL ;
1095
1096 if( GetPixelFormatSize(interim.GetPixelFormat())!= 32 )
1097 {
1098 image = Bitmap::FromHICON(hIcon);
1099 }
1100 else
1101 {
1102 size_t width = interim.GetWidth();
1103 size_t height = interim.GetHeight();
1104 Rect bounds(0,0,width,height);
1105 BitmapData data ;
1106
1107 interim.LockBits(&bounds, ImageLockModeRead,
1108 interim.GetPixelFormat(),&data);
1109 image = new Bitmap(data.Width, data.Height, data.Stride,
1110 PixelFormat32bppARGB , (BYTE*) data.Scan0);
1111 interim.UnlockBits(&data);
1112 }
1113
1114 m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ;
1115
1116 delete image ;
1117 DeleteObject(iconInfo.hbmColor);
1118 DeleteObject(iconInfo.hbmMask);
1119 }
1120
1121 void wxGDIPlusContext::DrawText( const wxString &str, wxDouble x, wxDouble y )
1122 {
1123 if ( m_font.IsNull() || str.IsEmpty())
1124 return ;
1125
1126 wxWCharBuffer s = str.wc_str( *wxConvUI );
1127 m_context->DrawString( s , -1 , ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont() ,
1128 PointF( x , y ) , ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusBrush() );
1129 // TODO m_backgroundMode == wxSOLID
1130 }
1131
1132 void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height,
1133 wxDouble *descent, wxDouble *externalLeading ) const
1134 {
1135 wxWCharBuffer s = str.wc_str( *wxConvUI );
1136 FontFamily ffamily ;
1137 Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont();
1138
1139 f->GetFamily(&ffamily) ;
1140
1141 REAL factorY = m_context->GetDpiY() / 72.0 ;
1142
1143 REAL rDescent = ffamily.GetCellDescent(FontStyleRegular) *
1144 f->GetSize() / ffamily.GetEmHeight(FontStyleRegular);
1145 REAL rAscent = ffamily.GetCellAscent(FontStyleRegular) *
1146 f->GetSize() / ffamily.GetEmHeight(FontStyleRegular);
1147 REAL rHeight = ffamily.GetLineSpacing(FontStyleRegular) *
1148 f->GetSize() / ffamily.GetEmHeight(FontStyleRegular);
1149
1150 if ( height )
1151 *height = rHeight * factorY + 0.5 ;
1152 if ( descent )
1153 *descent = rDescent * factorY + 0.5 ;
1154 if ( externalLeading )
1155 *externalLeading = (rHeight - rAscent - rDescent) * factorY + 0.5 ;
1156 // measuring empty strings is not guaranteed, so do it by hand
1157 if ( str.IsEmpty())
1158 {
1159 if ( width )
1160 *width = 0 ;
1161 }
1162 else
1163 {
1164 // MeasureString does return a rectangle that is way too large, so it is
1165 // not usable here
1166 RectF layoutRect(0,0, 100000.0f, 100000.0f);
1167 StringFormat strFormat;
1168 CharacterRange strRange(0,wcslen(s));
1169 strFormat.SetMeasurableCharacterRanges(1,&strRange);
1170 Region region ;
1171 m_context->MeasureCharacterRanges(s, -1 , f,layoutRect, &strFormat,1,&region) ;
1172 RectF bbox ;
1173 region.GetBounds(&bbox,m_context);
1174 if ( width )
1175 *width = bbox.GetRight()-bbox.GetLeft()+0.5;
1176 }
1177 }
1178
1179 void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const
1180 {
1181 widths.Empty();
1182 widths.Add(0, text.length());
1183
1184 if (text.empty())
1185 return;
1186
1187 Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont();
1188 wxWCharBuffer ws = text.wc_str( *wxConvUI );
1189 size_t len = wcslen( ws ) ;
1190 wxASSERT_MSG(text.length() == len , wxT("GetPartialTextExtents not yet implemented for multichar situations"));
1191
1192 RectF layoutRect(0,0, 100000.0f, 100000.0f);
1193 StringFormat strFormat;
1194
1195 CharacterRange* ranges = new CharacterRange[len] ;
1196 Region* regions = new Region[len];
1197 for( size_t i = 0 ; i < len ; ++i)
1198 {
1199 ranges[i].First = i ;
1200 ranges[i].Length = 1 ;
1201 }
1202 strFormat.SetMeasurableCharacterRanges(len,ranges);
1203 m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,1,regions) ;
1204
1205 RectF bbox ;
1206 for ( size_t i = 0 ; i < len ; ++i)
1207 {
1208 regions[i].GetBounds(&bbox,m_context);
1209 widths[i] = bbox.GetRight()-bbox.GetLeft();
1210 }
1211 }
1212
1213 void* wxGDIPlusContext::GetNativeContext()
1214 {
1215 return m_context;
1216 }
1217
1218 // concatenates this transform with the current transform of this context
1219 void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix* matrix )
1220 {
1221 m_context->MultiplyTransform((Matrix*) matrix->GetNativeMatrix());
1222 }
1223
1224 // sets the transform of this context
1225 void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix* matrix )
1226 {
1227 m_context->SetTransform((Matrix*) matrix->GetNativeMatrix());
1228 }
1229
1230 // gets the matrix of this context
1231 void wxGDIPlusContext::GetTransform( wxGraphicsMatrix* matrix )
1232 {
1233 m_context->GetTransform((Matrix*) matrix->GetNativeMatrix());
1234 }
1235 //-----------------------------------------------------------------------------
1236 // wxGDIPlusRenderer declaration
1237 //-----------------------------------------------------------------------------
1238
1239 class WXDLLIMPEXP_CORE wxGDIPlusRenderer : public wxGraphicsRenderer
1240 {
1241 public :
1242 wxGDIPlusRenderer()
1243 {
1244 m_loaded = false;
1245 m_gditoken = NULL;
1246 }
1247
1248 virtual ~wxGDIPlusRenderer()
1249 {
1250 if (m_loaded)
1251 {
1252 Unload();
1253 }
1254 }
1255
1256 // Context
1257
1258 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc);
1259
1260 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context );
1261
1262 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window );
1263
1264 virtual wxGraphicsContext * CreateContext( wxWindow* window );
1265
1266 // Path
1267
1268 virtual wxGraphicsPath * CreatePath();
1269
1270 // Matrix
1271
1272 virtual wxGraphicsMatrix * CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
1273 wxDouble tx=0.0, wxDouble ty=0.0);
1274
1275
1276 virtual wxGraphicsPen CreatePen(const wxPen& pen) ;
1277
1278 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) ;
1279
1280 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1281 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
1282 const wxColour&c1, const wxColour&c2) ;
1283
1284 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1285 // with radius r and color cColor
1286 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
1287 const wxColour &oColor, const wxColour &cColor) ;
1288
1289 // sets the font
1290 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) ;
1291 protected :
1292 void EnsureIsLoaded();
1293 void Load();
1294 void Unload();
1295
1296 private :
1297 bool m_loaded;
1298 DWORD m_gditoken;
1299
1300 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer)
1301 } ;
1302
1303 //-----------------------------------------------------------------------------
1304 // wxGDIPlusRenderer implementation
1305 //-----------------------------------------------------------------------------
1306
1307 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer,wxGraphicsRenderer)
1308
1309 static wxGDIPlusRenderer gs_GDIPlusRenderer;
1310
1311 wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer()
1312 {
1313 return &gs_GDIPlusRenderer;
1314 }
1315
1316 void wxGDIPlusRenderer::EnsureIsLoaded()
1317 {
1318 if (!m_loaded)
1319 {
1320 Load();
1321 }
1322 }
1323
1324 void wxGDIPlusRenderer::Load()
1325 {
1326 GdiplusStartupInput input;
1327 GdiplusStartupOutput output;
1328 GdiplusStartup(&m_gditoken,&input,&output);
1329 m_loaded = true;
1330 }
1331
1332 void wxGDIPlusRenderer::Unload()
1333 {
1334 if ( m_gditoken )
1335 GdiplusShutdown(m_gditoken);
1336 }
1337
1338 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc)
1339 {
1340 EnsureIsLoaded();
1341 return new wxGDIPlusContext(this,(HDC) dc.GetHDC());
1342 }
1343
1344 wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeContext( void * context )
1345 {
1346 EnsureIsLoaded();
1347 return new wxGDIPlusContext(this,(Graphics*) context);
1348 }
1349
1350
1351 wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window )
1352 {
1353 EnsureIsLoaded();
1354 return new wxGDIPlusContext(this,(HWND) window);
1355 }
1356
1357 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window )
1358 {
1359 EnsureIsLoaded();
1360 return new wxGDIPlusContext(this, (HWND) window->GetHWND() );
1361 }
1362
1363 // Path
1364
1365 wxGraphicsPath * wxGDIPlusRenderer::CreatePath()
1366 {
1367 EnsureIsLoaded();
1368 return new wxGDIPlusPath( this );
1369 }
1370
1371
1372 // Matrix
1373
1374 wxGraphicsMatrix * wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d,
1375 wxDouble tx, wxDouble ty)
1376
1377 {
1378 EnsureIsLoaded();
1379 wxGDIPlusMatrix* m = new wxGDIPlusMatrix( this );
1380 m->Set( a,b,c,d,tx,ty ) ;
1381 return m;
1382 }
1383
1384 wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
1385 {
1386 EnsureIsLoaded();
1387 if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
1388 return wxNullGraphicsPen;
1389 else
1390 {
1391 wxGraphicsPen p;
1392 p.SetRefData(new wxGDIPlusPenData( this, pen ));
1393 return p;
1394 }
1395 }
1396
1397 wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
1398 {
1399 EnsureIsLoaded();
1400 if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
1401 return wxNullGraphicsBrush;
1402 else
1403 {
1404 wxGraphicsBrush p;
1405 p.SetRefData(new wxGDIPlusBrushData( this, brush ));
1406 return p;
1407 }
1408 }
1409
1410 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1411 wxGraphicsBrush wxGDIPlusRenderer::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
1412 const wxColour&c1, const wxColour&c2)
1413 {
1414 EnsureIsLoaded();
1415 wxGraphicsBrush p;
1416 wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
1417 d->CreateLinearGradientBrush(x1, y1, x2, y2, c1, c2);
1418 p.SetRefData(d);
1419 return p;
1420 }
1421
1422 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1423 // with radius r and color cColor
1424 wxGraphicsBrush wxGDIPlusRenderer::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
1425 const wxColour &oColor, const wxColour &cColor)
1426 {
1427 EnsureIsLoaded();
1428 wxGraphicsBrush p;
1429 wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
1430 d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,oColor,cColor);
1431 p.SetRefData(d);
1432 return p;
1433 }
1434
1435 // sets the font
1436 wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColour &col )
1437 {
1438 EnsureIsLoaded();
1439 if ( font.Ok() )
1440 {
1441 wxGraphicsFont p;
1442 p.SetRefData(new wxGDIPlusFontData( this , font, col ));
1443 return p;
1444 }
1445 else
1446 return wxNullGraphicsFont;
1447 }
1448
1449 #endif // wxUSE_GRAPHICS_CONTEXT