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();
72 // apply the stored transformations to the passed in context
73 ComputeScaleAndOrigin();
74 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
75 m_graphicContext
->SetPen( m_pen
);
76 m_graphicContext
->SetBrush( m_brush
);
80 wxGCDC::wxGCDC(const wxWindowDC
& dc
)
83 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
90 m_mm_to_pix_x
= mm2pt
;
91 m_mm_to_pix_y
= mm2pt
;
94 m_font
= *wxNORMAL_FONT
;
95 m_brush
= *wxWHITE_BRUSH
;
97 m_graphicContext
= NULL
;
103 delete m_graphicContext
;
106 void wxGCDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
108 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
109 wxCHECK_RET( bmp
.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
111 if ( bmp
.GetDepth() == 1 )
113 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
114 m_graphicContext
->SetBrush( wxBrush( m_textBackgroundColour
, wxSOLID
) );
115 m_graphicContext
->DrawRectangle( x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
116 m_graphicContext
->SetBrush( wxBrush( m_textForegroundColour
, wxSOLID
) );
117 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
118 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(m_brush
));
119 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(m_pen
));
122 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
125 void wxGCDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
127 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
128 wxCHECK_RET( icon
.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
130 wxCoord w
= icon
.GetWidth();
131 wxCoord h
= icon
.GetHeight();
133 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
136 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
138 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
140 m_graphicContext
->Clip( x
, y
, w
, h
);
143 m_clipX1
= wxMax( m_clipX1
, x
);
144 m_clipY1
= wxMax( m_clipY1
, y
);
145 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
146 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
159 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
161 // region is in device coordinates
162 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
166 DestroyClippingRegion();
170 wxRegion
logRegion( region
);
173 logRegion
.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
174 logRegion
.GetBox( x
, y
, w
, h
);
176 m_graphicContext
->Clip( logRegion
);
179 m_clipX1
= wxMax( m_clipX1
, x
);
180 m_clipY1
= wxMax( m_clipY1
, y
);
181 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
182 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
195 void wxGCDC::DestroyClippingRegion()
197 m_graphicContext
->ResetClip();
198 m_graphicContext
->SetPen( m_pen
);
199 m_graphicContext
->SetBrush( m_brush
);
204 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
210 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
212 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
215 void wxGCDC::SetTextForeground( const wxColour
&col
)
217 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
219 if ( col
!= m_textForegroundColour
)
221 m_textForegroundColour
= col
;
222 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
226 void wxGCDC::SetTextBackground( const wxColour
&col
)
228 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
230 m_textBackgroundColour
= col
;
233 void wxGCDC::SetMapMode( int mode
)
238 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
242 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
246 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
250 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
255 SetLogicalScale( 1.0, 1.0 );
259 ComputeScaleAndOrigin();
262 void wxGCDC::SetUserScale( double x
, double y
)
264 // allow negative ? -> no
268 ComputeScaleAndOrigin();
271 void wxGCDC::SetLogicalScale( double x
, double y
)
276 ComputeScaleAndOrigin();
279 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
281 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
282 m_logicalOriginY
= y
* m_signY
;
283 ComputeScaleAndOrigin();
286 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
290 ComputeScaleAndOrigin();
293 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
295 m_signX
= (xLeftRight
? 1 : -1);
296 m_signY
= (yBottomUp
? -1 : 1);
297 ComputeScaleAndOrigin();
300 wxSize
wxGCDC::GetPPI() const
302 return wxSize(72, 72);
305 int wxGCDC::GetDepth() const
310 void wxGCDC::ComputeScaleAndOrigin()
312 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
313 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
315 if ( m_graphicContext
)
317 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
318 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
319 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
320 // the logical origin sets the origin to have new coordinates
321 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
323 m_graphicContext
->SetTransform( m_matrixOriginal
);
324 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
328 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
333 void wxGCDC::SetBackgroundMode( int mode
)
335 m_backgroundMode
= mode
;
338 void wxGCDC::SetFont( const wxFont
&font
)
341 if ( m_graphicContext
)
345 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
346 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
350 void wxGCDC::SetPen( const wxPen
&pen
)
356 if ( m_graphicContext
)
358 m_graphicContext
->SetPen( m_pen
);
362 void wxGCDC::SetBrush( const wxBrush
&brush
)
364 if (m_brush
== brush
)
368 if ( m_graphicContext
)
370 m_graphicContext
->SetBrush( m_brush
);
374 void wxGCDC::SetBackground( const wxBrush
&brush
)
376 if (m_backgroundBrush
== brush
)
379 m_backgroundBrush
= brush
;
380 if (!m_backgroundBrush
.Ok())
384 void wxGCDC::SetLogicalFunction( int function
)
386 if (m_logicalFunction
== function
)
389 m_logicalFunction
= function
;
390 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
392 CGContextRef cgContext
= ((wxCairoContext
*)(m_graphicContext
))->GetNativeContext();
393 if ( m_logicalFunction
== wxCOPY
)
394 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
395 else if ( m_logicalFunction
== wxINVERT
)
396 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
);
398 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
403 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
404 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
409 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
411 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
415 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
417 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
419 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
421 if ( m_logicalFunction
!= wxCOPY
)
425 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
427 CalcBoundingBox(x1
, y1
);
428 CalcBoundingBox(x2
, y2
);
431 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
433 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
435 if ( m_logicalFunction
!= wxCOPY
)
442 m_graphicContext
->StrokeLine(0,y
,w
,y
);
443 m_graphicContext
->StrokeLine(x
,0,x
,h
);
445 CalcBoundingBox(0, 0);
446 CalcBoundingBox(0+w
, 0+h
);
449 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
450 wxCoord x2
, wxCoord y2
,
451 wxCoord xc
, wxCoord yc
)
453 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
455 if ( m_logicalFunction
!= wxCOPY
)
460 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
461 wxCoord rad
= (wxCoord
)radius
;
463 if (x1
== x2
&& y1
== y2
)
468 else if (radius
== 0.0)
474 sa
= (x1
- xc
== 0) ?
475 (y1
- yc
< 0) ? 90.0 : -90.0 :
476 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
477 ea
= (x2
- xc
== 0) ?
478 (y2
- yc
< 0) ? 90.0 : -90.0 :
479 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
482 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
484 wxGraphicsPath path
= m_graphicContext
->CreatePath();
485 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
486 path
.MoveToPoint( xc
, yc
);
487 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
488 // get clockwise angles
489 path
.AddArc( xc
, yc
, rad
, DegToRad(-sa
) , DegToRad(-ea
), false );
490 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
491 path
.AddLineToPoint( xc
, yc
);
492 m_graphicContext
->DrawPath(path
);
495 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
496 double sa
, double ea
)
498 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
500 if ( m_logicalFunction
!= wxCOPY
)
503 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
505 wxGraphicsPath path
= m_graphicContext
->CreatePath();
506 m_graphicContext
->PushState();
507 m_graphicContext
->Translate(x
+w
/2,y
+h
/2);
508 wxDouble factor
= ((wxDouble
) w
) / h
;
509 m_graphicContext
->Scale( factor
, 1.0);
510 if ( fill
&& (sa
!=ea
) )
511 path
.MoveToPoint(0,0);
512 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
513 // get clockwise angles
514 path
.AddArc( 0, 0, h
/2 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
515 if ( fill
&& (sa
!=ea
) )
516 path
.AddLineToPoint(0,0);
517 m_graphicContext
->DrawPath( path
);
518 m_graphicContext
->PopState();
521 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
523 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
525 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
528 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
529 wxCoord xoffset
, wxCoord yoffset
)
531 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
533 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
535 if ( m_logicalFunction
!= wxCOPY
)
539 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
540 for( int i
= 0; i
< n
; ++i
)
542 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
543 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
546 m_graphicContext
->StrokeLines( n
, pointsD
);
551 void wxGCDC::DoDrawSpline(wxList
*points
)
553 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
555 if ( m_logicalFunction
!= wxCOPY
)
558 wxGraphicsPath path
= m_graphicContext
->CreatePath();
560 wxList::compatibility_iterator node
= points
->GetFirst();
561 if (node
== wxList::compatibility_iterator())
565 wxPoint
*p
= (wxPoint
*)node
->GetData();
570 node
= node
->GetNext();
571 p
= (wxPoint
*)node
->GetData();
575 wxCoord cx1
= ( x1
+ x2
) / 2;
576 wxCoord cy1
= ( y1
+ y2
) / 2;
578 path
.MoveToPoint( x1
, y1
);
579 path
.AddLineToPoint( cx1
, cy1
);
582 while ((node
= node
->GetNext()) != NULL
)
585 while ((node
= node
->GetNext()))
589 p
= (wxPoint
*)node
->GetData();
594 wxCoord cx4
= (x1
+ x2
) / 2;
595 wxCoord cy4
= (y1
+ y2
) / 2;
597 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
603 path
.AddLineToPoint( x2
, y2
);
605 m_graphicContext
->StrokePath( path
);
607 #endif // wxUSE_SPLINES
609 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
610 wxCoord xoffset
, wxCoord yoffset
,
613 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
615 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
617 if ( m_logicalFunction
!= wxCOPY
)
620 bool closeIt
= false;
621 if (points
[n
-1] != points
[0])
624 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
625 for( int i
= 0; i
< n
; ++i
)
627 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
628 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
631 pointsD
[n
] = pointsD
[0];
633 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
637 void wxGCDC::DoDrawPolyPolygon(int n
,
645 wxGraphicsPath path
= m_graphicContext
->CreatePath();
648 for ( int j
= 0; j
< n
; ++j
)
650 wxPoint start
= points
[i
];
651 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
654 for ( int k
= 1; k
< l
; ++k
)
656 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
660 if ( start
!= points
[i
-1])
661 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
663 m_graphicContext
->DrawPath( path
, fillStyle
);
666 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
668 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
670 if ( m_logicalFunction
!= wxCOPY
)
673 // CMB: draw nothing if transformed w or h is 0
674 if (w
== 0 || h
== 0)
677 if ( m_graphicContext
->ShouldOffset() )
679 // if we are offsetting the entire rectangle is moved 0.5, so the
680 // border line gets off by 1
684 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
687 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
688 wxCoord w
, wxCoord h
,
691 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
693 if ( m_logicalFunction
!= wxCOPY
)
697 radius
= - radius
* ((w
< h
) ? w
: h
);
699 // CMB: draw nothing if transformed w or h is 0
700 if (w
== 0 || h
== 0)
703 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
706 void wxGCDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
708 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
710 if ( m_logicalFunction
!= wxCOPY
)
713 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
716 bool wxGCDC::CanDrawBitmap() const
722 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
723 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool WXUNUSED(useMask
),
724 wxCoord xsrcMask
, wxCoord ysrcMask
)
726 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
727 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
729 if ( logical_func
== wxNO_OP
)
731 else if ( logical_func
!= wxCOPY
)
733 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
737 if (xsrcMask
== -1 && ysrcMask
== -1)
743 wxRect
subrect(source
-> LogicalToDeviceX(xsrc
),source
-> LogicalToDeviceY(ysrc
),
744 source
-> LogicalToDeviceXRel(width
),source
-> LogicalToDeviceYRel(height
));
746 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
750 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
, width
, height
);
754 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
761 void wxGCDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
764 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
766 if ( str
.length() == 0 )
768 if ( m_logicalFunction
!= wxCOPY
)
771 if ( m_backgroundMode
== wxTRANSPARENT
)
772 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
774 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
), m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
777 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
779 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
781 if ( str
.length() == 0 )
783 if ( m_logicalFunction
!= wxCOPY
)
786 if ( m_backgroundMode
== wxTRANSPARENT
)
787 m_graphicContext
->DrawText( str
, x
,y
);
789 m_graphicContext
->DrawText( str
, x
,y
, m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
792 bool wxGCDC::CanGetTextExtent() const
794 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
799 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
800 wxCoord
*descent
, wxCoord
*externalLeading
,
801 wxFont
*theFont
) const
803 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
807 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
810 wxDouble h
, d
, e
, w
;
812 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
815 *height
= (wxCoord
)h
;
817 *descent
= (wxCoord
)d
;
818 if ( externalLeading
)
819 *externalLeading
= (wxCoord
)e
;
825 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
829 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
831 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
833 widths
.Add(0,text
.Length());
834 if ( text
.IsEmpty() )
837 wxArrayDouble widthsD
;
839 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
840 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
841 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
846 wxCoord
wxGCDC::GetCharWidth(void) const
849 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
854 wxCoord
wxGCDC::GetCharHeight(void) const
857 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
862 void wxGCDC::Clear(void)
864 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
865 // TODO better implementation / incorporate size info into wxGCDC or context
866 m_graphicContext
->SetBrush( m_backgroundBrush
);
867 wxPen p
= *wxTRANSPARENT_PEN
;
868 m_graphicContext
->SetPen( p
);
869 DoDrawRectangle( 0, 0, 32000 , 32000 );
870 m_graphicContext
->SetPen( m_pen
);
871 m_graphicContext
->SetBrush( m_brush
);
874 void wxGCDC::DoGetSize(int *width
, int *height
) const
880 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
881 const wxColour
& initialColour
,
882 const wxColour
& destColour
,
883 wxDirection nDirection
)
890 start
= rect
.GetRightBottom();
892 end
= rect
.GetLeftBottom();
895 start
= rect
.GetLeftBottom();
896 end
= rect
.GetRightBottom();
900 start
= rect
.GetLeftBottom();
902 end
= rect
.GetLeftTop();
905 start
= rect
.GetLeftTop();
906 end
= rect
.GetLeftBottom();
913 if (rect
.width
== 0 || rect
.height
== 0)
916 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
917 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
918 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
919 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
920 m_graphicContext
->SetPen(m_pen
);
923 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
924 const wxColour
& initialColour
,
925 const wxColour
& destColour
,
926 const wxPoint
& circleCenter
)
929 wxInt32 cx
= rect
.GetWidth() / 2;
930 wxInt32 cy
= rect
.GetHeight() / 2;
937 // make sure the background is filled (todo move into specific platform implementation ?)
938 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
939 m_graphicContext
->SetBrush( wxBrush( destColour
) );
940 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
942 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
943 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
944 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
945 nRadius
,initialColour
,destColour
));
947 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
948 m_graphicContext
->SetPen(m_pen
);
951 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
952 wxCoord width
, wxCoord height
)
954 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
957 #endif // wxUSE_GRAPHICS_CONTEXT