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 if ( m_graphicContext
)
66 m_matrixOriginal
= m_graphicContext
->GetTransform();
68 // apply the stored transformations to the passed in context
69 ComputeScaleAndOrigin();
70 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
71 m_graphicContext
->SetPen( m_pen
);
72 m_graphicContext
->SetBrush( m_brush
);
76 wxGCDC::wxGCDC(const wxWindowDC
& dc
)
79 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
83 wxGCDC::wxGCDC(const wxMemoryDC
& dc
)
86 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
94 m_mm_to_pix_x
= mm2pt
;
95 m_mm_to_pix_y
= mm2pt
;
98 m_font
= *wxNORMAL_FONT
;
99 m_brush
= *wxWHITE_BRUSH
;
101 m_graphicContext
= NULL
;
102 m_logicalFunctionSupported
= true;
108 delete m_graphicContext
;
111 void wxGCDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
113 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
114 wxCHECK_RET( bmp
.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
116 if ( bmp
.GetDepth() == 1 )
118 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
119 m_graphicContext
->SetBrush( wxBrush( m_textBackgroundColour
, wxSOLID
) );
120 m_graphicContext
->DrawRectangle( x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
121 m_graphicContext
->SetBrush( wxBrush( m_textForegroundColour
, wxSOLID
) );
122 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
123 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(m_brush
));
124 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(m_pen
));
127 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
130 void wxGCDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
132 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
133 wxCHECK_RET( icon
.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
135 wxCoord w
= icon
.GetWidth();
136 wxCoord h
= icon
.GetHeight();
138 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
141 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
143 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
145 m_graphicContext
->Clip( x
, y
, w
, h
);
148 m_clipX1
= wxMax( m_clipX1
, x
);
149 m_clipY1
= wxMax( m_clipY1
, y
);
150 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
151 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
164 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
166 // region is in device coordinates
167 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
171 DestroyClippingRegion();
175 wxRegion
logRegion( region
);
178 logRegion
.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
179 logRegion
.GetBox( x
, y
, w
, h
);
181 m_graphicContext
->Clip( logRegion
);
184 m_clipX1
= wxMax( m_clipX1
, x
);
185 m_clipY1
= wxMax( m_clipY1
, y
);
186 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
187 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
200 void wxGCDC::DestroyClippingRegion()
202 m_graphicContext
->ResetClip();
203 // currently the clip eg of a window extends to the area between the scrollbars
204 // so we must explicitely make sure it only covers the area we want it to draw
206 GetSize( &width
, &height
) ;
207 m_graphicContext
->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , width
, height
);
209 m_graphicContext
->SetPen( m_pen
);
210 m_graphicContext
->SetBrush( m_brush
);
215 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
221 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
223 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
226 void wxGCDC::SetTextForeground( const wxColour
&col
)
228 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
230 if ( col
!= m_textForegroundColour
)
232 m_textForegroundColour
= col
;
233 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
237 void wxGCDC::SetTextBackground( const wxColour
&col
)
239 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
241 m_textBackgroundColour
= col
;
244 void wxGCDC::SetMapMode( int mode
)
249 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
253 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
257 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
261 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
266 SetLogicalScale( 1.0, 1.0 );
270 ComputeScaleAndOrigin();
273 void wxGCDC::SetUserScale( double x
, double y
)
275 // allow negative ? -> no
279 ComputeScaleAndOrigin();
282 void wxGCDC::SetLogicalScale( double x
, double y
)
287 ComputeScaleAndOrigin();
290 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
292 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
293 m_logicalOriginY
= y
* m_signY
;
294 ComputeScaleAndOrigin();
297 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
301 ComputeScaleAndOrigin();
304 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
306 m_signX
= (xLeftRight
? 1 : -1);
307 m_signY
= (yBottomUp
? -1 : 1);
308 ComputeScaleAndOrigin();
311 wxSize
wxGCDC::GetPPI() const
313 return wxSize(72, 72);
316 int wxGCDC::GetDepth() const
321 void wxGCDC::ComputeScaleAndOrigin()
323 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
324 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
326 if ( m_graphicContext
)
328 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
329 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
330 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
331 // the logical origin sets the origin to have new coordinates
332 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
334 m_graphicContext
->SetTransform( m_matrixOriginal
);
335 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
339 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
344 void wxGCDC::SetBackgroundMode( int mode
)
346 m_backgroundMode
= mode
;
349 void wxGCDC::SetFont( const wxFont
&font
)
352 if ( m_graphicContext
)
356 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
357 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
361 void wxGCDC::SetPen( const wxPen
&pen
)
367 if ( m_graphicContext
)
369 m_graphicContext
->SetPen( m_pen
);
373 void wxGCDC::SetBrush( const wxBrush
&brush
)
375 if (m_brush
== brush
)
379 if ( m_graphicContext
)
381 m_graphicContext
->SetBrush( m_brush
);
385 void wxGCDC::SetBackground( const wxBrush
&brush
)
387 if (m_backgroundBrush
== brush
)
390 m_backgroundBrush
= brush
;
391 if (!m_backgroundBrush
.Ok())
395 void wxGCDC::SetLogicalFunction( int function
)
397 if (m_logicalFunction
== function
)
400 m_logicalFunction
= function
;
401 if ( m_graphicContext
->SetLogicalFunction( function
) )
402 m_logicalFunctionSupported
=true;
404 m_logicalFunctionSupported
=false;
407 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
408 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
413 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
415 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
419 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
421 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
423 if ( !m_logicalFunctionSupported
)
426 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
428 CalcBoundingBox(x1
, y1
);
429 CalcBoundingBox(x2
, y2
);
432 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
434 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
436 if ( !m_logicalFunctionSupported
)
443 m_graphicContext
->StrokeLine(0,y
,w
,y
);
444 m_graphicContext
->StrokeLine(x
,0,x
,h
);
446 CalcBoundingBox(0, 0);
447 CalcBoundingBox(0+w
, 0+h
);
450 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
451 wxCoord x2
, wxCoord y2
,
452 wxCoord xc
, wxCoord yc
)
454 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
456 if ( !m_logicalFunctionSupported
)
461 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
462 wxCoord rad
= (wxCoord
)radius
;
464 if (x1
== x2
&& y1
== y2
)
469 else if (radius
== 0.0)
475 sa
= (x1
- xc
== 0) ?
476 (y1
- yc
< 0) ? 90.0 : -90.0 :
477 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
478 ea
= (x2
- xc
== 0) ?
479 (y2
- yc
< 0) ? 90.0 : -90.0 :
480 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
483 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
485 wxGraphicsPath path
= m_graphicContext
->CreatePath();
486 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
487 path
.MoveToPoint( xc
, yc
);
488 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
489 // get clockwise angles
490 path
.AddArc( xc
, yc
, rad
, DegToRad(-sa
) , DegToRad(-ea
), false );
491 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
492 path
.AddLineToPoint( xc
, yc
);
493 m_graphicContext
->DrawPath(path
);
496 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
497 double sa
, double ea
)
499 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
501 if ( !m_logicalFunctionSupported
)
504 wxGraphicsPath path
= m_graphicContext
->CreatePath();
505 m_graphicContext
->PushState();
506 m_graphicContext
->Translate(x
+w
/2.0,y
+h
/2.0);
507 wxDouble factor
= ((wxDouble
) w
) / h
;
508 m_graphicContext
->Scale( factor
, 1.0);
510 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
511 // get clockwise angles
512 path
.AddArc( 0, 0, h
/2.0 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
513 m_graphicContext
->DrawPath( path
);
514 m_graphicContext
->PopState();
517 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
519 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
521 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
524 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
525 wxCoord xoffset
, wxCoord yoffset
)
527 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
529 if ( !m_logicalFunctionSupported
)
532 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
533 for( int i
= 0; i
< n
; ++i
)
535 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
536 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
539 m_graphicContext
->StrokeLines( n
, pointsD
);
544 void wxGCDC::DoDrawSpline(wxList
*points
)
546 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
548 if ( !m_logicalFunctionSupported
)
551 wxGraphicsPath path
= m_graphicContext
->CreatePath();
553 wxList::compatibility_iterator node
= points
->GetFirst();
554 if (node
== wxList::compatibility_iterator())
558 wxPoint
*p
= (wxPoint
*)node
->GetData();
563 node
= node
->GetNext();
564 p
= (wxPoint
*)node
->GetData();
568 wxCoord cx1
= ( x1
+ x2
) / 2;
569 wxCoord cy1
= ( y1
+ y2
) / 2;
571 path
.MoveToPoint( x1
, y1
);
572 path
.AddLineToPoint( cx1
, cy1
);
575 while ((node
= node
->GetNext()) != NULL
)
578 while ((node
= node
->GetNext()))
582 p
= (wxPoint
*)node
->GetData();
587 wxCoord cx4
= (x1
+ x2
) / 2;
588 wxCoord cy4
= (y1
+ y2
) / 2;
590 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
596 path
.AddLineToPoint( x2
, y2
);
598 m_graphicContext
->StrokePath( path
);
600 #endif // wxUSE_SPLINES
602 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
603 wxCoord xoffset
, wxCoord yoffset
,
606 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
608 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
610 if ( !m_logicalFunctionSupported
)
613 bool closeIt
= false;
614 if (points
[n
-1] != points
[0])
617 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
618 for( int i
= 0; i
< n
; ++i
)
620 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
621 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
624 pointsD
[n
] = pointsD
[0];
626 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
630 void wxGCDC::DoDrawPolyPolygon(int n
,
638 wxGraphicsPath path
= m_graphicContext
->CreatePath();
641 for ( int j
= 0; j
< n
; ++j
)
643 wxPoint start
= points
[i
];
644 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
647 for ( int k
= 1; k
< l
; ++k
)
649 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
653 if ( start
!= points
[i
-1])
654 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
656 m_graphicContext
->DrawPath( path
, fillStyle
);
659 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
661 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
663 if ( !m_logicalFunctionSupported
)
666 // CMB: draw nothing if transformed w or h is 0
667 if (w
== 0 || h
== 0)
670 if ( m_graphicContext
->ShouldOffset() )
672 // if we are offsetting the entire rectangle is moved 0.5, so the
673 // border line gets off by 1
677 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
680 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
681 wxCoord w
, wxCoord h
,
684 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
686 if ( !m_logicalFunctionSupported
)
690 radius
= - radius
* ((w
< h
) ? w
: h
);
692 // CMB: draw nothing if transformed w or h is 0
693 if (w
== 0 || h
== 0)
696 if ( m_graphicContext
->ShouldOffset() )
698 // if we are offsetting the entire rectangle is moved 0.5, so the
699 // border line gets off by 1
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_logicalFunctionSupported
)
713 if ( m_graphicContext
->ShouldOffset() )
715 // if we are offsetting the entire rectangle is moved 0.5, so the
716 // border line gets off by 1
720 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
723 bool wxGCDC::CanDrawBitmap() const
729 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
730 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
731 wxCoord xsrcMask
, wxCoord ysrcMask
)
733 return DoStretchBlit( xdest
, ydest
, width
, height
,
734 source
, xsrc
, ysrc
, width
, height
, logical_func
, useMask
,
738 bool wxGCDC::DoStretchBlit(
739 wxCoord xdest
, wxCoord ydest
, wxCoord dstWidth
, wxCoord dstHeight
,
740 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, wxCoord srcWidth
, wxCoord srcHeight
,
741 int logical_func
, bool WXUNUSED(useMask
),
742 wxCoord xsrcMask
, wxCoord ysrcMask
)
744 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
745 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
747 if ( logical_func
== wxNO_OP
)
749 else if ( logical_func
!= wxCOPY
)
751 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
755 if (xsrcMask
== -1 && ysrcMask
== -1)
761 wxRect
subrect(source
->LogicalToDeviceX(xsrc
),
762 source
->LogicalToDeviceY(ysrc
),
763 source
->LogicalToDeviceXRel(srcWidth
),
764 source
->LogicalToDeviceYRel(srcHeight
));
766 // if needed clip the subrect down to the size of the source DC
768 source
->GetSize(&sw
, &sh
);
769 sw
= source
->LogicalToDeviceXRel(sw
);
770 sh
= source
->LogicalToDeviceYRel(sh
);
771 if (subrect
.x
+ subrect
.width
> sw
)
772 subrect
.width
= sw
- subrect
.x
;
773 if (subrect
.y
+ subrect
.height
> sh
)
774 subrect
.height
= sh
- subrect
.y
;
776 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
780 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
,
781 dstWidth
, dstHeight
);
785 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
792 void wxGCDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
795 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
797 if ( str
.length() == 0 )
799 if ( !m_logicalFunctionSupported
)
802 if ( m_backgroundMode
== wxTRANSPARENT
)
803 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
805 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
), m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
808 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
810 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
812 if ( str
.length() == 0 )
815 if ( !m_logicalFunctionSupported
)
818 if ( m_backgroundMode
== wxTRANSPARENT
)
819 m_graphicContext
->DrawText( str
, x
,y
);
821 m_graphicContext
->DrawText( str
, x
,y
, m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
824 bool wxGCDC::CanGetTextExtent() const
826 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
831 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
832 wxCoord
*descent
, wxCoord
*externalLeading
,
833 const wxFont
*theFont
) const
835 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
839 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
842 wxDouble h
, d
, e
, w
;
844 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
847 *height
= (wxCoord
)h
;
849 *descent
= (wxCoord
)d
;
850 if ( externalLeading
)
851 *externalLeading
= (wxCoord
)e
;
857 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
861 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
863 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
865 widths
.Add(0,text
.Length());
866 if ( text
.IsEmpty() )
869 wxArrayDouble widthsD
;
871 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
872 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
873 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
878 wxCoord
wxGCDC::GetCharWidth(void) const
881 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
886 wxCoord
wxGCDC::GetCharHeight(void) const
889 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
894 void wxGCDC::Clear(void)
896 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
897 // TODO better implementation / incorporate size info into wxGCDC or context
898 m_graphicContext
->SetBrush( m_backgroundBrush
);
899 wxPen p
= *wxTRANSPARENT_PEN
;
900 m_graphicContext
->SetPen( p
);
901 DoDrawRectangle( 0, 0, 32000 , 32000 );
902 m_graphicContext
->SetPen( m_pen
);
903 m_graphicContext
->SetBrush( m_brush
);
906 void wxGCDC::DoGetSize(int *width
, int *height
) const
912 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
913 const wxColour
& initialColour
,
914 const wxColour
& destColour
,
915 wxDirection nDirection
)
922 start
= rect
.GetRightBottom();
924 end
= rect
.GetLeftBottom();
927 start
= rect
.GetLeftBottom();
928 end
= rect
.GetRightBottom();
932 start
= rect
.GetLeftBottom();
934 end
= rect
.GetLeftTop();
937 start
= rect
.GetLeftTop();
938 end
= rect
.GetLeftBottom();
945 if (rect
.width
== 0 || rect
.height
== 0)
948 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
949 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
950 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
951 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
952 m_graphicContext
->SetPen(m_pen
);
955 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
956 const wxColour
& initialColour
,
957 const wxColour
& destColour
,
958 const wxPoint
& circleCenter
)
961 wxInt32 cx
= rect
.GetWidth() / 2;
962 wxInt32 cy
= rect
.GetHeight() / 2;
969 // make sure the background is filled (todo move into specific platform implementation ?)
970 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
971 m_graphicContext
->SetBrush( wxBrush( destColour
) );
972 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
974 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
975 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
976 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
977 nRadius
,initialColour
,destColour
));
979 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
980 m_graphicContext
->SetPen(m_pen
);
983 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
984 wxCoord width
, wxCoord height
)
986 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
989 #endif // wxUSE_GRAPHICS_CONTEXT