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 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 static const double RAD2DEG
= 180.0 / M_PI
;
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 static inline double DegToRad(double deg
)
42 return (deg
* M_PI
) / 180.0;
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
50 IMPLEMENT_DYNAMIC_CLASS(wxGCDC
, wxDCBase
)
52 IMPLEMENT_DYNAMIC_CLASS(wxGCDC
, wxDC
)
60 void wxGCDC::SetGraphicsContext( wxGraphicsContext
* ctx
)
62 delete m_graphicContext
;
63 m_graphicContext
= ctx
;
64 m_matrixOriginal
= m_graphicContext
->GetTransform();
67 wxGCDC::wxGCDC(const wxWindowDC
& dc
)
70 m_graphicContext
= wxGraphicsContext::Create(dc
);
71 m_matrixOriginal
= m_graphicContext
->GetTransform();
73 if ( dc
.GetFont().Ok())
74 m_graphicContext
->SetFont( m_graphicContext
->CreateFont(dc
.GetFont(),dc
.GetTextForeground()));
75 if ( dc
.GetPen().Ok())
76 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(dc
.GetPen()));
77 if ( dc
.GetBrush().Ok())
78 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(dc
.GetBrush()));
85 m_mm_to_pix_x
= mm2pt
;
86 m_mm_to_pix_y
= mm2pt
;
89 m_font
= *wxNORMAL_FONT
;
90 m_brush
= *wxWHITE_BRUSH
;
92 m_graphicContext
= NULL
;
98 delete m_graphicContext
;
101 void wxGCDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
103 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
104 wxCHECK_RET( bmp
.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
106 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
109 void wxGCDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
111 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
112 wxCHECK_RET( icon
.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
114 wxCoord w
= icon
.GetWidth();
115 wxCoord h
= icon
.GetHeight();
117 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
120 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
122 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
124 m_graphicContext
->Clip( x
, y
, w
, h
);
127 m_clipX1
= wxMax( m_clipX1
, x
);
128 m_clipY1
= wxMax( m_clipY1
, y
);
129 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
130 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
143 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
145 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
149 DestroyClippingRegion();
154 region
.GetBox( x
, y
, w
, h
);
156 m_graphicContext
->Clip( region
);
159 m_clipX1
= wxMax( m_clipX1
, x
);
160 m_clipY1
= wxMax( m_clipY1
, y
);
161 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
162 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
175 void wxGCDC::DestroyClippingRegion()
177 m_graphicContext
->ResetClip();
178 m_graphicContext
->SetPen( m_pen
);
179 m_graphicContext
->SetBrush( m_brush
);
184 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
190 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
192 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
195 void wxGCDC::SetTextForeground( const wxColour
&col
)
197 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
199 if ( col
!= m_textForegroundColour
)
201 m_textForegroundColour
= col
;
202 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
206 void wxGCDC::SetTextBackground( const wxColour
&col
)
208 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
210 m_textBackgroundColour
= col
;
213 void wxGCDC::SetMapMode( int mode
)
218 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
222 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
226 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
230 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
235 SetLogicalScale( 1.0, 1.0 );
239 ComputeScaleAndOrigin();
242 void wxGCDC::SetUserScale( double x
, double y
)
244 // allow negative ? -> no
248 ComputeScaleAndOrigin();
251 void wxGCDC::SetLogicalScale( double x
, double y
)
256 ComputeScaleAndOrigin();
259 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
261 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
262 m_logicalOriginY
= y
* m_signY
;
263 ComputeScaleAndOrigin();
266 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
270 ComputeScaleAndOrigin();
273 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
275 m_signX
= (xLeftRight
? 1 : -1);
276 m_signY
= (yBottomUp
? -1 : 1);
277 ComputeScaleAndOrigin();
280 wxSize
wxGCDC::GetPPI() const
282 return wxSize(72, 72);
285 int wxGCDC::GetDepth() const
290 void wxGCDC::ComputeScaleAndOrigin()
292 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
293 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
294 m_deviceOriginX
= /* m_deviceOriginX + */ m_logicalOriginX
;
295 m_deviceOriginY
= /* m_deviceOriginY + */ m_logicalOriginY
;
297 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
298 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
299 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
301 m_graphicContext
->SetTransform( m_matrixOriginal
);
302 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
305 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
310 void wxGCDC::SetBackgroundMode( int mode
)
312 m_backgroundMode
= mode
;
315 void wxGCDC::SetFont( const wxFont
&font
)
318 if ( m_graphicContext
)
322 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
323 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
327 void wxGCDC::SetPen( const wxPen
&pen
)
333 if ( m_graphicContext
)
335 m_graphicContext
->SetPen( m_pen
);
339 void wxGCDC::SetBrush( const wxBrush
&brush
)
341 if (m_brush
== brush
)
345 if ( m_graphicContext
)
347 m_graphicContext
->SetBrush( m_brush
);
351 void wxGCDC::SetBackground( const wxBrush
&brush
)
353 if (m_backgroundBrush
== brush
)
356 m_backgroundBrush
= brush
;
357 if (!m_backgroundBrush
.Ok())
361 void wxGCDC::SetLogicalFunction( int function
)
363 if (m_logicalFunction
== function
)
366 m_logicalFunction
= function
;
367 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
369 CGContextRef cgContext
= ((wxCairoContext
*)(m_graphicContext
))->GetNativeContext();
370 if ( m_logicalFunction
== wxCOPY
)
371 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
372 else if ( m_logicalFunction
== wxINVERT
)
373 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
);
375 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
380 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
381 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
386 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
388 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
392 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
394 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
396 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
398 if ( m_logicalFunction
!= wxCOPY
)
402 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
404 CalcBoundingBox(x1
, y1
);
405 CalcBoundingBox(x2
, y2
);
408 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
410 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
412 if ( m_logicalFunction
!= wxCOPY
)
419 m_graphicContext
->StrokeLine(0,y
,w
,y
);
420 m_graphicContext
->StrokeLine(x
,0,x
,h
);
422 CalcBoundingBox(0, 0);
423 CalcBoundingBox(0+w
, 0+h
);
426 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
427 wxCoord x2
, wxCoord y2
,
428 wxCoord xc
, wxCoord yc
)
430 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
432 if ( m_logicalFunction
!= wxCOPY
)
437 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
438 wxCoord rad
= (wxCoord
)radius
;
440 if (x1
== x2
&& y1
== y2
)
445 else if (radius
== 0.0)
451 sa
= (x1
- xc
== 0) ?
452 (y1
- yc
< 0) ? 90.0 : -90.0 :
453 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
454 ea
= (x2
- xc
== 0) ?
455 (y2
- yc
< 0) ? 90.0 : -90.0 :
456 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
459 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
461 wxGraphicsPath path
= m_graphicContext
->CreatePath();
462 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
463 path
.MoveToPoint( xc
, yc
);
464 path
.AddArc( xc
, yc
, rad
, DegToRad(sa
) , DegToRad(ea
), false );
465 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
466 path
.AddLineToPoint( xc
, yc
);
467 m_graphicContext
->DrawPath(path
);
470 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
471 double sa
, double ea
)
473 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
475 if ( m_logicalFunction
!= wxCOPY
)
478 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
480 wxGraphicsPath path
= m_graphicContext
->CreatePath();
481 m_graphicContext
->PushState();
482 m_graphicContext
->Translate(x
+w
/2,y
+h
/2);
483 wxDouble factor
= ((wxDouble
) w
) / h
;
484 m_graphicContext
->Scale( factor
, 1.0);
485 if ( fill
&& (sa
!=ea
) )
486 path
.MoveToPoint(0,0);
487 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
488 // get clockwise angles
489 path
.AddArc( 0, 0, h
/2 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
490 if ( fill
&& (sa
!=ea
) )
491 path
.AddLineToPoint(0,0);
492 m_graphicContext
->DrawPath( path
);
493 m_graphicContext
->PopState();
496 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
498 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
500 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
503 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
504 wxCoord xoffset
, wxCoord yoffset
)
506 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
508 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
510 if ( m_logicalFunction
!= wxCOPY
)
514 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
515 for( int i
= 0; i
< n
; ++i
)
517 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
518 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
521 m_graphicContext
->StrokeLines( n
, pointsD
);
526 void wxGCDC::DoDrawSpline(wxList
*points
)
528 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
530 if ( m_logicalFunction
!= wxCOPY
)
533 wxGraphicsPath path
= m_graphicContext
->CreatePath();
535 wxList::compatibility_iterator node
= points
->GetFirst();
536 if (node
== wxList::compatibility_iterator())
540 wxPoint
*p
= (wxPoint
*)node
->GetData();
545 node
= node
->GetNext();
546 p
= (wxPoint
*)node
->GetData();
550 wxCoord cx1
= ( x1
+ x2
) / 2;
551 wxCoord cy1
= ( y1
+ y2
) / 2;
553 path
.MoveToPoint( x1
, y1
);
554 path
.AddLineToPoint( cx1
, cy1
);
557 while ((node
= node
->GetNext()) != NULL
)
560 while ((node
= node
->GetNext()))
564 p
= (wxPoint
*)node
->GetData();
569 wxCoord cx4
= (x1
+ x2
) / 2;
570 wxCoord cy4
= (y1
+ y2
) / 2;
572 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
578 path
.AddLineToPoint( x2
, y2
);
580 m_graphicContext
->StrokePath( path
);
582 #endif // wxUSE_SPLINES
584 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
585 wxCoord xoffset
, wxCoord yoffset
,
588 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
590 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
592 if ( m_logicalFunction
!= wxCOPY
)
595 bool closeIt
= false;
596 if (points
[n
-1] != points
[0])
599 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
600 for( int i
= 0; i
< n
; ++i
)
602 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
603 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
606 pointsD
[n
] = pointsD
[0];
608 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
612 void wxGCDC::DoDrawPolyPolygon(int n
,
620 wxGraphicsPath path
= m_graphicContext
->CreatePath();
623 for ( int j
= 0; j
< n
; ++j
)
625 wxPoint start
= points
[i
];
626 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
629 for ( int k
= 1; k
< l
; ++k
)
631 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
635 if ( start
!= points
[i
-1])
636 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
638 m_graphicContext
->DrawPath( path
, fillStyle
);
641 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
643 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
645 if ( m_logicalFunction
!= wxCOPY
)
648 // CMB: draw nothing if transformed w or h is 0
649 if (w
== 0 || h
== 0)
652 if ( m_graphicContext
->ShouldOffset() )
654 // if we are offsetting the entire rectangle is moved 0.5, so the
655 // border line gets off by 1
659 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
662 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
663 wxCoord w
, wxCoord h
,
666 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
668 if ( m_logicalFunction
!= wxCOPY
)
672 radius
= - radius
* ((w
< h
) ? w
: h
);
674 // CMB: draw nothing if transformed w or h is 0
675 if (w
== 0 || h
== 0)
678 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
681 void wxGCDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
683 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
685 if ( m_logicalFunction
!= wxCOPY
)
688 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
691 bool wxGCDC::CanDrawBitmap() const
697 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
698 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool WXUNUSED(useMask
),
699 wxCoord xsrcMask
, wxCoord ysrcMask
)
701 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
702 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
704 if ( logical_func
== wxNO_OP
)
706 else if ( logical_func
!= wxCOPY
)
708 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
712 if (xsrcMask
== -1 && ysrcMask
== -1)
718 wxCoord yysrc
= source
-> LogicalToDeviceY(ysrc
);
719 wxCoord xxsrc
= source
-> LogicalToDeviceX(xsrc
);
720 wxCoord wwsrc
= source
-> LogicalToDeviceXRel(width
);
721 wxCoord hhsrc
= source
-> LogicalToDeviceYRel(height
);
724 wxMemoryDC
* memdc
= wxDynamicCast(source
,wxMemoryDC
);
727 blit
= memdc
->GetSelectedBitmap();
729 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") );
731 wxCoord bmpwidth
= blit
.GetWidth();
732 wxCoord bmpheight
= blit
.GetHeight();
734 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
736 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
);
737 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
);
738 if ( wwsrc
> 0 && hhsrc
> 0 )
740 if ( xxsrc
>= 0 && yysrc
>= 0 )
742 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
);
743 // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
744 blit
= blit
.GetSubBitmap( subrect
);
748 // in this case we'd probably have to adjust the different coordinates, but
749 // we have to find out proper contract first
761 wxWindowDC
* windc
= wxDynamicCast(source
,wxWindowDC
);
765 bmp
= windc
->GetAsBitmap();
767 blit
= bmp
.GetSubBitmap( wxRect(xsrc
, ysrc
, width
, height
) );
773 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
, width
, height
);
777 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
784 void wxGCDC::DoDrawRotatedText(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 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
797 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
799 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
801 if ( str
.length() == 0 )
803 if ( m_logicalFunction
!= wxCOPY
)
806 m_graphicContext
->DrawText( str
, x
,y
);
809 bool wxGCDC::CanGetTextExtent() const
811 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
816 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
817 wxCoord
*descent
, wxCoord
*externalLeading
,
818 wxFont
*theFont
) const
820 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
824 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
827 wxDouble h
, d
, e
, w
;
829 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
835 if ( externalLeading
)
842 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
846 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
848 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
850 widths
.Add(0,text
.Length());
851 if ( text
.IsEmpty() )
854 wxArrayDouble widthsD
;
856 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
857 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
858 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
863 wxCoord
wxGCDC::GetCharWidth(void) const
866 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
871 wxCoord
wxGCDC::GetCharHeight(void) const
874 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
879 void wxGCDC::Clear(void)
881 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
882 // TODO better implementation / incorporate size info into wxGCDC or context
883 m_graphicContext
->SetBrush( m_backgroundBrush
);
884 wxPen p
= *wxTRANSPARENT_PEN
;
885 m_graphicContext
->SetPen( p
);
886 DoDrawRectangle( 0, 0, 32000 , 32000 );
887 m_graphicContext
->SetPen( m_pen
);
888 m_graphicContext
->SetBrush( m_brush
);
891 void wxGCDC::DoGetSize(int *width
, int *height
) const
897 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
898 const wxColour
& initialColour
,
899 const wxColour
& destColour
,
900 wxDirection nDirection
)
907 start
= rect
.GetRightBottom();
909 end
= rect
.GetLeftBottom();
912 start
= rect
.GetLeftBottom();
913 end
= rect
.GetRightBottom();
917 start
= rect
.GetLeftBottom();
919 end
= rect
.GetLeftTop();
922 start
= rect
.GetLeftTop();
923 end
= rect
.GetLeftBottom();
930 if (rect
.width
== 0 || rect
.height
== 0)
933 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
934 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
935 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
936 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
937 m_graphicContext
->SetPen(m_pen
);
940 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
941 const wxColour
& initialColour
,
942 const wxColour
& destColour
,
943 const wxPoint
& circleCenter
)
946 wxInt32 cx
= rect
.GetWidth() / 2;
947 wxInt32 cy
= rect
.GetHeight() / 2;
954 // make sure the background is filled (todo move into specific platform implementation ?)
955 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
956 m_graphicContext
->SetBrush( wxBrush( destColour
) );
957 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
959 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
960 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
961 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
962 nRadius
,initialColour
,destColour
));
964 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
965 m_graphicContext
->SetPen(m_pen
);
968 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
969 wxCoord width
, wxCoord height
)
971 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
974 #endif // wxUSE_GRAPHICS_CONTEXT