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