1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/graphcmn.cpp
3 // Purpose: graphics context methods common to all platforms
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #if defined(__BORLANDC__)
19 #if wxUSE_GRAPHICS_CONTEXT
21 #include "wx/private/graphics.h"
25 #include "wx/bitmap.h"
26 #include "wx/dcmemory.h"
27 #include "wx/region.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 static const double RAD2DEG
= 180.0 / M_PI
;
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 static inline double DegToRad(double deg
)
43 return (deg
* M_PI
) / 180.0;
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsObject
, wxObject
)
54 wxGraphicsObjectRefData::wxGraphicsObjectRefData( wxGraphicsRenderer
* renderer
)
56 m_renderer
= renderer
;
58 wxGraphicsObjectRefData::wxGraphicsObjectRefData( const wxGraphicsObjectRefData
* data
)
60 m_renderer
= data
->m_renderer
;
62 wxGraphicsRenderer
* wxGraphicsObjectRefData::GetRenderer() const
67 wxGraphicsObjectRefData
* wxGraphicsObjectRefData::Clone() const
69 return new wxGraphicsObjectRefData(this);
72 wxGraphicsObject::wxGraphicsObject()
76 wxGraphicsObject::wxGraphicsObject( wxGraphicsRenderer
* renderer
)
78 SetRefData( new wxGraphicsObjectRefData(renderer
));
81 wxGraphicsObject::~wxGraphicsObject()
85 bool wxGraphicsObject::IsNull() const
87 return m_refData
== NULL
;
90 wxGraphicsRenderer
* wxGraphicsObject::GetRenderer() const
92 return ( IsNull() ? NULL
: GetGraphicsData()->GetRenderer() );
95 wxGraphicsObjectRefData
* wxGraphicsObject::GetGraphicsData() const
97 return (wxGraphicsObjectRefData
*) m_refData
;
100 wxObjectRefData
* wxGraphicsObject::CreateRefData() const
102 wxLogDebug(wxT("A Null Object cannot be changed"));
106 wxObjectRefData
* wxGraphicsObject::CloneRefData(const wxObjectRefData
* data
) const
108 const wxGraphicsObjectRefData
* ptr
= (const wxGraphicsObjectRefData
*) data
;
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
116 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsPen
, wxGraphicsObject
)
117 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBrush
, wxGraphicsObject
)
118 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsFont
, wxGraphicsObject
)
119 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBitmap
, wxGraphicsObject
)
121 WXDLLIMPEXP_DATA_CORE(wxGraphicsPen
) wxNullGraphicsPen
;
122 WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush
) wxNullGraphicsBrush
;
123 WXDLLIMPEXP_DATA_CORE(wxGraphicsFont
) wxNullGraphicsFont
;
124 WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap
) wxNullGraphicsBitmap
;
126 //-----------------------------------------------------------------------------
128 //-----------------------------------------------------------------------------
130 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsMatrix
, wxGraphicsObject
)
131 WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix
) wxNullGraphicsMatrix
;
133 // concatenates the matrix
134 void wxGraphicsMatrix::Concat( const wxGraphicsMatrix
*t
)
137 GetMatrixData()->Concat(t
->GetMatrixData());
140 // sets the matrix to the respective values
141 void wxGraphicsMatrix::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
142 wxDouble tx
, wxDouble ty
)
145 GetMatrixData()->Set(a
,b
,c
,d
,tx
,ty
);
148 // gets the component valuess of the matrix
149 void wxGraphicsMatrix::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
150 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
152 GetMatrixData()->Get(a
, b
, c
, d
, tx
, ty
);
155 // makes this the inverse matrix
156 void wxGraphicsMatrix::Invert()
159 GetMatrixData()->Invert();
162 // returns true if the elements of the transformation matrix are equal ?
163 bool wxGraphicsMatrix::IsEqual( const wxGraphicsMatrix
* t
) const
165 return GetMatrixData()->IsEqual(t
->GetMatrixData());
168 // return true if this is the identity matrix
169 bool wxGraphicsMatrix::IsIdentity() const
171 return GetMatrixData()->IsIdentity();
174 // add the translation to this matrix
175 void wxGraphicsMatrix::Translate( wxDouble dx
, wxDouble dy
)
178 GetMatrixData()->Translate(dx
,dy
);
181 // add the scale to this matrix
182 void wxGraphicsMatrix::Scale( wxDouble xScale
, wxDouble yScale
)
185 GetMatrixData()->Scale(xScale
,yScale
);
188 // add the rotation to this matrix (radians)
189 void wxGraphicsMatrix::Rotate( wxDouble angle
)
192 GetMatrixData()->Rotate(angle
);
196 // apply the transforms
199 // applies that matrix to the point
200 void wxGraphicsMatrix::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
202 GetMatrixData()->TransformPoint(x
,y
);
205 // applies the matrix except for translations
206 void wxGraphicsMatrix::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
208 GetMatrixData()->TransformDistance(dx
,dy
);
211 // returns the native representation
212 void * wxGraphicsMatrix::GetNativeMatrix() const
214 return GetMatrixData()->GetNativeMatrix();
217 //-----------------------------------------------------------------------------
219 //-----------------------------------------------------------------------------
221 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsPath
, wxGraphicsObject
)
222 WXDLLIMPEXP_DATA_CORE(wxGraphicsPath
) wxNullGraphicsPath
;
224 // convenience functions, for using wxPoint2DDouble etc
226 wxPoint2DDouble
wxGraphicsPath::GetCurrentPoint() const
229 GetCurrentPoint(&x
,&y
);
230 return wxPoint2DDouble(x
,y
);
233 void wxGraphicsPath::MoveToPoint( const wxPoint2DDouble
& p
)
235 MoveToPoint( p
.m_x
, p
.m_y
);
238 void wxGraphicsPath::AddLineToPoint( const wxPoint2DDouble
& p
)
240 AddLineToPoint( p
.m_x
, p
.m_y
);
243 void wxGraphicsPath::AddCurveToPoint( const wxPoint2DDouble
& c1
, const wxPoint2DDouble
& c2
, const wxPoint2DDouble
& e
)
245 AddCurveToPoint(c1
.m_x
, c1
.m_y
, c2
.m_x
, c2
.m_y
, e
.m_x
, e
.m_y
);
248 void wxGraphicsPath::AddArc( const wxPoint2DDouble
& c
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
250 AddArc(c
.m_x
, c
.m_y
, r
, startAngle
, endAngle
, clockwise
);
253 wxRect2DDouble
wxGraphicsPath::GetBox() const
257 return wxRect2DDouble( x
,y
,w
,h
);
260 bool wxGraphicsPath::Contains( const wxPoint2DDouble
& c
, wxPolygonFillMode fillStyle
) const
262 return Contains( c
.m_x
, c
.m_y
, fillStyle
);
267 // begins a new subpath at (x,y)
268 void wxGraphicsPath::MoveToPoint( wxDouble x
, wxDouble y
)
271 GetPathData()->MoveToPoint(x
,y
);
274 // adds a straight line from the current point to (x,y)
275 void wxGraphicsPath::AddLineToPoint( wxDouble x
, wxDouble y
)
278 GetPathData()->AddLineToPoint(x
,y
);
281 // adds a cubic Bezier curve from the current point, using two control points and an end point
282 void wxGraphicsPath::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
285 GetPathData()->AddCurveToPoint(cx1
,cy1
,cx2
,cy2
,x
,y
);
289 void wxGraphicsPath::AddPath( const wxGraphicsPath
& path
)
292 GetPathData()->AddPath(path
.GetPathData());
295 // closes the current sub-path
296 void wxGraphicsPath::CloseSubpath()
299 GetPathData()->CloseSubpath();
302 // gets the last point of the current path, (0,0) if not yet set
303 void wxGraphicsPath::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
305 GetPathData()->GetCurrentPoint(x
,y
);
308 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
309 void wxGraphicsPath::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
312 GetPathData()->AddArc(x
,y
,r
,startAngle
,endAngle
,clockwise
);
316 // These are convenience functions which - if not available natively will be assembled
317 // using the primitives from above
320 // adds a quadratic Bezier curve from the current point, using a control point and an end point
321 void wxGraphicsPath::AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
)
324 GetPathData()->AddQuadCurveToPoint(cx
,cy
,x
,y
);
327 // appends a rectangle as a new closed subpath
328 void wxGraphicsPath::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
331 GetPathData()->AddRectangle(x
,y
,w
,h
);
334 // appends an ellipsis as a new closed subpath fitting the passed rectangle
335 void wxGraphicsPath::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
338 GetPathData()->AddCircle(x
,y
,r
);
341 // appends 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)
342 void wxGraphicsPath::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
344 GetPathData()->AddArcToPoint(x1
,y1
,x2
,y2
,r
);
347 // appends an ellipse
348 void wxGraphicsPath::AddEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
351 GetPathData()->AddEllipse(x
,y
,w
,h
);
354 // appends a rounded rectangle
355 void wxGraphicsPath::AddRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
)
358 GetPathData()->AddRoundedRectangle(x
,y
,w
,h
,radius
);
361 // returns the native path
362 void * wxGraphicsPath::GetNativePath() const
364 return GetPathData()->GetNativePath();
367 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
368 void wxGraphicsPath::UnGetNativePath(void *p
)const
370 GetPathData()->UnGetNativePath(p
);
373 // transforms each point of this path by the matrix
374 void wxGraphicsPath::Transform( const wxGraphicsMatrix
& matrix
)
377 GetPathData()->Transform(matrix
.GetMatrixData());
380 // gets the bounding box enclosing all points (possibly including control points)
381 void wxGraphicsPath::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
383 GetPathData()->GetBox(x
,y
,w
,h
);
386 bool wxGraphicsPath::Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
) const
388 return GetPathData()->Contains(x
,y
,fillStyle
);
392 // Emulations, these mus be implemented in the ...Data classes in order to allow for proper overrides
395 void wxGraphicsPathData::AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
)
397 // calculate using degree elevation to a cubic bezier
401 wxPoint2DDouble start
;
402 GetCurrentPoint(&start
.m_x
,&start
.m_y
);
403 wxPoint2DDouble
end(x
,y
);
404 wxPoint2DDouble
c(cx
,cy
);
405 c1
= wxDouble(1/3.0) * start
+ wxDouble(2/3.0) * c
;
406 c2
= wxDouble(2/3.0) * c
+ wxDouble(1/3.0) * end
;
407 AddCurveToPoint(c1
.m_x
,c1
.m_y
,c2
.m_x
,c2
.m_y
,x
,y
);
410 void wxGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
413 AddLineToPoint(x
,y
+h
);
414 AddLineToPoint(x
+w
,y
+h
);
415 AddLineToPoint(x
+w
,y
);
419 void wxGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
422 AddArc( x
,y
,r
,0,2*M_PI
,false);
426 void wxGraphicsPathData::AddEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
428 if (w
<= 0. || h
<= 0.)
433 wxDouble xc
= x
+ rw
;
434 wxDouble yc
= y
+ rh
;
435 wxGraphicsMatrix m
= GetRenderer()->CreateMatrix();
438 wxGraphicsPath p
= GetRenderer()->CreatePath();
441 AddPath(p
.GetPathData());
444 void wxGraphicsPathData::AddRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
)
447 AddRectangle(x
,y
,w
,h
);
450 MoveToPoint( x
+ w
, y
+ h
/ 2);
451 AddArcToPoint(x
+ w
, y
+ h
, x
+ w
/ 2, y
+ h
, radius
);
452 AddArcToPoint(x
, y
+ h
, x
, y
+ h
/ 2, radius
);
453 AddArcToPoint(x
, y
, x
+ w
/ 2, y
, radius
);
454 AddArcToPoint(x
+ w
, y
, x
+ w
, y
+ h
/ 2, radius
);
459 // 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)
460 void wxGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
462 wxPoint2DDouble current
;
463 GetCurrentPoint(¤t
.m_x
,¤t
.m_y
);
464 wxPoint2DDouble
p1(x1
,y1
);
465 wxPoint2DDouble
p2(x2
,y2
);
467 wxPoint2DDouble v1
= current
- p1
;
469 wxPoint2DDouble v2
= p2
- p1
;
472 wxDouble alpha
= v1
.GetVectorAngle() - v2
.GetVectorAngle();
476 // TODO obtuse angles
478 alpha
= DegToRad(alpha
);
480 wxDouble dist
= r
/ sin(alpha
/2) * cos(alpha
/2);
481 // calculate tangential points
482 wxPoint2DDouble t1
= dist
*v1
+ p1
;
483 wxPoint2DDouble t2
= dist
*v2
+ p1
;
485 wxPoint2DDouble nv1
= v1
;
486 nv1
.SetVectorAngle(v1
.GetVectorAngle()-90);
487 wxPoint2DDouble c
= t1
+ r
*nv1
;
489 wxDouble a1
= v1
.GetVectorAngle()+90;
490 wxDouble a2
= v2
.GetVectorAngle()-90;
492 AddLineToPoint(t1
.m_x
,t1
.m_y
);
493 AddArc(c
.m_x
,c
.m_y
,r
,DegToRad(a1
),DegToRad(a2
),true);
494 AddLineToPoint(p2
.m_x
,p2
.m_y
);
497 //-----------------------------------------------------------------------------
498 // wxGraphicsContext Convenience Methods
499 //-----------------------------------------------------------------------------
501 IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext
, wxObject
)
504 wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsObject(renderer
)
506 m_logicalFunction
= wxCOPY
;
509 wxGraphicsContext::~wxGraphicsContext()
513 bool wxGraphicsContext::StartDoc(const wxString
& WXUNUSED(message
))
518 void wxGraphicsContext::EndDoc()
522 void wxGraphicsContext::StartPage(wxDouble
WXUNUSED(width
),
523 wxDouble
WXUNUSED(height
))
527 void wxGraphicsContext::EndPage()
531 void wxGraphicsContext::Flush()
536 void wxGraphicsContext::SetAlpha( wxDouble
WXUNUSED(alpha
) )
540 wxDouble
wxGraphicsContext::GetAlpha() const
546 void wxGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
552 void wxGraphicsContext::GetDPI( wxDouble
* dpiX
, wxDouble
* dpiY
)
559 void wxGraphicsContext::SetPen( const wxGraphicsPen
& pen
)
564 void wxGraphicsContext::SetPen( const wxPen
& pen
)
566 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
567 SetPen( wxNullGraphicsPen
);
569 SetPen( CreatePen( pen
) );
572 // sets the brush for filling
573 void wxGraphicsContext::SetBrush( const wxGraphicsBrush
& brush
)
578 void wxGraphicsContext::SetBrush( const wxBrush
& brush
)
580 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
581 SetBrush( wxNullGraphicsBrush
);
583 SetBrush( CreateBrush( brush
) );
586 // sets the brush for filling
587 void wxGraphicsContext::SetFont( const wxGraphicsFont
& font
)
592 bool wxGraphicsContext::SetLogicalFunction( wxRasterOperationMode function
)
594 if ( function
== wxCOPY
)
596 m_logicalFunction
= function
;
602 void wxGraphicsContext::SetFont( const wxFont
& font
, const wxColour
& colour
)
605 SetFont( CreateFont( font
, colour
) );
607 SetFont( wxNullGraphicsFont
);
610 void wxGraphicsContext::DrawPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
)
612 FillPath( path
, fillStyle
);
617 wxGraphicsContext::DoDrawRotatedText(const wxString
&str
,
624 DrawText( str
, 0, 0 );
630 wxGraphicsContext::DoDrawFilledText(const wxString
&str
,
633 const wxGraphicsBrush
& backgroundBrush
)
635 wxGraphicsBrush formerBrush
= m_brush
;
636 wxGraphicsPen formerPen
= m_pen
;
640 wxDouble externalLeading
;
641 GetTextExtent( str
, &width
, &height
, &descent
, &externalLeading
);
642 SetBrush( backgroundBrush
);
643 // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
644 SetPen( wxNullGraphicsPen
);
646 wxGraphicsPath path
= CreatePath();
647 path
.AddRectangle( x
, y
, width
, height
);
650 DrawText( str
, x
,y
);
651 SetBrush( formerBrush
);
656 wxGraphicsContext::DoDrawRotatedFilledText(const wxString
&str
,
657 wxDouble x
, wxDouble y
,
659 const wxGraphicsBrush
& backgroundBrush
)
661 wxGraphicsBrush formerBrush
= m_brush
;
662 wxGraphicsPen formerPen
= m_pen
;
667 wxDouble externalLeading
;
668 GetTextExtent( str
, &width
, &height
, &descent
, &externalLeading
);
669 SetBrush( backgroundBrush
);
670 // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
671 SetPen( wxNullGraphicsPen
);
673 wxGraphicsPath path
= CreatePath();
674 path
.MoveToPoint( x
, y
);
675 path
.AddLineToPoint( (int) (x
+ sin(angle
) * height
) , (int) (y
+ cos(angle
) * height
) );
677 (int) (x
+ sin(angle
) * height
+ cos(angle
) * width
) ,
678 (int) (y
+ cos(angle
) * height
- sin(angle
) * width
));
679 path
.AddLineToPoint((int) (x
+ cos(angle
) * width
) , (int) (y
- sin(angle
) * width
) );
681 DrawText( str
, x
,y
, angle
);
682 SetBrush( formerBrush
);
686 void wxGraphicsContext::StrokeLine( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
)
688 wxGraphicsPath path
= CreatePath();
689 path
.MoveToPoint(x1
, y1
);
690 path
.AddLineToPoint( x2
, y2
);
694 void wxGraphicsContext::DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
696 wxGraphicsPath path
= CreatePath();
697 path
.AddRectangle( x
, y
, w
, h
);
701 void wxGraphicsContext::DrawEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
703 wxGraphicsPath path
= CreatePath();
704 path
.AddEllipse(x
,y
,w
,h
);
708 void wxGraphicsContext::DrawRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
)
710 wxGraphicsPath path
= CreatePath();
711 path
.AddRoundedRectangle(x
,y
,w
,h
,radius
);
715 void wxGraphicsContext::StrokeLines( size_t n
, const wxPoint2DDouble
*points
)
718 wxGraphicsPath path
= CreatePath();
719 path
.MoveToPoint(points
[0].m_x
, points
[0].m_y
);
720 for ( size_t i
= 1; i
< n
; ++i
)
721 path
.AddLineToPoint( points
[i
].m_x
, points
[i
].m_y
);
725 void wxGraphicsContext::DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
)
728 wxGraphicsPath path
= CreatePath();
729 path
.MoveToPoint(points
[0].m_x
, points
[0].m_y
);
730 for ( size_t i
= 1; i
< n
; ++i
)
731 path
.AddLineToPoint( points
[i
].m_x
, points
[i
].m_y
);
732 DrawPath( path
, fillStyle
);
735 void wxGraphicsContext::StrokeLines( size_t n
, const wxPoint2DDouble
*beginPoints
, const wxPoint2DDouble
*endPoints
)
738 wxGraphicsPath path
= CreatePath();
739 for ( size_t i
= 0; i
< n
; ++i
)
741 path
.MoveToPoint(beginPoints
[i
].m_x
, beginPoints
[i
].m_y
);
742 path
.AddLineToPoint( endPoints
[i
].m_x
, endPoints
[i
].m_y
);
747 // create a 'native' matrix corresponding to these values
748 wxGraphicsMatrix
wxGraphicsContext::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
749 wxDouble tx
, wxDouble ty
) const
751 return GetRenderer()->CreateMatrix(a
,b
,c
,d
,tx
,ty
);
754 wxGraphicsPath
wxGraphicsContext::CreatePath() const
756 return GetRenderer()->CreatePath();
759 wxGraphicsPen
wxGraphicsContext::CreatePen(const wxPen
& pen
) const
761 return GetRenderer()->CreatePen(pen
);
764 wxGraphicsBrush
wxGraphicsContext::CreateBrush(const wxBrush
& brush
) const
766 return GetRenderer()->CreateBrush(brush
);
769 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
770 wxGraphicsBrush
wxGraphicsContext::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
771 const wxColour
&c1
, const wxColour
&c2
) const
773 return GetRenderer()->CreateLinearGradientBrush(x1
,y1
,x2
,y2
,c1
,c2
);
776 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
777 // with radius r and color cColor
778 wxGraphicsBrush
wxGraphicsContext::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
779 const wxColour
&oColor
, const wxColour
&cColor
) const
781 return GetRenderer()->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
785 wxGraphicsFont
wxGraphicsContext::CreateFont( const wxFont
&font
, const wxColour
&col
) const
787 return GetRenderer()->CreateFont(font
,col
);
790 wxGraphicsBitmap
wxGraphicsContext::CreateBitmap( const wxBitmap
& bmp
) const
793 return GetRenderer()->CreateBitmap(bmp
);
795 return wxNullGraphicsBitmap
;
799 wxGraphicsBitmap
wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) const
802 return GetRenderer()->CreateSubBitmap(bmp
,x
,y
,w
,h
);
804 return wxNullGraphicsBitmap
;
808 /* static */ wxGraphicsContext
* wxGraphicsContext::Create( const wxWindowDC
& dc
)
810 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc
);
813 /* static */ wxGraphicsContext
* wxGraphicsContext::Create( const wxMemoryDC
& dc
)
815 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc
);
818 #if wxUSE_PRINTING_ARCHITECTURE
819 /* static */ wxGraphicsContext
* wxGraphicsContext::Create( const wxPrinterDC
& dc
)
821 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc
);
825 wxGraphicsContext
* wxGraphicsContext::CreateFromNative( void * context
)
827 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeContext(context
);
830 wxGraphicsContext
* wxGraphicsContext::CreateFromNativeWindow( void * window
)
832 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeWindow(window
);
835 wxGraphicsContext
* wxGraphicsContext::Create( wxWindow
* window
)
837 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window
);
840 wxGraphicsContext
* wxGraphicsContext::Create()
842 return wxGraphicsRenderer::GetDefaultRenderer()->CreateMeasuringContext();
845 //-----------------------------------------------------------------------------
846 // wxGraphicsRenderer
847 //-----------------------------------------------------------------------------
849 IMPLEMENT_ABSTRACT_CLASS(wxGraphicsRenderer
, wxObject
)
851 #endif // wxUSE_GRAPHICS_CONTEXT