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
) );
119 wxGCDCImpl::wxGCDCImpl( wxDC
*owner
, const wxMemoryDC
& dc
) :
123 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
126 void wxGCDCImpl::Init()
130 m_mm_to_pix_x
= mm2pt
;
131 m_mm_to_pix_y
= mm2pt
;
133 m_pen
= *wxBLACK_PEN
;
134 m_font
= *wxNORMAL_FONT
;
135 m_brush
= *wxWHITE_BRUSH
;
137 m_graphicContext
= NULL
;
138 m_logicalFunctionSupported
= true;
142 wxGCDCImpl::~wxGCDCImpl()
144 delete m_graphicContext
;
147 void wxGCDCImpl::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
149 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
150 wxCHECK_RET( bmp
.IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
152 if ( bmp
.GetDepth() == 1 )
154 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
155 m_graphicContext
->SetBrush( wxBrush( m_textBackgroundColour
, wxSOLID
) );
156 m_graphicContext
->DrawRectangle( x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
157 m_graphicContext
->SetBrush( wxBrush( m_textForegroundColour
, wxSOLID
) );
158 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
159 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(m_brush
));
160 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(m_pen
));
163 m_graphicContext
->DrawBitmap( bmp
, x
, y
, bmp
.GetWidth() , bmp
.GetHeight() );
166 void wxGCDCImpl::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
168 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
169 wxCHECK_RET( icon
.IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
171 wxCoord w
= icon
.GetWidth();
172 wxCoord h
= icon
.GetHeight();
174 m_graphicContext
->DrawIcon( icon
, x
, y
, w
, h
);
177 bool wxGCDCImpl::StartDoc( const wxString
& WXUNUSED(message
) )
182 void wxGCDCImpl::EndDoc()
186 void wxGCDCImpl::StartPage()
190 void wxGCDCImpl::EndPage()
194 void wxGCDCImpl::Flush()
197 CGContextFlush( (CGContextRef
) m_graphicContext
->GetNativeContext() );
201 void wxGCDCImpl::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
203 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
205 m_graphicContext
->Clip( x
, y
, w
, h
);
208 m_clipX1
= wxMax( m_clipX1
, x
);
209 m_clipY1
= wxMax( m_clipY1
, y
);
210 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
211 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
224 void wxGCDCImpl::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
226 // region is in device coordinates
227 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
231 //DestroyClippingRegion();
235 wxRegion
logRegion( region
);
238 logRegion
.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
239 logRegion
.GetBox( x
, y
, w
, h
);
241 m_graphicContext
->Clip( logRegion
);
244 m_clipX1
= wxMax( m_clipX1
, x
);
245 m_clipY1
= wxMax( m_clipY1
, y
);
246 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
247 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
260 void wxGCDCImpl::DestroyClippingRegion()
262 m_graphicContext
->ResetClip();
263 // currently the clip eg of a window extends to the area between the scrollbars
264 // so we must explicitely make sure it only covers the area we want it to draw
266 GetOwner()->GetSize( &width
, &height
) ;
267 m_graphicContext
->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , DeviceToLogicalXRel(width
), DeviceToLogicalYRel(height
) );
269 m_graphicContext
->SetPen( m_pen
);
270 m_graphicContext
->SetBrush( m_brush
);
275 void wxGCDCImpl::DoGetSizeMM( int* width
, int* height
) const
279 GetOwner()->GetSize( &w
, &h
);
281 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
283 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
286 void wxGCDCImpl::SetTextForeground( const wxColour
&col
)
288 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
290 if ( col
!= m_textForegroundColour
)
292 m_textForegroundColour
= col
;
293 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
297 void wxGCDCImpl::SetTextBackground( const wxColour
&col
)
299 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
301 m_textBackgroundColour
= col
;
304 void wxGCDCImpl::SetMapMode( int mode
)
309 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
313 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
317 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
321 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
326 SetLogicalScale( 1.0, 1.0 );
330 ComputeScaleAndOrigin();
333 wxSize
wxGCDCImpl::GetPPI() const
335 return wxSize(72, 72);
338 int wxGCDCImpl::GetDepth() const
343 void wxGCDCImpl::ComputeScaleAndOrigin()
345 wxDCImpl::ComputeScaleAndOrigin();
347 if ( m_graphicContext
)
349 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
350 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
351 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
352 // the logical origin sets the origin to have new coordinates
353 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
355 m_graphicContext
->SetTransform( m_matrixOriginal
);
356 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
360 void wxGCDCImpl::SetPalette( const wxPalette
& WXUNUSED(palette
) )
365 void wxGCDCImpl::SetBackgroundMode( int mode
)
367 m_backgroundMode
= mode
;
370 void wxGCDCImpl::SetFont( const wxFont
&font
)
373 if ( m_graphicContext
)
377 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
378 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
382 void wxGCDCImpl::SetPen( const wxPen
&pen
)
388 if ( m_graphicContext
)
390 m_graphicContext
->SetPen( m_pen
);
394 void wxGCDCImpl::SetBrush( const wxBrush
&brush
)
396 if (m_brush
== brush
)
400 if ( m_graphicContext
)
402 m_graphicContext
->SetBrush( m_brush
);
406 void wxGCDCImpl::SetBackground( const wxBrush
&brush
)
408 if (m_backgroundBrush
== brush
)
411 m_backgroundBrush
= brush
;
412 if (!m_backgroundBrush
.IsOk())
416 void wxGCDCImpl::SetLogicalFunction( int function
)
418 if (m_logicalFunction
== function
)
421 m_logicalFunction
= function
;
422 if ( m_graphicContext
->SetLogicalFunction( function
) )
423 m_logicalFunctionSupported
=true;
425 m_logicalFunctionSupported
=false;
428 bool wxGCDCImpl::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
429 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
434 bool wxGCDCImpl::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
436 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
440 void wxGCDCImpl::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
442 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
444 if ( !m_logicalFunctionSupported
)
447 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
449 CalcBoundingBox(x1
, y1
);
450 CalcBoundingBox(x2
, y2
);
453 void wxGCDCImpl::DoCrossHair( wxCoord x
, wxCoord y
)
455 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
457 if ( !m_logicalFunctionSupported
)
462 GetOwner()->GetSize( &w
, &h
);
464 m_graphicContext
->StrokeLine(0,y
,w
,y
);
465 m_graphicContext
->StrokeLine(x
,0,x
,h
);
467 CalcBoundingBox(0, 0);
468 CalcBoundingBox(0+w
, 0+h
);
471 void wxGCDCImpl::DoDrawArc( wxCoord x1
, wxCoord y1
,
472 wxCoord x2
, wxCoord y2
,
473 wxCoord xc
, wxCoord yc
)
475 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
477 if ( !m_logicalFunctionSupported
)
482 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
483 wxCoord rad
= (wxCoord
)radius
;
485 if (x1
== x2
&& y1
== y2
)
490 else if (radius
== 0.0)
496 sa
= (x1
- xc
== 0) ?
497 (y1
- yc
< 0) ? 90.0 : -90.0 :
498 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
499 ea
= (x2
- xc
== 0) ?
500 (y2
- yc
< 0) ? 90.0 : -90.0 :
501 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
504 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
506 wxGraphicsPath path
= m_graphicContext
->CreatePath();
507 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
508 path
.MoveToPoint( xc
, yc
);
509 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
510 // get clockwise angles
511 path
.AddArc( xc
, yc
, rad
, DegToRad(-sa
) , DegToRad(-ea
), false );
512 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
513 path
.AddLineToPoint( xc
, yc
);
514 m_graphicContext
->DrawPath(path
);
517 void wxGCDCImpl::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
518 double sa
, double ea
)
520 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
522 if ( !m_logicalFunctionSupported
)
525 m_graphicContext
->PushState();
526 m_graphicContext
->Translate(x
+w
/2.0,y
+h
/2.0);
527 wxDouble factor
= ((wxDouble
) w
) / h
;
528 m_graphicContext
->Scale( factor
, 1.0);
530 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
531 // get clockwise angles
532 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
534 wxGraphicsPath path
= m_graphicContext
->CreatePath();
535 path
.MoveToPoint( 0, 0 );
536 path
.AddLineToPoint( h
/ 2.0 * cos(DegToRad(sa
)) , h
/ 2.0 * sin(DegToRad(-sa
)) );
537 path
.AddLineToPoint( h
/ 2.0 * cos(DegToRad(ea
)) , h
/ 2.0 * sin(DegToRad(-ea
)) );
538 path
.AddLineToPoint( 0, 0 );
539 m_graphicContext
->FillPath( path
);
541 path
= m_graphicContext
->CreatePath();
542 path
.AddArc( 0, 0, h
/2.0 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
543 m_graphicContext
->FillPath( path
);
544 m_graphicContext
->StrokePath( path
);
548 wxGraphicsPath path
= m_graphicContext
->CreatePath();
549 path
.AddArc( 0, 0, h
/2.0 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
550 m_graphicContext
->DrawPath( path
);
553 m_graphicContext
->PopState();
556 void wxGCDCImpl::DoDrawPoint( wxCoord x
, wxCoord y
)
558 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
560 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
563 void wxGCDCImpl::DoDrawLines(int n
, wxPoint points
[],
564 wxCoord xoffset
, wxCoord yoffset
)
566 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
568 if ( !m_logicalFunctionSupported
)
571 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
572 for( int i
= 0; i
< n
; ++i
)
574 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
575 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
578 m_graphicContext
->StrokeLines( n
, pointsD
);
583 void wxGCDCImpl::DoDrawSpline(const wxPointList
*points
)
585 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
587 if ( !m_logicalFunctionSupported
)
590 wxGraphicsPath path
= m_graphicContext
->CreatePath();
592 wxPointList::compatibility_iterator node
= points
->GetFirst();
593 if (node
== wxPointList::compatibility_iterator())
597 wxPoint
*p
= node
->GetData();
602 node
= node
->GetNext();
607 wxCoord cx1
= ( x1
+ x2
) / 2;
608 wxCoord cy1
= ( y1
+ y2
) / 2;
610 path
.MoveToPoint( x1
, y1
);
611 path
.AddLineToPoint( cx1
, cy1
);
614 while ((node
= node
->GetNext()) != NULL
)
617 while ((node
= node
->GetNext()))
626 wxCoord cx4
= (x1
+ x2
) / 2;
627 wxCoord cy4
= (y1
+ y2
) / 2;
629 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
635 path
.AddLineToPoint( x2
, y2
);
637 m_graphicContext
->StrokePath( path
);
639 #endif // wxUSE_SPLINES
641 void wxGCDCImpl::DoDrawPolygon( int n
, wxPoint points
[],
642 wxCoord xoffset
, wxCoord yoffset
,
645 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
647 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
649 if ( !m_logicalFunctionSupported
)
652 bool closeIt
= false;
653 if (points
[n
-1] != points
[0])
656 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
657 for( int i
= 0; i
< n
; ++i
)
659 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
660 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
663 pointsD
[n
] = pointsD
[0];
665 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
669 void wxGCDCImpl::DoDrawPolyPolygon(int n
,
677 wxGraphicsPath path
= m_graphicContext
->CreatePath();
680 for ( int j
= 0; j
< n
; ++j
)
682 wxPoint start
= points
[i
];
683 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
686 for ( int k
= 1; k
< l
; ++k
)
688 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
692 if ( start
!= points
[i
-1])
693 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
695 m_graphicContext
->DrawPath( path
, fillStyle
);
698 void wxGCDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
700 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
702 if ( !m_logicalFunctionSupported
)
705 // CMB: draw nothing if transformed w or h is 0
706 if (w
== 0 || h
== 0)
709 if ( m_graphicContext
->ShouldOffset() )
711 // if we are offsetting the entire rectangle is moved 0.5, so the
712 // border line gets off by 1
716 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
719 void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
720 wxCoord w
, wxCoord h
,
723 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
725 if ( !m_logicalFunctionSupported
)
729 radius
= - radius
* ((w
< h
) ? w
: h
);
731 // CMB: draw nothing if transformed w or h is 0
732 if (w
== 0 || h
== 0)
735 if ( m_graphicContext
->ShouldOffset() )
737 // if we are offsetting the entire rectangle is moved 0.5, so the
738 // border line gets off by 1
742 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
745 void wxGCDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
747 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
749 if ( !m_logicalFunctionSupported
)
752 if ( m_graphicContext
->ShouldOffset() )
754 // if we are offsetting the entire rectangle is moved 0.5, so the
755 // border line gets off by 1
759 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
762 bool wxGCDCImpl::CanDrawBitmap() const
767 bool wxGCDCImpl::DoBlit(
768 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
769 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
770 wxCoord xsrcMask
, wxCoord ysrcMask
)
772 return DoStretchBlit( xdest
, ydest
, width
, height
,
773 source
, xsrc
, ysrc
, width
, height
, logical_func
, useMask
,
777 bool wxGCDCImpl::DoStretchBlit(
778 wxCoord xdest
, wxCoord ydest
, wxCoord dstWidth
, wxCoord dstHeight
,
779 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, wxCoord srcWidth
, wxCoord srcHeight
,
780 int logical_func
, bool WXUNUSED(useMask
),
781 wxCoord xsrcMask
, wxCoord ysrcMask
)
783 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
784 wxCHECK_MSG( source
->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
786 if ( logical_func
== wxNO_OP
)
788 else if ( !m_graphicContext
->SetLogicalFunction( logical_func
) )
791 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
795 if (xsrcMask
== -1 && ysrcMask
== -1)
801 wxRect
subrect(source
->LogicalToDeviceX(xsrc
),
802 source
->LogicalToDeviceY(ysrc
),
803 source
->LogicalToDeviceXRel(srcWidth
),
804 source
->LogicalToDeviceYRel(srcHeight
));
806 // if needed clip the subrect down to the size of the source DC
808 source
->GetSize(&sw
, &sh
);
809 sw
= source
->LogicalToDeviceXRel(sw
);
810 sh
= source
->LogicalToDeviceYRel(sh
);
811 if (subrect
.x
+ subrect
.width
> sw
)
812 subrect
.width
= sw
- subrect
.x
;
813 if (subrect
.y
+ subrect
.height
> sh
)
814 subrect
.height
= sh
- subrect
.y
;
816 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
820 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
,
821 dstWidth
, dstHeight
);
825 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
829 // reset logical function
830 m_graphicContext
->SetLogicalFunction( m_logicalFunction
);
835 void wxGCDCImpl::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
838 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
840 if ( str
.length() == 0 )
842 if ( !m_logicalFunctionSupported
)
845 if ( m_backgroundMode
== wxTRANSPARENT
)
846 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
848 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
), m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
851 void wxGCDCImpl::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
853 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
855 if ( str
.length() == 0 )
858 if ( !m_logicalFunctionSupported
)
861 if ( m_backgroundMode
== wxTRANSPARENT
)
862 m_graphicContext
->DrawText( str
, x
,y
);
864 m_graphicContext
->DrawText( str
, x
,y
, m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
867 bool wxGCDCImpl::CanGetTextExtent() const
869 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
874 void wxGCDCImpl::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
875 wxCoord
*descent
, wxCoord
*externalLeading
,
876 const wxFont
*theFont
) const
878 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
882 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
885 wxDouble h
, d
, e
, w
;
887 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
890 *height
= (wxCoord
)(h
+0.5);
892 *descent
= (wxCoord
)(d
+0.5);
893 if ( externalLeading
)
894 *externalLeading
= (wxCoord
)(e
+0.5);
896 *width
= (wxCoord
)(w
+0.5);
900 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
904 bool wxGCDCImpl::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
906 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
908 widths
.Add(0,text
.Length());
909 if ( text
.IsEmpty() )
912 wxArrayDouble widthsD
;
914 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
915 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
916 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
921 wxCoord
wxGCDCImpl::GetCharWidth(void) const
924 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
929 wxCoord
wxGCDCImpl::GetCharHeight(void) const
932 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
937 void wxGCDCImpl::Clear(void)
939 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") );
940 // TODO better implementation / incorporate size info into wxGCDC or context
941 m_graphicContext
->SetBrush( m_backgroundBrush
);
942 wxPen p
= *wxTRANSPARENT_PEN
;
943 m_graphicContext
->SetPen( p
);
944 DoDrawRectangle( 0, 0, 32000 , 32000 );
945 m_graphicContext
->SetPen( m_pen
);
946 m_graphicContext
->SetBrush( m_brush
);
949 void wxGCDCImpl::DoGetSize(int *width
, int *height
) const
955 void wxGCDCImpl::DoGradientFillLinear(const wxRect
& rect
,
956 const wxColour
& initialColour
,
957 const wxColour
& destColour
,
958 wxDirection nDirection
)
965 start
= rect
.GetRightBottom();
967 end
= rect
.GetLeftBottom();
970 start
= rect
.GetLeftBottom();
971 end
= rect
.GetRightBottom();
975 start
= rect
.GetLeftBottom();
977 end
= rect
.GetLeftTop();
980 start
= rect
.GetLeftTop();
981 end
= rect
.GetLeftBottom();
988 if (rect
.width
== 0 || rect
.height
== 0)
991 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
992 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
993 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
994 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
995 m_graphicContext
->SetPen(m_pen
);
998 void wxGCDCImpl::DoGradientFillConcentric(const wxRect
& rect
,
999 const wxColour
& initialColour
,
1000 const wxColour
& destColour
,
1001 const wxPoint
& circleCenter
)
1004 wxInt32 cx
= rect
.GetWidth() / 2;
1005 wxInt32 cy
= rect
.GetHeight() / 2;
1012 // make sure the background is filled (todo move into specific platform implementation ?)
1013 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
1014 m_graphicContext
->SetBrush( wxBrush( destColour
) );
1015 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
1017 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
1018 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
1019 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
1020 nRadius
,initialColour
,destColour
));
1022 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
1023 m_graphicContext
->SetPen(m_pen
);
1026 void wxGCDCImpl::DoDrawCheckMark(wxCoord x
, wxCoord y
,
1027 wxCoord width
, wxCoord height
)
1029 wxDCImpl::DoDrawCheckMark(x
,y
,width
,height
);
1032 #endif // wxUSE_GRAPHICS_CONTEXT