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"
22 #include "wx/dcgraph.h"
26 #include "wx/bitmap.h"
27 #include "wx/dcmemory.h"
28 #include "wx/region.h"
32 #include "wx/mac/private.h"
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 //-----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxGCDC
, wxDC
)
55 wxGCDC::wxGCDC(const wxWindowDC
& dc
) :
56 wxDC( new wxGCDCImpl( this, dc
) )
60 wxGCDC::wxGCDC( const wxMemoryDC
& dc
) :
61 wxDC( new wxGCDCImpl( this, dc
) )
66 wxDC( new wxGCDCImpl( this ) )
74 wxGraphicsContext
* wxGCDC::GetGraphicsContext()
76 if (!m_pimpl
) return NULL
;
77 wxGCDCImpl
*gc_impl
= (wxGCDCImpl
*) m_pimpl
;
78 return gc_impl
->GetGraphicsContext();
81 void wxGCDC::SetGraphicsContext( wxGraphicsContext
* ctx
)
84 wxGCDCImpl
*gc_impl
= (wxGCDCImpl
*) m_pimpl
;
85 gc_impl
->SetGraphicsContext( ctx
);
88 IMPLEMENT_ABSTRACT_CLASS(wxGCDCImpl
, wxDCImpl
)
90 wxGCDCImpl::wxGCDCImpl( wxDC
*owner
) :
96 void wxGCDCImpl::SetGraphicsContext( wxGraphicsContext
* ctx
)
98 delete m_graphicContext
;
99 m_graphicContext
= ctx
;
100 if ( m_graphicContext
)
102 m_matrixOriginal
= m_graphicContext
->GetTransform();
104 // apply the stored transformations to the passed in context
105 ComputeScaleAndOrigin();
106 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
107 m_graphicContext
->SetPen( m_pen
);
108 m_graphicContext
->SetBrush( m_brush
);
112 wxGCDCImpl::wxGCDCImpl( wxDC
*owner
, const wxWindowDC
& dc
) :
116 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
117 m_window
= dc
.GetWindow();
120 wxGCDCImpl::wxGCDCImpl( wxDC
*owner
, const wxMemoryDC
& dc
) :
124 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
127 void wxGCDCImpl::Init()
131 m_mm_to_pix_x
= mm2pt
;
132 m_mm_to_pix_y
= mm2pt
;
134 m_pen
= *wxBLACK_PEN
;
135 m_font
= *wxNORMAL_FONT
;
136 m_brush
= *wxWHITE_BRUSH
;
138 m_graphicContext
= NULL
;
139 m_logicalFunctionSupported
= true;
143 wxGCDCImpl::~wxGCDCImpl()
145 delete m_graphicContext
;
148 void wxGCDCImpl::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
150 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
151 wxCHECK_RET( bmp
.IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
153 if ( bmp
.GetDepth() == 1 )
155 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
156 m_graphicContext
->SetBrush( wxBrush( m_textBackgroundColour
, wxSOLID
) );
157 m_graphicContext
->DrawRectangle( x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
158 m_graphicContext
->SetBrush( wxBrush( m_textForegroundColour
, wxSOLID
) );
159 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
160 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(m_brush
));
161 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(m_pen
));
164 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
167 void wxGCDCImpl::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
169 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
170 wxCHECK_RET( icon
.IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
172 wxCoord w
= icon
.GetWidth();
173 wxCoord h
= icon
.GetHeight();
175 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
178 bool wxGCDCImpl::StartDoc( const wxString
& WXUNUSED(message
) )
183 void wxGCDCImpl::EndDoc()
187 void wxGCDCImpl::StartPage()
191 void wxGCDCImpl::EndPage()
195 void wxGCDCImpl::Flush()
198 CGContextFlush( (CGContextRef
) m_graphicContext
->GetNativeContext() );
202 void wxGCDCImpl::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
204 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
206 m_graphicContext
->Clip( x
, y
, w
, h
);
209 m_clipX1
= wxMax( m_clipX1
, x
);
210 m_clipY1
= wxMax( m_clipY1
, y
);
211 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
212 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
225 void wxGCDCImpl::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
227 // region is in device coordinates
228 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
232 //DestroyClippingRegion();
236 wxRegion
logRegion( region
);
239 logRegion
.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
240 logRegion
.GetBox( x
, y
, w
, h
);
242 m_graphicContext
->Clip( logRegion
);
245 m_clipX1
= wxMax( m_clipX1
, x
);
246 m_clipY1
= wxMax( m_clipY1
, y
);
247 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
248 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
261 void wxGCDCImpl::DestroyClippingRegion()
263 m_graphicContext
->ResetClip();
264 // currently the clip eg of a window extends to the area between the scrollbars
265 // so we must explicitely make sure it only covers the area we want it to draw
267 GetOwner()->GetSize( &width
, &height
) ;
268 m_graphicContext
->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , DeviceToLogicalXRel(width
), DeviceToLogicalYRel(height
) );
270 m_graphicContext
->SetPen( m_pen
);
271 m_graphicContext
->SetBrush( m_brush
);
276 void wxGCDCImpl::DoGetSizeMM( int* width
, int* height
) const
280 GetOwner()->GetSize( &w
, &h
);
282 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
284 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
287 void wxGCDCImpl::SetTextForeground( const wxColour
&col
)
289 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
291 if ( col
!= m_textForegroundColour
)
293 m_textForegroundColour
= col
;
294 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
298 void wxGCDCImpl::SetTextBackground( const wxColour
&col
)
300 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
302 m_textBackgroundColour
= col
;
305 void wxGCDCImpl::SetMapMode( int mode
)
310 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
314 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
318 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
322 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
327 SetLogicalScale( 1.0, 1.0 );
331 ComputeScaleAndOrigin();
334 wxSize
wxGCDCImpl::GetPPI() const
336 return wxSize(72, 72);
339 int wxGCDCImpl::GetDepth() const
344 void wxGCDCImpl::ComputeScaleAndOrigin()
346 wxDCImpl::ComputeScaleAndOrigin();
348 if ( m_graphicContext
)
350 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
351 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
352 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
353 // the logical origin sets the origin to have new coordinates
354 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
356 m_graphicContext
->SetTransform( m_matrixOriginal
);
357 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
361 void wxGCDCImpl::SetPalette( const wxPalette
& WXUNUSED(palette
) )
366 void wxGCDCImpl::SetBackgroundMode( int mode
)
368 m_backgroundMode
= mode
;
371 void wxGCDCImpl::SetFont( const wxFont
&font
)
374 if ( m_graphicContext
)
378 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
379 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
383 void wxGCDCImpl::SetPen( const wxPen
&pen
)
389 if ( m_graphicContext
)
391 m_graphicContext
->SetPen( m_pen
);
395 void wxGCDCImpl::SetBrush( const wxBrush
&brush
)
397 if (m_brush
== brush
)
401 if ( m_graphicContext
)
403 m_graphicContext
->SetBrush( m_brush
);
407 void wxGCDCImpl::SetBackground( const wxBrush
&brush
)
409 if (m_backgroundBrush
== brush
)
412 m_backgroundBrush
= brush
;
413 if (!m_backgroundBrush
.IsOk())
417 void wxGCDCImpl::SetLogicalFunction( int function
)
419 if (m_logicalFunction
== function
)
422 m_logicalFunction
= function
;
423 if ( m_graphicContext
->SetLogicalFunction( function
) )
424 m_logicalFunctionSupported
=true;
426 m_logicalFunctionSupported
=false;
429 bool wxGCDCImpl::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
430 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
435 bool wxGCDCImpl::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
437 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
441 void wxGCDCImpl::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
443 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
445 if ( !m_logicalFunctionSupported
)
448 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
450 CalcBoundingBox(x1
, y1
);
451 CalcBoundingBox(x2
, y2
);
454 void wxGCDCImpl::DoCrossHair( wxCoord x
, wxCoord y
)
456 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
458 if ( !m_logicalFunctionSupported
)
463 GetOwner()->GetSize( &w
, &h
);
465 m_graphicContext
->StrokeLine(0,y
,w
,y
);
466 m_graphicContext
->StrokeLine(x
,0,x
,h
);
468 CalcBoundingBox(0, 0);
469 CalcBoundingBox(0+w
, 0+h
);
472 void wxGCDCImpl::DoDrawArc( wxCoord x1
, wxCoord y1
,
473 wxCoord x2
, wxCoord y2
,
474 wxCoord xc
, wxCoord yc
)
476 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
478 if ( !m_logicalFunctionSupported
)
483 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
484 wxCoord rad
= (wxCoord
)radius
;
486 if (x1
== x2
&& y1
== y2
)
491 else if (radius
== 0.0)
497 sa
= (x1
- xc
== 0) ?
498 (y1
- yc
< 0) ? 90.0 : -90.0 :
499 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
500 ea
= (x2
- xc
== 0) ?
501 (y2
- yc
< 0) ? 90.0 : -90.0 :
502 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
505 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
507 wxGraphicsPath path
= m_graphicContext
->CreatePath();
508 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
509 path
.MoveToPoint( xc
, yc
);
510 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
511 // get clockwise angles
512 path
.AddArc( xc
, yc
, rad
, DegToRad(-sa
) , DegToRad(-ea
), false );
513 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
514 path
.AddLineToPoint( xc
, yc
);
515 m_graphicContext
->DrawPath(path
);
518 void wxGCDCImpl::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
519 double sa
, double ea
)
521 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
523 if ( !m_logicalFunctionSupported
)
526 m_graphicContext
->PushState();
527 m_graphicContext
->Translate(x
+w
/2.0,y
+h
/2.0);
528 wxDouble factor
= ((wxDouble
) w
) / h
;
529 m_graphicContext
->Scale( factor
, 1.0);
531 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
532 // get clockwise angles
533 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
535 wxGraphicsPath path
= m_graphicContext
->CreatePath();
536 path
.MoveToPoint( 0, 0 );
537 path
.AddLineToPoint( h
/ 2.0 * cos(DegToRad(sa
)) , h
/ 2.0 * sin(DegToRad(-sa
)) );
538 path
.AddLineToPoint( h
/ 2.0 * cos(DegToRad(ea
)) , h
/ 2.0 * sin(DegToRad(-ea
)) );
539 path
.AddLineToPoint( 0, 0 );
540 m_graphicContext
->FillPath( path
);
542 path
= m_graphicContext
->CreatePath();
543 path
.AddArc( 0, 0, h
/2.0 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
544 m_graphicContext
->FillPath( path
);
545 m_graphicContext
->StrokePath( path
);
549 wxGraphicsPath path
= m_graphicContext
->CreatePath();
550 path
.AddArc( 0, 0, h
/2.0 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
551 m_graphicContext
->DrawPath( path
);
554 m_graphicContext
->PopState();
557 void wxGCDCImpl::DoDrawPoint( wxCoord x
, wxCoord y
)
559 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
561 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
564 void wxGCDCImpl::DoDrawLines(int n
, wxPoint points
[],
565 wxCoord xoffset
, wxCoord yoffset
)
567 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
569 if ( !m_logicalFunctionSupported
)
572 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
573 for( int i
= 0; i
< n
; ++i
)
575 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
576 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
579 m_graphicContext
->StrokeLines( n
, pointsD
);
584 void wxGCDCImpl::DoDrawSpline(const wxPointList
*points
)
586 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
588 if ( !m_logicalFunctionSupported
)
591 wxGraphicsPath path
= m_graphicContext
->CreatePath();
593 wxPointList::compatibility_iterator node
= points
->GetFirst();
594 if (node
== wxPointList::compatibility_iterator())
598 wxPoint
*p
= node
->GetData();
603 node
= node
->GetNext();
608 wxCoord cx1
= ( x1
+ x2
) / 2;
609 wxCoord cy1
= ( y1
+ y2
) / 2;
611 path
.MoveToPoint( x1
, y1
);
612 path
.AddLineToPoint( cx1
, cy1
);
615 while ((node
= node
->GetNext()) != NULL
)
618 while ((node
= node
->GetNext()))
627 wxCoord cx4
= (x1
+ x2
) / 2;
628 wxCoord cy4
= (y1
+ y2
) / 2;
630 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
636 path
.AddLineToPoint( x2
, y2
);
638 m_graphicContext
->StrokePath( path
);
640 #endif // wxUSE_SPLINES
642 void wxGCDCImpl::DoDrawPolygon( int n
, wxPoint points
[],
643 wxCoord xoffset
, wxCoord yoffset
,
646 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
648 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
650 if ( !m_logicalFunctionSupported
)
653 bool closeIt
= false;
654 if (points
[n
-1] != points
[0])
657 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
658 for( int i
= 0; i
< n
; ++i
)
660 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
661 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
664 pointsD
[n
] = pointsD
[0];
666 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
670 void wxGCDCImpl::DoDrawPolyPolygon(int n
,
678 wxGraphicsPath path
= m_graphicContext
->CreatePath();
681 for ( int j
= 0; j
< n
; ++j
)
683 wxPoint start
= points
[i
];
684 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
687 for ( int k
= 1; k
< l
; ++k
)
689 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
693 if ( start
!= points
[i
-1])
694 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
696 m_graphicContext
->DrawPath( path
, fillStyle
);
699 void wxGCDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
701 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
703 if ( !m_logicalFunctionSupported
)
706 // CMB: draw nothing if transformed w or h is 0
707 if (w
== 0 || h
== 0)
710 if ( m_graphicContext
->ShouldOffset() )
712 // if we are offsetting the entire rectangle is moved 0.5, so the
713 // border line gets off by 1
717 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
720 void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
721 wxCoord w
, wxCoord h
,
724 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
726 if ( !m_logicalFunctionSupported
)
730 radius
= - radius
* ((w
< h
) ? w
: h
);
732 // CMB: draw nothing if transformed w or h is 0
733 if (w
== 0 || h
== 0)
736 if ( m_graphicContext
->ShouldOffset() )
738 // if we are offsetting the entire rectangle is moved 0.5, so the
739 // border line gets off by 1
743 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
746 void wxGCDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
748 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
750 if ( !m_logicalFunctionSupported
)
753 if ( m_graphicContext
->ShouldOffset() )
755 // if we are offsetting the entire rectangle is moved 0.5, so the
756 // border line gets off by 1
760 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
763 bool wxGCDCImpl::CanDrawBitmap() const
768 bool wxGCDCImpl::DoBlit(
769 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
770 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
771 wxCoord xsrcMask
, wxCoord ysrcMask
)
773 return DoStretchBlit( xdest
, ydest
, width
, height
,
774 source
, xsrc
, ysrc
, width
, height
, logical_func
, useMask
,
778 bool wxGCDCImpl::DoStretchBlit(
779 wxCoord xdest
, wxCoord ydest
, wxCoord dstWidth
, wxCoord dstHeight
,
780 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, wxCoord srcWidth
, wxCoord srcHeight
,
781 int logical_func
, bool WXUNUSED(useMask
),
782 wxCoord xsrcMask
, wxCoord ysrcMask
)
784 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
785 wxCHECK_MSG( source
->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
787 if ( logical_func
== wxNO_OP
)
789 else if ( !m_graphicContext
->SetLogicalFunction( logical_func
) )
792 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
796 if (xsrcMask
== -1 && ysrcMask
== -1)
802 wxRect
subrect(source
->LogicalToDeviceX(xsrc
),
803 source
->LogicalToDeviceY(ysrc
),
804 source
->LogicalToDeviceXRel(srcWidth
),
805 source
->LogicalToDeviceYRel(srcHeight
));
807 // if needed clip the subrect down to the size of the source DC
809 source
->GetSize(&sw
, &sh
);
810 sw
= source
->LogicalToDeviceXRel(sw
);
811 sh
= source
->LogicalToDeviceYRel(sh
);
812 if (subrect
.x
+ subrect
.width
> sw
)
813 subrect
.width
= sw
- subrect
.x
;
814 if (subrect
.y
+ subrect
.height
> sh
)
815 subrect
.height
= sh
- subrect
.y
;
817 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
821 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
,
822 dstWidth
, dstHeight
);
826 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
830 // reset logical function
831 m_graphicContext
->SetLogicalFunction( m_logicalFunction
);
836 void wxGCDCImpl::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
839 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
841 if ( str
.length() == 0 )
843 if ( !m_logicalFunctionSupported
)
846 if ( m_backgroundMode
== wxTRANSPARENT
)
847 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
849 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
), m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
852 void wxGCDCImpl::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
854 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
856 if ( str
.length() == 0 )
859 if ( !m_logicalFunctionSupported
)
862 if ( m_backgroundMode
== wxTRANSPARENT
)
863 m_graphicContext
->DrawText( str
, x
,y
);
865 m_graphicContext
->DrawText( str
, x
,y
, m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
868 bool wxGCDCImpl::CanGetTextExtent() const
870 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
875 void wxGCDCImpl::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
876 wxCoord
*descent
, wxCoord
*externalLeading
,
877 const wxFont
*theFont
) const
879 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
883 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
886 wxDouble h
, d
, e
, w
;
888 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
891 *height
= (wxCoord
)(h
+0.5);
893 *descent
= (wxCoord
)(d
+0.5);
894 if ( externalLeading
)
895 *externalLeading
= (wxCoord
)(e
+0.5);
897 *width
= (wxCoord
)(w
+0.5);
901 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
905 bool wxGCDCImpl::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
907 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
909 widths
.Add(0,text
.Length());
910 if ( text
.IsEmpty() )
913 wxArrayDouble widthsD
;
915 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
916 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
917 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
922 wxCoord
wxGCDCImpl::GetCharWidth(void) const
925 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
930 wxCoord
wxGCDCImpl::GetCharHeight(void) const
933 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
938 void wxGCDCImpl::Clear(void)
940 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") );
941 // TODO better implementation / incorporate size info into wxGCDC or context
942 m_graphicContext
->SetBrush( m_backgroundBrush
);
943 wxPen p
= *wxTRANSPARENT_PEN
;
944 m_graphicContext
->SetPen( p
);
945 DoDrawRectangle( 0, 0, 32000 , 32000 );
946 m_graphicContext
->SetPen( m_pen
);
947 m_graphicContext
->SetBrush( m_brush
);
950 void wxGCDCImpl::DoGetSize(int *width
, int *height
) const
956 void wxGCDCImpl::DoGradientFillLinear(const wxRect
& rect
,
957 const wxColour
& initialColour
,
958 const wxColour
& destColour
,
959 wxDirection nDirection
)
966 start
= rect
.GetRightBottom();
968 end
= rect
.GetLeftBottom();
971 start
= rect
.GetLeftBottom();
972 end
= rect
.GetRightBottom();
976 start
= rect
.GetLeftBottom();
978 end
= rect
.GetLeftTop();
981 start
= rect
.GetLeftTop();
982 end
= rect
.GetLeftBottom();
989 if (rect
.width
== 0 || rect
.height
== 0)
992 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
993 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
994 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
995 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
996 m_graphicContext
->SetPen(m_pen
);
999 void wxGCDCImpl::DoGradientFillConcentric(const wxRect
& rect
,
1000 const wxColour
& initialColour
,
1001 const wxColour
& destColour
,
1002 const wxPoint
& circleCenter
)
1005 wxInt32 cx
= rect
.GetWidth() / 2;
1006 wxInt32 cy
= rect
.GetHeight() / 2;
1013 // make sure the background is filled (todo move into specific platform implementation ?)
1014 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
1015 m_graphicContext
->SetBrush( wxBrush( destColour
) );
1016 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
1018 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
1019 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
1020 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
1021 nRadius
,initialColour
,destColour
));
1023 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
1024 m_graphicContext
->SetPen(m_pen
);
1027 void wxGCDCImpl::DoDrawCheckMark(wxCoord x
, wxCoord y
,
1028 wxCoord width
, wxCoord height
)
1030 wxDCImpl::DoDrawCheckMark(x
,y
,width
,height
);
1033 #endif // wxUSE_GRAPHICS_CONTEXT