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