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