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