]> git.saurik.com Git - wxWidgets.git/blob - src/common/graphcmn.cpp
Fix warning.
[wxWidgets.git] / src / common / graphcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/graphcmn.cpp
3 // Purpose: graphics context methods common to all platforms
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if defined(__BORLANDC__)
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_GRAPHICS_CONTEXT
20
21 #include "wx/graphics.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/icon.h"
25 #include "wx/bitmap.h"
26 #include "wx/dcmemory.h"
27 #include "wx/region.h"
28 #endif
29
30 #if !defined(wxMAC_USE_CORE_GRAPHICS_BLEND_MODES)
31 #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
32 #endif
33
34 //-----------------------------------------------------------------------------
35 // constants
36 //-----------------------------------------------------------------------------
37
38 static const double RAD2DEG = 180.0 / M_PI;
39
40 //-----------------------------------------------------------------------------
41 // Local functions
42 //-----------------------------------------------------------------------------
43
44 static inline double DegToRad(double deg)
45 {
46 return (deg * M_PI) / 180.0;
47 }
48
49 //-----------------------------------------------------------------------------
50
51 wxPoint2DDouble wxGraphicsPath::GetCurrentPoint()
52 {
53 wxDouble x,y;
54 GetCurrentPoint(x,y);
55 return wxPoint2DDouble(x,y);
56 }
57
58 void wxGraphicsPath::MoveToPoint( const wxPoint2DDouble& p)
59 {
60 MoveToPoint( p.m_x , p.m_y);
61 }
62
63 void wxGraphicsPath::AddLineToPoint( const wxPoint2DDouble& p)
64 {
65 AddLineToPoint( p.m_x , p.m_y);
66 }
67
68 void wxGraphicsPath::AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e)
69 {
70 AddCurveToPoint(c1.m_x, c1.m_y, c2.m_x, c2.m_y, e.m_x, e.m_y);
71 }
72
73 void wxGraphicsPath::AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise)
74 {
75 AddArc(c.m_x, c.m_y, r, startAngle, endAngle, clockwise);
76 }
77
78 //
79 // Emulations
80 //
81
82 void wxGraphicsPath::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y )
83 {
84 // calculate using degree elevation to a cubic bezier
85 wxPoint2DDouble c1;
86 wxPoint2DDouble c2;
87
88 wxPoint2DDouble start = GetCurrentPoint();
89 wxPoint2DDouble end(x,y);
90 wxPoint2DDouble c(cx,cy);
91 c1 = wxDouble(1/3.0) * start + wxDouble(2/3.0) * c;
92 c2 = wxDouble(2/3.0) * c + wxDouble(1/3.0) * end;
93 AddCurveToPoint(c1.m_x,c1.m_y,c2.m_x,c2.m_y,x,y);
94 }
95
96 void wxGraphicsPath::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
97 {
98 MoveToPoint(x,y);
99 AddLineToPoint(x,y+h);
100 AddLineToPoint(x+w,y+h);
101 AddLineToPoint(x+w,y);
102 CloseSubpath();
103 }
104
105 void wxGraphicsPath::AddCircle( wxDouble x, wxDouble y, wxDouble r )
106 {
107 MoveToPoint(x+r,y);
108 AddArc( x,y,r,0,2*M_PI,false);
109 CloseSubpath();
110 }
111
112 // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
113 void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r )
114 {
115 wxPoint2DDouble current = GetCurrentPoint();
116 wxPoint2DDouble p1(x1,y1);
117 wxPoint2DDouble p2(x2,y2);
118
119 wxPoint2DDouble v1 = current - p1;
120 v1.Normalize();
121 wxPoint2DDouble v2 = p2 - p1;
122 v2.Normalize();
123
124 wxDouble alpha = v1.GetVectorAngle() - v2.GetVectorAngle();
125
126 if ( alpha < 0 )
127 alpha = 360 + alpha;
128 // TODO obtuse angles
129
130 alpha = DegToRad(alpha);
131
132 wxDouble dist = r / sin(alpha/2) * cos(alpha/2);
133 // calculate tangential points
134 wxPoint2DDouble t1 = dist*v1 + p1;
135 wxPoint2DDouble t2 = dist*v2 + p1;
136
137 wxPoint2DDouble nv1 = v1;
138 nv1.SetVectorAngle(v1.GetVectorAngle()-90);
139 wxPoint2DDouble c = t1 + r*nv1;
140
141 wxDouble a1 = v1.GetVectorAngle()+90;
142 wxDouble a2 = v2.GetVectorAngle()-90;
143
144 AddLineToPoint(t1);
145 AddArc(c.m_x,c.m_y,r,DegToRad(a1),DegToRad(a2),true);
146 AddLineToPoint(p2);
147 }
148
149 //-----------------------------------------------------------------------------
150 // wxGraphicsContext Convenience Methods
151 //-----------------------------------------------------------------------------
152
153 void wxGraphicsContext::DrawPath( const wxGraphicsPath *path, int fillStyle )
154 {
155 FillPath( path , fillStyle );
156 StrokePath( path );
157 }
158
159 void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle )
160 {
161 Translate(x,y);
162 Rotate( -angle );
163 DrawText( str , 0, 0 );
164 Rotate( angle );
165 Translate(-x,-y);
166 }
167
168 void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2)
169 {
170 wxGraphicsPath* path = CreatePath();
171 path->MoveToPoint(x1, y1);
172 path->AddLineToPoint( x2, y2 );
173 StrokePath( path );
174 delete path;
175 }
176
177 void wxGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
178 {
179 wxGraphicsPath* path = CreatePath();
180 path->AddRectangle( x , y , w , h );
181 DrawPath( path );
182 delete path;
183 }
184
185 void wxGraphicsContext::DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
186 {
187 wxGraphicsPath* path = CreatePath();
188 if ( w == h )
189 {
190 path->AddCircle( x+w/2,y+w/2,w/2);
191 DrawPath(path);
192 }
193 else
194 {
195 PushState();
196 Translate(x+w/2,y+h/2);
197 wxDouble factor = ((wxDouble) w) / h;
198 Scale( factor , 1.0);
199 path->AddCircle(0,0,h/2);
200 DrawPath(path);
201 PopState();
202 }
203 delete path;
204 }
205
206 void wxGraphicsContext::DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius)
207 {
208 wxGraphicsPath* path = CreatePath();
209 if ( radius == 0)
210 {
211 path->AddRectangle( x , y , w , h );
212 DrawPath( path );
213 }
214 else
215 {
216 PushState();
217 Translate( x , y );
218
219 path->MoveToPoint(w, h / 2);
220 path->AddArcToPoint(w, h, w / 2, h, radius);
221 path->AddArcToPoint(0, h, 0, h / 2, radius);
222 path->AddArcToPoint(0, 0, w / 2, 0, radius);
223 path->AddArcToPoint(w, 0, w, h / 2, radius);
224 path->CloseSubpath();
225 DrawPath( path );
226 PopState();
227 }
228 delete path;
229 }
230
231 void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *points)
232 {
233 wxASSERT(n > 1);
234 wxGraphicsPath* path = CreatePath();
235 path->MoveToPoint(points[0].m_x, points[0].m_y);
236 for ( size_t i = 1; i < n; ++i)
237 path->AddLineToPoint( points[i].m_x, points[i].m_y );
238 StrokePath( path );
239 delete path;
240 }
241
242 void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle)
243 {
244 wxASSERT(n > 1);
245 wxGraphicsPath* path = CreatePath();
246 path->MoveToPoint(points[0].m_x, points[0].m_y);
247 for ( size_t i = 1; i < n; ++i)
248 path->AddLineToPoint( points[i].m_x, points[i].m_y );
249 DrawPath( path , fillStyle);
250 delete path;
251 }
252
253 void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints)
254 {
255 wxASSERT(n > 0);
256 wxGraphicsPath* path = CreatePath();
257 for ( size_t i = 0; i < n; ++i)
258 {
259 path->MoveToPoint(beginPoints[i].m_x, beginPoints[i].m_y);
260 path->AddLineToPoint( endPoints[i].m_x, endPoints[i].m_y );
261 }
262 StrokePath( path );
263 delete path;
264 }
265
266 IMPLEMENT_ABSTRACT_CLASS(wxGCDC, wxObject)
267
268 //-----------------------------------------------------------------------------
269 // wxDC bridge class
270 //-----------------------------------------------------------------------------
271
272 wxGCDC::wxGCDC()
273 {
274 Init();
275 }
276
277 void wxGCDC::SetGraphicsContext( wxGraphicsContext* ctx )
278 {
279 delete m_graphicContext;
280 m_graphicContext = ctx;
281 }
282
283 wxGCDC::wxGCDC(const wxWindowDC& dc)
284 {
285 Init();
286 m_graphicContext = wxGraphicsContext::Create(dc);
287 m_ok = true;
288 if ( dc.GetFont().Ok())
289 m_graphicContext->SetFont(dc.GetFont());
290 if ( dc.GetPen().Ok())
291 m_graphicContext->SetPen(dc.GetPen());
292 if ( dc.GetBrush().Ok())
293 m_graphicContext->SetBrush(dc.GetBrush());
294 m_graphicContext->SetTextColor(dc.GetTextForeground());
295 }
296
297 void wxGCDC::Init()
298 {
299 m_ok = false;
300 m_colour = true;
301 m_mm_to_pix_x = mm2pt;
302 m_mm_to_pix_y = mm2pt;
303
304 m_pen = *wxBLACK_PEN;
305 m_font = *wxNORMAL_FONT;
306 m_brush = *wxWHITE_BRUSH;
307
308 m_graphicContext = NULL;
309 }
310
311
312 wxGCDC::~wxGCDC()
313 {
314 delete m_graphicContext;
315 }
316
317 void wxGCDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool WXUNUSED(useMask) )
318 {
319 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
320 wxCHECK_RET( bmp.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
321
322 wxCoord xx = LogicalToDeviceX(x);
323 wxCoord yy = LogicalToDeviceY(y);
324 wxCoord w = bmp.GetWidth();
325 wxCoord h = bmp.GetHeight();
326 wxCoord ww = LogicalToDeviceXRel(w);
327 wxCoord hh = LogicalToDeviceYRel(h);
328
329 m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh );
330 }
331
332 void wxGCDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
333 {
334 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
335 wxCHECK_RET( icon.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
336
337 wxCoord xx = LogicalToDeviceX(x);
338 wxCoord yy = LogicalToDeviceY(y);
339 wxCoord w = icon.GetWidth();
340 wxCoord h = icon.GetHeight();
341 wxCoord ww = LogicalToDeviceXRel(w);
342 wxCoord hh = LogicalToDeviceYRel(h);
343
344 m_graphicContext->DrawIcon( icon , xx, yy, ww, hh );
345 }
346
347 void wxGCDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
348 {
349 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
350
351 wxCoord xx, yy, ww, hh;
352 xx = LogicalToDeviceX(x);
353 yy = LogicalToDeviceY(y);
354 ww = LogicalToDeviceXRel(width);
355 hh = LogicalToDeviceYRel(height);
356
357 m_graphicContext->Clip( xx, yy, ww, hh );
358 if ( m_clipping )
359 {
360 m_clipX1 = wxMax( m_clipX1, xx );
361 m_clipY1 = wxMax( m_clipY1, yy );
362 m_clipX2 = wxMin( m_clipX2, (xx + ww) );
363 m_clipY2 = wxMin( m_clipY2, (yy + hh) );
364 }
365 else
366 {
367 m_clipping = true;
368
369 m_clipX1 = xx;
370 m_clipY1 = yy;
371 m_clipX2 = xx + ww;
372 m_clipY2 = yy + hh;
373 }
374 }
375
376 void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion &region )
377 {
378 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
379
380 if (region.Empty())
381 {
382 DestroyClippingRegion();
383 return;
384 }
385
386 wxCoord x, y, w, h;
387 region.GetBox( x, y, w, h );
388 wxCoord xx, yy, ww, hh;
389 xx = LogicalToDeviceX(x);
390 yy = LogicalToDeviceY(y);
391 ww = LogicalToDeviceXRel(w);
392 hh = LogicalToDeviceYRel(h);
393
394 // if we have a scaling that we cannot map onto native regions
395 // we must use the box
396 if ( ww != w || hh != h )
397 {
398 wxGCDC::DoSetClippingRegion( x, y, w, h );
399 }
400 else
401 {
402 m_graphicContext->Clip( region );
403 if ( m_clipping )
404 {
405 m_clipX1 = wxMax( m_clipX1, xx );
406 m_clipY1 = wxMax( m_clipY1, yy );
407 m_clipX2 = wxMin( m_clipX2, (xx + ww) );
408 m_clipY2 = wxMin( m_clipY2, (yy + hh) );
409 }
410 else
411 {
412 m_clipping = true;
413
414 m_clipX1 = xx;
415 m_clipY1 = yy;
416 m_clipX2 = xx + ww;
417 m_clipY2 = yy + hh;
418 }
419 }
420 }
421
422 void wxGCDC::DestroyClippingRegion()
423 {
424 m_graphicContext->ResetClip();
425 m_graphicContext->SetPen( m_pen );
426 m_graphicContext->SetBrush( m_brush );
427
428 m_clipping = false;
429 }
430
431 void wxGCDC::DoGetSizeMM( int* width, int* height ) const
432 {
433 int w = 0, h = 0;
434
435 GetSize( &w, &h );
436 if (width)
437 *width = long( double(w) / (m_scaleX * m_mm_to_pix_x) );
438 if (height)
439 *height = long( double(h) / (m_scaleY * m_mm_to_pix_y) );
440 }
441
442 void wxGCDC::SetTextForeground( const wxColour &col )
443 {
444 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
445
446 if ( col != m_textForegroundColour )
447 {
448 m_textForegroundColour = col;
449 m_graphicContext->SetTextColor( col );
450 }
451 }
452
453 void wxGCDC::SetTextBackground( const wxColour &col )
454 {
455 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
456
457 m_textBackgroundColour = col;
458 }
459
460 void wxGCDC::SetMapMode( int mode )
461 {
462 switch (mode)
463 {
464 case wxMM_TWIPS:
465 SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y );
466 break;
467
468 case wxMM_POINTS:
469 SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y );
470 break;
471
472 case wxMM_METRIC:
473 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
474 break;
475
476 case wxMM_LOMETRIC:
477 SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 );
478 break;
479
480 case wxMM_TEXT:
481 default:
482 SetLogicalScale( 1.0, 1.0 );
483 break;
484 }
485
486 ComputeScaleAndOrigin();
487 }
488
489 void wxGCDC::SetUserScale( double x, double y )
490 {
491 // allow negative ? -> no
492
493 m_userScaleX = x;
494 m_userScaleY = y;
495 ComputeScaleAndOrigin();
496 }
497
498 void wxGCDC::SetLogicalScale( double x, double y )
499 {
500 // allow negative ?
501 m_logicalScaleX = x;
502 m_logicalScaleY = y;
503 ComputeScaleAndOrigin();
504 }
505
506 void wxGCDC::SetLogicalOrigin( wxCoord x, wxCoord y )
507 {
508 m_logicalOriginX = x * m_signX; // is this still correct ?
509 m_logicalOriginY = y * m_signY;
510 ComputeScaleAndOrigin();
511 }
512
513 void wxGCDC::SetDeviceOrigin( wxCoord x, wxCoord y )
514 {
515 m_deviceOriginX = x;
516 m_deviceOriginY = y;
517 ComputeScaleAndOrigin();
518 }
519
520 void wxGCDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
521 {
522 m_signX = (xLeftRight ? 1 : -1);
523 m_signY = (yBottomUp ? -1 : 1);
524 ComputeScaleAndOrigin();
525 }
526
527 wxSize wxGCDC::GetPPI() const
528 {
529 return wxSize(72, 72);
530 }
531
532 int wxGCDC::GetDepth() const
533 {
534 return 32;
535 }
536
537 void wxGCDC::ComputeScaleAndOrigin()
538 {
539 // CMB: copy scale to see if it changes
540 double origScaleX = m_scaleX;
541 double origScaleY = m_scaleY;
542 m_scaleX = m_logicalScaleX * m_userScaleX;
543 m_scaleY = m_logicalScaleY * m_userScaleY;
544 m_deviceOriginX = m_deviceOriginX + m_logicalOriginX;
545 m_deviceOriginY = m_deviceOriginY + m_logicalOriginY;
546
547 // CMB: if scale has changed call SetPen to recalulate the line width
548 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
549 {
550 // this is a bit artificial, but we need to force wxDC to think
551 // the pen has changed
552 wxPen pen(GetPen());
553 m_pen = wxNullPen;
554 SetPen(pen);
555 SetFont(m_font);
556 }
557 }
558
559 void wxGCDC::SetPalette( const wxPalette& WXUNUSED(palette) )
560 {
561
562 }
563
564 void wxGCDC::SetBackgroundMode( int mode )
565 {
566 m_backgroundMode = mode;
567 }
568
569 void wxGCDC::SetFont( const wxFont &font )
570 {
571 m_font = font;
572 if ( m_graphicContext )
573 {
574 wxFont f = font;
575 if ( f.Ok() )
576 f.SetPointSize( LogicalToDeviceYRel(font.GetPointSize()));
577 m_graphicContext->SetFont( f );
578 }
579 }
580
581 void wxGCDC::SetPen( const wxPen &pen )
582 {
583 if ( m_pen == pen )
584 return;
585
586 m_pen = pen;
587 if ( m_graphicContext )
588 {
589 if ( m_pen.GetStyle() == wxSOLID || m_pen.GetStyle() == wxTRANSPARENT )
590 {
591 m_graphicContext->SetPen( m_pen );
592 }
593 else
594 {
595 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
596 // eg when using a wxScrollWindow and scrolling around
597 int origX = LogicalToDeviceX( 0 );
598 int origY = LogicalToDeviceY( 0 );
599 m_graphicContext->Translate( origX , origY );
600 m_graphicContext->SetPen( m_pen );
601 m_graphicContext->Translate( -origX , -origY );
602 }
603 }
604 }
605
606 void wxGCDC::SetBrush( const wxBrush &brush )
607 {
608 if (m_brush == brush)
609 return;
610
611 m_brush = brush;
612 if ( m_graphicContext )
613 {
614 if ( brush.GetStyle() == wxSOLID || brush.GetStyle() == wxTRANSPARENT )
615 {
616 m_graphicContext->SetBrush( m_brush );
617 }
618 else
619 {
620 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
621 // eg when using a wxScrollWindow and scrolling around
622 // TODO on MSW / GDIPlus this still occurs with hatched brushes
623 int origX = LogicalToDeviceX(0);
624 int origY = LogicalToDeviceY(0);
625 m_graphicContext->Translate( origX , origY );
626 m_graphicContext->SetBrush( m_brush );
627 m_graphicContext->Translate( -origX , -origY );
628 }
629 }
630 }
631
632 void wxGCDC::SetBackground( const wxBrush &brush )
633 {
634 if (m_backgroundBrush == brush)
635 return;
636
637 m_backgroundBrush = brush;
638 if (!m_backgroundBrush.Ok())
639 return;
640 }
641
642 void wxGCDC::SetLogicalFunction( int function )
643 {
644 if (m_logicalFunction == function)
645 return;
646
647 m_logicalFunction = function;
648 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
649
650 CGContextRef cgContext = ((wxCairoContext*)(m_graphicContext))->GetNativeContext();
651 if ( m_logicalFunction == wxCOPY )
652 CGContextSetBlendMode( cgContext, kCGBlendModeNormal );
653 else if ( m_logicalFunction == wxINVERT )
654 CGContextSetBlendMode( cgContext, kCGBlendModeExclusion );
655 else
656 CGContextSetBlendMode( cgContext, kCGBlendModeNormal );
657 #endif
658
659 }
660
661 bool wxGCDC::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
662 const wxColour& WXUNUSED(col), int WXUNUSED(style))
663 {
664 return false;
665 }
666
667 bool wxGCDC::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const
668 {
669 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
670 return false;
671 }
672
673 void wxGCDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
674 {
675 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
676
677 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
678
679 if ( m_logicalFunction != wxCOPY )
680 return;
681 #endif
682
683 wxCoord xx1 = LogicalToDeviceX(x1);
684 wxCoord yy1 = LogicalToDeviceY(y1);
685 wxCoord xx2 = LogicalToDeviceX(x2);
686 wxCoord yy2 = LogicalToDeviceY(y2);
687
688 m_graphicContext->StrokeLine(xx1,yy1,xx2,yy2);
689
690 CalcBoundingBox(x1, y1);
691 CalcBoundingBox(x2, y2);
692 }
693
694 void wxGCDC::DoCrossHair( wxCoord x, wxCoord y )
695 {
696 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
697
698 if ( m_logicalFunction != wxCOPY )
699 return;
700
701 int w = 0, h = 0;
702
703 GetSize( &w, &h );
704
705 wxCoord xx = LogicalToDeviceX(x);
706 wxCoord yy = LogicalToDeviceY(y);
707 wxCoord xw = LogicalToDeviceX(w);
708 wxCoord x0 = LogicalToDeviceX(0);
709 wxCoord y0 = LogicalToDeviceY(0);
710 wxCoord yh = LogicalToDeviceY(h);
711
712 m_graphicContext->StrokeLine(x0,yy,xw,yy);
713 m_graphicContext->StrokeLine(xx,y0,xx,yh);
714
715 CalcBoundingBox(x0, y0);
716 CalcBoundingBox(x0+xw, y0+yh);
717 }
718
719 void wxGCDC::DoDrawArc( wxCoord x1, wxCoord y1,
720 wxCoord x2, wxCoord y2,
721 wxCoord xc, wxCoord yc )
722 {
723 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
724
725 if ( m_logicalFunction != wxCOPY )
726 return;
727
728 wxCoord xx1 = LogicalToDeviceX(x1);
729 wxCoord yy1 = LogicalToDeviceY(y1);
730 wxCoord xx2 = LogicalToDeviceX(x2);
731 wxCoord yy2 = LogicalToDeviceY(y2);
732 wxCoord xxc = LogicalToDeviceX(xc);
733 wxCoord yyc = LogicalToDeviceY(yc);
734
735 double dx = xx1 - xxc;
736 double dy = yy1 - yyc;
737 double radius = sqrt((double)(dx * dx + dy * dy));
738 wxCoord rad = (wxCoord)radius;
739 double sa, ea;
740 if (xx1 == xx2 && yy1 == yy2)
741 {
742 sa = 0.0;
743 ea = 360.0;
744 }
745 else if (radius == 0.0)
746 {
747 sa = ea = 0.0;
748 }
749 else
750 {
751 sa = (xx1 - xxc == 0) ?
752 (yy1 - yyc < 0) ? 90.0 : -90.0 :
753 -atan2(double(yy1 - yyc), double(xx1 - xxc)) * RAD2DEG;
754 ea = (xx2 - xxc == 0) ?
755 (yy2 - yyc < 0) ? 90.0 : -90.0 :
756 -atan2(double(yy2 - yyc), double(xx2 - xxc)) * RAD2DEG;
757 }
758
759 bool fill = m_brush.GetStyle() != wxTRANSPARENT;
760
761 wxGraphicsPath* path = m_graphicContext->CreatePath();
762 if ( fill && ((x1!=x2)||(y1!=y2)) )
763 path->MoveToPoint( xxc, yyc );
764 path->AddArc( xxc, yyc , rad , DegToRad(sa) , DegToRad(ea), false );
765 if ( fill && ((x1!=x2)||(y1!=y2)) )
766 path->AddLineToPoint( xxc, yyc );
767 m_graphicContext->DrawPath(path);
768 delete path;
769 }
770
771 void wxGCDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
772 double sa, double ea )
773 {
774 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
775
776 if ( m_logicalFunction != wxCOPY )
777 return;
778
779 wxCoord xx = LogicalToDeviceX(x);
780 wxCoord yy = LogicalToDeviceY(y);
781 wxCoord ww = m_signX * LogicalToDeviceXRel(w);
782 wxCoord hh = m_signY * LogicalToDeviceYRel(h);
783
784 // handle -ve width and/or height
785 if (ww < 0)
786 {
787 ww = -ww;
788 xx = xx - ww;
789 }
790 if (hh < 0)
791 {
792 hh = -hh;
793 yy = yy - hh;
794 }
795
796 bool fill = m_brush.GetStyle() != wxTRANSPARENT;
797
798 wxGraphicsPath* path = m_graphicContext->CreatePath();
799 m_graphicContext->PushState();
800 m_graphicContext->Translate(xx+ww/2,yy+hh/2);
801 wxDouble factor = ((wxDouble) ww) / hh;
802 m_graphicContext->Scale( factor , 1.0);
803 if ( fill && (sa!=ea) )
804 path->MoveToPoint(0,0);
805 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
806 // get clockwise angles
807 path->AddArc( 0, 0, hh/2 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
808 if ( fill && (sa!=ea) )
809 path->AddLineToPoint(0,0);
810 m_graphicContext->DrawPath( path );
811 m_graphicContext->PopState();
812 delete path;
813 }
814
815 void wxGCDC::DoDrawPoint( wxCoord x, wxCoord y )
816 {
817 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
818
819 DoDrawLine( x , y , x + 1 , y + 1 );
820 }
821
822 void wxGCDC::DoDrawLines(int n, wxPoint points[],
823 wxCoord xoffset, wxCoord yoffset)
824 {
825 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
826
827 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
828
829 if ( m_logicalFunction != wxCOPY )
830 return;
831 #endif
832
833 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n];
834 for( int i = 0; i < n; ++i)
835 {
836 pointsD[i].m_x = LogicalToDeviceX(points[i].x + xoffset);
837 pointsD[i].m_y = LogicalToDeviceY(points[i].y + yoffset);
838 }
839
840 m_graphicContext->StrokeLines( n , pointsD);
841 delete[] pointsD;
842 }
843
844 #if wxUSE_SPLINES
845 void wxGCDC::DoDrawSpline(wxList *points)
846 {
847 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
848
849 if ( m_logicalFunction != wxCOPY )
850 return;
851
852 wxGraphicsPath* path = m_graphicContext->CreatePath();
853
854 wxList::compatibility_iterator node = points->GetFirst();
855 if (node == wxList::compatibility_iterator())
856 // empty list
857 return;
858
859 wxPoint *p = (wxPoint *)node->GetData();
860
861 wxCoord x1 = p->x;
862 wxCoord y1 = p->y;
863
864 node = node->GetNext();
865 p = (wxPoint *)node->GetData();
866
867 wxCoord x2 = p->x;
868 wxCoord y2 = p->y;
869 wxCoord cx1 = ( x1 + x2 ) / 2;
870 wxCoord cy1 = ( y1 + y2 ) / 2;
871
872 path->MoveToPoint( LogicalToDeviceX( x1 ) , LogicalToDeviceY( y1 ) );
873 path->AddLineToPoint( LogicalToDeviceX( cx1 ) , LogicalToDeviceY( cy1 ) );
874 #if !wxUSE_STL
875
876 while ((node = node->GetNext()) != NULL)
877 #else
878
879 while ((node = node->GetNext()))
880 #endif // !wxUSE_STL
881
882 {
883 p = (wxPoint *)node->GetData();
884 x1 = x2;
885 y1 = y2;
886 x2 = p->x;
887 y2 = p->y;
888 wxCoord cx4 = (x1 + x2) / 2;
889 wxCoord cy4 = (y1 + y2) / 2;
890
891 path->AddQuadCurveToPoint(
892 LogicalToDeviceX( x1 ) , LogicalToDeviceY( y1 ) ,
893 LogicalToDeviceX( cx4 ) , LogicalToDeviceY( cy4 ) );
894
895 cx1 = cx4;
896 cy1 = cy4;
897 }
898
899 path->AddLineToPoint( LogicalToDeviceX( x2 ) , LogicalToDeviceY( y2 ) );
900
901 m_graphicContext->StrokePath( path );
902 delete path;
903 }
904 #endif // wxUSE_SPLINES
905
906 void wxGCDC::DoDrawPolygon( int n, wxPoint points[],
907 wxCoord xoffset, wxCoord yoffset,
908 int fillStyle )
909 {
910 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
911
912 if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) )
913 return;
914 if ( m_logicalFunction != wxCOPY )
915 return;
916
917 bool closeIt = false;
918 if (points[n-1] != points[0])
919 closeIt = true;
920
921 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)];
922 for( int i = 0; i < n; ++i)
923 {
924 pointsD[i].m_x = LogicalToDeviceX(points[i].x + xoffset);
925 pointsD[i].m_y = LogicalToDeviceY(points[i].y + yoffset);
926 }
927 if ( closeIt )
928 pointsD[n] = pointsD[0];
929
930 m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle);
931 delete[] pointsD;
932 }
933
934 void wxGCDC::DoDrawPolyPolygon(int n,
935 int count[],
936 wxPoint points[],
937 wxCoord xoffset,
938 wxCoord yoffset,
939 int fillStyle)
940 {
941 wxASSERT(n > 1);
942 wxGraphicsPath* path = m_graphicContext->CreatePath();
943
944 int i = 0;
945 for ( int j = 0; j < n; ++j)
946 {
947 wxPoint start = points[i];
948 path->MoveToPoint(LogicalToDeviceX(start.x+ xoffset), LogicalToDeviceY(start.y+ yoffset));
949 ++i;
950 int l = count[j];
951 for ( int k = 1; k < l; ++k)
952 {
953 path->AddLineToPoint( LogicalToDeviceX(points[i].x+ xoffset), LogicalToDeviceY(points[i].y+ yoffset));
954 ++i;
955 }
956 // close the polygon
957 if ( start != points[i-1])
958 path->AddLineToPoint( LogicalToDeviceX(start.x+ xoffset), LogicalToDeviceY(start.y+ yoffset));
959 }
960 m_graphicContext->DrawPath( path , fillStyle);
961 delete path;
962 }
963
964 void wxGCDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
965 {
966 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
967
968 if ( m_logicalFunction != wxCOPY )
969 return;
970
971 wxCoord xx = LogicalToDeviceX(x);
972 wxCoord yy = LogicalToDeviceY(y);
973 wxCoord ww = m_signX * LogicalToDeviceXRel(width);
974 wxCoord hh = m_signY * LogicalToDeviceYRel(height);
975
976 // CMB: draw nothing if transformed w or h is 0
977 if (ww == 0 || hh == 0)
978 return;
979
980 // CMB: handle -ve width and/or height
981 if (ww < 0)
982 {
983 ww = -ww;
984 xx = xx - ww;
985 }
986 if (hh < 0)
987 {
988 hh = -hh;
989 yy = yy - hh;
990 }
991 m_graphicContext->DrawRectangle( xx,yy,ww,hh);
992 }
993
994 void wxGCDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
995 wxCoord width, wxCoord height,
996 double radius)
997 {
998 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
999
1000 if ( m_logicalFunction != wxCOPY )
1001 return;
1002
1003 if (radius < 0.0)
1004 radius = - radius * ((width < height) ? width : height);
1005 wxCoord xx = LogicalToDeviceX(x);
1006 wxCoord yy = LogicalToDeviceY(y);
1007 wxCoord ww = m_signX * LogicalToDeviceXRel(width);
1008 wxCoord hh = m_signY * LogicalToDeviceYRel(height);
1009
1010 // CMB: draw nothing if transformed w or h is 0
1011 if (ww == 0 || hh == 0)
1012 return;
1013
1014 // CMB: handle -ve width and/or height
1015 if (ww < 0)
1016 {
1017 ww = -ww;
1018 xx = xx - ww;
1019 }
1020 if (hh < 0)
1021 {
1022 hh = -hh;
1023 yy = yy - hh;
1024 }
1025
1026 m_graphicContext->DrawRoundedRectangle( xx,yy,ww,hh,radius);
1027 }
1028
1029 void wxGCDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1030 {
1031 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
1032
1033 if ( m_logicalFunction != wxCOPY )
1034 return;
1035
1036 wxDouble xx = LogicalToDeviceX(x);
1037 wxDouble yy = LogicalToDeviceY(y);
1038 wxDouble ww = m_signX * LogicalToDeviceXRel(width);
1039 wxDouble hh = m_signY * LogicalToDeviceYRel(height);
1040
1041 // CMB: draw nothing if transformed w or h is 0
1042 if (ww == 0 || hh == 0)
1043 return;
1044
1045 // CMB: handle -ve width and/or height
1046 if (ww < 0)
1047 {
1048 ww = -ww;
1049 xx = xx - ww;
1050 }
1051 if (hh < 0)
1052 {
1053 hh = -hh;
1054 yy = yy - hh;
1055 }
1056
1057 m_graphicContext->DrawEllipse(xx,yy,ww,hh);
1058 }
1059
1060 bool wxGCDC::CanDrawBitmap() const
1061 {
1062 return true;
1063 }
1064
1065 bool wxGCDC::DoBlit(
1066 wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
1067 wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool WXUNUSED(useMask),
1068 wxCoord xsrcMask, wxCoord ysrcMask )
1069 {
1070 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
1071 wxCHECK_MSG( source->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
1072
1073 if ( logical_func == wxNO_OP )
1074 return true;
1075
1076 if (xsrcMask == -1 && ysrcMask == -1)
1077 {
1078 xsrcMask = xsrc;
1079 ysrcMask = ysrc;
1080 }
1081
1082 wxCoord yysrc = source-> LogicalToDeviceY(ysrc);
1083 wxCoord xxsrc = source-> LogicalToDeviceX(xsrc);
1084 wxCoord wwsrc = source-> LogicalToDeviceXRel(width);
1085 wxCoord hhsrc = source-> LogicalToDeviceYRel(height);
1086
1087 wxCoord yydest = LogicalToDeviceY(ydest);
1088 wxCoord xxdest = LogicalToDeviceX(xdest);
1089 wxCoord wwdest = LogicalToDeviceXRel(width);
1090 wxCoord hhdest = LogicalToDeviceYRel(height);
1091
1092 wxMemoryDC* memdc = dynamic_cast<wxMemoryDC*>(source);
1093 if ( memdc && logical_func == wxCOPY )
1094 {
1095 wxBitmap blit = memdc->GetSelectedBitmap();
1096
1097 wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") );
1098
1099 wxCoord bmpwidth = blit.GetWidth();
1100 wxCoord bmpheight = blit.GetHeight();
1101
1102 if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc )
1103 {
1104 wwsrc = wxMin( wwsrc , bmpwidth - xxsrc );
1105 hhsrc = wxMin( hhsrc , bmpheight - yysrc );
1106 if ( wwsrc > 0 && hhsrc > 0 )
1107 {
1108 if ( xxsrc >= 0 && yysrc >= 0 )
1109 {
1110 wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc );
1111 // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
1112 blit = blit.GetSubBitmap( subrect );
1113 }
1114 else
1115 {
1116 // in this case we'd probably have to adjust the different coordinates, but
1117 // we have to find out proper contract first
1118 blit = wxNullBitmap;
1119 }
1120 }
1121 else
1122 {
1123 blit = wxNullBitmap;
1124 }
1125 }
1126
1127 if ( blit.Ok() )
1128 {
1129 m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest );
1130 }
1131 }
1132 else
1133 {
1134 wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") );
1135 return false;
1136 }
1137
1138 return true;
1139 }
1140
1141 void wxGCDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
1142 double angle)
1143 {
1144 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
1145
1146 if ( str.length() == 0 )
1147 return;
1148 if ( m_logicalFunction != wxCOPY )
1149 return;
1150
1151 int drawX = LogicalToDeviceX(x);
1152 int drawY = LogicalToDeviceY(y);
1153
1154 m_graphicContext->DrawText( str, drawX ,drawY , DegToRad(angle ));
1155 }
1156
1157 void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y)
1158 {
1159 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
1160
1161 if ( str.length() == 0 )
1162 return;
1163 if ( m_logicalFunction != wxCOPY )
1164 return;
1165
1166 int drawX = LogicalToDeviceX(x);
1167 int drawY = LogicalToDeviceY(y);
1168
1169 m_graphicContext->DrawText( str, drawX ,drawY);
1170 }
1171
1172 bool wxGCDC::CanGetTextExtent() const
1173 {
1174 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
1175
1176 return true;
1177 }
1178
1179 void wxGCDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
1180 wxCoord *descent, wxCoord *externalLeading ,
1181 wxFont *theFont ) const
1182 {
1183 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
1184
1185 if ( theFont )
1186 {
1187 m_graphicContext->SetFont( *theFont );
1188 }
1189
1190 wxDouble h , d , e , w;
1191
1192 m_graphicContext->GetTextExtent( str, &w, &h, &d, &e );
1193
1194 if ( height )
1195 *height = DeviceToLogicalYRel((wxCoord)h);
1196 if ( descent )
1197 *descent = DeviceToLogicalYRel((wxCoord)d);
1198 if ( externalLeading )
1199 *externalLeading = DeviceToLogicalYRel((wxCoord)e);
1200 if ( width )
1201 *width = DeviceToLogicalXRel((wxCoord)w);
1202
1203 if ( theFont )
1204 {
1205 m_graphicContext->SetFont( m_font );
1206 }
1207 }
1208
1209 bool wxGCDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
1210 {
1211 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
1212 widths.Clear();
1213 widths.Add(0,text.Length());
1214 if ( text.IsEmpty() )
1215 return true;
1216
1217 wxArrayDouble widthsD;
1218
1219 m_graphicContext->GetPartialTextExtents( text, widthsD );
1220 for ( size_t i = 0; i < widths.GetCount(); ++i )
1221 widths[i] = DeviceToLogicalXRel((wxCoord)(widthsD[i] + 0.5));
1222
1223 return true;
1224 }
1225
1226 wxCoord wxGCDC::GetCharWidth(void) const
1227 {
1228 wxCoord width;
1229 DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
1230
1231 return width;
1232 }
1233
1234 wxCoord wxGCDC::GetCharHeight(void) const
1235 {
1236 wxCoord height;
1237 DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
1238
1239 return height;
1240 }
1241
1242 void wxGCDC::Clear(void)
1243 {
1244 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
1245 // TODO better implementation / incorporate size info into wxGCDC or context
1246 m_graphicContext->SetBrush( m_backgroundBrush );
1247 wxPen p = *wxTRANSPARENT_PEN;
1248 m_graphicContext->SetPen( p );
1249 DoDrawRectangle( 0, 0, 32000 , 32000 );
1250 m_graphicContext->SetPen( m_pen );
1251 m_graphicContext->SetBrush( m_brush );
1252 }
1253
1254 void wxGCDC::DoGetSize(int *width, int *height) const
1255 {
1256 *width = 1000;
1257 *height = 1000;
1258 }
1259
1260 void wxGCDC::DoGradientFillLinear(const wxRect& rect,
1261 const wxColour& initialColour,
1262 const wxColour& destColour,
1263 wxDirection nDirection )
1264 {
1265 wxPoint start;
1266 wxPoint end;
1267 switch( nDirection)
1268 {
1269 case wxWEST :
1270 start = rect.GetRightBottom();
1271 start.x++;
1272 end = rect.GetLeftBottom();
1273 break;
1274 case wxEAST :
1275 start = rect.GetLeftBottom();
1276 end = rect.GetRightBottom();
1277 end.x++;
1278 break;
1279 case wxNORTH :
1280 start = rect.GetLeftBottom();
1281 start.y++;
1282 end = rect.GetLeftTop();
1283 break;
1284 case wxSOUTH :
1285 start = rect.GetLeftTop();
1286 end = rect.GetLeftBottom();
1287 end.y++;
1288 break;
1289 default :
1290 break;
1291 }
1292
1293 m_graphicContext->SetLinearGradientBrush(
1294 LogicalToDeviceX(start.x),LogicalToDeviceY(start.y),
1295 LogicalToDeviceX(end.x),LogicalToDeviceY(end.y), initialColour, destColour);
1296
1297 wxDouble xx = LogicalToDeviceX(rect.x);
1298 wxDouble yy = LogicalToDeviceY(rect.y);
1299 wxDouble ww = m_signX * LogicalToDeviceXRel(rect.width);
1300 wxDouble hh = m_signY * LogicalToDeviceYRel(rect.height);
1301
1302 if (ww == 0 || hh == 0)
1303 return;
1304
1305 if (ww < 0)
1306 {
1307 ww = -ww;
1308 xx = xx - ww;
1309 }
1310 if (hh < 0)
1311 {
1312 hh = -hh;
1313 yy = yy - hh;
1314 }
1315
1316 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
1317 m_graphicContext->DrawRectangle(xx,yy,ww,hh);
1318 m_graphicContext->SetPen(m_pen);
1319 }
1320
1321 void wxGCDC::DoGradientFillConcentric(const wxRect& rect,
1322 const wxColour& initialColour,
1323 const wxColour& destColour,
1324 const wxPoint& circleCenter)
1325 {
1326 //Radius
1327 wxInt32 cx = rect.GetWidth() / 2;
1328 wxInt32 cy = rect.GetHeight() / 2;
1329 wxInt32 nRadius;
1330 if (cx < cy)
1331 nRadius = cx;
1332 else
1333 nRadius = cy;
1334
1335 wxDouble xx = LogicalToDeviceX(rect.x);
1336 wxDouble yy = LogicalToDeviceY(rect.y);
1337 wxDouble ww = m_signX * LogicalToDeviceXRel(rect.width);
1338 wxDouble hh = m_signY * LogicalToDeviceYRel(rect.height);
1339
1340 if (ww == 0 || hh == 0)
1341 return;
1342
1343 if (ww < 0)
1344 {
1345 ww = -ww;
1346 xx = xx - ww;
1347 }
1348 if (hh < 0)
1349 {
1350 hh = -hh;
1351 yy = yy - hh;
1352 }
1353
1354 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
1355 m_graphicContext->SetBrush( wxBrush( destColour) );
1356 m_graphicContext->DrawRectangle( xx,yy,ww,hh);
1357
1358 m_graphicContext->SetRadialGradientBrush(
1359 xx+LogicalToDeviceX(circleCenter.x),yy+LogicalToDeviceY(circleCenter.y),
1360 xx+LogicalToDeviceX(circleCenter.x),yy+LogicalToDeviceY(circleCenter.y),
1361 LogicalToDeviceXRel(nRadius),
1362 initialColour,destColour);
1363
1364 m_graphicContext->DrawRectangle( xx,yy,ww,hh);
1365 m_graphicContext->SetPen(m_pen);
1366 }
1367
1368 void wxGCDC::DoDrawCheckMark(wxCoord x, wxCoord y,
1369 wxCoord width, wxCoord height)
1370 {
1371 wxDCBase::DoDrawCheckMark(x,y,width,height);
1372 }
1373
1374 #endif // wxUSE_GRAPHICS_CONTEXT