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();
77 wxGCDC::wxGCDC(const wxWindowDC
& dc
)
80 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
81 if ( dc
.GetFont().Ok())
82 m_graphicContext
->SetFont( m_graphicContext
->CreateFont(dc
.GetFont(),dc
.GetTextForeground()));
83 if ( dc
.GetPen().Ok())
84 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(dc
.GetPen()));
85 if ( dc
.GetBrush().Ok())
86 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(dc
.GetBrush()));
93 m_mm_to_pix_x
= mm2pt
;
94 m_mm_to_pix_y
= mm2pt
;
97 m_font
= *wxNORMAL_FONT
;
98 m_brush
= *wxWHITE_BRUSH
;
100 m_graphicContext
= NULL
;
106 delete m_graphicContext
;
109 void wxGCDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
111 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
112 wxCHECK_RET( bmp
.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
114 if ( bmp
.GetDepth() == 1 )
116 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
117 m_graphicContext
->SetBrush( wxBrush( m_textBackgroundColour
, wxSOLID
) );
118 m_graphicContext
->DrawRectangle( x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
119 m_graphicContext
->SetBrush( wxBrush( m_textForegroundColour
, wxSOLID
) );
120 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
121 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(m_brush
));
122 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(m_pen
));
125 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
128 void wxGCDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
130 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
131 wxCHECK_RET( icon
.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
133 wxCoord w
= icon
.GetWidth();
134 wxCoord h
= icon
.GetHeight();
136 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
139 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
141 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
143 m_graphicContext
->Clip( x
, y
, w
, h
);
146 m_clipX1
= wxMax( m_clipX1
, x
);
147 m_clipY1
= wxMax( m_clipY1
, y
);
148 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
149 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
162 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
164 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
168 DestroyClippingRegion();
173 region
.GetBox( x
, y
, w
, h
);
175 m_graphicContext
->Clip( region
);
178 m_clipX1
= wxMax( m_clipX1
, x
);
179 m_clipY1
= wxMax( m_clipY1
, y
);
180 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
181 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
194 void wxGCDC::DestroyClippingRegion()
196 m_graphicContext
->ResetClip();
197 m_graphicContext
->SetPen( m_pen
);
198 m_graphicContext
->SetBrush( m_brush
);
203 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
209 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
211 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
214 void wxGCDC::SetTextForeground( const wxColour
&col
)
216 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
218 if ( col
!= m_textForegroundColour
)
220 m_textForegroundColour
= col
;
221 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
225 void wxGCDC::SetTextBackground( const wxColour
&col
)
227 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
229 m_textBackgroundColour
= col
;
232 void wxGCDC::SetMapMode( int mode
)
237 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
241 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
245 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
249 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
254 SetLogicalScale( 1.0, 1.0 );
258 ComputeScaleAndOrigin();
261 void wxGCDC::SetUserScale( double x
, double y
)
263 // allow negative ? -> no
267 ComputeScaleAndOrigin();
270 void wxGCDC::SetLogicalScale( double x
, double y
)
275 ComputeScaleAndOrigin();
278 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
280 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
281 m_logicalOriginY
= y
* m_signY
;
282 ComputeScaleAndOrigin();
285 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
289 ComputeScaleAndOrigin();
292 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
294 m_signX
= (xLeftRight
? 1 : -1);
295 m_signY
= (yBottomUp
? -1 : 1);
296 ComputeScaleAndOrigin();
299 wxSize
wxGCDC::GetPPI() const
301 return wxSize(72, 72);
304 int wxGCDC::GetDepth() const
309 void wxGCDC::ComputeScaleAndOrigin()
311 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
312 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
314 if ( m_graphicContext
)
316 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
317 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
318 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
319 // the logical origin sets the origin to have new coordinates
320 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
322 m_graphicContext
->SetTransform( m_matrixOriginal
);
323 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
327 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
332 void wxGCDC::SetBackgroundMode( int mode
)
334 m_backgroundMode
= mode
;
337 void wxGCDC::SetFont( const wxFont
&font
)
340 if ( m_graphicContext
)
344 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
345 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
349 void wxGCDC::SetPen( const wxPen
&pen
)
355 if ( m_graphicContext
)
357 m_graphicContext
->SetPen( m_pen
);
361 void wxGCDC::SetBrush( const wxBrush
&brush
)
363 if (m_brush
== brush
)
367 if ( m_graphicContext
)
369 m_graphicContext
->SetBrush( m_brush
);
373 void wxGCDC::SetBackground( const wxBrush
&brush
)
375 if (m_backgroundBrush
== brush
)
378 m_backgroundBrush
= brush
;
379 if (!m_backgroundBrush
.Ok())
383 void wxGCDC::SetLogicalFunction( int function
)
385 if (m_logicalFunction
== function
)
388 m_logicalFunction
= function
;
389 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
391 CGContextRef cgContext
= ((wxCairoContext
*)(m_graphicContext
))->GetNativeContext();
392 if ( m_logicalFunction
== wxCOPY
)
393 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
394 else if ( m_logicalFunction
== wxINVERT
)
395 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
);
397 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
402 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
403 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
408 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
410 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
414 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
416 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
418 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
420 if ( m_logicalFunction
!= wxCOPY
)
424 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
426 CalcBoundingBox(x1
, y1
);
427 CalcBoundingBox(x2
, y2
);
430 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
432 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
434 if ( m_logicalFunction
!= wxCOPY
)
441 m_graphicContext
->StrokeLine(0,y
,w
,y
);
442 m_graphicContext
->StrokeLine(x
,0,x
,h
);
444 CalcBoundingBox(0, 0);
445 CalcBoundingBox(0+w
, 0+h
);
448 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
449 wxCoord x2
, wxCoord y2
,
450 wxCoord xc
, wxCoord yc
)
452 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
454 if ( m_logicalFunction
!= wxCOPY
)
459 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
460 wxCoord rad
= (wxCoord
)radius
;
462 if (x1
== x2
&& y1
== y2
)
467 else if (radius
== 0.0)
473 sa
= (x1
- xc
== 0) ?
474 (y1
- yc
< 0) ? 90.0 : -90.0 :
475 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
476 ea
= (x2
- xc
== 0) ?
477 (y2
- yc
< 0) ? 90.0 : -90.0 :
478 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
481 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
483 wxGraphicsPath path
= m_graphicContext
->CreatePath();
484 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
485 path
.MoveToPoint( xc
, yc
);
486 path
.AddArc( xc
, yc
, rad
, DegToRad(sa
) , DegToRad(ea
), false );
487 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
488 path
.AddLineToPoint( xc
, yc
);
489 m_graphicContext
->DrawPath(path
);
492 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
493 double sa
, double ea
)
495 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
497 if ( m_logicalFunction
!= wxCOPY
)
500 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
502 wxGraphicsPath path
= m_graphicContext
->CreatePath();
503 m_graphicContext
->PushState();
504 m_graphicContext
->Translate(x
+w
/2,y
+h
/2);
505 wxDouble factor
= ((wxDouble
) w
) / h
;
506 m_graphicContext
->Scale( factor
, 1.0);
507 if ( fill
&& (sa
!=ea
) )
508 path
.MoveToPoint(0,0);
509 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
510 // get clockwise angles
511 path
.AddArc( 0, 0, h
/2 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
512 if ( fill
&& (sa
!=ea
) )
513 path
.AddLineToPoint(0,0);
514 m_graphicContext
->DrawPath( path
);
515 m_graphicContext
->PopState();
518 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
520 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
522 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
525 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
526 wxCoord xoffset
, wxCoord yoffset
)
528 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
530 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
532 if ( m_logicalFunction
!= wxCOPY
)
536 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
537 for( int i
= 0; i
< n
; ++i
)
539 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
540 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
543 m_graphicContext
->StrokeLines( n
, pointsD
);
548 void wxGCDC::DoDrawSpline(wxList
*points
)
550 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
552 if ( m_logicalFunction
!= wxCOPY
)
555 wxGraphicsPath path
= m_graphicContext
->CreatePath();
557 wxList::compatibility_iterator node
= points
->GetFirst();
558 if (node
== wxList::compatibility_iterator())
562 wxPoint
*p
= (wxPoint
*)node
->GetData();
567 node
= node
->GetNext();
568 p
= (wxPoint
*)node
->GetData();
572 wxCoord cx1
= ( x1
+ x2
) / 2;
573 wxCoord cy1
= ( y1
+ y2
) / 2;
575 path
.MoveToPoint( x1
, y1
);
576 path
.AddLineToPoint( cx1
, cy1
);
579 while ((node
= node
->GetNext()) != NULL
)
582 while ((node
= node
->GetNext()))
586 p
= (wxPoint
*)node
->GetData();
591 wxCoord cx4
= (x1
+ x2
) / 2;
592 wxCoord cy4
= (y1
+ y2
) / 2;
594 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
600 path
.AddLineToPoint( x2
, y2
);
602 m_graphicContext
->StrokePath( path
);
604 #endif // wxUSE_SPLINES
606 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
607 wxCoord xoffset
, wxCoord yoffset
,
610 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
612 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
614 if ( m_logicalFunction
!= wxCOPY
)
617 bool closeIt
= false;
618 if (points
[n
-1] != points
[0])
621 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
622 for( int i
= 0; i
< n
; ++i
)
624 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
625 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
628 pointsD
[n
] = pointsD
[0];
630 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
634 void wxGCDC::DoDrawPolyPolygon(int n
,
642 wxGraphicsPath path
= m_graphicContext
->CreatePath();
645 for ( int j
= 0; j
< n
; ++j
)
647 wxPoint start
= points
[i
];
648 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
651 for ( int k
= 1; k
< l
; ++k
)
653 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
657 if ( start
!= points
[i
-1])
658 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
660 m_graphicContext
->DrawPath( path
, fillStyle
);
663 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
665 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
667 if ( m_logicalFunction
!= wxCOPY
)
670 // CMB: draw nothing if transformed w or h is 0
671 if (w
== 0 || h
== 0)
674 if ( m_graphicContext
->ShouldOffset() )
676 // if we are offsetting the entire rectangle is moved 0.5, so the
677 // border line gets off by 1
681 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
684 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
685 wxCoord w
, wxCoord h
,
688 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
690 if ( m_logicalFunction
!= wxCOPY
)
694 radius
= - radius
* ((w
< h
) ? w
: h
);
696 // CMB: draw nothing if transformed w or h is 0
697 if (w
== 0 || h
== 0)
700 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
703 void wxGCDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
705 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
707 if ( m_logicalFunction
!= wxCOPY
)
710 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
713 bool wxGCDC::CanDrawBitmap() const
719 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
720 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool WXUNUSED(useMask
),
721 wxCoord xsrcMask
, wxCoord ysrcMask
)
723 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
724 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
726 if ( logical_func
== wxNO_OP
)
728 else if ( logical_func
!= wxCOPY
)
730 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
734 if (xsrcMask
== -1 && ysrcMask
== -1)
740 wxRect
subrect(source
-> LogicalToDeviceX(xsrc
),source
-> LogicalToDeviceY(ysrc
),
741 source
-> LogicalToDeviceXRel(width
),source
-> LogicalToDeviceYRel(height
));
743 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
747 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
, width
, height
);
751 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
758 void wxGCDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
761 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
763 if ( str
.length() == 0 )
765 if ( m_logicalFunction
!= wxCOPY
)
768 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
771 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
773 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
775 if ( str
.length() == 0 )
777 if ( m_logicalFunction
!= wxCOPY
)
780 m_graphicContext
->DrawText( str
, x
,y
);
783 bool wxGCDC::CanGetTextExtent() const
785 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
790 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
791 wxCoord
*descent
, wxCoord
*externalLeading
,
792 wxFont
*theFont
) const
794 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
798 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
801 wxDouble h
, d
, e
, w
;
803 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
806 *height
= (wxCoord
)h
;
808 *descent
= (wxCoord
)d
;
809 if ( externalLeading
)
810 *externalLeading
= (wxCoord
)e
;
816 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
820 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
822 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
824 widths
.Add(0,text
.Length());
825 if ( text
.IsEmpty() )
828 wxArrayDouble widthsD
;
830 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
831 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
832 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
837 wxCoord
wxGCDC::GetCharWidth(void) const
840 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
845 wxCoord
wxGCDC::GetCharHeight(void) const
848 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
853 void wxGCDC::Clear(void)
855 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
856 // TODO better implementation / incorporate size info into wxGCDC or context
857 m_graphicContext
->SetBrush( m_backgroundBrush
);
858 wxPen p
= *wxTRANSPARENT_PEN
;
859 m_graphicContext
->SetPen( p
);
860 DoDrawRectangle( 0, 0, 32000 , 32000 );
861 m_graphicContext
->SetPen( m_pen
);
862 m_graphicContext
->SetBrush( m_brush
);
865 void wxGCDC::DoGetSize(int *width
, int *height
) const
871 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
872 const wxColour
& initialColour
,
873 const wxColour
& destColour
,
874 wxDirection nDirection
)
881 start
= rect
.GetRightBottom();
883 end
= rect
.GetLeftBottom();
886 start
= rect
.GetLeftBottom();
887 end
= rect
.GetRightBottom();
891 start
= rect
.GetLeftBottom();
893 end
= rect
.GetLeftTop();
896 start
= rect
.GetLeftTop();
897 end
= rect
.GetLeftBottom();
904 if (rect
.width
== 0 || rect
.height
== 0)
907 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
908 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
909 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
910 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
911 m_graphicContext
->SetPen(m_pen
);
914 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
915 const wxColour
& initialColour
,
916 const wxColour
& destColour
,
917 const wxPoint
& circleCenter
)
920 wxInt32 cx
= rect
.GetWidth() / 2;
921 wxInt32 cy
= rect
.GetHeight() / 2;
928 // make sure the background is filled (todo move into specific platform implementation ?)
929 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
930 m_graphicContext
->SetBrush( wxBrush( destColour
) );
931 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
933 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
934 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
935 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
936 nRadius
,initialColour
,destColour
));
938 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
939 m_graphicContext
->SetPen(m_pen
);
942 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
943 wxCoord width
, wxCoord height
)
945 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
948 #endif // wxUSE_GRAPHICS_CONTEXT