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