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/graphics.h"
25 #include "wx/bitmap.h"
26 #include "wx/dcmemory.h"
27 #include "wx/region.h"
30 #ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
31 #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 static const double RAD2DEG
= 180.0 / M_PI
;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 static inline double DegToRad(double deg
)
46 return (deg
* M_PI
) / 180.0;
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
54 IMPLEMENT_DYNAMIC_CLASS(wxGCDC
, wxDCBase
)
56 IMPLEMENT_DYNAMIC_CLASS(wxGCDC
, wxDC
)
64 void wxGCDC::SetGraphicsContext( wxGraphicsContext
* ctx
)
66 delete m_graphicContext
;
67 m_graphicContext
= ctx
;
68 if ( m_graphicContext
)
70 m_matrixOriginal
= m_graphicContext
->GetTransform();
75 wxGCDC::wxGCDC(const wxWindowDC
& dc
)
78 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
79 if ( dc
.GetFont().Ok())
80 m_graphicContext
->SetFont( m_graphicContext
->CreateFont(dc
.GetFont(),dc
.GetTextForeground()));
81 if ( dc
.GetPen().Ok())
82 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(dc
.GetPen()));
83 if ( dc
.GetBrush().Ok())
84 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(dc
.GetBrush()));
91 m_mm_to_pix_x
= mm2pt
;
92 m_mm_to_pix_y
= mm2pt
;
95 m_font
= *wxNORMAL_FONT
;
96 m_brush
= *wxWHITE_BRUSH
;
98 m_graphicContext
= NULL
;
104 delete m_graphicContext
;
107 void wxGCDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
109 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
110 wxCHECK_RET( bmp
.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
112 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
115 void wxGCDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
117 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
118 wxCHECK_RET( icon
.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
120 wxCoord w
= icon
.GetWidth();
121 wxCoord h
= icon
.GetHeight();
123 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
126 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
128 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
130 m_graphicContext
->Clip( x
, y
, w
, h
);
133 m_clipX1
= wxMax( m_clipX1
, x
);
134 m_clipY1
= wxMax( m_clipY1
, y
);
135 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
136 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
149 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
151 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
155 DestroyClippingRegion();
160 region
.GetBox( x
, y
, w
, h
);
162 m_graphicContext
->Clip( region
);
165 m_clipX1
= wxMax( m_clipX1
, x
);
166 m_clipY1
= wxMax( m_clipY1
, y
);
167 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
168 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
181 void wxGCDC::DestroyClippingRegion()
183 m_graphicContext
->ResetClip();
184 m_graphicContext
->SetPen( m_pen
);
185 m_graphicContext
->SetBrush( m_brush
);
190 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
196 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
198 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
201 void wxGCDC::SetTextForeground( const wxColour
&col
)
203 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
205 if ( col
!= m_textForegroundColour
)
207 m_textForegroundColour
= col
;
208 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
212 void wxGCDC::SetTextBackground( const wxColour
&col
)
214 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
216 m_textBackgroundColour
= col
;
219 void wxGCDC::SetMapMode( int mode
)
224 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
228 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
232 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
236 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
241 SetLogicalScale( 1.0, 1.0 );
245 ComputeScaleAndOrigin();
248 void wxGCDC::SetUserScale( double x
, double y
)
250 // allow negative ? -> no
254 ComputeScaleAndOrigin();
257 void wxGCDC::SetLogicalScale( double x
, double y
)
262 ComputeScaleAndOrigin();
265 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
267 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
268 m_logicalOriginY
= y
* m_signY
;
269 ComputeScaleAndOrigin();
272 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
276 ComputeScaleAndOrigin();
279 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
281 m_signX
= (xLeftRight
? 1 : -1);
282 m_signY
= (yBottomUp
? -1 : 1);
283 ComputeScaleAndOrigin();
286 wxSize
wxGCDC::GetPPI() const
288 return wxSize(72, 72);
291 int wxGCDC::GetDepth() const
296 void wxGCDC::ComputeScaleAndOrigin()
298 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
299 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
301 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
302 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
303 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
304 // the logical origin sets the origin to have new coordinates
305 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
307 m_graphicContext
->SetTransform( m_matrixOriginal
);
308 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
311 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
316 void wxGCDC::SetBackgroundMode( int mode
)
318 m_backgroundMode
= mode
;
321 void wxGCDC::SetFont( const wxFont
&font
)
324 if ( m_graphicContext
)
328 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
329 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
333 void wxGCDC::SetPen( const wxPen
&pen
)
339 if ( m_graphicContext
)
341 m_graphicContext
->SetPen( m_pen
);
345 void wxGCDC::SetBrush( const wxBrush
&brush
)
347 if (m_brush
== brush
)
351 if ( m_graphicContext
)
353 m_graphicContext
->SetBrush( m_brush
);
357 void wxGCDC::SetBackground( const wxBrush
&brush
)
359 if (m_backgroundBrush
== brush
)
362 m_backgroundBrush
= brush
;
363 if (!m_backgroundBrush
.Ok())
367 void wxGCDC::SetLogicalFunction( int function
)
369 if (m_logicalFunction
== function
)
372 m_logicalFunction
= function
;
373 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
375 CGContextRef cgContext
= ((wxCairoContext
*)(m_graphicContext
))->GetNativeContext();
376 if ( m_logicalFunction
== wxCOPY
)
377 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
378 else if ( m_logicalFunction
== wxINVERT
)
379 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
);
381 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
386 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
387 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
392 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
394 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
398 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
400 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
402 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
404 if ( m_logicalFunction
!= wxCOPY
)
408 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
410 CalcBoundingBox(x1
, y1
);
411 CalcBoundingBox(x2
, y2
);
414 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
416 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
418 if ( m_logicalFunction
!= wxCOPY
)
425 m_graphicContext
->StrokeLine(0,y
,w
,y
);
426 m_graphicContext
->StrokeLine(x
,0,x
,h
);
428 CalcBoundingBox(0, 0);
429 CalcBoundingBox(0+w
, 0+h
);
432 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
433 wxCoord x2
, wxCoord y2
,
434 wxCoord xc
, wxCoord yc
)
436 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
438 if ( m_logicalFunction
!= wxCOPY
)
443 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
444 wxCoord rad
= (wxCoord
)radius
;
446 if (x1
== x2
&& y1
== y2
)
451 else if (radius
== 0.0)
457 sa
= (x1
- xc
== 0) ?
458 (y1
- yc
< 0) ? 90.0 : -90.0 :
459 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
460 ea
= (x2
- xc
== 0) ?
461 (y2
- yc
< 0) ? 90.0 : -90.0 :
462 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
465 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
467 wxGraphicsPath path
= m_graphicContext
->CreatePath();
468 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
469 path
.MoveToPoint( xc
, yc
);
470 path
.AddArc( xc
, yc
, rad
, DegToRad(sa
) , DegToRad(ea
), false );
471 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
472 path
.AddLineToPoint( xc
, yc
);
473 m_graphicContext
->DrawPath(path
);
476 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
477 double sa
, double ea
)
479 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
481 if ( m_logicalFunction
!= wxCOPY
)
484 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
486 wxGraphicsPath path
= m_graphicContext
->CreatePath();
487 m_graphicContext
->PushState();
488 m_graphicContext
->Translate(x
+w
/2,y
+h
/2);
489 wxDouble factor
= ((wxDouble
) w
) / h
;
490 m_graphicContext
->Scale( factor
, 1.0);
491 if ( fill
&& (sa
!=ea
) )
492 path
.MoveToPoint(0,0);
493 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
494 // get clockwise angles
495 path
.AddArc( 0, 0, h
/2 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
496 if ( fill
&& (sa
!=ea
) )
497 path
.AddLineToPoint(0,0);
498 m_graphicContext
->DrawPath( path
);
499 m_graphicContext
->PopState();
502 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
504 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
506 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
509 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
510 wxCoord xoffset
, wxCoord yoffset
)
512 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
514 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
516 if ( m_logicalFunction
!= wxCOPY
)
520 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
521 for( int i
= 0; i
< n
; ++i
)
523 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
524 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
527 m_graphicContext
->StrokeLines( n
, pointsD
);
532 void wxGCDC::DoDrawSpline(wxList
*points
)
534 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
536 if ( m_logicalFunction
!= wxCOPY
)
539 wxGraphicsPath path
= m_graphicContext
->CreatePath();
541 wxList::compatibility_iterator node
= points
->GetFirst();
542 if (node
== wxList::compatibility_iterator())
546 wxPoint
*p
= (wxPoint
*)node
->GetData();
551 node
= node
->GetNext();
552 p
= (wxPoint
*)node
->GetData();
556 wxCoord cx1
= ( x1
+ x2
) / 2;
557 wxCoord cy1
= ( y1
+ y2
) / 2;
559 path
.MoveToPoint( x1
, y1
);
560 path
.AddLineToPoint( cx1
, cy1
);
563 while ((node
= node
->GetNext()) != NULL
)
566 while ((node
= node
->GetNext()))
570 p
= (wxPoint
*)node
->GetData();
575 wxCoord cx4
= (x1
+ x2
) / 2;
576 wxCoord cy4
= (y1
+ y2
) / 2;
578 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
584 path
.AddLineToPoint( x2
, y2
);
586 m_graphicContext
->StrokePath( path
);
588 #endif // wxUSE_SPLINES
590 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
591 wxCoord xoffset
, wxCoord yoffset
,
594 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
596 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
598 if ( m_logicalFunction
!= wxCOPY
)
601 bool closeIt
= false;
602 if (points
[n
-1] != points
[0])
605 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
606 for( int i
= 0; i
< n
; ++i
)
608 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
609 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
612 pointsD
[n
] = pointsD
[0];
614 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
618 void wxGCDC::DoDrawPolyPolygon(int n
,
626 wxGraphicsPath path
= m_graphicContext
->CreatePath();
629 for ( int j
= 0; j
< n
; ++j
)
631 wxPoint start
= points
[i
];
632 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
635 for ( int k
= 1; k
< l
; ++k
)
637 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
641 if ( start
!= points
[i
-1])
642 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
644 m_graphicContext
->DrawPath( path
, fillStyle
);
647 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
649 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
651 if ( m_logicalFunction
!= wxCOPY
)
654 // CMB: draw nothing if transformed w or h is 0
655 if (w
== 0 || h
== 0)
658 if ( m_graphicContext
->ShouldOffset() )
660 // if we are offsetting the entire rectangle is moved 0.5, so the
661 // border line gets off by 1
665 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
668 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
669 wxCoord w
, wxCoord h
,
672 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
674 if ( m_logicalFunction
!= wxCOPY
)
678 radius
= - radius
* ((w
< h
) ? w
: h
);
680 // CMB: draw nothing if transformed w or h is 0
681 if (w
== 0 || h
== 0)
684 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
687 void wxGCDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
689 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
691 if ( m_logicalFunction
!= wxCOPY
)
694 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
697 bool wxGCDC::CanDrawBitmap() const
703 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
704 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool WXUNUSED(useMask
),
705 wxCoord xsrcMask
, wxCoord ysrcMask
)
707 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
708 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
710 if ( logical_func
== wxNO_OP
)
712 else if ( logical_func
!= wxCOPY
)
714 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
718 if (xsrcMask
== -1 && ysrcMask
== -1)
724 wxRect
subrect(source
-> LogicalToDeviceX(xsrc
),source
-> LogicalToDeviceY(ysrc
),
725 source
-> LogicalToDeviceXRel(width
),source
-> LogicalToDeviceYRel(height
));
727 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
731 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
, width
, height
);
735 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
742 void wxGCDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
745 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
747 if ( str
.length() == 0 )
749 if ( m_logicalFunction
!= wxCOPY
)
752 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
755 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
757 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
759 if ( str
.length() == 0 )
761 if ( m_logicalFunction
!= wxCOPY
)
764 m_graphicContext
->DrawText( str
, x
,y
);
767 bool wxGCDC::CanGetTextExtent() const
769 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
774 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
775 wxCoord
*descent
, wxCoord
*externalLeading
,
776 wxFont
*theFont
) const
778 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
782 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
785 wxDouble h
, d
, e
, w
;
787 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
790 *height
= (wxCoord
)h
;
792 *descent
= (wxCoord
)d
;
793 if ( externalLeading
)
794 *externalLeading
= (wxCoord
)e
;
800 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
804 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
806 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
808 widths
.Add(0,text
.Length());
809 if ( text
.IsEmpty() )
812 wxArrayDouble widthsD
;
814 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
815 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
816 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
821 wxCoord
wxGCDC::GetCharWidth(void) const
824 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
829 wxCoord
wxGCDC::GetCharHeight(void) const
832 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
837 void wxGCDC::Clear(void)
839 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
840 // TODO better implementation / incorporate size info into wxGCDC or context
841 m_graphicContext
->SetBrush( m_backgroundBrush
);
842 wxPen p
= *wxTRANSPARENT_PEN
;
843 m_graphicContext
->SetPen( p
);
844 DoDrawRectangle( 0, 0, 32000 , 32000 );
845 m_graphicContext
->SetPen( m_pen
);
846 m_graphicContext
->SetBrush( m_brush
);
849 void wxGCDC::DoGetSize(int *width
, int *height
) const
855 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
856 const wxColour
& initialColour
,
857 const wxColour
& destColour
,
858 wxDirection nDirection
)
865 start
= rect
.GetRightBottom();
867 end
= rect
.GetLeftBottom();
870 start
= rect
.GetLeftBottom();
871 end
= rect
.GetRightBottom();
875 start
= rect
.GetLeftBottom();
877 end
= rect
.GetLeftTop();
880 start
= rect
.GetLeftTop();
881 end
= rect
.GetLeftBottom();
888 if (rect
.width
== 0 || rect
.height
== 0)
891 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
892 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
893 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
894 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
895 m_graphicContext
->SetPen(m_pen
);
898 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
899 const wxColour
& initialColour
,
900 const wxColour
& destColour
,
901 const wxPoint
& circleCenter
)
904 wxInt32 cx
= rect
.GetWidth() / 2;
905 wxInt32 cy
= rect
.GetHeight() / 2;
912 // make sure the background is filled (todo move into specific platform implementation ?)
913 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
914 m_graphicContext
->SetBrush( wxBrush( destColour
) );
915 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
917 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
918 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
919 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
920 nRadius
,initialColour
,destColour
));
922 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
923 m_graphicContext
->SetPen(m_pen
);
926 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
927 wxCoord width
, wxCoord height
)
929 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
932 #endif // wxUSE_GRAPHICS_CONTEXT