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 if ( bmp
.GetDepth() == 1 )
114 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
115 m_graphicContext
->SetBrush( wxBrush( m_textBackgroundColour
, wxSOLID
) );
116 m_graphicContext
->DrawRectangle( x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
117 m_graphicContext
->SetBrush( wxBrush( m_textForegroundColour
, wxSOLID
) );
118 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
119 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(m_brush
));
120 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(m_pen
));
123 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
126 void wxGCDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
128 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
129 wxCHECK_RET( icon
.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
131 wxCoord w
= icon
.GetWidth();
132 wxCoord h
= icon
.GetHeight();
134 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
137 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
139 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
141 m_graphicContext
->Clip( x
, y
, w
, h
);
144 m_clipX1
= wxMax( m_clipX1
, x
);
145 m_clipY1
= wxMax( m_clipY1
, y
);
146 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
147 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
160 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
162 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
166 DestroyClippingRegion();
171 region
.GetBox( x
, y
, w
, h
);
173 m_graphicContext
->Clip( region
);
176 m_clipX1
= wxMax( m_clipX1
, x
);
177 m_clipY1
= wxMax( m_clipY1
, y
);
178 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
179 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
192 void wxGCDC::DestroyClippingRegion()
194 m_graphicContext
->ResetClip();
195 m_graphicContext
->SetPen( m_pen
);
196 m_graphicContext
->SetBrush( m_brush
);
201 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
207 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
209 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
212 void wxGCDC::SetTextForeground( const wxColour
&col
)
214 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
216 if ( col
!= m_textForegroundColour
)
218 m_textForegroundColour
= col
;
219 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
223 void wxGCDC::SetTextBackground( const wxColour
&col
)
225 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
227 m_textBackgroundColour
= col
;
230 void wxGCDC::SetMapMode( int mode
)
235 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
239 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
243 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
247 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
252 SetLogicalScale( 1.0, 1.0 );
256 ComputeScaleAndOrigin();
259 void wxGCDC::SetUserScale( double x
, double y
)
261 // allow negative ? -> no
265 ComputeScaleAndOrigin();
268 void wxGCDC::SetLogicalScale( double x
, double y
)
273 ComputeScaleAndOrigin();
276 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
278 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
279 m_logicalOriginY
= y
* m_signY
;
280 ComputeScaleAndOrigin();
283 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
287 ComputeScaleAndOrigin();
290 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
292 m_signX
= (xLeftRight
? 1 : -1);
293 m_signY
= (yBottomUp
? -1 : 1);
294 ComputeScaleAndOrigin();
297 wxSize
wxGCDC::GetPPI() const
299 return wxSize(72, 72);
302 int wxGCDC::GetDepth() const
307 void wxGCDC::ComputeScaleAndOrigin()
309 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
310 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
312 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
313 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
314 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
315 // the logical origin sets the origin to have new coordinates
316 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
318 m_graphicContext
->SetTransform( m_matrixOriginal
);
319 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
322 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
327 void wxGCDC::SetBackgroundMode( int mode
)
329 m_backgroundMode
= mode
;
332 void wxGCDC::SetFont( const wxFont
&font
)
335 if ( m_graphicContext
)
339 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
340 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
344 void wxGCDC::SetPen( const wxPen
&pen
)
350 if ( m_graphicContext
)
352 m_graphicContext
->SetPen( m_pen
);
356 void wxGCDC::SetBrush( const wxBrush
&brush
)
358 if (m_brush
== brush
)
362 if ( m_graphicContext
)
364 m_graphicContext
->SetBrush( m_brush
);
368 void wxGCDC::SetBackground( const wxBrush
&brush
)
370 if (m_backgroundBrush
== brush
)
373 m_backgroundBrush
= brush
;
374 if (!m_backgroundBrush
.Ok())
378 void wxGCDC::SetLogicalFunction( int function
)
380 if (m_logicalFunction
== function
)
383 m_logicalFunction
= function
;
384 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
386 CGContextRef cgContext
= ((wxCairoContext
*)(m_graphicContext
))->GetNativeContext();
387 if ( m_logicalFunction
== wxCOPY
)
388 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
389 else if ( m_logicalFunction
== wxINVERT
)
390 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
);
392 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
397 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
398 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
403 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
405 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
409 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
411 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
413 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
415 if ( m_logicalFunction
!= wxCOPY
)
419 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
421 CalcBoundingBox(x1
, y1
);
422 CalcBoundingBox(x2
, y2
);
425 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
427 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
429 if ( m_logicalFunction
!= wxCOPY
)
436 m_graphicContext
->StrokeLine(0,y
,w
,y
);
437 m_graphicContext
->StrokeLine(x
,0,x
,h
);
439 CalcBoundingBox(0, 0);
440 CalcBoundingBox(0+w
, 0+h
);
443 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
444 wxCoord x2
, wxCoord y2
,
445 wxCoord xc
, wxCoord yc
)
447 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
449 if ( m_logicalFunction
!= wxCOPY
)
454 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
455 wxCoord rad
= (wxCoord
)radius
;
457 if (x1
== x2
&& y1
== y2
)
462 else if (radius
== 0.0)
468 sa
= (x1
- xc
== 0) ?
469 (y1
- yc
< 0) ? 90.0 : -90.0 :
470 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
471 ea
= (x2
- xc
== 0) ?
472 (y2
- yc
< 0) ? 90.0 : -90.0 :
473 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
476 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
478 wxGraphicsPath path
= m_graphicContext
->CreatePath();
479 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
480 path
.MoveToPoint( xc
, yc
);
481 path
.AddArc( xc
, yc
, rad
, DegToRad(sa
) , DegToRad(ea
), false );
482 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
483 path
.AddLineToPoint( xc
, yc
);
484 m_graphicContext
->DrawPath(path
);
487 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
488 double sa
, double ea
)
490 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
492 if ( m_logicalFunction
!= wxCOPY
)
495 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
497 wxGraphicsPath path
= m_graphicContext
->CreatePath();
498 m_graphicContext
->PushState();
499 m_graphicContext
->Translate(x
+w
/2,y
+h
/2);
500 wxDouble factor
= ((wxDouble
) w
) / h
;
501 m_graphicContext
->Scale( factor
, 1.0);
502 if ( fill
&& (sa
!=ea
) )
503 path
.MoveToPoint(0,0);
504 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
505 // get clockwise angles
506 path
.AddArc( 0, 0, h
/2 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
507 if ( fill
&& (sa
!=ea
) )
508 path
.AddLineToPoint(0,0);
509 m_graphicContext
->DrawPath( path
);
510 m_graphicContext
->PopState();
513 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
515 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
517 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
520 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
521 wxCoord xoffset
, wxCoord yoffset
)
523 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
525 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
527 if ( m_logicalFunction
!= wxCOPY
)
531 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
532 for( int i
= 0; i
< n
; ++i
)
534 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
535 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
538 m_graphicContext
->StrokeLines( n
, pointsD
);
543 void wxGCDC::DoDrawSpline(wxList
*points
)
545 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
547 if ( m_logicalFunction
!= wxCOPY
)
550 wxGraphicsPath path
= m_graphicContext
->CreatePath();
552 wxList::compatibility_iterator node
= points
->GetFirst();
553 if (node
== wxList::compatibility_iterator())
557 wxPoint
*p
= (wxPoint
*)node
->GetData();
562 node
= node
->GetNext();
563 p
= (wxPoint
*)node
->GetData();
567 wxCoord cx1
= ( x1
+ x2
) / 2;
568 wxCoord cy1
= ( y1
+ y2
) / 2;
570 path
.MoveToPoint( x1
, y1
);
571 path
.AddLineToPoint( cx1
, cy1
);
574 while ((node
= node
->GetNext()) != NULL
)
577 while ((node
= node
->GetNext()))
581 p
= (wxPoint
*)node
->GetData();
586 wxCoord cx4
= (x1
+ x2
) / 2;
587 wxCoord cy4
= (y1
+ y2
) / 2;
589 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
595 path
.AddLineToPoint( x2
, y2
);
597 m_graphicContext
->StrokePath( path
);
599 #endif // wxUSE_SPLINES
601 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
602 wxCoord xoffset
, wxCoord yoffset
,
605 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
607 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
609 if ( m_logicalFunction
!= wxCOPY
)
612 bool closeIt
= false;
613 if (points
[n
-1] != points
[0])
616 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
617 for( int i
= 0; i
< n
; ++i
)
619 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
620 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
623 pointsD
[n
] = pointsD
[0];
625 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
629 void wxGCDC::DoDrawPolyPolygon(int n
,
637 wxGraphicsPath path
= m_graphicContext
->CreatePath();
640 for ( int j
= 0; j
< n
; ++j
)
642 wxPoint start
= points
[i
];
643 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
646 for ( int k
= 1; k
< l
; ++k
)
648 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
652 if ( start
!= points
[i
-1])
653 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
655 m_graphicContext
->DrawPath( path
, fillStyle
);
658 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
660 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
662 if ( m_logicalFunction
!= wxCOPY
)
665 // CMB: draw nothing if transformed w or h is 0
666 if (w
== 0 || h
== 0)
669 if ( m_graphicContext
->ShouldOffset() )
671 // if we are offsetting the entire rectangle is moved 0.5, so the
672 // border line gets off by 1
676 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
679 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
680 wxCoord w
, wxCoord h
,
683 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
685 if ( m_logicalFunction
!= wxCOPY
)
689 radius
= - radius
* ((w
< h
) ? w
: h
);
691 // CMB: draw nothing if transformed w or h is 0
692 if (w
== 0 || h
== 0)
695 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
698 void wxGCDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
700 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
702 if ( m_logicalFunction
!= wxCOPY
)
705 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
708 bool wxGCDC::CanDrawBitmap() const
714 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
715 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool WXUNUSED(useMask
),
716 wxCoord xsrcMask
, wxCoord ysrcMask
)
718 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
719 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
721 if ( logical_func
== wxNO_OP
)
723 else if ( logical_func
!= wxCOPY
)
725 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
729 if (xsrcMask
== -1 && ysrcMask
== -1)
735 wxRect
subrect(source
-> LogicalToDeviceX(xsrc
),source
-> LogicalToDeviceY(ysrc
),
736 source
-> LogicalToDeviceXRel(width
),source
-> LogicalToDeviceYRel(height
));
738 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
742 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
, width
, height
);
746 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
753 void wxGCDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
756 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
758 if ( str
.length() == 0 )
760 if ( m_logicalFunction
!= wxCOPY
)
763 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
766 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
768 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
770 if ( str
.length() == 0 )
772 if ( m_logicalFunction
!= wxCOPY
)
775 m_graphicContext
->DrawText( str
, x
,y
);
778 bool wxGCDC::CanGetTextExtent() const
780 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
785 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
786 wxCoord
*descent
, wxCoord
*externalLeading
,
787 wxFont
*theFont
) const
789 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
793 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
796 wxDouble h
, d
, e
, w
;
798 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
801 *height
= (wxCoord
)h
;
803 *descent
= (wxCoord
)d
;
804 if ( externalLeading
)
805 *externalLeading
= (wxCoord
)e
;
811 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
815 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
817 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
819 widths
.Add(0,text
.Length());
820 if ( text
.IsEmpty() )
823 wxArrayDouble widthsD
;
825 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
826 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
827 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
832 wxCoord
wxGCDC::GetCharWidth(void) const
835 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
840 wxCoord
wxGCDC::GetCharHeight(void) const
843 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
848 void wxGCDC::Clear(void)
850 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
851 // TODO better implementation / incorporate size info into wxGCDC or context
852 m_graphicContext
->SetBrush( m_backgroundBrush
);
853 wxPen p
= *wxTRANSPARENT_PEN
;
854 m_graphicContext
->SetPen( p
);
855 DoDrawRectangle( 0, 0, 32000 , 32000 );
856 m_graphicContext
->SetPen( m_pen
);
857 m_graphicContext
->SetBrush( m_brush
);
860 void wxGCDC::DoGetSize(int *width
, int *height
) const
866 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
867 const wxColour
& initialColour
,
868 const wxColour
& destColour
,
869 wxDirection nDirection
)
876 start
= rect
.GetRightBottom();
878 end
= rect
.GetLeftBottom();
881 start
= rect
.GetLeftBottom();
882 end
= rect
.GetRightBottom();
886 start
= rect
.GetLeftBottom();
888 end
= rect
.GetLeftTop();
891 start
= rect
.GetLeftTop();
892 end
= rect
.GetLeftBottom();
899 if (rect
.width
== 0 || rect
.height
== 0)
902 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
903 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
904 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
905 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
906 m_graphicContext
->SetPen(m_pen
);
909 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
910 const wxColour
& initialColour
,
911 const wxColour
& destColour
,
912 const wxPoint
& circleCenter
)
915 wxInt32 cx
= rect
.GetWidth() / 2;
916 wxInt32 cy
= rect
.GetHeight() / 2;
923 // make sure the background is filled (todo move into specific platform implementation ?)
924 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
925 m_graphicContext
->SetBrush( wxBrush( destColour
) );
926 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
928 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
929 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
930 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
931 nRadius
,initialColour
,destColour
));
933 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
934 m_graphicContext
->SetPen(m_pen
);
937 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
938 wxCoord width
, wxCoord height
)
940 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
943 #endif // wxUSE_GRAPHICS_CONTEXT