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
) );
87 wxGCDC::wxGCDC(const wxMemoryDC
& dc
)
90 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
98 m_mm_to_pix_x
= mm2pt
;
99 m_mm_to_pix_y
= mm2pt
;
101 m_pen
= *wxBLACK_PEN
;
102 m_font
= *wxNORMAL_FONT
;
103 m_brush
= *wxWHITE_BRUSH
;
105 m_graphicContext
= NULL
;
111 delete m_graphicContext
;
114 void wxGCDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
116 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
117 wxCHECK_RET( bmp
.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
119 if ( bmp
.GetDepth() == 1 )
121 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
122 m_graphicContext
->SetBrush( wxBrush( m_textBackgroundColour
, wxSOLID
) );
123 m_graphicContext
->DrawRectangle( x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
124 m_graphicContext
->SetBrush( wxBrush( m_textForegroundColour
, wxSOLID
) );
125 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
126 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(m_brush
));
127 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(m_pen
));
130 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
133 void wxGCDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
135 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
136 wxCHECK_RET( icon
.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
138 wxCoord w
= icon
.GetWidth();
139 wxCoord h
= icon
.GetHeight();
141 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
144 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
146 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
148 m_graphicContext
->Clip( x
, y
, w
, h
);
151 m_clipX1
= wxMax( m_clipX1
, x
);
152 m_clipY1
= wxMax( m_clipY1
, y
);
153 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
154 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
167 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
169 // region is in device coordinates
170 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
174 DestroyClippingRegion();
178 wxRegion
logRegion( region
);
181 logRegion
.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
182 logRegion
.GetBox( x
, y
, w
, h
);
184 m_graphicContext
->Clip( logRegion
);
187 m_clipX1
= wxMax( m_clipX1
, x
);
188 m_clipY1
= wxMax( m_clipY1
, y
);
189 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
190 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
203 void wxGCDC::DestroyClippingRegion()
205 m_graphicContext
->ResetClip();
206 m_graphicContext
->SetPen( m_pen
);
207 m_graphicContext
->SetBrush( m_brush
);
212 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
218 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
220 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
223 void wxGCDC::SetTextForeground( const wxColour
&col
)
225 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
227 if ( col
!= m_textForegroundColour
)
229 m_textForegroundColour
= col
;
230 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
234 void wxGCDC::SetTextBackground( const wxColour
&col
)
236 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
238 m_textBackgroundColour
= col
;
241 void wxGCDC::SetMapMode( int mode
)
246 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
250 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
254 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
258 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
263 SetLogicalScale( 1.0, 1.0 );
267 ComputeScaleAndOrigin();
270 void wxGCDC::SetUserScale( double x
, double y
)
272 // allow negative ? -> no
276 ComputeScaleAndOrigin();
279 void wxGCDC::SetLogicalScale( double x
, double y
)
284 ComputeScaleAndOrigin();
287 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
289 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
290 m_logicalOriginY
= y
* m_signY
;
291 ComputeScaleAndOrigin();
294 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
298 ComputeScaleAndOrigin();
301 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
303 m_signX
= (xLeftRight
? 1 : -1);
304 m_signY
= (yBottomUp
? -1 : 1);
305 ComputeScaleAndOrigin();
308 wxSize
wxGCDC::GetPPI() const
310 return wxSize(72, 72);
313 int wxGCDC::GetDepth() const
318 void wxGCDC::ComputeScaleAndOrigin()
320 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
321 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
323 if ( m_graphicContext
)
325 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
326 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
327 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
328 // the logical origin sets the origin to have new coordinates
329 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
331 m_graphicContext
->SetTransform( m_matrixOriginal
);
332 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
336 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
341 void wxGCDC::SetBackgroundMode( int mode
)
343 m_backgroundMode
= mode
;
346 void wxGCDC::SetFont( const wxFont
&font
)
349 if ( m_graphicContext
)
353 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
354 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
358 void wxGCDC::SetPen( const wxPen
&pen
)
364 if ( m_graphicContext
)
366 m_graphicContext
->SetPen( m_pen
);
370 void wxGCDC::SetBrush( const wxBrush
&brush
)
372 if (m_brush
== brush
)
376 if ( m_graphicContext
)
378 m_graphicContext
->SetBrush( m_brush
);
382 void wxGCDC::SetBackground( const wxBrush
&brush
)
384 if (m_backgroundBrush
== brush
)
387 m_backgroundBrush
= brush
;
388 if (!m_backgroundBrush
.Ok())
392 void wxGCDC::SetLogicalFunction( int function
)
394 if (m_logicalFunction
== function
)
397 m_logicalFunction
= function
;
398 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
400 CGContextRef cgContext
= ((wxCairoContext
*)(m_graphicContext
))->GetNativeContext();
401 if ( m_logicalFunction
== wxCOPY
)
402 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
403 else if ( m_logicalFunction
== wxINVERT
)
404 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
);
406 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
411 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
412 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
417 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
419 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
423 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
425 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
427 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
429 if ( m_logicalFunction
!= wxCOPY
)
433 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
435 CalcBoundingBox(x1
, y1
);
436 CalcBoundingBox(x2
, y2
);
439 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
441 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
443 if ( m_logicalFunction
!= wxCOPY
)
450 m_graphicContext
->StrokeLine(0,y
,w
,y
);
451 m_graphicContext
->StrokeLine(x
,0,x
,h
);
453 CalcBoundingBox(0, 0);
454 CalcBoundingBox(0+w
, 0+h
);
457 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
458 wxCoord x2
, wxCoord y2
,
459 wxCoord xc
, wxCoord yc
)
461 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
463 if ( m_logicalFunction
!= wxCOPY
)
468 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
469 wxCoord rad
= (wxCoord
)radius
;
471 if (x1
== x2
&& y1
== y2
)
476 else if (radius
== 0.0)
482 sa
= (x1
- xc
== 0) ?
483 (y1
- yc
< 0) ? 90.0 : -90.0 :
484 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
485 ea
= (x2
- xc
== 0) ?
486 (y2
- yc
< 0) ? 90.0 : -90.0 :
487 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
490 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
492 wxGraphicsPath path
= m_graphicContext
->CreatePath();
493 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
494 path
.MoveToPoint( xc
, yc
);
495 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
496 // get clockwise angles
497 path
.AddArc( xc
, yc
, rad
, DegToRad(-sa
) , DegToRad(-ea
), false );
498 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
499 path
.AddLineToPoint( xc
, yc
);
500 m_graphicContext
->DrawPath(path
);
503 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
504 double sa
, double ea
)
506 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
508 if ( m_logicalFunction
!= wxCOPY
)
511 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
513 wxGraphicsPath path
= m_graphicContext
->CreatePath();
514 m_graphicContext
->PushState();
515 m_graphicContext
->Translate(x
+w
/2,y
+h
/2);
516 wxDouble factor
= ((wxDouble
) w
) / h
;
517 m_graphicContext
->Scale( factor
, 1.0);
518 if ( fill
&& (sa
!=ea
) )
519 path
.MoveToPoint(0,0);
520 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
521 // get clockwise angles
522 path
.AddArc( 0, 0, h
/2 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
523 if ( fill
&& (sa
!=ea
) )
524 path
.AddLineToPoint(0,0);
525 m_graphicContext
->DrawPath( path
);
526 m_graphicContext
->PopState();
529 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
531 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
533 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
536 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
537 wxCoord xoffset
, wxCoord yoffset
)
539 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
541 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
543 if ( m_logicalFunction
!= wxCOPY
)
547 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
548 for( int i
= 0; i
< n
; ++i
)
550 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
551 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
554 m_graphicContext
->StrokeLines( n
, pointsD
);
559 void wxGCDC::DoDrawSpline(wxList
*points
)
561 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
563 if ( m_logicalFunction
!= wxCOPY
)
566 wxGraphicsPath path
= m_graphicContext
->CreatePath();
568 wxList::compatibility_iterator node
= points
->GetFirst();
569 if (node
== wxList::compatibility_iterator())
573 wxPoint
*p
= (wxPoint
*)node
->GetData();
578 node
= node
->GetNext();
579 p
= (wxPoint
*)node
->GetData();
583 wxCoord cx1
= ( x1
+ x2
) / 2;
584 wxCoord cy1
= ( y1
+ y2
) / 2;
586 path
.MoveToPoint( x1
, y1
);
587 path
.AddLineToPoint( cx1
, cy1
);
590 while ((node
= node
->GetNext()) != NULL
)
593 while ((node
= node
->GetNext()))
597 p
= (wxPoint
*)node
->GetData();
602 wxCoord cx4
= (x1
+ x2
) / 2;
603 wxCoord cy4
= (y1
+ y2
) / 2;
605 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
611 path
.AddLineToPoint( x2
, y2
);
613 m_graphicContext
->StrokePath( path
);
615 #endif // wxUSE_SPLINES
617 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
618 wxCoord xoffset
, wxCoord yoffset
,
621 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
623 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
625 if ( m_logicalFunction
!= wxCOPY
)
628 bool closeIt
= false;
629 if (points
[n
-1] != points
[0])
632 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
633 for( int i
= 0; i
< n
; ++i
)
635 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
636 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
639 pointsD
[n
] = pointsD
[0];
641 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
645 void wxGCDC::DoDrawPolyPolygon(int n
,
653 wxGraphicsPath path
= m_graphicContext
->CreatePath();
656 for ( int j
= 0; j
< n
; ++j
)
658 wxPoint start
= points
[i
];
659 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
662 for ( int k
= 1; k
< l
; ++k
)
664 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
668 if ( start
!= points
[i
-1])
669 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
671 m_graphicContext
->DrawPath( path
, fillStyle
);
674 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
676 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
678 if ( m_logicalFunction
!= wxCOPY
)
681 // CMB: draw nothing if transformed w or h is 0
682 if (w
== 0 || h
== 0)
685 if ( m_graphicContext
->ShouldOffset() )
687 // if we are offsetting the entire rectangle is moved 0.5, so the
688 // border line gets off by 1
692 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
695 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
696 wxCoord w
, wxCoord h
,
699 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
701 if ( m_logicalFunction
!= wxCOPY
)
705 radius
= - radius
* ((w
< h
) ? w
: h
);
707 // CMB: draw nothing if transformed w or h is 0
708 if (w
== 0 || h
== 0)
711 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
714 void wxGCDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
716 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
718 if ( m_logicalFunction
!= wxCOPY
)
721 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
724 bool wxGCDC::CanDrawBitmap() const
730 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
731 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool WXUNUSED(useMask
),
732 wxCoord xsrcMask
, wxCoord ysrcMask
)
734 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
735 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
737 if ( logical_func
== wxNO_OP
)
739 else if ( logical_func
!= wxCOPY
)
741 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
745 if (xsrcMask
== -1 && ysrcMask
== -1)
751 wxRect
subrect(source
-> LogicalToDeviceX(xsrc
),source
-> LogicalToDeviceY(ysrc
),
752 source
-> LogicalToDeviceXRel(width
),source
-> LogicalToDeviceYRel(height
));
754 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
758 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
, width
, height
);
762 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
769 void wxGCDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
772 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
774 if ( str
.length() == 0 )
776 if ( m_logicalFunction
!= wxCOPY
)
779 if ( m_backgroundMode
== wxTRANSPARENT
)
780 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
782 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
), m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
785 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
787 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
789 if ( str
.length() == 0 )
791 if ( m_logicalFunction
!= wxCOPY
)
794 if ( m_backgroundMode
== wxTRANSPARENT
)
795 m_graphicContext
->DrawText( str
, x
,y
);
797 m_graphicContext
->DrawText( str
, x
,y
, m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
800 bool wxGCDC::CanGetTextExtent() const
802 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
807 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
808 wxCoord
*descent
, wxCoord
*externalLeading
,
809 wxFont
*theFont
) const
811 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
815 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
818 wxDouble h
, d
, e
, w
;
820 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
823 *height
= (wxCoord
)h
;
825 *descent
= (wxCoord
)d
;
826 if ( externalLeading
)
827 *externalLeading
= (wxCoord
)e
;
833 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
837 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
839 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
841 widths
.Add(0,text
.Length());
842 if ( text
.IsEmpty() )
845 wxArrayDouble widthsD
;
847 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
848 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
849 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
854 wxCoord
wxGCDC::GetCharWidth(void) const
857 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
862 wxCoord
wxGCDC::GetCharHeight(void) const
865 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
870 void wxGCDC::Clear(void)
872 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
873 // TODO better implementation / incorporate size info into wxGCDC or context
874 m_graphicContext
->SetBrush( m_backgroundBrush
);
875 wxPen p
= *wxTRANSPARENT_PEN
;
876 m_graphicContext
->SetPen( p
);
877 DoDrawRectangle( 0, 0, 32000 , 32000 );
878 m_graphicContext
->SetPen( m_pen
);
879 m_graphicContext
->SetBrush( m_brush
);
882 void wxGCDC::DoGetSize(int *width
, int *height
) const
888 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
889 const wxColour
& initialColour
,
890 const wxColour
& destColour
,
891 wxDirection nDirection
)
898 start
= rect
.GetRightBottom();
900 end
= rect
.GetLeftBottom();
903 start
= rect
.GetLeftBottom();
904 end
= rect
.GetRightBottom();
908 start
= rect
.GetLeftBottom();
910 end
= rect
.GetLeftTop();
913 start
= rect
.GetLeftTop();
914 end
= rect
.GetLeftBottom();
921 if (rect
.width
== 0 || rect
.height
== 0)
924 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
925 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
926 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
927 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
928 m_graphicContext
->SetPen(m_pen
);
931 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
932 const wxColour
& initialColour
,
933 const wxColour
& destColour
,
934 const wxPoint
& circleCenter
)
937 wxInt32 cx
= rect
.GetWidth() / 2;
938 wxInt32 cy
= rect
.GetHeight() / 2;
945 // make sure the background is filled (todo move into specific platform implementation ?)
946 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
947 m_graphicContext
->SetBrush( wxBrush( destColour
) );
948 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
950 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
951 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
952 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
953 nRadius
,initialColour
,destColour
));
955 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
956 m_graphicContext
->SetPen(m_pen
);
959 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
960 wxCoord width
, wxCoord height
)
962 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
965 #endif // wxUSE_GRAPHICS_CONTEXT