]> git.saurik.com Git - wxWidgets.git/blame - src/common/graphcmn.cpp
on demand creation of native CGContexts , so that pure text measuring contexts don...
[wxWidgets.git] / src / common / graphcmn.cpp
CommitLineData
50581042
SC
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
50581042
SC
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
9fd707a5
PC
19#if wxUSE_GRAPHICS_CONTEXT
20
50581042
SC
21#include "wx/graphics.h"
22
539872ae
SC
23#ifndef WX_PRECOMP
24 #include "wx/icon.h"
25 #include "wx/bitmap.h"
26 #include "wx/dcmemory.h"
9fd707a5 27 #include "wx/region.h"
539872ae
SC
28#endif
29
2f34cf60
RD
30#if !defined(wxMAC_USE_CORE_GRAPHICS_BLEND_MODES)
31#define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
32#endif
33
d94228a2
SC
34//-----------------------------------------------------------------------------
35// constants
36//-----------------------------------------------------------------------------
37
9fd707a5 38static const double RAD2DEG = 180.0 / M_PI;
d94228a2
SC
39
40//-----------------------------------------------------------------------------
41// Local functions
42//-----------------------------------------------------------------------------
43
d94228a2
SC
44static inline double DegToRad(double deg)
45{
46 return (deg * M_PI) / 180.0;
47}
d94228a2 48
9fd707a5 49//-----------------------------------------------------------------------------
d94228a2 50
8ddf8e82
SC
51IMPLEMENT_ABSTRACT_CLASS(wxGraphicsPath, wxObject)
52
50581042
SC
53wxPoint2DDouble wxGraphicsPath::GetCurrentPoint()
54{
a2d6d210 55 wxDouble x,y;
50581042
SC
56 GetCurrentPoint(x,y);
57 return wxPoint2DDouble(x,y);
58}
59
60void wxGraphicsPath::MoveToPoint( const wxPoint2DDouble& p)
61{
62 MoveToPoint( p.m_x , p.m_y);
63}
64
65void wxGraphicsPath::AddLineToPoint( const wxPoint2DDouble& p)
66{
67 AddLineToPoint( p.m_x , p.m_y);
68}
69
70void 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
75void 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
84void wxGraphicsPath::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y )
85{
86 // calculate using degree elevation to a cubic bezier
a2d6d210
VZ
87 wxPoint2DDouble c1;
88 wxPoint2DDouble c2;
50581042 89
a2d6d210 90 wxPoint2DDouble start = GetCurrentPoint();
50581042
SC
91 wxPoint2DDouble end(x,y);
92 wxPoint2DDouble c(cx,cy);
5ce3abfb 93 c1 = wxDouble(1/3.0) * start + wxDouble(2/3.0) * c;
a2d6d210 94 c2 = wxDouble(2/3.0) * c + wxDouble(1/3.0) * end;
50581042
SC
95 AddCurveToPoint(c1.m_x,c1.m_y,c2.m_x,c2.m_y,x,y);
96}
97
98void 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
107void 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
d94228a2
SC
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)
115void 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
a2d6d210 121 wxPoint2DDouble v1 = current - p1;
d94228a2 122 v1.Normalize();
a2d6d210 123 wxPoint2DDouble v2 = p2 - p1;
d94228a2
SC
124 v2.Normalize();
125
126 wxDouble alpha = v1.GetVectorAngle() - v2.GetVectorAngle();
127
128 if ( alpha < 0 )
a2d6d210 129 alpha = 360 + alpha;
d94228a2
SC
130 // TODO obtuse angles
131
132 alpha = DegToRad(alpha);
133
a2d6d210 134 wxDouble dist = r / sin(alpha/2) * cos(alpha/2);
d94228a2 135 // calculate tangential points
a2d6d210
VZ
136 wxPoint2DDouble t1 = dist*v1 + p1;
137 wxPoint2DDouble t2 = dist*v2 + p1;
d94228a2 138
a2d6d210 139 wxPoint2DDouble nv1 = v1;
d94228a2
SC
140 nv1.SetVectorAngle(v1.GetVectorAngle()-90);
141 wxPoint2DDouble c = t1 + r*nv1;
142
a2d6d210
VZ
143 wxDouble a1 = v1.GetVectorAngle()+90;
144 wxDouble a2 = v2.GetVectorAngle()-90;
d94228a2
SC
145
146 AddLineToPoint(t1);
147 AddArc(c.m_x,c.m_y,r,DegToRad(a1),DegToRad(a2),true);
148 AddLineToPoint(p2);
149}
150
50581042
SC
151//-----------------------------------------------------------------------------
152// wxGraphicsContext Convenience Methods
153//-----------------------------------------------------------------------------
154
8ddf8e82
SC
155IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext, wxObject)
156
50581042
SC
157void wxGraphicsContext::DrawPath( const wxGraphicsPath *path, int fillStyle )
158{
159 FillPath( path , fillStyle );
160 StrokePath( path );
161}
162
163void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle )
164{
a2d6d210 165 Translate(x,y);
50581042
SC
166 Rotate( -angle );
167 DrawText( str , 0, 0 );
168 Rotate( angle );
a2d6d210 169 Translate(-x,-y);
50581042
SC
170}
171
172void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2)
173{
174 wxGraphicsPath* path = CreatePath();
a2d6d210 175 path->MoveToPoint(x1, y1);
50581042
SC
176 path->AddLineToPoint( x2, y2 );
177 StrokePath( path );
178 delete path;
179}
180
181void 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
189void 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);
a2d6d210
VZ
201 wxDouble factor = ((wxDouble) w) / h;
202 Scale( factor , 1.0);
50581042
SC
203 path->AddCircle(0,0,h/2);
204 DrawPath(path);
205 PopState();
206 }
207 delete path;
208}
209
210void 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
50581042
SC
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
235void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *points)
236{
237 wxASSERT(n > 1);
238 wxGraphicsPath* path = CreatePath();
a2d6d210
VZ
239 path->MoveToPoint(points[0].m_x, points[0].m_y);
240 for ( size_t i = 1; i < n; ++i)
50581042
SC
241 path->AddLineToPoint( points[i].m_x, points[i].m_y );
242 StrokePath( path );
243 delete path;
244}
245
246void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle)
247{
248 wxASSERT(n > 1);
249 wxGraphicsPath* path = CreatePath();
a2d6d210
VZ
250 path->MoveToPoint(points[0].m_x, points[0].m_y);
251 for ( size_t i = 1; i < n; ++i)
50581042
SC
252 path->AddLineToPoint( points[i].m_x, points[i].m_y );
253 DrawPath( path , fillStyle);
254 delete path;
255}
256
257void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints)
258{
259 wxASSERT(n > 0);
260 wxGraphicsPath* path = CreatePath();
a2d6d210 261 for ( size_t i = 0; i < n; ++i)
50581042 262 {
a2d6d210 263 path->MoveToPoint(beginPoints[i].m_x, beginPoints[i].m_y);
50581042
SC
264 path->AddLineToPoint( endPoints[i].m_x, endPoints[i].m_y );
265 }
266 StrokePath( path );
267 delete path;
268}
269
50581042
SC
270IMPLEMENT_ABSTRACT_CLASS(wxGCDC, wxObject)
271
50581042
SC
272//-----------------------------------------------------------------------------
273// wxDC bridge class
274//-----------------------------------------------------------------------------
275
276wxGCDC::wxGCDC()
277{
278 Init();
279}
280
ddb0ed69
RR
281void wxGCDC::SetGraphicsContext( wxGraphicsContext* ctx )
282{
283 delete m_graphicContext;
284 m_graphicContext = ctx;
285}
50581042
SC
286
287wxGCDC::wxGCDC(const wxWindowDC& dc)
288{
289 Init();
290 m_graphicContext = wxGraphicsContext::Create(dc);
291 m_ok = true;
d94228a2
SC
292 if ( dc.GetFont().Ok())
293 m_graphicContext->SetFont(dc.GetFont());
af863805
SC
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());
50581042
SC
299}
300
301void 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
316wxGCDC::~wxGCDC()
317{
318 delete m_graphicContext;
319}
320
12f72836 321void wxGCDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool WXUNUSED(useMask) )
50581042
SC
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
336void 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
f2ee37d5 351void wxGCDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
50581042 352{
50581042
SC
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
a2d6d210 361 m_graphicContext->Clip( xx, yy, ww, hh );
50581042
SC
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 }
50581042
SC
378}
379
380void 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 {
a2d6d210
VZ
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 }
50581042
SC
424}
425
426void wxGCDC::DestroyClippingRegion()
427{
a2d6d210
VZ
428 m_graphicContext->ResetClip();
429 m_graphicContext->SetPen( m_pen );
430 m_graphicContext->SetBrush( m_brush );
50581042
SC
431
432 m_clipping = false;
50581042
SC
433}
434
435void 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
446void 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
457void wxGCDC::SetTextBackground( const wxColour &col )
458{
459 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
460
461 m_textBackgroundColour = col;
462}
463
464void 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
493void wxGCDC::SetUserScale( double x, double y )
494{
495 // allow negative ? -> no
f2ee37d5 496
50581042
SC
497 m_userScaleX = x;
498 m_userScaleY = y;
a2d6d210 499 ComputeScaleAndOrigin();
50581042
SC
500}
501
502void wxGCDC::SetLogicalScale( double x, double y )
503{
504 // allow negative ?
505 m_logicalScaleX = x;
506 m_logicalScaleY = y;
507 ComputeScaleAndOrigin();
508}
509
510void 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
517void wxGCDC::SetDeviceOrigin( wxCoord x, wxCoord y )
518{
519 m_deviceOriginX = x;
520 m_deviceOriginY = y;
521 ComputeScaleAndOrigin();
522}
523
524void wxGCDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
525{
526 m_signX = (xLeftRight ? 1 : -1);
527 m_signY = (yBottomUp ? -1 : 1);
528 ComputeScaleAndOrigin();
529}
530
531wxSize wxGCDC::GetPPI() const
532{
533 return wxSize(72, 72);
534}
535
536int wxGCDC::GetDepth() const
537{
538 return 32;
539}
540
541void wxGCDC::ComputeScaleAndOrigin()
542{
f2ee37d5
SC
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;
50581042 550
f2ee37d5
SC
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);
a2d6d210 559 SetFont(m_font);
f2ee37d5 560 }
50581042
SC
561}
562
12f72836
SC
563void wxGCDC::SetPalette( const wxPalette& WXUNUSED(palette) )
564{
565
566}
50581042
SC
567
568void wxGCDC::SetBackgroundMode( int mode )
569{
570 m_backgroundMode = mode;
571}
572
573void wxGCDC::SetFont( const wxFont &font )
574{
575 m_font = font;
576 if ( m_graphicContext )
a2d6d210
VZ
577 {
578 wxFont f = font;
579 if ( f.Ok() )
580 f.SetPointSize( LogicalToDeviceYRel(font.GetPointSize()));
f2ee37d5 581 m_graphicContext->SetFont( f );
a2d6d210 582 }
50581042
SC
583}
584
585void 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
610void 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
636void 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
646void 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
12f72836
SC
665bool wxGCDC::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
666 const wxColour& WXUNUSED(col), int WXUNUSED(style))
50581042 667{
50581042
SC
668 return false;
669}
670
12f72836 671bool wxGCDC::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const
50581042
SC
672{
673 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
674 return false;
675}
676
677void 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
698void 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
723void 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
775void 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);
a2d6d210
VZ
805 wxDouble factor = ((wxDouble) ww) / hh;
806 m_graphicContext->Scale( factor , 1.0);
50581042
SC
807 if ( fill && (sa!=ea) )
808 path->MoveToPoint(0,0);
d94228a2
SC
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 );
50581042
SC
812 if ( fill && (sa!=ea) )
813 path->AddLineToPoint(0,0);
814 m_graphicContext->DrawPath( path );
815 m_graphicContext->PopState();
816 delete path;
817}
818
819void 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
826void 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
a2d6d210
VZ
837 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n];
838 for( int i = 0; i < n; ++i)
50581042
SC
839 {
840 pointsD[i].m_x = LogicalToDeviceX(points[i].x + xoffset);
841 pointsD[i].m_y = LogicalToDeviceY(points[i].y + yoffset);
842 }
843
a2d6d210 844 m_graphicContext->StrokeLines( n , pointsD);
50581042
SC
845 delete[] pointsD;
846}
847
848#if wxUSE_SPLINES
849void 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}
9fd707a5 908#endif // wxUSE_SPLINES
50581042
SC
909
910void 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
a2d6d210 921 bool closeIt = false;
50581042 922 if (points[n-1] != points[0])
a2d6d210 923 closeIt = true;
50581042 924
a2d6d210
VZ
925 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)];
926 for( int i = 0; i < n; ++i)
50581042
SC
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
a2d6d210 934 m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle);
50581042
SC
935 delete[] pointsD;
936}
937
938void 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
a2d6d210
VZ
948 int i = 0;
949 for ( int j = 0; j < n; ++j)
50581042
SC
950 {
951 wxPoint start = points[i];
a2d6d210 952 path->MoveToPoint(LogicalToDeviceX(start.x+ xoffset), LogicalToDeviceY(start.y+ yoffset));
50581042
SC
953 ++i;
954 int l = count[j];
a2d6d210 955 for ( int k = 1; k < l; ++k)
50581042
SC
956 {
957 path->AddLineToPoint( LogicalToDeviceX(points[i].x+ xoffset), LogicalToDeviceY(points[i].y+ yoffset));
a2d6d210 958 ++i;
50581042
SC
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
968void 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 m_graphicContext->DrawRectangle( xx,yy,ww,hh);
996}
997
998void wxGCDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
999 wxCoord width, wxCoord height,
1000 double radius)
1001{
1002 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1003
1004 if ( m_logicalFunction != wxCOPY )
1005 return;
1006
1007 if (radius < 0.0)
1008 radius = - radius * ((width < height) ? width : height);
1009 wxCoord xx = LogicalToDeviceX(x);
1010 wxCoord yy = LogicalToDeviceY(y);
1011 wxCoord ww = m_signX * LogicalToDeviceXRel(width);
1012 wxCoord hh = m_signY * LogicalToDeviceYRel(height);
1013
1014 // CMB: draw nothing if transformed w or h is 0
1015 if (ww == 0 || hh == 0)
1016 return;
1017
1018 // CMB: handle -ve width and/or height
1019 if (ww < 0)
1020 {
1021 ww = -ww;
1022 xx = xx - ww;
1023 }
1024 if (hh < 0)
1025 {
1026 hh = -hh;
1027 yy = yy - hh;
1028 }
1029
1030 m_graphicContext->DrawRoundedRectangle( xx,yy,ww,hh,radius);
1031}
1032
1033void wxGCDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1034{
1035 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
1036
1037 if ( m_logicalFunction != wxCOPY )
1038 return;
1039
a2d6d210
VZ
1040 wxDouble xx = LogicalToDeviceX(x);
1041 wxDouble yy = LogicalToDeviceY(y);
50581042 1042 wxDouble ww = m_signX * LogicalToDeviceXRel(width);
a2d6d210 1043 wxDouble hh = m_signY * LogicalToDeviceYRel(height);
50581042
SC
1044
1045 // CMB: draw nothing if transformed w or h is 0
1046 if (ww == 0 || hh == 0)
1047 return;
1048
1049 // CMB: handle -ve width and/or height
1050 if (ww < 0)
1051 {
1052 ww = -ww;
1053 xx = xx - ww;
1054 }
1055 if (hh < 0)
1056 {
1057 hh = -hh;
1058 yy = yy - hh;
1059 }
1060
1061 m_graphicContext->DrawEllipse(xx,yy,ww,hh);
1062}
1063
1064bool wxGCDC::CanDrawBitmap() const
1065{
1066 return true;
1067}
1068
1069bool wxGCDC::DoBlit(
f2ee37d5 1070 wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
0b1cc7bf 1071 wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool WXUNUSED(useMask),
f2ee37d5 1072 wxCoord xsrcMask, wxCoord ysrcMask )
50581042
SC
1073{
1074 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
1075 wxCHECK_MSG( source->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
1076
1077 if ( logical_func == wxNO_OP )
1078 return true;
1079
1080 if (xsrcMask == -1 && ysrcMask == -1)
1081 {
1082 xsrcMask = xsrc;
1083 ysrcMask = ysrc;
1084 }
1085
1086 wxCoord yysrc = source-> LogicalToDeviceY(ysrc);
1087 wxCoord xxsrc = source-> LogicalToDeviceX(xsrc);
1088 wxCoord wwsrc = source-> LogicalToDeviceXRel(width);
1089 wxCoord hhsrc = source-> LogicalToDeviceYRel(height);
1090
1091 wxCoord yydest = LogicalToDeviceY(ydest);
1092 wxCoord xxdest = LogicalToDeviceX(xdest);
1093 wxCoord wwdest = LogicalToDeviceXRel(width);
1094 wxCoord hhdest = LogicalToDeviceYRel(height);
1095
8ddf8e82 1096 wxMemoryDC* memdc = wxDynamicCast(source,wxMemoryDC);
50581042
SC
1097 if ( memdc && logical_func == wxCOPY )
1098 {
0b1cc7bf 1099 wxBitmap blit = memdc->GetSelectedBitmap();
50581042
SC
1100
1101 wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") );
1102
1103 wxCoord bmpwidth = blit.GetWidth();
1104 wxCoord bmpheight = blit.GetHeight();
1105
1106 if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc )
1107 {
1108 wwsrc = wxMin( wwsrc , bmpwidth - xxsrc );
1109 hhsrc = wxMin( hhsrc , bmpheight - yysrc );
1110 if ( wwsrc > 0 && hhsrc > 0 )
1111 {
1112 if ( xxsrc >= 0 && yysrc >= 0 )
1113 {
1114 wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc );
1115 // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
1116 blit = blit.GetSubBitmap( subrect );
1117 }
1118 else
1119 {
1120 // in this case we'd probably have to adjust the different coordinates, but
1121 // we have to find out proper contract first
1122 blit = wxNullBitmap;
1123 }
1124 }
1125 else
1126 {
1127 blit = wxNullBitmap;
1128 }
1129 }
1130
1131 if ( blit.Ok() )
1132 {
1133 m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest );
1134 }
50581042
SC
1135 }
1136 else
1137 {
7ed14752 1138 wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") );
50581042
SC
1139 return false;
1140 }
1141
f2ee37d5 1142 return true;
50581042
SC
1143}
1144
1145void wxGCDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
1146 double angle)
1147{
1148 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
1149
1150 if ( str.length() == 0 )
1151 return;
1152 if ( m_logicalFunction != wxCOPY )
1153 return;
1154
1155 int drawX = LogicalToDeviceX(x);
1156 int drawY = LogicalToDeviceY(y);
1157
1158 m_graphicContext->DrawText( str, drawX ,drawY , DegToRad(angle ));
1159}
1160
1161void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y)
1162{
1163 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
1164
1165 if ( str.length() == 0 )
1166 return;
1167 if ( m_logicalFunction != wxCOPY )
1168 return;
1169
1170 int drawX = LogicalToDeviceX(x);
1171 int drawY = LogicalToDeviceY(y);
1172
1173 m_graphicContext->DrawText( str, drawX ,drawY);
1174}
1175
1176bool wxGCDC::CanGetTextExtent() const
1177{
1178 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
1179
1180 return true;
1181}
1182
1183void wxGCDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
1184 wxCoord *descent, wxCoord *externalLeading ,
1185 wxFont *theFont ) const
1186{
1187 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
1188
50581042
SC
1189 if ( theFont )
1190 {
1191 m_graphicContext->SetFont( *theFont );
1192 }
1193
1194 wxDouble h , d , e , w;
1195
1196 m_graphicContext->GetTextExtent( str, &w, &h, &d, &e );
1197
1198 if ( height )
a2d6d210 1199 *height = DeviceToLogicalYRel((wxCoord)h);
50581042 1200 if ( descent )
a2d6d210 1201 *descent = DeviceToLogicalYRel((wxCoord)d);
50581042 1202 if ( externalLeading )
a2d6d210 1203 *externalLeading = DeviceToLogicalYRel((wxCoord)e);
50581042 1204 if ( width )
a2d6d210 1205 *width = DeviceToLogicalXRel((wxCoord)w);
50581042
SC
1206
1207 if ( theFont )
1208 {
1209 m_graphicContext->SetFont( m_font );
1210 }
1211}
1212
1213bool wxGCDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
1214{
1215 wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
1216 widths.Clear();
1217 widths.Add(0,text.Length());
1218 if ( text.IsEmpty() )
a2d6d210 1219 return true;
50581042 1220
a2d6d210 1221 wxArrayDouble widthsD;
50581042
SC
1222
1223 m_graphicContext->GetPartialTextExtents( text, widthsD );
1224 for ( size_t i = 0; i < widths.GetCount(); ++i )
a2d6d210 1225 widths[i] = DeviceToLogicalXRel((wxCoord)(widthsD[i] + 0.5));
50581042
SC
1226
1227 return true;
1228}
1229
1230wxCoord wxGCDC::GetCharWidth(void) const
1231{
1232 wxCoord width;
1233 DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
1234
1235 return width;
1236}
1237
1238wxCoord wxGCDC::GetCharHeight(void) const
1239{
1240 wxCoord height;
1241 DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
1242
1243 return height;
1244}
1245
1246void wxGCDC::Clear(void)
1247{
1248 wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") );
f2ee37d5 1249 // TODO better implementation / incorporate size info into wxGCDC or context
a2d6d210
VZ
1250 m_graphicContext->SetBrush( m_backgroundBrush );
1251 wxPen p = *wxTRANSPARENT_PEN;
1252 m_graphicContext->SetPen( p );
1253 DoDrawRectangle( 0, 0, 32000 , 32000 );
1254 m_graphicContext->SetPen( m_pen );
1255 m_graphicContext->SetBrush( m_brush );
50581042
SC
1256}
1257
1258void wxGCDC::DoGetSize(int *width, int *height) const
1259{
1260 *width = 1000;
1261 *height = 1000;
1262}
1263
1264void wxGCDC::DoGradientFillLinear(const wxRect& rect,
1265 const wxColour& initialColour,
1266 const wxColour& destColour,
1267 wxDirection nDirection )
1268{
a2d6d210
VZ
1269 wxPoint start;
1270 wxPoint end;
50581042
SC
1271 switch( nDirection)
1272 {
1273 case wxWEST :
1274 start = rect.GetRightBottom();
1275 start.x++;
1276 end = rect.GetLeftBottom();
a2d6d210 1277 break;
50581042
SC
1278 case wxEAST :
1279 start = rect.GetLeftBottom();
1280 end = rect.GetRightBottom();
1281 end.x++;
a2d6d210 1282 break;
50581042
SC
1283 case wxNORTH :
1284 start = rect.GetLeftBottom();
1285 start.y++;
1286 end = rect.GetLeftTop();
a2d6d210 1287 break;
50581042
SC
1288 case wxSOUTH :
1289 start = rect.GetLeftTop();
1290 end = rect.GetLeftBottom();
1291 end.y++;
a2d6d210
VZ
1292 break;
1293 default :
1294 break;
50581042
SC
1295 }
1296
1297 m_graphicContext->SetLinearGradientBrush(
1298 LogicalToDeviceX(start.x),LogicalToDeviceY(start.y),
1299 LogicalToDeviceX(end.x),LogicalToDeviceY(end.y), initialColour, destColour);
1300
a2d6d210
VZ
1301 wxDouble xx = LogicalToDeviceX(rect.x);
1302 wxDouble yy = LogicalToDeviceY(rect.y);
50581042 1303 wxDouble ww = m_signX * LogicalToDeviceXRel(rect.width);
a2d6d210 1304 wxDouble hh = m_signY * LogicalToDeviceYRel(rect.height);
50581042
SC
1305
1306 if (ww == 0 || hh == 0)
1307 return;
1308
1309 if (ww < 0)
1310 {
1311 ww = -ww;
1312 xx = xx - ww;
1313 }
1314 if (hh < 0)
1315 {
1316 hh = -hh;
1317 yy = yy - hh;
1318 }
1319
1320 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
1321 m_graphicContext->DrawRectangle(xx,yy,ww,hh);
1322 m_graphicContext->SetPen(m_pen);
1323}
1324
1325void wxGCDC::DoGradientFillConcentric(const wxRect& rect,
1326 const wxColour& initialColour,
1327 const wxColour& destColour,
1328 const wxPoint& circleCenter)
1329{
1330 //Radius
1331 wxInt32 cx = rect.GetWidth() / 2;
1332 wxInt32 cy = rect.GetHeight() / 2;
1333 wxInt32 nRadius;
1334 if (cx < cy)
1335 nRadius = cx;
1336 else
1337 nRadius = cy;
1338
a2d6d210
VZ
1339 wxDouble xx = LogicalToDeviceX(rect.x);
1340 wxDouble yy = LogicalToDeviceY(rect.y);
50581042 1341 wxDouble ww = m_signX * LogicalToDeviceXRel(rect.width);
a2d6d210 1342 wxDouble hh = m_signY * LogicalToDeviceYRel(rect.height);
50581042
SC
1343
1344 if (ww == 0 || hh == 0)
1345 return;
1346
1347 if (ww < 0)
1348 {
1349 ww = -ww;
1350 xx = xx - ww;
1351 }
1352 if (hh < 0)
1353 {
1354 hh = -hh;
1355 yy = yy - hh;
1356 }
1357
1358 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
a2d6d210 1359 m_graphicContext->SetBrush( wxBrush( destColour) );
50581042
SC
1360 m_graphicContext->DrawRectangle( xx,yy,ww,hh);
1361
1362 m_graphicContext->SetRadialGradientBrush(
1363 xx+LogicalToDeviceX(circleCenter.x),yy+LogicalToDeviceY(circleCenter.y),
1364 xx+LogicalToDeviceX(circleCenter.x),yy+LogicalToDeviceY(circleCenter.y),
1365 LogicalToDeviceXRel(nRadius),
1366 initialColour,destColour);
1367
1368 m_graphicContext->DrawRectangle( xx,yy,ww,hh);
1369 m_graphicContext->SetPen(m_pen);
1370}
1371
1372void wxGCDC::DoDrawCheckMark(wxCoord x, wxCoord y,
1373 wxCoord width, wxCoord height)
1374{
1375 wxDCBase::DoDrawCheckMark(x,y,width,height);
1376}
1377
9fd707a5 1378#endif // wxUSE_GRAPHICS_CONTEXT