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