]> git.saurik.com Git - wxWidgets.git/blame - src/common/dcgraph.cpp
Use C locale representation for floating point numbers in wxAny.
[wxWidgets.git] / src / common / dcgraph.cpp
CommitLineData
1b89a5cd 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/common/dcgraph.cpp
1b89a5cd
SC
3// Purpose: graphics context methods common to all platforms
4// Author: Stefan Csomor
5// Modified by:
6c0aace2 6// Created:
1b89a5cd
SC
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
888dde65 21#include "wx/dcgraph.h"
1b89a5cd
SC
22
23#ifndef WX_PRECOMP
24 #include "wx/icon.h"
38ae64e6 25 #include "wx/dcclient.h"
1b89a5cd 26 #include "wx/dcmemory.h"
fcaea2fa 27#endif
b02d4340 28
1b89a5cd
SC
29//-----------------------------------------------------------------------------
30// constants
31//-----------------------------------------------------------------------------
32
33static const double RAD2DEG = 180.0 / M_PI;
34
35//-----------------------------------------------------------------------------
36// Local functions
37//-----------------------------------------------------------------------------
38
39static inline double DegToRad(double deg)
40{
41 return (deg * M_PI) / 180.0;
42}
43
fec4e458 44static wxCompositionMode TranslateRasterOp(wxRasterOperationMode function)
bf02a7f9
SC
45{
46 switch ( function )
47 {
954c66fa
SC
48 case wxCOPY: // src
49 // since we are supporting alpha, _OVER is closer to the intention than _SOURCE
d13b34d3 50 // since the latter would overwrite even when alpha is not set to opaque
fec4e458
VZ
51 return wxCOMPOSITION_OVER;
52
bf02a7f9 53 case wxOR: // src OR dst
fec4e458
VZ
54 return wxCOMPOSITION_ADD;
55
bf02a7f9 56 case wxNO_OP: // dst
fec4e458
VZ
57 return wxCOMPOSITION_DEST; // ignore the source
58
bf02a7f9 59 case wxCLEAR: // 0
fec4e458
VZ
60 return wxCOMPOSITION_CLEAR;// clear dst
61
bf02a7f9 62 case wxXOR: // src XOR dst
fec4e458 63 return wxCOMPOSITION_XOR;
03647350 64
bf02a7f9
SC
65 case wxAND: // src AND dst
66 case wxAND_INVERT: // (NOT src) AND dst
67 case wxAND_REVERSE:// src AND (NOT dst)
68 case wxEQUIV: // (NOT src) XOR dst
69 case wxINVERT: // NOT dst
70 case wxNAND: // (NOT src) OR (NOT dst)
71 case wxNOR: // (NOT src) AND (NOT dst)
72 case wxOR_INVERT: // (NOT src) OR dst
73 case wxOR_REVERSE: // src OR (NOT dst)
74 case wxSET: // 1
75 case wxSRC_INVERT: // NOT src
fec4e458 76 break;
bf02a7f9 77 }
fec4e458
VZ
78
79 return wxCOMPOSITION_INVALID;
bf02a7f9
SC
80}
81
1b89a5cd
SC
82//-----------------------------------------------------------------------------
83// wxDC bridge class
84//-----------------------------------------------------------------------------
85
1b89a5cd 86IMPLEMENT_DYNAMIC_CLASS(wxGCDC, wxDC)
888dde65 87
7b1a66bb
RR
88wxGCDC::wxGCDC(const wxWindowDC& dc) :
89 wxDC( new wxGCDCImpl( this, dc ) )
888dde65 90{
888dde65
RR
91}
92
7b1a66bb
RR
93wxGCDC::wxGCDC( const wxMemoryDC& dc) :
94 wxDC( new wxGCDCImpl( this, dc ) )
888dde65 95{
888dde65 96}
1b89a5cd 97
6d0d8455 98#if wxUSE_PRINTING_ARCHITECTURE
b25c34aa
RR
99wxGCDC::wxGCDC( const wxPrinterDC& dc) :
100 wxDC( new wxGCDCImpl( this, dc ) )
101{
102}
6d0d8455 103#endif
b25c34aa 104
2d770c4f
VZ
105#if defined(__WXMSW__) && wxUSE_ENH_METAFILE
106wxGCDC::wxGCDC(const wxEnhMetaFileDC& dc)
107 : wxDC(new wxGCDCImpl(this, dc))
108{
109}
110#endif
111
932d0768
RD
112wxGCDC::wxGCDC(wxGraphicsContext* context) :
113 wxDC( new wxGCDCImpl( this ) )
114{
115 SetGraphicsContext(context);
116}
117
7b1a66bb
RR
118wxGCDC::wxGCDC() :
119 wxDC( new wxGCDCImpl( this ) )
1b89a5cd 120{
888dde65
RR
121}
122
9412ee9a
SC
123wxGCDC::~wxGCDC()
124{
125}
126
6c0e710f 127wxGraphicsContext* wxGCDC::GetGraphicsContext() const
888dde65
RR
128{
129 if (!m_pimpl) return NULL;
130 wxGCDCImpl *gc_impl = (wxGCDCImpl*) m_pimpl;
131 return gc_impl->GetGraphicsContext();
1b89a5cd
SC
132}
133
134void wxGCDC::SetGraphicsContext( wxGraphicsContext* ctx )
888dde65
RR
135{
136 if (!m_pimpl) return;
137 wxGCDCImpl *gc_impl = (wxGCDCImpl*) m_pimpl;
138 gc_impl->SetGraphicsContext( ctx );
139}
140
141IMPLEMENT_ABSTRACT_CLASS(wxGCDCImpl, wxDCImpl)
142
143wxGCDCImpl::wxGCDCImpl( wxDC *owner ) :
144 wxDCImpl( owner )
145{
e7042ce7 146 Init(wxGraphicsContext::Create());
888dde65
RR
147}
148
149void wxGCDCImpl::SetGraphicsContext( wxGraphicsContext* ctx )
6c0aace2 150{
1b89a5cd
SC
151 delete m_graphicContext;
152 m_graphicContext = ctx;
914fd3f1
SC
153 if ( m_graphicContext )
154 {
155 m_matrixOriginal = m_graphicContext->GetTransform();
156 m_ok = true;
fd791571
SC
157 // apply the stored transformations to the passed in context
158 ComputeScaleAndOrigin();
ad667945
SC
159 m_graphicContext->SetFont( m_font , m_textForegroundColour );
160 m_graphicContext->SetPen( m_pen );
161 m_graphicContext->SetBrush( m_brush);
914fd3f1 162 }
1b89a5cd
SC
163}
164
888dde65
RR
165wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxWindowDC& dc ) :
166 wxDCImpl( owner )
1b89a5cd 167{
e7042ce7 168 Init(wxGraphicsContext::Create(dc));
7b98cf02 169 m_window = dc.GetWindow();
1b89a5cd
SC
170}
171
888dde65
RR
172wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxMemoryDC& dc ) :
173 wxDCImpl( owner )
773ccc31 174{
e7042ce7 175 Init(wxGraphicsContext::Create(dc));
773ccc31 176}
773ccc31 177
6d0d8455 178#if wxUSE_PRINTING_ARCHITECTURE
b25c34aa
RR
179wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxPrinterDC& dc ) :
180 wxDCImpl( owner )
181{
e7042ce7 182 Init(wxGraphicsContext::Create(dc));
b25c34aa 183}
6d0d8455 184#endif
b25c34aa 185
2d770c4f
VZ
186#if defined(__WXMSW__) && wxUSE_ENH_METAFILE
187wxGCDCImpl::wxGCDCImpl(wxDC *owner, const wxEnhMetaFileDC& dc)
188 : wxDCImpl(owner)
189{
e7042ce7 190 Init(wxGraphicsContext::Create(dc));
2d770c4f
VZ
191}
192#endif
193
f30b9eed
PC
194wxGCDCImpl::wxGCDCImpl(wxDC* owner, int)
195 : wxDCImpl(owner)
196{
197 // derived class will set a context
198 Init(NULL);
199}
200
e7042ce7 201void wxGCDCImpl::Init(wxGraphicsContext* ctx)
1b89a5cd
SC
202{
203 m_ok = false;
204 m_colour = true;
205 m_mm_to_pix_x = mm2pt;
206 m_mm_to_pix_y = mm2pt;
207
208 m_pen = *wxBLACK_PEN;
209 m_font = *wxNORMAL_FONT;
210 m_brush = *wxWHITE_BRUSH;
211
e7042ce7
PC
212 m_graphicContext = NULL;
213 if (ctx)
214 SetGraphicsContext(ctx);
215
4280b879 216 m_logicalFunctionSupported = true;
1b89a5cd
SC
217}
218
888dde65 219wxGCDCImpl::~wxGCDCImpl()
1b89a5cd
SC
220{
221 delete m_graphicContext;
222}
223
08de4403
VZ
224void wxGCDCImpl::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y,
225 bool useMask )
1b89a5cd 226{
888dde65
RR
227 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
228 wxCHECK_RET( bmp.IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
1b89a5cd 229
08de4403
VZ
230 int w = bmp.GetWidth();
231 int h = bmp.GetHeight();
f889bdb3
SC
232 if ( bmp.GetDepth() == 1 )
233 {
234 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
235 m_graphicContext->SetBrush( wxBrush( m_textBackgroundColour , wxSOLID ) );
08de4403 236 m_graphicContext->DrawRectangle( x, y, w, h );
f889bdb3 237 m_graphicContext->SetBrush( wxBrush( m_textForegroundColour , wxSOLID ) );
08de4403 238 m_graphicContext->DrawBitmap( bmp, x, y, w, h );
f889bdb3
SC
239 m_graphicContext->SetBrush( m_graphicContext->CreateBrush(m_brush));
240 m_graphicContext->SetPen( m_graphicContext->CreatePen(m_pen));
241 }
08de4403
VZ
242 else // not a monochrome bitmap, handle it normally
243 {
244 // make a copy in case we need to remove its mask, if we don't modify
245 // it the copy is cheap as bitmaps are reference-counted
246 wxBitmap bmpCopy(bmp);
247 if ( !useMask && bmp.GetMask() )
248 bmpCopy.SetMask(NULL);
249
250 m_graphicContext->DrawBitmap( bmpCopy, x, y, w, h );
251 }
1b89a5cd
SC
252}
253
888dde65 254void wxGCDCImpl::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
1b89a5cd 255{
888dde65
RR
256 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
257 wxCHECK_RET( icon.IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
1b89a5cd 258
1b89a5cd
SC
259 wxCoord w = icon.GetWidth();
260 wxCoord h = icon.GetHeight();
1b89a5cd 261
0ebd9515 262 m_graphicContext->DrawIcon( icon , x, y, w, h );
1b89a5cd
SC
263}
264
b02d4340 265bool wxGCDCImpl::StartDoc( const wxString& WXUNUSED(message) )
fcaea2fa 266{
26dfebbd 267 return true;
fcaea2fa
SC
268}
269
b02d4340 270void wxGCDCImpl::EndDoc()
fcaea2fa
SC
271{
272}
273
888dde65 274void wxGCDCImpl::StartPage()
fcaea2fa
SC
275{
276}
277
b02d4340 278void wxGCDCImpl::EndPage()
fcaea2fa
SC
279{
280}
b02d4340 281
888dde65 282void wxGCDCImpl::Flush()
fcaea2fa 283{
50211394 284 m_graphicContext->Flush();
fcaea2fa
SC
285}
286
888dde65 287void wxGCDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
1b89a5cd 288{
888dde65 289 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
1b89a5cd 290
0ebd9515 291 m_graphicContext->Clip( x, y, w, h );
1b89a5cd 292
332afcdb 293 wxDCImpl::DoSetClippingRegion(x, y, w, h);
1b89a5cd
SC
294}
295
fdaad94e 296void wxGCDCImpl::DoSetDeviceClippingRegion( const wxRegion &region )
1b89a5cd 297{
4bae004c 298 // region is in device coordinates
fdaad94e 299 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetDeviceClippingRegion - invalid DC") );
1b89a5cd
SC
300
301 if (region.Empty())
302 {
fcaea2fa 303 //DestroyClippingRegion();
1b89a5cd
SC
304 return;
305 }
306
4bae004c 307 wxRegion logRegion( region );
1b89a5cd 308 wxCoord x, y, w, h;
0ebd9515 309
4bae004c
SC
310 logRegion.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
311 logRegion.GetBox( x, y, w, h );
312
313 m_graphicContext->Clip( logRegion );
0ebd9515 314 if ( m_clipping )
1b89a5cd 315 {
0ebd9515
SC
316 m_clipX1 = wxMax( m_clipX1, x );
317 m_clipY1 = wxMax( m_clipY1, y );
318 m_clipX2 = wxMin( m_clipX2, (x + w) );
319 m_clipY2 = wxMin( m_clipY2, (y + h) );
1b89a5cd
SC
320 }
321 else
322 {
0ebd9515 323 m_clipping = true;
1b89a5cd 324
0ebd9515
SC
325 m_clipX1 = x;
326 m_clipY1 = y;
327 m_clipX2 = x + w;
328 m_clipY2 = y + h;
1b89a5cd
SC
329 }
330}
331
888dde65 332void wxGCDCImpl::DestroyClippingRegion()
1b89a5cd
SC
333{
334 m_graphicContext->ResetClip();
cb6e26b8 335 // currently the clip eg of a window extends to the area between the scrollbars
4c51a665 336 // so we must explicitly make sure it only covers the area we want it to draw
cb6e26b8 337 int width, height ;
888dde65 338 GetOwner()->GetSize( &width , &height ) ;
fcaea2fa 339 m_graphicContext->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , DeviceToLogicalXRel(width), DeviceToLogicalYRel(height) );
b02d4340 340
1b89a5cd
SC
341 m_graphicContext->SetPen( m_pen );
342 m_graphicContext->SetBrush( m_brush );
343
344 m_clipping = false;
345}
346
888dde65 347void wxGCDCImpl::DoGetSizeMM( int* width, int* height ) const
1b89a5cd
SC
348{
349 int w = 0, h = 0;
350
888dde65 351 GetOwner()->GetSize( &w, &h );
1b89a5cd
SC
352 if (width)
353 *width = long( double(w) / (m_scaleX * m_mm_to_pix_x) );
354 if (height)
355 *height = long( double(h) / (m_scaleY * m_mm_to_pix_y) );
356}
357
888dde65 358void wxGCDCImpl::SetTextForeground( const wxColour &col )
1b89a5cd 359{
888dde65 360 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
1b89a5cd 361
9c17ca3f
SC
362 // don't set m_textForegroundColour to an invalid colour as we'd crash
363 // later then (we use m_textForegroundColour.GetColor() without checking
364 // in a few places)
38274d1d 365 if ( col.IsOk() )
1b89a5cd
SC
366 {
367 m_textForegroundColour = col;
368 m_graphicContext->SetFont( m_font, m_textForegroundColour );
369 }
370}
371
888dde65 372void wxGCDCImpl::SetTextBackground( const wxColour &col )
1b89a5cd 373{
888dde65 374 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
1b89a5cd
SC
375
376 m_textBackgroundColour = col;
377}
378
888dde65 379wxSize wxGCDCImpl::GetPPI() const
1b89a5cd
SC
380{
381 return wxSize(72, 72);
382}
383
888dde65 384int wxGCDCImpl::GetDepth() const
1b89a5cd
SC
385{
386 return 32;
387}
388
888dde65 389void wxGCDCImpl::ComputeScaleAndOrigin()
b02d4340 390{
2dedef25 391 wxDCImpl::ComputeScaleAndOrigin();
1b89a5cd 392
fd791571
SC
393 if ( m_graphicContext )
394 {
395 m_matrixCurrent = m_graphicContext->CreateMatrix();
08de4403 396
fd791571 397 // the logical origin sets the origin to have new coordinates
08de4403 398 m_matrixCurrent.Translate( m_deviceOriginX - m_logicalOriginX * m_signX * m_scaleX,
d225267e 399 m_deviceOriginY-m_logicalOriginY * m_signY * m_scaleY);
08de4403 400
d225267e 401 m_matrixCurrent.Scale( m_scaleX * m_signX, m_scaleY * m_signY );
08de4403 402
fd791571
SC
403 m_graphicContext->SetTransform( m_matrixOriginal );
404 m_graphicContext->ConcatTransform( m_matrixCurrent );
405 }
1b89a5cd
SC
406}
407
9eefb5c1
RD
408void* wxGCDCImpl::GetHandle() const
409{
410 void* cgctx = NULL;
411 wxGraphicsContext* gc = GetGraphicsContext();
412 if (gc) {
413 cgctx = gc->GetNativeContext();
414 }
415 return cgctx;
416}
417
888dde65 418void wxGCDCImpl::SetPalette( const wxPalette& WXUNUSED(palette) )
1b89a5cd
SC
419{
420
421}
422
888dde65 423void wxGCDCImpl::SetBackgroundMode( int mode )
1b89a5cd
SC
424{
425 m_backgroundMode = mode;
426}
427
888dde65 428void wxGCDCImpl::SetFont( const wxFont &font )
1b89a5cd
SC
429{
430 m_font = font;
431 if ( m_graphicContext )
432 {
8bcf695e 433 m_graphicContext->SetFont(font, m_textForegroundColour);
1b89a5cd
SC
434 }
435}
436
888dde65 437void wxGCDCImpl::SetPen( const wxPen &pen )
1b89a5cd 438{
1b89a5cd
SC
439 m_pen = pen;
440 if ( m_graphicContext )
441 {
0ebd9515 442 m_graphicContext->SetPen( m_pen );
1b89a5cd
SC
443 }
444}
445
888dde65 446void wxGCDCImpl::SetBrush( const wxBrush &brush )
1b89a5cd 447{
1b89a5cd
SC
448 m_brush = brush;
449 if ( m_graphicContext )
450 {
0ebd9515 451 m_graphicContext->SetBrush( m_brush );
1b89a5cd
SC
452 }
453}
b02d4340 454
888dde65 455void wxGCDCImpl::SetBackground( const wxBrush &brush )
1b89a5cd 456{
1b89a5cd 457 m_backgroundBrush = brush;
888dde65 458 if (!m_backgroundBrush.IsOk())
1b89a5cd
SC
459 return;
460}
461
89efaf2b 462void wxGCDCImpl::SetLogicalFunction( wxRasterOperationMode function )
1b89a5cd 463{
1b89a5cd 464 m_logicalFunction = function;
03647350 465
fec4e458
VZ
466 wxCompositionMode mode = TranslateRasterOp( function );
467 m_logicalFunctionSupported = mode != wxCOMPOSITION_INVALID;
bf02a7f9
SC
468 if (m_logicalFunctionSupported)
469 m_logicalFunctionSupported = m_graphicContext->SetCompositionMode(mode);
03647350 470
584be856 471 if ( function == wxXOR )
bf02a7f9 472 m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE);
1b89a5cd 473 else
bf02a7f9 474 m_graphicContext->SetAntialiasMode(wxANTIALIAS_DEFAULT);
1b89a5cd
SC
475}
476
888dde65 477bool wxGCDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
03647350 478 const wxColour& WXUNUSED(col),
89efaf2b 479 wxFloodFillStyle WXUNUSED(style))
1b89a5cd
SC
480{
481 return false;
482}
483
888dde65 484bool wxGCDCImpl::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const
1b89a5cd
SC
485{
486 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
487 return false;
488}
489
888dde65 490void wxGCDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
1b89a5cd 491{
888dde65 492 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
1b89a5cd 493
4280b879 494 if ( !m_logicalFunctionSupported )
1b89a5cd 495 return;
1b89a5cd 496
0ebd9515 497 m_graphicContext->StrokeLine(x1,y1,x2,y2);
1b89a5cd
SC
498
499 CalcBoundingBox(x1, y1);
500 CalcBoundingBox(x2, y2);
501}
502
888dde65 503void wxGCDCImpl::DoCrossHair( wxCoord x, wxCoord y )
1b89a5cd 504{
888dde65 505 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
1b89a5cd 506
4280b879 507 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
508 return;
509
510 int w = 0, h = 0;
511
888dde65 512 GetOwner()->GetSize( &w, &h );
1b89a5cd 513
0ebd9515
SC
514 m_graphicContext->StrokeLine(0,y,w,y);
515 m_graphicContext->StrokeLine(x,0,x,h);
1b89a5cd 516
0ebd9515
SC
517 CalcBoundingBox(0, 0);
518 CalcBoundingBox(0+w, 0+h);
1b89a5cd
SC
519}
520
888dde65 521void wxGCDCImpl::DoDrawArc( wxCoord x1, wxCoord y1,
1b89a5cd
SC
522 wxCoord x2, wxCoord y2,
523 wxCoord xc, wxCoord yc )
524{
888dde65 525 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
1b89a5cd 526
4280b879 527 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
528 return;
529
0ebd9515
SC
530 double dx = x1 - xc;
531 double dy = y1 - yc;
1b89a5cd
SC
532 double radius = sqrt((double)(dx * dx + dy * dy));
533 wxCoord rad = (wxCoord)radius;
534 double sa, ea;
0ebd9515 535 if (x1 == x2 && y1 == y2)
1b89a5cd
SC
536 {
537 sa = 0.0;
538 ea = 360.0;
539 }
540 else if (radius == 0.0)
541 {
542 sa = ea = 0.0;
543 }
544 else
545 {
0ebd9515
SC
546 sa = (x1 - xc == 0) ?
547 (y1 - yc < 0) ? 90.0 : -90.0 :
548 -atan2(double(y1 - yc), double(x1 - xc)) * RAD2DEG;
549 ea = (x2 - xc == 0) ?
550 (y2 - yc < 0) ? 90.0 : -90.0 :
551 -atan2(double(y2 - yc), double(x2 - xc)) * RAD2DEG;
1b89a5cd
SC
552 }
553
554 bool fill = m_brush.GetStyle() != wxTRANSPARENT;
555
a4e73390 556 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd 557 if ( fill && ((x1!=x2)||(y1!=y2)) )
0ebd9515 558 path.MoveToPoint( xc, yc );
4bae004c
SC
559 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
560 // get clockwise angles
561 path.AddArc( xc, yc , rad , DegToRad(-sa) , DegToRad(-ea), false );
1b89a5cd 562 if ( fill && ((x1!=x2)||(y1!=y2)) )
0ebd9515 563 path.AddLineToPoint( xc, yc );
1b89a5cd 564 m_graphicContext->DrawPath(path);
1b89a5cd
SC
565}
566
888dde65 567void wxGCDCImpl::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
1b89a5cd
SC
568 double sa, double ea )
569{
888dde65 570 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
1b89a5cd 571
4280b879 572 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
573 return;
574
1b89a5cd 575 m_graphicContext->PushState();
d9485f89 576 m_graphicContext->Translate(x+w/2.0,y+h/2.0);
0ebd9515 577 wxDouble factor = ((wxDouble) w) / h;
1b89a5cd 578 m_graphicContext->Scale( factor , 1.0);
d9485f89 579
1b89a5cd
SC
580 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
581 // get clockwise angles
fcaea2fa
SC
582 if ( m_brush.GetStyle() != wxTRANSPARENT )
583 {
584 wxGraphicsPath path = m_graphicContext->CreatePath();
585 path.MoveToPoint( 0, 0 );
47c1bb95 586 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
fcaea2fa
SC
587 path.AddLineToPoint( 0, 0 );
588 m_graphicContext->FillPath( path );
589
590 path = m_graphicContext->CreatePath();
591 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
fcaea2fa
SC
592 m_graphicContext->StrokePath( path );
593 }
594 else
595 {
596 wxGraphicsPath path = m_graphicContext->CreatePath();
47c1bb95
SC
597 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
598 m_graphicContext->DrawPath( path );
fcaea2fa
SC
599 }
600
1b89a5cd 601 m_graphicContext->PopState();
1b89a5cd
SC
602}
603
888dde65 604void wxGCDCImpl::DoDrawPoint( wxCoord x, wxCoord y )
1b89a5cd 605{
888dde65 606 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
1b89a5cd
SC
607
608 DoDrawLine( x , y , x + 1 , y + 1 );
609}
610
4787c92d 611void wxGCDCImpl::DoDrawLines(int n, const wxPoint points[],
1b89a5cd
SC
612 wxCoord xoffset, wxCoord yoffset)
613{
888dde65 614 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
1b89a5cd 615
4280b879 616 if ( !m_logicalFunctionSupported )
1b89a5cd 617 return;
1b89a5cd
SC
618
619 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n];
620 for( int i = 0; i < n; ++i)
621 {
0ebd9515
SC
622 pointsD[i].m_x = points[i].x + xoffset;
623 pointsD[i].m_y = points[i].y + yoffset;
1b89a5cd
SC
624 }
625
626 m_graphicContext->StrokeLines( n , pointsD);
627 delete[] pointsD;
628}
629
630#if wxUSE_SPLINES
888dde65 631void wxGCDCImpl::DoDrawSpline(const wxPointList *points)
1b89a5cd 632{
888dde65 633 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
1b89a5cd 634
4280b879 635 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
636 return;
637
a4e73390 638 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd 639
b0d7707b 640 wxPointList::compatibility_iterator node = points->GetFirst();
cb98e78b 641 if ( !node )
1b89a5cd
SC
642 // empty list
643 return;
644
4787c92d 645 const wxPoint *p = node->GetData();
1b89a5cd
SC
646
647 wxCoord x1 = p->x;
648 wxCoord y1 = p->y;
649
650 node = node->GetNext();
b0d7707b 651 p = node->GetData();
1b89a5cd
SC
652
653 wxCoord x2 = p->x;
654 wxCoord y2 = p->y;
655 wxCoord cx1 = ( x1 + x2 ) / 2;
656 wxCoord cy1 = ( y1 + y2 ) / 2;
657
0ebd9515
SC
658 path.MoveToPoint( x1 , y1 );
659 path.AddLineToPoint( cx1 , cy1 );
01871bf6 660#if !wxUSE_STD_CONTAINERS
1b89a5cd
SC
661
662 while ((node = node->GetNext()) != NULL)
663#else
664
665 while ((node = node->GetNext()))
01871bf6 666#endif // !wxUSE_STD_CONTAINERS
1b89a5cd
SC
667
668 {
b0d7707b 669 p = node->GetData();
1b89a5cd
SC
670 x1 = x2;
671 y1 = y2;
672 x2 = p->x;
673 y2 = p->y;
674 wxCoord cx4 = (x1 + x2) / 2;
675 wxCoord cy4 = (y1 + y2) / 2;
676
0ebd9515 677 path.AddQuadCurveToPoint(x1 , y1 ,cx4 , cy4 );
1b89a5cd
SC
678
679 cx1 = cx4;
680 cy1 = cy4;
681 }
682
0ebd9515 683 path.AddLineToPoint( x2 , y2 );
1b89a5cd
SC
684
685 m_graphicContext->StrokePath( path );
1b89a5cd
SC
686}
687#endif // wxUSE_SPLINES
688
4787c92d 689void wxGCDCImpl::DoDrawPolygon( int n, const wxPoint points[],
89efaf2b
FM
690 wxCoord xoffset, wxCoord yoffset,
691 wxPolygonFillMode fillStyle )
1b89a5cd 692{
888dde65 693 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
1b89a5cd
SC
694
695 if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) )
696 return;
4280b879 697 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
698 return;
699
700 bool closeIt = false;
701 if (points[n-1] != points[0])
702 closeIt = true;
703
704 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)];
705 for( int i = 0; i < n; ++i)
706 {
0ebd9515
SC
707 pointsD[i].m_x = points[i].x + xoffset;
708 pointsD[i].m_y = points[i].y + yoffset;
1b89a5cd
SC
709 }
710 if ( closeIt )
711 pointsD[n] = pointsD[0];
712
713 m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle);
714 delete[] pointsD;
715}
716
888dde65 717void wxGCDCImpl::DoDrawPolyPolygon(int n,
4787c92d
PC
718 const int count[],
719 const wxPoint points[],
1b89a5cd
SC
720 wxCoord xoffset,
721 wxCoord yoffset,
89efaf2b 722 wxPolygonFillMode fillStyle)
1b89a5cd
SC
723{
724 wxASSERT(n > 1);
a4e73390 725 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd
SC
726
727 int i = 0;
728 for ( int j = 0; j < n; ++j)
729 {
730 wxPoint start = points[i];
0ebd9515 731 path.MoveToPoint( start.x+ xoffset, start.y+ yoffset);
1b89a5cd
SC
732 ++i;
733 int l = count[j];
734 for ( int k = 1; k < l; ++k)
735 {
0ebd9515 736 path.AddLineToPoint( points[i].x+ xoffset, points[i].y+ yoffset);
1b89a5cd
SC
737 ++i;
738 }
739 // close the polygon
740 if ( start != points[i-1])
0ebd9515 741 path.AddLineToPoint( start.x+ xoffset, start.y+ yoffset);
1b89a5cd
SC
742 }
743 m_graphicContext->DrawPath( path , fillStyle);
1b89a5cd
SC
744}
745
888dde65 746void wxGCDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
1b89a5cd 747{
888dde65 748 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
1b89a5cd 749
4280b879 750 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
751 return;
752
1b89a5cd 753 // CMB: draw nothing if transformed w or h is 0
0ebd9515 754 if (w == 0 || h == 0)
1b89a5cd
SC
755 return;
756
5ebfdf41
SC
757 if ( m_graphicContext->ShouldOffset() )
758 {
759 // if we are offsetting the entire rectangle is moved 0.5, so the
760 // border line gets off by 1
0ebd9515
SC
761 w -= 1;
762 h -= 1;
5ebfdf41 763 }
0ebd9515 764 m_graphicContext->DrawRectangle(x,y,w,h);
1b89a5cd
SC
765}
766
888dde65 767void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
0ebd9515 768 wxCoord w, wxCoord h,
1b89a5cd
SC
769 double radius)
770{
888dde65 771 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1b89a5cd 772
4280b879 773 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
774 return;
775
776 if (radius < 0.0)
0ebd9515 777 radius = - radius * ((w < h) ? w : h);
1b89a5cd
SC
778
779 // CMB: draw nothing if transformed w or h is 0
0ebd9515 780 if (w == 0 || h == 0)
1b89a5cd
SC
781 return;
782
d9485f89
RD
783 if ( m_graphicContext->ShouldOffset() )
784 {
785 // if we are offsetting the entire rectangle is moved 0.5, so the
786 // border line gets off by 1
787 w -= 1;
788 h -= 1;
789 }
0ebd9515 790 m_graphicContext->DrawRoundedRectangle( x,y,w,h,radius);
1b89a5cd
SC
791}
792
888dde65 793void wxGCDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
1b89a5cd 794{
888dde65 795 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
1b89a5cd 796
4280b879 797 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
798 return;
799
d9485f89
RD
800 if ( m_graphicContext->ShouldOffset() )
801 {
802 // if we are offsetting the entire rectangle is moved 0.5, so the
803 // border line gets off by 1
804 w -= 1;
805 h -= 1;
806 }
0ebd9515 807 m_graphicContext->DrawEllipse(x,y,w,h);
1b89a5cd
SC
808}
809
888dde65 810bool wxGCDCImpl::CanDrawBitmap() const
1b89a5cd
SC
811{
812 return true;
813}
814
888dde65 815bool wxGCDCImpl::DoBlit(
1b89a5cd 816 wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
03647350 817 wxDC *source, wxCoord xsrc, wxCoord ysrc,
89efaf2b 818 wxRasterOperationMode logical_func , bool useMask,
1b89a5cd
SC
819 wxCoord xsrcMask, wxCoord ysrcMask )
820{
e3b81044
VZ
821 return DoStretchBlit( xdest, ydest, width, height,
822 source, xsrc, ysrc, width, height, logical_func, useMask,
823 xsrcMask,ysrcMask );
824}
825
888dde65 826bool wxGCDCImpl::DoStretchBlit(
e3b81044
VZ
827 wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight,
828 wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight,
89efaf2b 829 wxRasterOperationMode logical_func , bool useMask,
e3b81044
VZ
830 wxCoord xsrcMask, wxCoord ysrcMask )
831{
888dde65
RR
832 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
833 wxCHECK_MSG( source->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
6c0aace2 834
1b89a5cd
SC
835 if ( logical_func == wxNO_OP )
836 return true;
03647350 837
fec4e458
VZ
838 wxCompositionMode mode = TranslateRasterOp(logical_func);
839 if ( mode == wxCOMPOSITION_INVALID )
c64c9cd3 840 {
bf02a7f9 841 wxFAIL_MSG( wxT("Blitting is not supported with this logical operation.") );
c64c9cd3
KO
842 return false;
843 }
1b89a5cd 844
d0f93bc7
PC
845 wxRect subrect(source->LogicalToDeviceX(xsrc),
846 source->LogicalToDeviceY(ysrc),
847 source->LogicalToDeviceXRel(srcWidth),
848 source->LogicalToDeviceYRel(srcHeight));
be88fea9 849 const wxRect subrectOrig = subrect;
d0f93bc7
PC
850 // clip the subrect down to the size of the source DC
851 wxRect clip;
852 source->GetSize(&clip.width, &clip.height);
853 subrect.Intersect(clip);
854 if (subrect.width == 0)
855 return true;
856
bf02a7f9 857 bool retval = true;
03647350 858
bf02a7f9
SC
859 wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
860 if (m_graphicContext->SetCompositionMode(mode))
1b89a5cd 861 {
bf02a7f9
SC
862 wxAntialiasMode formerAa = m_graphicContext->GetAntialiasMode();
863 if (mode == wxCOMPOSITION_XOR)
864 {
865 m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE);
866 }
03647350 867
bf02a7f9
SC
868 if (xsrcMask == -1 && ysrcMask == -1)
869 {
870 xsrcMask = xsrc;
871 ysrcMask = ysrc;
872 }
1b89a5cd 873
bf02a7f9 874 wxBitmap blit = source->GetAsBitmap( &subrect );
6c0aace2 875
bf02a7f9
SC
876 if ( blit.IsOk() )
877 {
878 if ( !useMask && blit.GetMask() )
879 blit.SetMask(NULL);
08de4403 880
be88fea9
PC
881 double x = xdest;
882 double y = ydest;
883 double w = dstWidth;
884 double h = dstHeight;
885 // adjust dest rect if source rect is clipped
886 if (subrect.width != subrectOrig.width || subrect.height != subrectOrig.height)
887 {
888 x += (subrect.x - subrectOrig.x) / double(subrectOrig.width) * dstWidth;
889 y += (subrect.y - subrectOrig.y) / double(subrectOrig.height) * dstHeight;
890 w *= double(subrect.width) / subrectOrig.width;
891 h *= double(subrect.height) / subrectOrig.height;
892 }
893 m_graphicContext->DrawBitmap(blit, x, y, w, h);
bf02a7f9
SC
894 }
895 else
896 {
897 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
898 retval = false;
899 }
03647350 900
bf02a7f9
SC
901 if (mode == wxCOMPOSITION_XOR)
902 {
903 m_graphicContext->SetAntialiasMode(formerAa);
904 }
1b89a5cd 905 }
bf02a7f9
SC
906 // reset composition
907 m_graphicContext->SetCompositionMode(formerMode);
1b89a5cd 908
bf02a7f9 909 return retval;
1b89a5cd
SC
910}
911
888dde65 912void wxGCDCImpl::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
1b89a5cd
SC
913 double angle)
914{
888dde65 915 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
1b89a5cd 916
6636ef8d 917 if ( str.empty() )
1b89a5cd 918 return;
4280b879 919 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
920 return;
921
068eb463
SC
922 if ( m_backgroundMode == wxTRANSPARENT )
923 m_graphicContext->DrawText( str, x ,y , DegToRad(angle ));
924 else
925 m_graphicContext->DrawText( str, x ,y , DegToRad(angle ), m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) );
1b89a5cd
SC
926}
927
888dde65 928void wxGCDCImpl::DoDrawText(const wxString& str, wxCoord x, wxCoord y)
1b89a5cd 929{
a6afde63
SC
930 // For compatibility with other ports (notably wxGTK) and because it's
931 // genuinely useful, we allow passing multiline strings to DrawText().
932 // However there is no native OSX function to draw them directly so we
933 // instead reuse the generic DrawLabel() method to render them. Of course,
934 // DrawLabel() itself will call back to us but with single line strings
935 // only so there won't be any infinite recursion here.
936 if ( str.find('\n') != wxString::npos )
937 {
938 GetOwner()->DrawLabel(str, wxRect(x, y, 0, 0));
939 return;
940 }
941
08de4403 942 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawText - invalid DC") );
1b89a5cd 943
6636ef8d 944 if ( str.empty() )
1b89a5cd 945 return;
4280b879
SC
946
947 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
948 return;
949
068eb463
SC
950 if ( m_backgroundMode == wxTRANSPARENT )
951 m_graphicContext->DrawText( str, x ,y);
952 else
953 m_graphicContext->DrawText( str, x ,y , m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) );
1b89a5cd
SC
954}
955
888dde65 956bool wxGCDCImpl::CanGetTextExtent() const
1b89a5cd 957{
888dde65 958 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
1b89a5cd
SC
959
960 return true;
961}
962
888dde65 963void wxGCDCImpl::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
1b89a5cd 964 wxCoord *descent, wxCoord *externalLeading ,
c94f845b 965 const wxFont *theFont ) const
1b89a5cd 966{
d9edff06 967 wxCHECK_RET( m_graphicContext, wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
1b89a5cd
SC
968
969 if ( theFont )
970 {
971 m_graphicContext->SetFont( *theFont, m_textForegroundColour );
972 }
973
974 wxDouble h , d , e , w;
975
976 m_graphicContext->GetTextExtent( str, &w, &h, &d, &e );
977
978 if ( height )
fcaea2fa 979 *height = (wxCoord)(h+0.5);
1b89a5cd 980 if ( descent )
fcaea2fa 981 *descent = (wxCoord)(d+0.5);
1b89a5cd 982 if ( externalLeading )
fcaea2fa 983 *externalLeading = (wxCoord)(e+0.5);
1b89a5cd 984 if ( width )
fcaea2fa 985 *width = (wxCoord)(w+0.5);
1b89a5cd
SC
986
987 if ( theFont )
988 {
989 m_graphicContext->SetFont( m_font, m_textForegroundColour );
990 }
991}
992
888dde65 993bool wxGCDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
1b89a5cd 994{
d9edff06 995 wxCHECK_MSG( m_graphicContext, false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
1b89a5cd
SC
996 widths.Clear();
997 widths.Add(0,text.Length());
998 if ( text.IsEmpty() )
999 return true;
1000
1001 wxArrayDouble widthsD;
1002
1003 m_graphicContext->GetPartialTextExtents( text, widthsD );
1004 for ( size_t i = 0; i < widths.GetCount(); ++i )
0ebd9515 1005 widths[i] = (wxCoord)(widthsD[i] + 0.5);
1b89a5cd
SC
1006
1007 return true;
1008}
1009
888dde65 1010wxCoord wxGCDCImpl::GetCharWidth(void) const
1b89a5cd
SC
1011{
1012 wxCoord width;
1013 DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
1014
1015 return width;
1016}
1017
888dde65 1018wxCoord wxGCDCImpl::GetCharHeight(void) const
1b89a5cd
SC
1019{
1020 wxCoord height;
1021 DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
1022
1023 return height;
1024}
1025
888dde65 1026void wxGCDCImpl::Clear(void)
1b89a5cd 1027{
888dde65 1028 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") );
1b89a5cd
SC
1029 // TODO better implementation / incorporate size info into wxGCDC or context
1030 m_graphicContext->SetBrush( m_backgroundBrush );
1031 wxPen p = *wxTRANSPARENT_PEN;
1032 m_graphicContext->SetPen( p );
954c66fa
SC
1033 wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
1034 m_graphicContext->SetCompositionMode(wxCOMPOSITION_SOURCE);
0c4438d2
PC
1035 // maximum positive coordinate Cairo can handle is 2^23 - 1
1036 DoDrawRectangle(
1037 DeviceToLogicalX(0), DeviceToLogicalY(0),
1038 DeviceToLogicalXRel(0x007fffff), DeviceToLogicalYRel(0x007fffff));
954c66fa 1039 m_graphicContext->SetCompositionMode(formerMode);
6c0aace2 1040 m_graphicContext->SetPen( m_pen );
1b89a5cd
SC
1041 m_graphicContext->SetBrush( m_brush );
1042}
1043
888dde65 1044void wxGCDCImpl::DoGetSize(int *width, int *height) const
1b89a5cd 1045{
1cc7d13a
SC
1046 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoGetSize - invalid DC") );
1047 wxDouble w,h;
1048 m_graphicContext->GetSize( &w, &h );
1049 if ( height )
1050 *height = (int) (h+0.5);
1051 if ( width )
1052 *width = (int) (w+0.5);
1b89a5cd
SC
1053}
1054
888dde65 1055void wxGCDCImpl::DoGradientFillLinear(const wxRect& rect,
1b89a5cd
SC
1056 const wxColour& initialColour,
1057 const wxColour& destColour,
1058 wxDirection nDirection )
1059{
1060 wxPoint start;
1061 wxPoint end;
1062 switch( nDirection)
1063 {
1064 case wxWEST :
1065 start = rect.GetRightBottom();
1066 start.x++;
1067 end = rect.GetLeftBottom();
1068 break;
1069 case wxEAST :
1070 start = rect.GetLeftBottom();
1071 end = rect.GetRightBottom();
1072 end.x++;
1073 break;
1074 case wxNORTH :
1075 start = rect.GetLeftBottom();
1076 start.y++;
1077 end = rect.GetLeftTop();
1078 break;
1079 case wxSOUTH :
1080 start = rect.GetLeftTop();
1081 end = rect.GetLeftBottom();
1082 end.y++;
1083 break;
1084 default :
1085 break;
1086 }
1087
0ebd9515 1088 if (rect.width == 0 || rect.height == 0)
1b89a5cd
SC
1089 return;
1090
0ebd9515
SC
1091 m_graphicContext->SetBrush( m_graphicContext->CreateLinearGradientBrush(
1092 start.x,start.y,end.x,end.y, initialColour, destColour));
1b89a5cd 1093 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
0ebd9515 1094 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd 1095 m_graphicContext->SetPen(m_pen);
be6b31f3 1096 m_graphicContext->SetBrush(m_brush);
1b89a5cd
SC
1097}
1098
888dde65 1099void wxGCDCImpl::DoGradientFillConcentric(const wxRect& rect,
1b89a5cd
SC
1100 const wxColour& initialColour,
1101 const wxColour& destColour,
1102 const wxPoint& circleCenter)
1103{
1104 //Radius
1105 wxInt32 cx = rect.GetWidth() / 2;
1106 wxInt32 cy = rect.GetHeight() / 2;
1107 wxInt32 nRadius;
1108 if (cx < cy)
1109 nRadius = cx;
1110 else
1111 nRadius = cy;
1112
0ebd9515 1113 // make sure the background is filled (todo move into specific platform implementation ?)
1b89a5cd
SC
1114 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
1115 m_graphicContext->SetBrush( wxBrush( destColour) );
0ebd9515 1116 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd
SC
1117
1118 m_graphicContext->SetBrush( m_graphicContext->CreateRadialGradientBrush(
0ebd9515
SC
1119 rect.x+circleCenter.x,rect.y+circleCenter.y,
1120 rect.x+circleCenter.x,rect.y+circleCenter.y,
1121 nRadius,initialColour,destColour));
1b89a5cd 1122
0ebd9515 1123 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd 1124 m_graphicContext->SetPen(m_pen);
be6b31f3 1125 m_graphicContext->SetBrush(m_brush);
1b89a5cd
SC
1126}
1127
888dde65 1128void wxGCDCImpl::DoDrawCheckMark(wxCoord x, wxCoord y,
1b89a5cd
SC
1129 wxCoord width, wxCoord height)
1130{
888dde65 1131 wxDCImpl::DoDrawCheckMark(x,y,width,height);
1b89a5cd
SC
1132}
1133
53d4bdbc
VZ
1134#ifdef __WXMSW__
1135wxRect wxGCDCImpl::MSWApplyGDIPlusTransform(const wxRect& r) const
1136{
1137 wxGraphicsContext* const gc = GetGraphicsContext();
1138 wxCHECK_MSG( gc, r, wxT("Invalid wxGCDC") );
1139
1140 double x = 0,
1141 y = 0;
1142 gc->GetTransform().TransformPoint(&x, &y);
1143
1144 wxRect rect(r);
1145 rect.Offset(x, y);
1146
1147 return rect;
1148}
1149#endif // __WXMSW__
1150
1b89a5cd 1151#endif // wxUSE_GRAPHICS_CONTEXT