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"
31 #include "wx/mac/private.h"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 static const double RAD2DEG
= 180.0 / M_PI
;
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 static inline double DegToRad(double deg
)
45 return (deg
* M_PI
) / 180.0;
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxGCDC
, wxDCBase
)
55 IMPLEMENT_DYNAMIC_CLASS(wxGCDC
, wxDC
)
63 void wxGCDC::SetGraphicsContext( wxGraphicsContext
* ctx
)
65 delete m_graphicContext
;
66 m_graphicContext
= ctx
;
67 if ( m_graphicContext
)
69 m_matrixOriginal
= m_graphicContext
->GetTransform();
71 // apply the stored transformations to the passed in context
72 ComputeScaleAndOrigin();
73 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
74 m_graphicContext
->SetPen( m_pen
);
75 m_graphicContext
->SetBrush( m_brush
);
79 wxGCDC::wxGCDC(const wxWindowDC
& dc
)
82 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
86 wxGCDC::wxGCDC(const wxMemoryDC
& dc
)
89 SetGraphicsContext( wxGraphicsContext::Create(dc
) );
97 m_mm_to_pix_x
= mm2pt
;
98 m_mm_to_pix_y
= mm2pt
;
100 m_pen
= *wxBLACK_PEN
;
101 m_font
= *wxNORMAL_FONT
;
102 m_brush
= *wxWHITE_BRUSH
;
104 m_graphicContext
= NULL
;
105 m_logicalFunctionSupported
= true;
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 bool wxGCDC::StartDoc( const wxString
& WXUNUSED(message
) )
149 void wxGCDC::EndDoc()
153 void wxGCDC::StartPage()
157 void wxGCDC::EndPage()
164 CGContextFlush( (CGContextRef
) m_graphicContext
->GetNativeContext() );
168 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
170 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
172 m_graphicContext
->Clip( x
, y
, w
, h
);
175 m_clipX1
= wxMax( m_clipX1
, x
);
176 m_clipY1
= wxMax( m_clipY1
, y
);
177 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
178 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
191 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
193 // region is in device coordinates
194 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
198 //DestroyClippingRegion();
202 wxRegion
logRegion( region
);
205 logRegion
.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
206 logRegion
.GetBox( x
, y
, w
, h
);
208 m_graphicContext
->Clip( logRegion
);
211 m_clipX1
= wxMax( m_clipX1
, x
);
212 m_clipY1
= wxMax( m_clipY1
, y
);
213 m_clipX2
= wxMin( m_clipX2
, (x
+ w
) );
214 m_clipY2
= wxMin( m_clipY2
, (y
+ h
) );
227 void wxGCDC::DestroyClippingRegion()
229 m_graphicContext
->ResetClip();
230 // currently the clip eg of a window extends to the area between the scrollbars
231 // so we must explicitely make sure it only covers the area we want it to draw
233 GetSize( &width
, &height
) ;
234 m_graphicContext
->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , DeviceToLogicalXRel(width
), DeviceToLogicalYRel(height
) );
236 m_graphicContext
->SetPen( m_pen
);
237 m_graphicContext
->SetBrush( m_brush
);
242 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
248 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
250 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
253 void wxGCDC::SetTextForeground( const wxColour
&col
)
255 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
257 if ( col
!= m_textForegroundColour
)
259 m_textForegroundColour
= col
;
260 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
264 void wxGCDC::SetTextBackground( const wxColour
&col
)
266 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
268 m_textBackgroundColour
= col
;
271 void wxGCDC::SetMapMode( int mode
)
276 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
280 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
284 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
288 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
293 SetLogicalScale( 1.0, 1.0 );
297 ComputeScaleAndOrigin();
300 void wxGCDC::SetUserScale( double x
, double y
)
302 // allow negative ? -> no
306 ComputeScaleAndOrigin();
309 void wxGCDC::SetLogicalScale( double x
, double y
)
314 ComputeScaleAndOrigin();
317 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
319 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
320 m_logicalOriginY
= y
* m_signY
;
321 ComputeScaleAndOrigin();
324 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
328 ComputeScaleAndOrigin();
331 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
333 m_signX
= (xLeftRight
? 1 : -1);
334 m_signY
= (yBottomUp
? -1 : 1);
335 ComputeScaleAndOrigin();
338 wxSize
wxGCDC::GetPPI() const
340 return wxSize(72, 72);
343 int wxGCDC::GetDepth() const
348 void wxGCDC::ComputeScaleAndOrigin()
350 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
351 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
353 if ( m_graphicContext
)
355 m_matrixCurrent
= m_graphicContext
->CreateMatrix();
356 m_matrixCurrent
.Translate( m_deviceOriginX
, m_deviceOriginY
);
357 m_matrixCurrent
.Scale( m_scaleX
, m_scaleY
);
358 // the logical origin sets the origin to have new coordinates
359 m_matrixCurrent
.Translate( -m_logicalOriginX
, -m_logicalOriginY
);
361 m_graphicContext
->SetTransform( m_matrixOriginal
);
362 m_graphicContext
->ConcatTransform( m_matrixCurrent
);
366 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
371 void wxGCDC::SetBackgroundMode( int mode
)
373 m_backgroundMode
= mode
;
376 void wxGCDC::SetFont( const wxFont
&font
)
379 if ( m_graphicContext
)
383 f
.SetPointSize( /*LogicalToDeviceYRel*/(font
.GetPointSize()));
384 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
388 void wxGCDC::SetPen( const wxPen
&pen
)
394 if ( m_graphicContext
)
396 m_graphicContext
->SetPen( m_pen
);
400 void wxGCDC::SetBrush( const wxBrush
&brush
)
402 if (m_brush
== brush
)
406 if ( m_graphicContext
)
408 m_graphicContext
->SetBrush( m_brush
);
412 void wxGCDC::SetBackground( const wxBrush
&brush
)
414 if (m_backgroundBrush
== brush
)
417 m_backgroundBrush
= brush
;
418 if (!m_backgroundBrush
.Ok())
422 void wxGCDC::SetLogicalFunction( int function
)
424 if (m_logicalFunction
== function
)
427 m_logicalFunction
= function
;
428 if ( m_graphicContext
->SetLogicalFunction( function
) )
429 m_logicalFunctionSupported
=true;
431 m_logicalFunctionSupported
=false;
434 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
435 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
440 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
442 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
446 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
448 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
450 if ( !m_logicalFunctionSupported
)
453 m_graphicContext
->StrokeLine(x1
,y1
,x2
,y2
);
455 CalcBoundingBox(x1
, y1
);
456 CalcBoundingBox(x2
, y2
);
459 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
461 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
463 if ( !m_logicalFunctionSupported
)
470 m_graphicContext
->StrokeLine(0,y
,w
,y
);
471 m_graphicContext
->StrokeLine(x
,0,x
,h
);
473 CalcBoundingBox(0, 0);
474 CalcBoundingBox(0+w
, 0+h
);
477 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
478 wxCoord x2
, wxCoord y2
,
479 wxCoord xc
, wxCoord yc
)
481 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
483 if ( !m_logicalFunctionSupported
)
488 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
489 wxCoord rad
= (wxCoord
)radius
;
491 if (x1
== x2
&& y1
== y2
)
496 else if (radius
== 0.0)
502 sa
= (x1
- xc
== 0) ?
503 (y1
- yc
< 0) ? 90.0 : -90.0 :
504 -atan2(double(y1
- yc
), double(x1
- xc
)) * RAD2DEG
;
505 ea
= (x2
- xc
== 0) ?
506 (y2
- yc
< 0) ? 90.0 : -90.0 :
507 -atan2(double(y2
- yc
), double(x2
- xc
)) * RAD2DEG
;
510 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
512 wxGraphicsPath path
= m_graphicContext
->CreatePath();
513 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
514 path
.MoveToPoint( xc
, yc
);
515 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
516 // get clockwise angles
517 path
.AddArc( xc
, yc
, rad
, DegToRad(-sa
) , DegToRad(-ea
), false );
518 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
519 path
.AddLineToPoint( xc
, yc
);
520 m_graphicContext
->DrawPath(path
);
523 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
524 double sa
, double ea
)
526 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
528 if ( !m_logicalFunctionSupported
)
531 m_graphicContext
->PushState();
532 m_graphicContext
->Translate(x
+w
/2.0,y
+h
/2.0);
533 wxDouble factor
= ((wxDouble
) w
) / h
;
534 m_graphicContext
->Scale( factor
, 1.0);
536 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
537 // get clockwise angles
538 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
540 wxGraphicsPath path
= m_graphicContext
->CreatePath();
541 path
.MoveToPoint( 0, 0 );
542 path
.AddLineToPoint( h
/ 2.0 * cos(DegToRad(sa
)) , h
/ 2.0 * sin(DegToRad(-sa
)) );
543 path
.AddLineToPoint( h
/ 2.0 * cos(DegToRad(ea
)) , h
/ 2.0 * sin(DegToRad(-ea
)) );
544 path
.AddLineToPoint( 0, 0 );
545 m_graphicContext
->FillPath( path
);
547 path
= m_graphicContext
->CreatePath();
548 path
.AddArc( 0, 0, h
/2.0 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
549 m_graphicContext
->FillPath( path
);
550 m_graphicContext
->StrokePath( path
);
554 wxGraphicsPath path
= m_graphicContext
->CreatePath();
555 path
.AddArc( 0, 0, h
/2.0 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
556 m_graphicContext
->DrawPath( path
);
559 m_graphicContext
->PopState();
562 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
564 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
566 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
569 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
570 wxCoord xoffset
, wxCoord yoffset
)
572 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
574 if ( !m_logicalFunctionSupported
)
577 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
578 for( int i
= 0; i
< n
; ++i
)
580 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
581 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
584 m_graphicContext
->StrokeLines( n
, pointsD
);
589 void wxGCDC::DoDrawSpline(const wxPointList
*points
)
591 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
593 if ( !m_logicalFunctionSupported
)
596 wxGraphicsPath path
= m_graphicContext
->CreatePath();
598 wxPointList::compatibility_iterator node
= points
->GetFirst();
599 if (node
== wxPointList::compatibility_iterator())
603 wxPoint
*p
= node
->GetData();
608 node
= node
->GetNext();
613 wxCoord cx1
= ( x1
+ x2
) / 2;
614 wxCoord cy1
= ( y1
+ y2
) / 2;
616 path
.MoveToPoint( x1
, y1
);
617 path
.AddLineToPoint( cx1
, cy1
);
620 while ((node
= node
->GetNext()) != NULL
)
623 while ((node
= node
->GetNext()))
632 wxCoord cx4
= (x1
+ x2
) / 2;
633 wxCoord cy4
= (y1
+ y2
) / 2;
635 path
.AddQuadCurveToPoint(x1
, y1
,cx4
, cy4
);
641 path
.AddLineToPoint( x2
, y2
);
643 m_graphicContext
->StrokePath( path
);
645 #endif // wxUSE_SPLINES
647 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
648 wxCoord xoffset
, wxCoord yoffset
,
651 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
653 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
655 if ( !m_logicalFunctionSupported
)
658 bool closeIt
= false;
659 if (points
[n
-1] != points
[0])
662 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
663 for( int i
= 0; i
< n
; ++i
)
665 pointsD
[i
].m_x
= points
[i
].x
+ xoffset
;
666 pointsD
[i
].m_y
= points
[i
].y
+ yoffset
;
669 pointsD
[n
] = pointsD
[0];
671 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
675 void wxGCDC::DoDrawPolyPolygon(int n
,
683 wxGraphicsPath path
= m_graphicContext
->CreatePath();
686 for ( int j
= 0; j
< n
; ++j
)
688 wxPoint start
= points
[i
];
689 path
.MoveToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
692 for ( int k
= 1; k
< l
; ++k
)
694 path
.AddLineToPoint( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
698 if ( start
!= points
[i
-1])
699 path
.AddLineToPoint( start
.x
+ xoffset
, start
.y
+ yoffset
);
701 m_graphicContext
->DrawPath( path
, fillStyle
);
704 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
706 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
708 if ( !m_logicalFunctionSupported
)
711 // CMB: draw nothing if transformed w or h is 0
712 if (w
== 0 || h
== 0)
715 if ( m_graphicContext
->ShouldOffset() )
717 // if we are offsetting the entire rectangle is moved 0.5, so the
718 // border line gets off by 1
722 m_graphicContext
->DrawRectangle(x
,y
,w
,h
);
725 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
726 wxCoord w
, wxCoord h
,
729 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
731 if ( !m_logicalFunctionSupported
)
735 radius
= - radius
* ((w
< h
) ? w
: h
);
737 // CMB: draw nothing if transformed w or h is 0
738 if (w
== 0 || h
== 0)
741 if ( m_graphicContext
->ShouldOffset() )
743 // if we are offsetting the entire rectangle is moved 0.5, so the
744 // border line gets off by 1
748 m_graphicContext
->DrawRoundedRectangle( x
,y
,w
,h
,radius
);
751 void wxGCDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
753 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
755 if ( !m_logicalFunctionSupported
)
758 if ( m_graphicContext
->ShouldOffset() )
760 // if we are offsetting the entire rectangle is moved 0.5, so the
761 // border line gets off by 1
765 m_graphicContext
->DrawEllipse(x
,y
,w
,h
);
768 bool wxGCDC::CanDrawBitmap() const
774 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
775 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
776 wxCoord xsrcMask
, wxCoord ysrcMask
)
778 return DoStretchBlit( xdest
, ydest
, width
, height
,
779 source
, xsrc
, ysrc
, width
, height
, logical_func
, useMask
,
783 bool wxGCDC::DoStretchBlit(
784 wxCoord xdest
, wxCoord ydest
, wxCoord dstWidth
, wxCoord dstHeight
,
785 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, wxCoord srcWidth
, wxCoord srcHeight
,
786 int logical_func
, bool WXUNUSED(useMask
),
787 wxCoord xsrcMask
, wxCoord ysrcMask
)
789 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
790 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
792 if ( logical_func
== wxNO_OP
)
794 else if ( !m_graphicContext
->SetLogicalFunction( logical_func
) )
797 wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
801 if (xsrcMask
== -1 && ysrcMask
== -1)
807 wxRect
subrect(source
->LogicalToDeviceX(xsrc
),
808 source
->LogicalToDeviceY(ysrc
),
809 source
->LogicalToDeviceXRel(srcWidth
),
810 source
->LogicalToDeviceYRel(srcHeight
));
812 // if needed clip the subrect down to the size of the source DC
814 source
->GetSize(&sw
, &sh
);
815 sw
= source
->LogicalToDeviceXRel(sw
);
816 sh
= source
->LogicalToDeviceYRel(sh
);
817 if (subrect
.x
+ subrect
.width
> sw
)
818 subrect
.width
= sw
- subrect
.x
;
819 if (subrect
.y
+ subrect
.height
> sh
)
820 subrect
.height
= sh
- subrect
.y
;
822 wxBitmap blit
= source
->GetAsBitmap( &subrect
);
826 m_graphicContext
->DrawBitmap( blit
, xdest
, ydest
,
827 dstWidth
, dstHeight
);
831 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
835 // reset logical function
836 m_graphicContext
->SetLogicalFunction( m_logicalFunction
);
841 void wxGCDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
844 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
846 if ( str
.length() == 0 )
848 if ( !m_logicalFunctionSupported
)
851 if ( m_backgroundMode
== wxTRANSPARENT
)
852 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
));
854 m_graphicContext
->DrawText( str
, x
,y
, DegToRad(angle
), m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
857 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
859 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
861 if ( str
.length() == 0 )
864 if ( !m_logicalFunctionSupported
)
867 if ( m_backgroundMode
== wxTRANSPARENT
)
868 m_graphicContext
->DrawText( str
, x
,y
);
870 m_graphicContext
->DrawText( str
, x
,y
, m_graphicContext
->CreateBrush( wxBrush(m_textBackgroundColour
,wxSOLID
) ) );
873 bool wxGCDC::CanGetTextExtent() const
875 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
880 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
881 wxCoord
*descent
, wxCoord
*externalLeading
,
882 const wxFont
*theFont
) const
884 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
888 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
891 wxDouble h
, d
, e
, w
;
893 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
896 *height
= (wxCoord
)(h
+0.5);
898 *descent
= (wxCoord
)(d
+0.5);
899 if ( externalLeading
)
900 *externalLeading
= (wxCoord
)(e
+0.5);
902 *width
= (wxCoord
)(w
+0.5);
906 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
910 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
912 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
914 widths
.Add(0,text
.Length());
915 if ( text
.IsEmpty() )
918 wxArrayDouble widthsD
;
920 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
921 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
922 widths
[i
] = (wxCoord
)(widthsD
[i
] + 0.5);
927 wxCoord
wxGCDC::GetCharWidth(void) const
930 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
935 wxCoord
wxGCDC::GetCharHeight(void) const
938 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
943 void wxGCDC::Clear(void)
945 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
946 // TODO better implementation / incorporate size info into wxGCDC or context
947 m_graphicContext
->SetBrush( m_backgroundBrush
);
948 wxPen p
= *wxTRANSPARENT_PEN
;
949 m_graphicContext
->SetPen( p
);
950 DoDrawRectangle( 0, 0, 32000 , 32000 );
951 m_graphicContext
->SetPen( m_pen
);
952 m_graphicContext
->SetBrush( m_brush
);
955 void wxGCDC::DoGetSize(int *width
, int *height
) const
961 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
962 const wxColour
& initialColour
,
963 const wxColour
& destColour
,
964 wxDirection nDirection
)
971 start
= rect
.GetRightBottom();
973 end
= rect
.GetLeftBottom();
976 start
= rect
.GetLeftBottom();
977 end
= rect
.GetRightBottom();
981 start
= rect
.GetLeftBottom();
983 end
= rect
.GetLeftTop();
986 start
= rect
.GetLeftTop();
987 end
= rect
.GetLeftBottom();
994 if (rect
.width
== 0 || rect
.height
== 0)
997 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
998 start
.x
,start
.y
,end
.x
,end
.y
, initialColour
, destColour
));
999 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
1000 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
1001 m_graphicContext
->SetPen(m_pen
);
1004 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
1005 const wxColour
& initialColour
,
1006 const wxColour
& destColour
,
1007 const wxPoint
& circleCenter
)
1010 wxInt32 cx
= rect
.GetWidth() / 2;
1011 wxInt32 cy
= rect
.GetHeight() / 2;
1018 // make sure the background is filled (todo move into specific platform implementation ?)
1019 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
1020 m_graphicContext
->SetBrush( wxBrush( destColour
) );
1021 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
1023 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
1024 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
1025 rect
.x
+circleCenter
.x
,rect
.y
+circleCenter
.y
,
1026 nRadius
,initialColour
,destColour
));
1028 m_graphicContext
->DrawRectangle(rect
.x
,rect
.y
,rect
.width
,rect
.height
);
1029 m_graphicContext
->SetPen(m_pen
);
1032 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
1033 wxCoord width
, wxCoord height
)
1035 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
1038 #endif // wxUSE_GRAPHICS_CONTEXT