1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/graphics.cpp
3 // Purpose: wxGCDC class
4 // Author: Stefan Csomor
8 // Copyright: (c) 2006 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #if wxUSE_GRAPHICS_CONTEXT
23 #include "wx/msw/wrapcdlg.h"
25 #include "wx/window.h"
28 #include "wx/dialog.h"
30 #include "wx/bitmap.h"
31 #include "wx/dcmemory.h"
34 #include "wx/dcprint.h"
35 #include "wx/module.h"
38 #include "wx/graphics.h"
39 #include "wx/msw/wrapgdip.h"
43 WX_DECLARE_STACK(GraphicsState
, GraphicsStates
);
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 const double RAD2DEG
= 180.0 / M_PI
;
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
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
; }
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
; }
61 //-----------------------------------------------------------------------------
62 // device context implementation
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 //-----------------------------------------------------------------------------
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)
73 //-----------------------------------------------------------------------------
74 // wxGraphicsPath implementation
75 //-----------------------------------------------------------------------------
77 #include "wx/msw/private.h" // needs to be before #include <commdlg.h>
79 #if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__)
83 class wxGDIPlusPathData
: public wxGraphicsPathData
86 wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
= NULL
);
89 virtual wxGraphicsObjectRefData
*Clone() const;
92 // These are the path primitives from which everything else can be constructed
95 // begins a new subpath at (x,y)
96 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
98 // adds a straight line from the current point to (x,y)
99 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
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
);
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
) ;
108 // gets the last point of the current path, (0,0) if not yet set
109 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
112 virtual void AddPath( const wxGraphicsPathData
* path
);
114 // closes the current sub-path
115 virtual void CloseSubpath();
118 // These are convenience functions which - if not available natively will be assembled
119 // using the primitives from above
122 // appends a rectangle as a new closed subpath
123 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) ;
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 ) ;
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 ) ;
133 // returns the native path
134 virtual void * GetNativePath() const { return m_path
; }
136 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
137 virtual void UnGetNativePath(void * WXUNUSED(path
)) const {}
139 // transforms each point of this path by the matrix
140 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
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;
145 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxODDEVEN_RULE
) const;
148 GraphicsPath
* m_path
;
151 class wxGDIPlusMatrixData
: public wxGraphicsMatrixData
154 wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
= NULL
) ;
155 virtual ~wxGDIPlusMatrixData() ;
157 virtual wxGraphicsObjectRefData
* Clone() const ;
159 // concatenates the matrix
160 virtual void Concat( const wxGraphicsMatrixData
*t
);
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);
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;
170 // makes this the inverse matrix
171 virtual void Invert();
173 // returns true if the elements of the transformation matrix are equal ?
174 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
176 // return true if this is the identity matrix
177 virtual bool IsIdentity() const;
183 // add the translation to this matrix
184 virtual void Translate( wxDouble dx
, wxDouble dy
);
186 // add the scale to this matrix
187 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
189 // add the rotation to this matrix (radians)
190 virtual void Rotate( wxDouble angle
);
193 // apply the transforms
196 // applies that matrix to the point
197 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
199 // applies the matrix except for translations
200 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
202 // returns the native representation
203 virtual void * GetNativeMatrix() const;
208 class wxGDIPlusPenData
: public wxGraphicsObjectRefData
211 wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
216 virtual wxDouble
GetWidth() { return m_width
; }
217 virtual Pen
* GetGDIPlusPen() { return m_pen
; }
227 class wxGDIPlusBrushData
: public wxGraphicsObjectRefData
230 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
);
231 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
232 ~wxGDIPlusBrushData ();
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
; }
246 GraphicsPath
* m_brushPath
;
249 class wxGDIPlusFontData
: public wxGraphicsObjectRefData
252 wxGDIPlusFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
253 ~wxGDIPlusFontData();
255 virtual Brush
* GetGDIPlusBrush() { return m_textBrush
; }
256 virtual Font
* GetGDIPlusFont() { return m_font
; }
262 class wxGDIPlusContext
: public wxGraphicsContext
265 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
);
266 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
);
267 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
);
270 virtual ~wxGDIPlusContext();
272 virtual void Clip( const wxRegion
®ion
);
273 // clips drawings to the rect
274 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
276 // resets the clipping to original extent
277 virtual void ResetClip();
279 virtual void * GetNativeContext();
281 virtual void StrokePath( const wxGraphicsPath
& p
);
282 virtual void FillPath( const wxGraphicsPath
& p
, int fillStyle
= wxODDEVEN_RULE
);
284 // stroke lines connecting each of the points
285 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
288 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, int fillStyle
= wxODDEVEN_RULE
);
290 virtual void Translate( wxDouble dx
, wxDouble dy
);
291 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
292 virtual void Rotate( wxDouble angle
);
294 // concatenates this transform with the current transform of this context
295 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
297 // sets the transform of this context
298 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
300 // gets the matrix of this context
301 virtual wxGraphicsMatrix
GetTransform() const;
303 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
304 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
305 virtual void PushState();
306 virtual void PopState();
308 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
309 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
310 wxDouble
*descent
, wxDouble
*externalLeading
) const;
311 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
312 virtual bool ShouldOffset() const;
319 GraphicsStates m_stateStack
;
320 GraphicsState m_state1
;
321 GraphicsState m_state2
;
323 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext
)
326 class WXDLLIMPEXP_CORE wxGDIPlusMeasuringContext
: public wxGDIPlusContext
329 wxGDIPlusMeasuringContext( wxGraphicsRenderer
* renderer
) : wxGDIPlusContext( renderer
, m_hdc
= GetDC(NULL
) )
332 wxGDIPlusMeasuringContext()
336 virtual ~wxGDIPlusMeasuringContext()
338 ReleaseDC( NULL
, m_hdc
);
343 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusMeasuringContext
)
346 //-----------------------------------------------------------------------------
347 // wxGDIPlusPen implementation
348 //-----------------------------------------------------------------------------
350 wxGDIPlusPenData::~wxGDIPlusPenData()
357 void wxGDIPlusPenData::Init()
364 wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
365 : wxGraphicsObjectRefData(renderer
)
368 m_width
= pen
.GetWidth();
372 m_pen
= new Pen(Color( pen
.GetColour().Alpha() , pen
.GetColour().Red() ,
373 pen
.GetColour().Green() , pen
.GetColour().Blue() ), m_width
);
376 switch ( pen
.GetCap() )
382 case wxCAP_PROJECTING
:
387 cap
= LineCapFlat
; // TODO verify
394 m_pen
->SetLineCap(cap
,cap
, DashCapFlat
);
397 switch ( pen
.GetJoin() )
400 join
= LineJoinBevel
;
404 join
= LineJoinMiter
;
408 join
= LineJoinRound
;
412 join
= LineJoinMiter
;
416 m_pen
->SetLineJoin(join
);
418 m_pen
->SetDashStyle(DashStyleSolid
);
420 DashStyle dashStyle
= DashStyleSolid
;
421 switch ( pen
.GetStyle() )
427 dashStyle
= DashStyleDot
;
431 dashStyle
= DashStyleDash
; // TODO verify
435 dashStyle
= DashStyleDash
;
439 dashStyle
= DashStyleDashDot
;
443 dashStyle
= DashStyleCustom
;
445 int count
= pen
.GetDashes( &dashes
);
446 if ((dashes
!= NULL
) && (count
> 0))
448 REAL
*userLengths
= new REAL
[count
];
449 for ( int i
= 0; i
< count
; ++i
)
451 userLengths
[i
] = dashes
[i
];
453 m_pen
->SetDashPattern( userLengths
, count
);
454 delete[] userLengths
;
460 wxBitmap
* bmp
= pen
.GetStipple();
461 if ( bmp
&& bmp
->Ok() )
463 m_penImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),(HPALETTE
)bmp
->GetPalette()->GetHPALETTE());
464 m_penBrush
= new TextureBrush(m_penImage
);
465 m_pen
->SetBrush( m_penBrush
);
471 if ( pen
.GetStyle() >= wxFIRST_HATCH
&& pen
.GetStyle() <= wxLAST_HATCH
)
473 HatchStyle style
= HatchStyleHorizontal
;
474 switch( pen
.GetStyle() )
476 case wxBDIAGONAL_HATCH
:
477 style
= HatchStyleBackwardDiagonal
;
479 case wxCROSSDIAG_HATCH
:
480 style
= HatchStyleDiagonalCross
;
482 case wxFDIAGONAL_HATCH
:
483 style
= HatchStyleForwardDiagonal
;
486 style
= HatchStyleCross
;
488 case wxHORIZONTAL_HATCH
:
489 style
= HatchStyleHorizontal
;
491 case wxVERTICAL_HATCH
:
492 style
= HatchStyleVertical
;
496 m_penBrush
= new HatchBrush(style
,Color( pen
.GetColour().Alpha() , pen
.GetColour().Red() ,
497 pen
.GetColour().Green() , pen
.GetColour().Blue() ), Color::Transparent
);
498 m_pen
->SetBrush( m_penBrush
);
502 if ( dashStyle
!= DashStyleSolid
)
503 m_pen
->SetDashStyle(dashStyle
);
506 //-----------------------------------------------------------------------------
507 // wxGDIPlusBrush implementation
508 //-----------------------------------------------------------------------------
510 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
)
511 : wxGraphicsObjectRefData(renderer
)
516 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
517 : wxGraphicsObjectRefData(renderer
)
520 if ( brush
.GetStyle() == wxSOLID
)
522 m_brush
= new SolidBrush( Color( brush
.GetColour().Alpha() , brush
.GetColour().Red() ,
523 brush
.GetColour().Green() , brush
.GetColour().Blue() ) );
525 else if ( brush
.IsHatch() )
527 HatchStyle style
= HatchStyleHorizontal
;
528 switch( brush
.GetStyle() )
530 case wxBDIAGONAL_HATCH
:
531 style
= HatchStyleBackwardDiagonal
;
533 case wxCROSSDIAG_HATCH
:
534 style
= HatchStyleDiagonalCross
;
536 case wxFDIAGONAL_HATCH
:
537 style
= HatchStyleForwardDiagonal
;
540 style
= HatchStyleCross
;
542 case wxHORIZONTAL_HATCH
:
543 style
= HatchStyleHorizontal
;
545 case wxVERTICAL_HATCH
:
546 style
= HatchStyleVertical
;
550 m_brush
= new HatchBrush(style
,Color( brush
.GetColour().Alpha() , brush
.GetColour().Red() ,
551 brush
.GetColour().Green() , brush
.GetColour().Blue() ), Color::Transparent
);
555 wxBitmap
* bmp
= brush
.GetStipple();
556 if ( bmp
&& bmp
->Ok() )
558 wxDELETE( m_brushImage
);
559 m_brushImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),(HPALETTE
)bmp
->GetPalette()->GetHPALETTE());
560 m_brush
= new TextureBrush(m_brushImage
);
565 wxGDIPlusBrushData::~wxGDIPlusBrushData()
572 void wxGDIPlusBrushData::Init()
579 void wxGDIPlusBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, const wxColour
&c1
, const wxColour
&c2
)
581 m_brush
= new LinearGradientBrush( PointF( x1
,y1
) , PointF( x2
,y2
),
582 Color( c1
.Alpha(), c1
.Red(),c1
.Green() , c1
.Blue() ),
583 Color( c2
.Alpha(), c2
.Red(),c2
.Green() , c2
.Blue() ));
586 void wxGDIPlusBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
587 const wxColour
&oColor
, const wxColour
&cColor
)
589 // Create a path that consists of a single circle.
590 m_brushPath
= new GraphicsPath();
591 m_brushPath
->AddEllipse( (REAL
)(xc
-radius
), (REAL
)(yc
-radius
), (REAL
)(2*radius
), (REAL
)(2*radius
));
593 PathGradientBrush
*b
= new PathGradientBrush(m_brushPath
);
595 b
->SetCenterPoint( PointF(xo
,yo
));
596 b
->SetCenterColor(Color( oColor
.Alpha(), oColor
.Red(),oColor
.Green() , oColor
.Blue() ));
598 Color colors
[] = {Color( cColor
.Alpha(), cColor
.Red(),cColor
.Green() , cColor
.Blue() )};
600 b
->SetSurroundColors(colors
, &count
);
603 //-----------------------------------------------------------------------------
604 // wxGDIPlusFont implementation
605 //-----------------------------------------------------------------------------
607 wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
,
608 const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
613 wxWCharBuffer s
= font
.GetFaceName().wc_str( *wxConvUI
);
614 int size
= font
.GetPointSize();
615 int style
= FontStyleRegular
;
616 if ( font
.GetStyle() == wxFONTSTYLE_ITALIC
)
617 style
|= FontStyleItalic
;
618 if ( font
.GetUnderlined() )
619 style
|= FontStyleUnderline
;
620 if ( font
.GetWeight() == wxFONTWEIGHT_BOLD
)
621 style
|= FontStyleBold
;
622 m_font
= new Font( s
, size
, style
);
623 m_textBrush
= new SolidBrush( Color( col
.Alpha() , col
.Red() ,
624 col
.Green() , col
.Blue() ));
627 wxGDIPlusFontData::~wxGDIPlusFontData()
633 //-----------------------------------------------------------------------------
634 // wxGDIPlusPath implementation
635 //-----------------------------------------------------------------------------
637 wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
) : wxGraphicsPathData(renderer
)
642 m_path
= new GraphicsPath();
645 wxGDIPlusPathData::~wxGDIPlusPathData()
650 wxGraphicsObjectRefData
* wxGDIPlusPathData::Clone() const
652 return new wxGDIPlusPathData( GetRenderer() , m_path
->Clone());
659 void wxGDIPlusPathData::MoveToPoint( wxDouble x
, wxDouble y
)
661 m_path
->StartFigure();
662 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
665 void wxGDIPlusPathData::AddLineToPoint( wxDouble x
, wxDouble y
)
667 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
670 void wxGDIPlusPathData::CloseSubpath()
672 m_path
->CloseFigure();
675 void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
681 m_path
->GetLastPoint(&start
);
682 m_path
->AddBezier(start
,c1
,c2
,end
);
685 // gets the last point of the current path, (0,0) if not yet set
686 void wxGDIPlusPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
689 m_path
->GetLastPoint(&start
);
694 void wxGDIPlusPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
696 double sweepAngle
= endAngle
- startAngle
;
697 if( fabs(sweepAngle
) >= 2*M_PI
)
699 sweepAngle
= 2 * M_PI
;
706 sweepAngle
+= 2 * M_PI
;
711 sweepAngle
-= 2 * M_PI
;
715 m_path
->AddArc((REAL
) (x
-r
),(REAL
) (y
-r
),(REAL
) (2*r
),(REAL
) (2*r
),RadToDeg(startAngle
),RadToDeg(sweepAngle
));
718 void wxGDIPlusPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
720 m_path
->AddRectangle(RectF(x
,y
,w
,h
));
723 void wxGDIPlusPathData::AddPath( const wxGraphicsPathData
* path
)
725 m_path
->AddPath( (GraphicsPath
*) path
->GetNativePath(), FALSE
);
729 // transforms each point of this path by the matrix
730 void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData
* matrix
)
732 m_path
->Transform( (Matrix
*) matrix
->GetNativeMatrix() );
735 // gets the bounding box enclosing all points (possibly including control points)
736 void wxGDIPlusPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
739 m_path
->GetBounds( &bounds
, NULL
, NULL
) ;
746 bool wxGDIPlusPathData::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
748 m_path
->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
749 return m_path
->IsVisible( (FLOAT
) x
,(FLOAT
) y
) == TRUE
;
752 //-----------------------------------------------------------------------------
753 // wxGDIPlusMatrixData implementation
754 //-----------------------------------------------------------------------------
756 wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
)
757 : wxGraphicsMatrixData(renderer
)
762 m_matrix
= new Matrix();
765 wxGDIPlusMatrixData::~wxGDIPlusMatrixData()
770 wxGraphicsObjectRefData
*wxGDIPlusMatrixData::Clone() const
772 return new wxGDIPlusMatrixData( GetRenderer(), m_matrix
->Clone());
775 // concatenates the matrix
776 void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData
*t
)
778 m_matrix
->Multiply( (Matrix
*) t
->GetNativeMatrix());
781 // sets the matrix to the respective values
782 void wxGDIPlusMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
783 wxDouble tx
, wxDouble ty
)
785 m_matrix
->SetElements(a
,b
,c
,d
,tx
,ty
);
788 // gets the component valuess of the matrix
789 void wxGDIPlusMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
790 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
793 m_matrix
->GetElements(elements
);
794 if (a
) *a
= elements
[0];
795 if (b
) *b
= elements
[1];
796 if (c
) *c
= elements
[2];
797 if (d
) *d
= elements
[3];
798 if (tx
) *tx
= elements
[4];
799 if (ty
) *ty
= elements
[5];
802 // makes this the inverse matrix
803 void wxGDIPlusMatrixData::Invert()
808 // returns true if the elements of the transformation matrix are equal ?
809 bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
811 return m_matrix
->Equals((Matrix
*) t
->GetNativeMatrix())== TRUE
;
814 // return true if this is the identity matrix
815 bool wxGDIPlusMatrixData::IsIdentity() const
817 return m_matrix
->IsIdentity() == TRUE
;
824 // add the translation to this matrix
825 void wxGDIPlusMatrixData::Translate( wxDouble dx
, wxDouble dy
)
827 m_matrix
->Translate(dx
,dy
);
830 // add the scale to this matrix
831 void wxGDIPlusMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
833 m_matrix
->Scale(xScale
,yScale
);
836 // add the rotation to this matrix (radians)
837 void wxGDIPlusMatrixData::Rotate( wxDouble angle
)
839 m_matrix
->Rotate( angle
);
843 // apply the transforms
846 // applies that matrix to the point
847 void wxGDIPlusMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
850 m_matrix
->TransformPoints(&pt
);
855 // applies the matrix except for translations
856 void wxGDIPlusMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
859 m_matrix
->TransformVectors(&pt
);
864 // returns the native representation
865 void * wxGDIPlusMatrixData::GetNativeMatrix() const
870 //-----------------------------------------------------------------------------
871 // wxGDIPlusContext implementation
872 //-----------------------------------------------------------------------------
874 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusContext
,wxGraphicsContext
)
875 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusMeasuringContext
,wxGDIPlusContext
)
877 class wxGDIPlusOffsetHelper
880 wxGDIPlusOffsetHelper( Graphics
* gr
, bool offset
)
885 m_gr
->TranslateTransform( 0.5, 0.5 );
887 ~wxGDIPlusOffsetHelper( )
890 m_gr
->TranslateTransform( -0.5, -0.5 );
897 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
)
898 : wxGraphicsContext(renderer
)
901 m_context
= new Graphics( hdc
);
905 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
)
906 : wxGraphicsContext(renderer
)
909 m_context
= new Graphics( hwnd
);
913 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
)
914 : wxGraphicsContext(renderer
)
921 wxGDIPlusContext::wxGDIPlusContext() : wxGraphicsContext(NULL
)
926 void wxGDIPlusContext::Init()
933 void wxGDIPlusContext::SetDefaults()
935 m_context
->SetTextRenderingHint(TextRenderingHintSystemDefault
);
936 m_context
->SetPixelOffsetMode(PixelOffsetModeHalf
);
937 m_context
->SetSmoothingMode(SmoothingModeHighQuality
);
938 m_state1
= m_context
->Save();
939 m_state2
= m_context
->Save();
942 wxGDIPlusContext::~wxGDIPlusContext()
946 m_context
->Restore( m_state2
);
947 m_context
->Restore( m_state1
);
953 void wxGDIPlusContext::Clip( const wxRegion
®ion
)
955 Region
rgn((HRGN
)region
.GetHRGN());
956 m_context
->SetClip(&rgn
,CombineModeIntersect
);
959 void wxGDIPlusContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
961 m_context
->SetClip(RectF(x
,y
,w
,h
),CombineModeIntersect
);
964 void wxGDIPlusContext::ResetClip()
966 m_context
->ResetClip();
969 void wxGDIPlusContext::StrokeLines( size_t n
, const wxPoint2DDouble
*points
)
971 if ( !m_pen
.IsNull() )
973 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
974 Point
*cpoints
= new Point
[n
];
975 for (size_t i
= 0; i
< n
; i
++)
977 cpoints
[i
].X
= (int)(points
[i
].m_x
);
978 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
980 } // for (size_t i = 0; i < n; i++)
981 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
986 void wxGDIPlusContext::DrawLines( size_t n
, const wxPoint2DDouble
*points
, int WXUNUSED(fillStyle
) )
988 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
989 Point
*cpoints
= new Point
[n
];
990 for (size_t i
= 0; i
< n
; i
++)
992 cpoints
[i
].X
= (int)(points
[i
].m_x
);
993 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
995 } // for (int i = 0; i < n; i++)
996 if ( !m_brush
.IsNull() )
997 m_context
->FillPolygon( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() , cpoints
, n
) ;
998 if ( !m_pen
.IsNull() )
999 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1003 void wxGDIPlusContext::StrokePath( const wxGraphicsPath
& path
)
1005 if ( !m_pen
.IsNull() )
1007 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1008 m_context
->DrawPath( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath
*) path
.GetNativePath() );
1012 void wxGDIPlusContext::FillPath( const wxGraphicsPath
& path
, int fillStyle
)
1014 if ( !m_brush
.IsNull() )
1016 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1017 ((GraphicsPath
*) path
.GetNativePath())->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1018 m_context
->FillPath( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() ,
1019 (GraphicsPath
*) path
.GetNativePath());
1023 void wxGDIPlusContext::Rotate( wxDouble angle
)
1025 m_context
->RotateTransform( RadToDeg(angle
) );
1028 void wxGDIPlusContext::Translate( wxDouble dx
, wxDouble dy
)
1030 m_context
->TranslateTransform( dx
, dy
);
1033 void wxGDIPlusContext::Scale( wxDouble xScale
, wxDouble yScale
)
1035 m_context
->ScaleTransform(xScale
,yScale
);
1038 void wxGDIPlusContext::PushState()
1040 GraphicsState state
= m_context
->Save();
1041 m_stateStack
.push(state
);
1044 void wxGDIPlusContext::PopState()
1046 GraphicsState state
= m_stateStack
.top();
1048 m_context
->Restore(state
);
1051 // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the
1052 // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied
1053 // bytes as parameter
1055 void wxGDIPlusContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1057 Bitmap
* image
= NULL
;
1058 Bitmap
* helper
= NULL
;
1059 if ( bmp
.GetMask() )
1061 Bitmap
interim((HBITMAP
)bmp
.GetHBITMAP(),(HPALETTE
)bmp
.GetPalette()->GetHPALETTE()) ;
1063 size_t width
= interim
.GetWidth();
1064 size_t height
= interim
.GetHeight();
1065 Rect
bounds(0,0,width
,height
);
1067 image
= new Bitmap(width
,height
,PixelFormat32bppPARGB
) ;
1069 Bitmap
interimMask((HBITMAP
)bmp
.GetMask()->GetMaskBitmap(),NULL
);
1070 wxASSERT(interimMask
.GetPixelFormat() == PixelFormat1bppIndexed
);
1072 BitmapData dataMask
;
1073 interimMask
.LockBits(&bounds
,ImageLockModeRead
,
1074 interimMask
.GetPixelFormat(),&dataMask
);
1077 BitmapData imageData
;
1078 image
->LockBits(&bounds
,ImageLockModeWrite
, PixelFormat32bppPARGB
, &imageData
);
1080 BYTE maskPattern
= 0 ;
1084 for ( size_t y
= 0 ; y
< height
; ++y
)
1087 for( size_t x
= 0 ; x
< width
; ++x
)
1092 maskByte
= *((BYTE
*)dataMask
.Scan0
+ dataMask
.Stride
*y
+ maskIndex
);
1096 maskPattern
= maskPattern
>> 1;
1098 ARGB
*dest
= (ARGB
*)((BYTE
*)imageData
.Scan0
+ imageData
.Stride
*y
+ x
*4);
1099 if ( (maskByte
& maskPattern
) == 0 )
1104 interim
.GetPixel(x
,y
,&c
) ;
1105 *dest
= (c
.GetValue() | Color::AlphaMask
);
1110 image
->UnlockBits(&imageData
);
1112 interimMask
.UnlockBits(&dataMask
);
1113 interim
.UnlockBits(&dataMask
);
1117 image
= Bitmap::FromHBITMAP((HBITMAP
)bmp
.GetHBITMAP(),(HPALETTE
)bmp
.GetPalette()->GetHPALETTE());
1118 if ( bmp
.HasAlpha() && GetPixelFormatSize(image
->GetPixelFormat()) == 32 )
1120 size_t width
= image
->GetWidth();
1121 size_t height
= image
->GetHeight();
1122 Rect
bounds(0,0,width
,height
);
1127 helper
->LockBits(&bounds
, ImageLockModeRead
,
1128 helper
->GetPixelFormat(),&data
);
1130 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1131 PixelFormat32bppPARGB
, (BYTE
*) data
.Scan0
);
1133 helper
->UnlockBits(&data
);
1137 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1142 void wxGDIPlusContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1144 // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
1145 // find out by looking at the bitmap data whether there really was alpha in it
1146 HICON hIcon
= (HICON
)icon
.GetHICON();
1148 // IconInfo creates the bitmaps for color and mask, we must dispose of them after use
1149 if (!GetIconInfo(hIcon
,&iconInfo
))
1152 Bitmap
interim(iconInfo
.hbmColor
,NULL
);
1154 Bitmap
* image
= NULL
;
1156 // if it's not 32 bit, it doesn't have an alpha channel, note that since the conversion doesn't
1157 // work correctly, asking IsAlphaPixelFormat at this point fails as well
1158 if( GetPixelFormatSize(interim
.GetPixelFormat())!= 32 )
1160 image
= Bitmap::FromHICON(hIcon
);
1164 size_t width
= interim
.GetWidth();
1165 size_t height
= interim
.GetHeight();
1166 Rect
bounds(0,0,width
,height
);
1169 interim
.LockBits(&bounds
, ImageLockModeRead
,
1170 interim
.GetPixelFormat(),&data
);
1172 bool hasAlpha
= false;
1173 for ( size_t y
= 0 ; y
< height
&& !hasAlpha
; ++y
)
1175 for( size_t x
= 0 ; x
< width
&& !hasAlpha
; ++x
)
1177 ARGB
*dest
= (ARGB
*)((BYTE
*)data
.Scan0
+ data
.Stride
*y
+ x
*4);
1178 if ( ( *dest
& Color::AlphaMask
) != 0 )
1185 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1186 PixelFormat32bppARGB
, (BYTE
*) data
.Scan0
);
1190 image
= Bitmap::FromHICON(hIcon
);
1193 interim
.UnlockBits(&data
);
1196 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1199 DeleteObject(iconInfo
.hbmColor
);
1200 DeleteObject(iconInfo
.hbmMask
);
1203 void wxGDIPlusContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1205 if ( m_font
.IsNull() || str
.IsEmpty())
1208 wxWCharBuffer s
= str
.wc_str( *wxConvUI
);
1209 m_context
->DrawString( s
, -1 , ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont() ,
1210 PointF( x
, y
) , StringFormat::GenericTypographic() , ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusBrush() );
1213 void wxGDIPlusContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1214 wxDouble
*descent
, wxDouble
*externalLeading
) const
1216 wxWCharBuffer s
= str
.wc_str( *wxConvUI
);
1217 FontFamily ffamily
;
1218 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1220 f
->GetFamily(&ffamily
) ;
1222 REAL factorY
= m_context
->GetDpiY() / 72.0 ;
1224 REAL rDescent
= ffamily
.GetCellDescent(FontStyleRegular
) *
1225 f
->GetSize() / ffamily
.GetEmHeight(FontStyleRegular
);
1226 REAL rAscent
= ffamily
.GetCellAscent(FontStyleRegular
) *
1227 f
->GetSize() / ffamily
.GetEmHeight(FontStyleRegular
);
1228 REAL rHeight
= ffamily
.GetLineSpacing(FontStyleRegular
) *
1229 f
->GetSize() / ffamily
.GetEmHeight(FontStyleRegular
);
1232 *height
= rHeight
* factorY
;
1234 *descent
= rDescent
* factorY
;
1235 if ( externalLeading
)
1236 *externalLeading
= (rHeight
- rAscent
- rDescent
) * factorY
;
1237 // measuring empty strings is not guaranteed, so do it by hand
1245 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1246 StringFormat
strFormat( StringFormat::GenericTypographic() );
1247 strFormat
.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces
| strFormat
.GetFormatFlags() );
1250 m_context
->MeasureString((const wchar_t *) s
, wcslen(s
) , f
, layoutRect
, &strFormat
, &bounds
) ;
1252 *width
= bounds
.Width
;
1256 void wxGDIPlusContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1259 widths
.Add(0, text
.length());
1264 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1265 wxWCharBuffer ws
= text
.wc_str( *wxConvUI
);
1266 size_t len
= wcslen( ws
) ;
1267 wxASSERT_MSG(text
.length() == len
, wxT("GetPartialTextExtents not yet implemented for multichar situations"));
1269 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1270 StringFormat
strFormat( StringFormat::GenericTypographic() );
1272 CharacterRange
* ranges
= new CharacterRange
[len
] ;
1273 Region
* regions
= new Region
[len
];
1274 for( size_t i
= 0 ; i
< len
; ++i
)
1276 ranges
[i
].First
= i
;
1277 ranges
[i
].Length
= 1 ;
1279 strFormat
.SetMeasurableCharacterRanges(len
,ranges
);
1280 strFormat
.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces
| strFormat
.GetFormatFlags() );
1281 m_context
->MeasureCharacterRanges(ws
, -1 , f
,layoutRect
, &strFormat
,1,regions
) ;
1284 for ( size_t i
= 0 ; i
< len
; ++i
)
1286 regions
[i
].GetBounds(&bbox
,m_context
);
1287 widths
[i
] = bbox
.GetRight()-bbox
.GetLeft();
1291 bool wxGDIPlusContext::ShouldOffset() const
1294 if ( !m_pen
.IsNull() )
1296 penwidth
= (int)((wxGDIPlusPenData
*)m_pen
.GetRefData())->GetWidth();
1297 if ( penwidth
== 0 )
1300 return ( penwidth
% 2 ) == 1;
1303 void* wxGDIPlusContext::GetNativeContext()
1308 // concatenates this transform with the current transform of this context
1309 void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1311 m_context
->MultiplyTransform((Matrix
*) matrix
.GetNativeMatrix());
1314 // sets the transform of this context
1315 void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1317 m_context
->SetTransform((Matrix
*) matrix
.GetNativeMatrix());
1320 // gets the matrix of this context
1321 wxGraphicsMatrix
wxGDIPlusContext::GetTransform() const
1323 wxGraphicsMatrix matrix
= CreateMatrix();
1324 m_context
->GetTransform((Matrix
*) matrix
.GetNativeMatrix());
1327 //-----------------------------------------------------------------------------
1328 // wxGDIPlusRenderer declaration
1329 //-----------------------------------------------------------------------------
1331 class wxGDIPlusRenderer
: public wxGraphicsRenderer
1340 virtual ~wxGDIPlusRenderer()
1350 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
1352 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
1354 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
1356 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
1358 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
1360 virtual wxGraphicsContext
* CreateMeasuringContext();
1364 virtual wxGraphicsPath
CreatePath();
1368 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
1369 wxDouble tx
=0.0, wxDouble ty
=0.0);
1372 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
1374 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
1376 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1377 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1378 const wxColour
&c1
, const wxColour
&c2
) ;
1380 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1381 // with radius r and color cColor
1382 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1383 const wxColour
&oColor
, const wxColour
&cColor
) ;
1386 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
1388 void EnsureIsLoaded();
1391 friend class wxGDIPlusRendererModule
;
1395 ULONG_PTR m_gditoken
;
1397 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer
)
1400 //-----------------------------------------------------------------------------
1401 // wxGDIPlusRenderer implementation
1402 //-----------------------------------------------------------------------------
1404 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer
,wxGraphicsRenderer
)
1406 static wxGDIPlusRenderer gs_GDIPlusRenderer
;
1408 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
1410 return &gs_GDIPlusRenderer
;
1413 void wxGDIPlusRenderer::EnsureIsLoaded()
1421 void wxGDIPlusRenderer::Load()
1423 GdiplusStartupInput input
;
1424 GdiplusStartupOutput output
;
1425 GdiplusStartup(&m_gditoken
,&input
,&output
);
1429 void wxGDIPlusRenderer::Unload()
1433 GdiplusShutdown(m_gditoken
);
1439 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxWindowDC
& dc
)
1442 wxMSWDCImpl
*msw
= wxDynamicCast( dc
.GetImpl() , wxMSWDCImpl
);
1443 return new wxGDIPlusContext(this,(HDC
) msw
->GetHDC());
1446 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxMemoryDC
& dc
)
1449 wxMSWDCImpl
*msw
= wxDynamicCast( dc
.GetImpl() , wxMSWDCImpl
);
1450 return new wxGDIPlusContext(this,(HDC
) msw
->GetHDC());
1453 wxGraphicsContext
* wxGDIPlusRenderer::CreateMeasuringContext()
1456 return new wxGDIPlusMeasuringContext(this);
1459 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeContext( void * context
)
1462 return new wxGDIPlusContext(this,(Graphics
*) context
);
1466 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window
)
1469 return new wxGDIPlusContext(this,(HWND
) window
);
1472 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( wxWindow
* window
)
1475 return new wxGDIPlusContext(this, (HWND
) window
->GetHWND() );
1480 wxGraphicsPath
wxGDIPlusRenderer::CreatePath()
1484 m
.SetRefData( new wxGDIPlusPathData(this));
1491 wxGraphicsMatrix
wxGDIPlusRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1492 wxDouble tx
, wxDouble ty
)
1497 wxGDIPlusMatrixData
* data
= new wxGDIPlusMatrixData( this );
1498 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
1503 wxGraphicsPen
wxGDIPlusRenderer::CreatePen(const wxPen
& pen
)
1506 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
1507 return wxNullGraphicsPen
;
1511 p
.SetRefData(new wxGDIPlusPenData( this, pen
));
1516 wxGraphicsBrush
wxGDIPlusRenderer::CreateBrush(const wxBrush
& brush
)
1519 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
1520 return wxNullGraphicsBrush
;
1524 p
.SetRefData(new wxGDIPlusBrushData( this, brush
));
1529 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
1530 wxGraphicsBrush
wxGDIPlusRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
1531 const wxColour
&c1
, const wxColour
&c2
)
1535 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
1536 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
1541 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
1542 // with radius r and color cColor
1543 wxGraphicsBrush
wxGDIPlusRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
1544 const wxColour
&oColor
, const wxColour
&cColor
)
1548 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
1549 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
1555 wxGraphicsFont
wxGDIPlusRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
1561 p
.SetRefData(new wxGDIPlusFontData( this , font
, col
));
1565 return wxNullGraphicsFont
;
1568 // Shutdown GDI+ at app exit, before possible dll unload
1569 class wxGDIPlusRendererModule
: public wxModule
1572 virtual bool OnInit() { return true; }
1573 virtual void OnExit() { gs_GDIPlusRenderer
.Unload(); }
1576 DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule
)
1579 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule
, wxModule
)
1581 #endif // wxUSE_GRAPHICS_CONTEXT