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
;
66 wxGCDC::wxGCDC(const wxWindowDC
& dc
)
69 m_graphicContext
= wxGraphicsContext::Create(dc
);
71 if ( dc
.GetFont().Ok())
72 m_graphicContext
->SetFont( m_graphicContext
->CreateFont(dc
.GetFont(),dc
.GetTextForeground()));
73 if ( dc
.GetPen().Ok())
74 m_graphicContext
->SetPen( m_graphicContext
->CreatePen(dc
.GetPen()));
75 if ( dc
.GetBrush().Ok())
76 m_graphicContext
->SetBrush( m_graphicContext
->CreateBrush(dc
.GetBrush()));
83 m_mm_to_pix_x
= mm2pt
;
84 m_mm_to_pix_y
= mm2pt
;
87 m_font
= *wxNORMAL_FONT
;
88 m_brush
= *wxWHITE_BRUSH
;
90 m_graphicContext
= NULL
;
96 delete m_graphicContext
;
99 void wxGCDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool WXUNUSED(useMask
) )
101 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
102 wxCHECK_RET( bmp
.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
104 wxCoord xx
= LogicalToDeviceX(x
);
105 wxCoord yy
= LogicalToDeviceY(y
);
106 wxCoord w
= bmp
.GetWidth();
107 wxCoord h
= bmp
.GetHeight();
108 wxCoord ww
= LogicalToDeviceXRel(w
);
109 wxCoord hh
= LogicalToDeviceYRel(h
);
111 m_graphicContext
->DrawBitmap( bmp
, xx
, yy
, ww
, hh
);
114 void wxGCDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
116 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
117 wxCHECK_RET( icon
.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
119 wxCoord xx
= LogicalToDeviceX(x
);
120 wxCoord yy
= LogicalToDeviceY(y
);
121 wxCoord w
= icon
.GetWidth();
122 wxCoord h
= icon
.GetHeight();
123 wxCoord ww
= LogicalToDeviceXRel(w
);
124 wxCoord hh
= LogicalToDeviceYRel(h
);
126 m_graphicContext
->DrawIcon( icon
, xx
, yy
, ww
, hh
);
129 void wxGCDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
131 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
133 wxCoord xx
, yy
, ww
, hh
;
134 xx
= LogicalToDeviceX(x
);
135 yy
= LogicalToDeviceY(y
);
136 ww
= LogicalToDeviceXRel(width
);
137 hh
= LogicalToDeviceYRel(height
);
139 m_graphicContext
->Clip( xx
, yy
, ww
, hh
);
142 m_clipX1
= wxMax( m_clipX1
, xx
);
143 m_clipY1
= wxMax( m_clipY1
, yy
);
144 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
145 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
158 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
160 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
164 DestroyClippingRegion();
169 region
.GetBox( x
, y
, w
, h
);
170 wxCoord xx
, yy
, ww
, hh
;
171 xx
= LogicalToDeviceX(x
);
172 yy
= LogicalToDeviceY(y
);
173 ww
= LogicalToDeviceXRel(w
);
174 hh
= LogicalToDeviceYRel(h
);
176 // if we have a scaling that we cannot map onto native regions
177 // we must use the box
178 if ( ww
!= w
|| hh
!= h
)
180 wxGCDC::DoSetClippingRegion( x
, y
, w
, h
);
184 m_graphicContext
->Clip( region
);
187 m_clipX1
= wxMax( m_clipX1
, xx
);
188 m_clipY1
= wxMax( m_clipY1
, yy
);
189 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
190 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
204 void wxGCDC::DestroyClippingRegion()
206 m_graphicContext
->ResetClip();
207 m_graphicContext
->SetPen( m_pen
);
208 m_graphicContext
->SetBrush( m_brush
);
213 void wxGCDC::DoGetSizeMM( int* width
, int* height
) const
219 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
221 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
224 void wxGCDC::SetTextForeground( const wxColour
&col
)
226 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
228 if ( col
!= m_textForegroundColour
)
230 m_textForegroundColour
= col
;
231 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
235 void wxGCDC::SetTextBackground( const wxColour
&col
)
237 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
239 m_textBackgroundColour
= col
;
242 void wxGCDC::SetMapMode( int mode
)
247 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
251 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
255 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
259 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
264 SetLogicalScale( 1.0, 1.0 );
268 ComputeScaleAndOrigin();
271 void wxGCDC::SetUserScale( double x
, double y
)
273 // allow negative ? -> no
277 ComputeScaleAndOrigin();
280 void wxGCDC::SetLogicalScale( double x
, double y
)
285 ComputeScaleAndOrigin();
288 void wxGCDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
290 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
291 m_logicalOriginY
= y
* m_signY
;
292 ComputeScaleAndOrigin();
295 void wxGCDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
299 ComputeScaleAndOrigin();
302 void wxGCDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
304 m_signX
= (xLeftRight
? 1 : -1);
305 m_signY
= (yBottomUp
? -1 : 1);
306 ComputeScaleAndOrigin();
309 wxSize
wxGCDC::GetPPI() const
311 return wxSize(72, 72);
314 int wxGCDC::GetDepth() const
319 void wxGCDC::ComputeScaleAndOrigin()
321 // CMB: copy scale to see if it changes
322 double origScaleX
= m_scaleX
;
323 double origScaleY
= m_scaleY
;
324 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
325 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
326 m_deviceOriginX
= m_deviceOriginX
+ m_logicalOriginX
;
327 m_deviceOriginY
= m_deviceOriginY
+ m_logicalOriginY
;
329 // CMB: if scale has changed call SetPen to recalulate the line width
330 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
332 // this is a bit artificial, but we need to force wxDC to think
333 // the pen has changed
341 void wxGCDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
346 void wxGCDC::SetBackgroundMode( int mode
)
348 m_backgroundMode
= mode
;
351 void wxGCDC::SetFont( const wxFont
&font
)
354 if ( m_graphicContext
)
358 f
.SetPointSize( LogicalToDeviceYRel(font
.GetPointSize()));
359 m_graphicContext
->SetFont( f
, m_textForegroundColour
);
363 void wxGCDC::SetPen( const wxPen
&pen
)
369 if ( m_graphicContext
)
371 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
373 m_graphicContext
->SetPen( m_pen
);
377 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
378 // eg when using a wxScrollWindow and scrolling around
379 int origX
= LogicalToDeviceX( 0 );
380 int origY
= LogicalToDeviceY( 0 );
381 m_graphicContext
->Translate( origX
, origY
);
382 m_graphicContext
->SetPen( m_pen
);
383 m_graphicContext
->Translate( -origX
, -origY
);
388 void wxGCDC::SetBrush( const wxBrush
&brush
)
390 if (m_brush
== brush
)
394 if ( m_graphicContext
)
396 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
398 m_graphicContext
->SetBrush( m_brush
);
402 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
403 // eg when using a wxScrollWindow and scrolling around
404 // TODO on MSW / GDIPlus this still occurs with hatched brushes
405 int origX
= LogicalToDeviceX(0);
406 int origY
= LogicalToDeviceY(0);
407 m_graphicContext
->Translate( origX
, origY
);
408 m_graphicContext
->SetBrush( m_brush
);
409 m_graphicContext
->Translate( -origX
, -origY
);
414 void wxGCDC::SetBackground( const wxBrush
&brush
)
416 if (m_backgroundBrush
== brush
)
419 m_backgroundBrush
= brush
;
420 if (!m_backgroundBrush
.Ok())
424 void wxGCDC::SetLogicalFunction( int function
)
426 if (m_logicalFunction
== function
)
429 m_logicalFunction
= function
;
430 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
432 CGContextRef cgContext
= ((wxCairoContext
*)(m_graphicContext
))->GetNativeContext();
433 if ( m_logicalFunction
== wxCOPY
)
434 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
435 else if ( m_logicalFunction
== wxINVERT
)
436 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
);
438 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
);
443 bool wxGCDC::DoFloodFill(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
444 const wxColour
& WXUNUSED(col
), int WXUNUSED(style
))
449 bool wxGCDC::DoGetPixel( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxColour
*WXUNUSED(col
) ) const
451 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
455 void wxGCDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
457 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
459 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
461 if ( m_logicalFunction
!= wxCOPY
)
465 wxCoord xx1
= LogicalToDeviceX(x1
);
466 wxCoord yy1
= LogicalToDeviceY(y1
);
467 wxCoord xx2
= LogicalToDeviceX(x2
);
468 wxCoord yy2
= LogicalToDeviceY(y2
);
470 m_graphicContext
->StrokeLine(xx1
,yy1
,xx2
,yy2
);
472 CalcBoundingBox(x1
, y1
);
473 CalcBoundingBox(x2
, y2
);
476 void wxGCDC::DoCrossHair( wxCoord x
, wxCoord y
)
478 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
480 if ( m_logicalFunction
!= wxCOPY
)
487 wxCoord xx
= LogicalToDeviceX(x
);
488 wxCoord yy
= LogicalToDeviceY(y
);
489 wxCoord xw
= LogicalToDeviceX(w
);
490 wxCoord x0
= LogicalToDeviceX(0);
491 wxCoord y0
= LogicalToDeviceY(0);
492 wxCoord yh
= LogicalToDeviceY(h
);
494 m_graphicContext
->StrokeLine(x0
,yy
,xw
,yy
);
495 m_graphicContext
->StrokeLine(xx
,y0
,xx
,yh
);
497 CalcBoundingBox(x0
, y0
);
498 CalcBoundingBox(x0
+xw
, y0
+yh
);
501 void wxGCDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
502 wxCoord x2
, wxCoord y2
,
503 wxCoord xc
, wxCoord yc
)
505 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
507 if ( m_logicalFunction
!= wxCOPY
)
510 wxCoord xx1
= LogicalToDeviceX(x1
);
511 wxCoord yy1
= LogicalToDeviceY(y1
);
512 wxCoord xx2
= LogicalToDeviceX(x2
);
513 wxCoord yy2
= LogicalToDeviceY(y2
);
514 wxCoord xxc
= LogicalToDeviceX(xc
);
515 wxCoord yyc
= LogicalToDeviceY(yc
);
517 double dx
= xx1
- xxc
;
518 double dy
= yy1
- yyc
;
519 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
520 wxCoord rad
= (wxCoord
)radius
;
522 if (xx1
== xx2
&& yy1
== yy2
)
527 else if (radius
== 0.0)
533 sa
= (xx1
- xxc
== 0) ?
534 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
535 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
536 ea
= (xx2
- xxc
== 0) ?
537 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
538 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
541 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
543 wxGraphicsPath
* path
= m_graphicContext
->CreatePath();
544 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
545 path
->MoveToPoint( xxc
, yyc
);
546 path
->AddArc( xxc
, yyc
, rad
, DegToRad(sa
) , DegToRad(ea
), false );
547 if ( fill
&& ((x1
!=x2
)||(y1
!=y2
)) )
548 path
->AddLineToPoint( xxc
, yyc
);
549 m_graphicContext
->DrawPath(path
);
553 void wxGCDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
554 double sa
, double ea
)
556 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
558 if ( m_logicalFunction
!= wxCOPY
)
561 wxCoord xx
= LogicalToDeviceX(x
);
562 wxCoord yy
= LogicalToDeviceY(y
);
563 wxCoord ww
= m_signX
* LogicalToDeviceXRel(w
);
564 wxCoord hh
= m_signY
* LogicalToDeviceYRel(h
);
566 // handle -ve width and/or height
578 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
580 wxGraphicsPath
* path
= m_graphicContext
->CreatePath();
581 m_graphicContext
->PushState();
582 m_graphicContext
->Translate(xx
+ww
/2,yy
+hh
/2);
583 wxDouble factor
= ((wxDouble
) ww
) / hh
;
584 m_graphicContext
->Scale( factor
, 1.0);
585 if ( fill
&& (sa
!=ea
) )
586 path
->MoveToPoint(0,0);
587 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
588 // get clockwise angles
589 path
->AddArc( 0, 0, hh
/2 , DegToRad(-sa
) , DegToRad(-ea
), sa
> ea
);
590 if ( fill
&& (sa
!=ea
) )
591 path
->AddLineToPoint(0,0);
592 m_graphicContext
->DrawPath( path
);
593 m_graphicContext
->PopState();
597 void wxGCDC::DoDrawPoint( wxCoord x
, wxCoord y
)
599 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
601 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 );
604 void wxGCDC::DoDrawLines(int n
, wxPoint points
[],
605 wxCoord xoffset
, wxCoord yoffset
)
607 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
609 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
611 if ( m_logicalFunction
!= wxCOPY
)
615 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
];
616 for( int i
= 0; i
< n
; ++i
)
618 pointsD
[i
].m_x
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
619 pointsD
[i
].m_y
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
622 m_graphicContext
->StrokeLines( n
, pointsD
);
627 void wxGCDC::DoDrawSpline(wxList
*points
)
629 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
631 if ( m_logicalFunction
!= wxCOPY
)
634 wxGraphicsPath
* path
= m_graphicContext
->CreatePath();
636 wxList::compatibility_iterator node
= points
->GetFirst();
637 if (node
== wxList::compatibility_iterator())
641 wxPoint
*p
= (wxPoint
*)node
->GetData();
646 node
= node
->GetNext();
647 p
= (wxPoint
*)node
->GetData();
651 wxCoord cx1
= ( x1
+ x2
) / 2;
652 wxCoord cy1
= ( y1
+ y2
) / 2;
654 path
->MoveToPoint( LogicalToDeviceX( x1
) , LogicalToDeviceY( y1
) );
655 path
->AddLineToPoint( LogicalToDeviceX( cx1
) , LogicalToDeviceY( cy1
) );
658 while ((node
= node
->GetNext()) != NULL
)
661 while ((node
= node
->GetNext()))
665 p
= (wxPoint
*)node
->GetData();
670 wxCoord cx4
= (x1
+ x2
) / 2;
671 wxCoord cy4
= (y1
+ y2
) / 2;
673 path
->AddQuadCurveToPoint(
674 LogicalToDeviceX( x1
) , LogicalToDeviceY( y1
) ,
675 LogicalToDeviceX( cx4
) , LogicalToDeviceY( cy4
) );
681 path
->AddLineToPoint( LogicalToDeviceX( x2
) , LogicalToDeviceY( y2
) );
683 m_graphicContext
->StrokePath( path
);
686 #endif // wxUSE_SPLINES
688 void wxGCDC::DoDrawPolygon( int n
, wxPoint points
[],
689 wxCoord xoffset
, wxCoord yoffset
,
692 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
694 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
696 if ( m_logicalFunction
!= wxCOPY
)
699 bool closeIt
= false;
700 if (points
[n
-1] != points
[0])
703 wxPoint2DDouble
* pointsD
= new wxPoint2DDouble
[n
+(closeIt
?1:0)];
704 for( int i
= 0; i
< n
; ++i
)
706 pointsD
[i
].m_x
= LogicalToDeviceX(points
[i
].x
+ xoffset
);
707 pointsD
[i
].m_y
= LogicalToDeviceY(points
[i
].y
+ yoffset
);
710 pointsD
[n
] = pointsD
[0];
712 m_graphicContext
->DrawLines( n
+(closeIt
?1:0) , pointsD
, fillStyle
);
716 void wxGCDC::DoDrawPolyPolygon(int n
,
724 wxGraphicsPath
* path
= m_graphicContext
->CreatePath();
727 for ( int j
= 0; j
< n
; ++j
)
729 wxPoint start
= points
[i
];
730 path
->MoveToPoint(LogicalToDeviceX(start
.x
+ xoffset
), LogicalToDeviceY(start
.y
+ yoffset
));
733 for ( int k
= 1; k
< l
; ++k
)
735 path
->AddLineToPoint( LogicalToDeviceX(points
[i
].x
+ xoffset
), LogicalToDeviceY(points
[i
].y
+ yoffset
));
739 if ( start
!= points
[i
-1])
740 path
->AddLineToPoint( LogicalToDeviceX(start
.x
+ xoffset
), LogicalToDeviceY(start
.y
+ yoffset
));
742 m_graphicContext
->DrawPath( path
, fillStyle
);
746 void wxGCDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
748 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
750 if ( m_logicalFunction
!= wxCOPY
)
753 wxCoord xx
= LogicalToDeviceX(x
);
754 wxCoord yy
= LogicalToDeviceY(y
);
755 wxCoord ww
= m_signX
* LogicalToDeviceXRel(width
);
756 wxCoord hh
= m_signY
* LogicalToDeviceYRel(height
);
758 // CMB: draw nothing if transformed w or h is 0
759 if (ww
== 0 || hh
== 0)
762 // CMB: handle -ve width and/or height
773 if ( m_graphicContext
->ShouldOffset() )
775 // if we are offsetting the entire rectangle is moved 0.5, so the
776 // border line gets off by 1
780 m_graphicContext
->DrawRectangle( xx
,yy
,ww
,hh
);
783 void wxGCDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
784 wxCoord width
, wxCoord height
,
787 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
789 if ( m_logicalFunction
!= wxCOPY
)
793 radius
= - radius
* ((width
< height
) ? width
: height
);
794 wxCoord xx
= LogicalToDeviceX(x
);
795 wxCoord yy
= LogicalToDeviceY(y
);
796 wxCoord ww
= m_signX
* LogicalToDeviceXRel(width
);
797 wxCoord hh
= m_signY
* LogicalToDeviceYRel(height
);
799 // CMB: draw nothing if transformed w or h is 0
800 if (ww
== 0 || hh
== 0)
803 // CMB: handle -ve width and/or height
815 m_graphicContext
->DrawRoundedRectangle( xx
,yy
,ww
,hh
,radius
);
818 void wxGCDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
820 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
822 if ( m_logicalFunction
!= wxCOPY
)
825 wxDouble xx
= LogicalToDeviceX(x
);
826 wxDouble yy
= LogicalToDeviceY(y
);
827 wxDouble ww
= m_signX
* LogicalToDeviceXRel(width
);
828 wxDouble hh
= m_signY
* LogicalToDeviceYRel(height
);
830 // CMB: draw nothing if transformed w or h is 0
831 if (ww
== 0 || hh
== 0)
834 // CMB: handle -ve width and/or height
846 m_graphicContext
->DrawEllipse(xx
,yy
,ww
,hh
);
849 bool wxGCDC::CanDrawBitmap() const
855 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
856 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool WXUNUSED(useMask
),
857 wxCoord xsrcMask
, wxCoord ysrcMask
)
859 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
860 wxCHECK_MSG( source
->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
862 if ( logical_func
== wxNO_OP
)
865 if (xsrcMask
== -1 && ysrcMask
== -1)
871 wxCoord yysrc
= source
-> LogicalToDeviceY(ysrc
);
872 wxCoord xxsrc
= source
-> LogicalToDeviceX(xsrc
);
873 wxCoord wwsrc
= source
-> LogicalToDeviceXRel(width
);
874 wxCoord hhsrc
= source
-> LogicalToDeviceYRel(height
);
876 wxCoord yydest
= LogicalToDeviceY(ydest
);
877 wxCoord xxdest
= LogicalToDeviceX(xdest
);
878 wxCoord wwdest
= LogicalToDeviceXRel(width
);
879 wxCoord hhdest
= LogicalToDeviceYRel(height
);
881 wxMemoryDC
* memdc
= wxDynamicCast(source
,wxMemoryDC
);
882 if ( memdc
&& logical_func
== wxCOPY
)
884 wxBitmap blit
= memdc
->GetSelectedBitmap();
886 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") );
888 wxCoord bmpwidth
= blit
.GetWidth();
889 wxCoord bmpheight
= blit
.GetHeight();
891 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
893 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
);
894 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
);
895 if ( wwsrc
> 0 && hhsrc
> 0 )
897 if ( xxsrc
>= 0 && yysrc
>= 0 )
899 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
);
900 // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
901 blit
= blit
.GetSubBitmap( subrect
);
905 // in this case we'd probably have to adjust the different coordinates, but
906 // we have to find out proper contract first
918 m_graphicContext
->DrawBitmap( blit
, xxdest
, yydest
, wwdest
, hhdest
);
923 wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") );
930 void wxGCDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
933 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
935 if ( str
.length() == 0 )
937 if ( m_logicalFunction
!= wxCOPY
)
940 int drawX
= LogicalToDeviceX(x
);
941 int drawY
= LogicalToDeviceY(y
);
943 m_graphicContext
->DrawText( str
, drawX
,drawY
, DegToRad(angle
));
946 void wxGCDC::DoDrawText(const wxString
& str
, wxCoord x
, wxCoord y
)
948 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
950 if ( str
.length() == 0 )
952 if ( m_logicalFunction
!= wxCOPY
)
955 int drawX
= LogicalToDeviceX(x
);
956 int drawY
= LogicalToDeviceY(y
);
958 m_graphicContext
->DrawText( str
, drawX
,drawY
);
961 bool wxGCDC::CanGetTextExtent() const
963 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
968 void wxGCDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
969 wxCoord
*descent
, wxCoord
*externalLeading
,
970 wxFont
*theFont
) const
972 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
976 m_graphicContext
->SetFont( *theFont
, m_textForegroundColour
);
979 wxDouble h
, d
, e
, w
;
981 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
984 *height
= DeviceToLogicalYRel((wxCoord
)h
);
986 *descent
= DeviceToLogicalYRel((wxCoord
)d
);
987 if ( externalLeading
)
988 *externalLeading
= DeviceToLogicalYRel((wxCoord
)e
);
990 *width
= DeviceToLogicalXRel((wxCoord
)w
);
994 m_graphicContext
->SetFont( m_font
, m_textForegroundColour
);
998 bool wxGCDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1000 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
1002 widths
.Add(0,text
.Length());
1003 if ( text
.IsEmpty() )
1006 wxArrayDouble widthsD
;
1008 m_graphicContext
->GetPartialTextExtents( text
, widthsD
);
1009 for ( size_t i
= 0; i
< widths
.GetCount(); ++i
)
1010 widths
[i
] = DeviceToLogicalXRel((wxCoord
)(widthsD
[i
] + 0.5));
1015 wxCoord
wxGCDC::GetCharWidth(void) const
1018 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1023 wxCoord
wxGCDC::GetCharHeight(void) const
1026 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1031 void wxGCDC::Clear(void)
1033 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
1034 // TODO better implementation / incorporate size info into wxGCDC or context
1035 m_graphicContext
->SetBrush( m_backgroundBrush
);
1036 wxPen p
= *wxTRANSPARENT_PEN
;
1037 m_graphicContext
->SetPen( p
);
1038 DoDrawRectangle( 0, 0, 32000 , 32000 );
1039 m_graphicContext
->SetPen( m_pen
);
1040 m_graphicContext
->SetBrush( m_brush
);
1043 void wxGCDC::DoGetSize(int *width
, int *height
) const
1049 void wxGCDC::DoGradientFillLinear(const wxRect
& rect
,
1050 const wxColour
& initialColour
,
1051 const wxColour
& destColour
,
1052 wxDirection nDirection
)
1059 start
= rect
.GetRightBottom();
1061 end
= rect
.GetLeftBottom();
1064 start
= rect
.GetLeftBottom();
1065 end
= rect
.GetRightBottom();
1069 start
= rect
.GetLeftBottom();
1071 end
= rect
.GetLeftTop();
1074 start
= rect
.GetLeftTop();
1075 end
= rect
.GetLeftBottom();
1082 m_graphicContext
->SetBrush( m_graphicContext
->CreateLinearGradientBrush(
1083 LogicalToDeviceX(start
.x
),LogicalToDeviceY(start
.y
),
1084 LogicalToDeviceX(end
.x
),LogicalToDeviceY(end
.y
), initialColour
, destColour
));
1086 wxDouble xx
= LogicalToDeviceX(rect
.x
);
1087 wxDouble yy
= LogicalToDeviceY(rect
.y
);
1088 wxDouble ww
= m_signX
* LogicalToDeviceXRel(rect
.width
);
1089 wxDouble hh
= m_signY
* LogicalToDeviceYRel(rect
.height
);
1091 if (ww
== 0 || hh
== 0)
1105 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
1106 m_graphicContext
->DrawRectangle(xx
,yy
,ww
,hh
);
1107 m_graphicContext
->SetPen(m_pen
);
1110 void wxGCDC::DoGradientFillConcentric(const wxRect
& rect
,
1111 const wxColour
& initialColour
,
1112 const wxColour
& destColour
,
1113 const wxPoint
& circleCenter
)
1116 wxInt32 cx
= rect
.GetWidth() / 2;
1117 wxInt32 cy
= rect
.GetHeight() / 2;
1124 wxDouble xx
= LogicalToDeviceX(rect
.x
);
1125 wxDouble yy
= LogicalToDeviceY(rect
.y
);
1126 wxDouble ww
= m_signX
* LogicalToDeviceXRel(rect
.width
);
1127 wxDouble hh
= m_signY
* LogicalToDeviceYRel(rect
.height
);
1129 if (ww
== 0 || hh
== 0)
1143 m_graphicContext
->SetPen(*wxTRANSPARENT_PEN
);
1144 m_graphicContext
->SetBrush( wxBrush( destColour
) );
1145 m_graphicContext
->DrawRectangle( xx
,yy
,ww
,hh
);
1147 m_graphicContext
->SetBrush( m_graphicContext
->CreateRadialGradientBrush(
1148 xx
+LogicalToDeviceX(circleCenter
.x
),yy
+LogicalToDeviceY(circleCenter
.y
),
1149 xx
+LogicalToDeviceX(circleCenter
.x
),yy
+LogicalToDeviceY(circleCenter
.y
),
1150 LogicalToDeviceXRel(nRadius
),
1151 initialColour
,destColour
));
1153 m_graphicContext
->DrawRectangle( xx
,yy
,ww
,hh
);
1154 m_graphicContext
->SetPen(m_pen
);
1157 void wxGCDC::DoDrawCheckMark(wxCoord x
, wxCoord y
,
1158 wxCoord width
, wxCoord height
)
1160 wxDCBase::DoDrawCheckMark(x
,y
,width
,height
);
1163 #endif // wxUSE_GRAPHICS_CONTEXT