]> git.saurik.com Git - wxWidgets.git/blame - src/common/dcgraph.cpp
Disable symbols visibility support for the Clang compiler.
[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
7b1a66bb
RR
124wxGCDC::wxGCDC() :
125 wxDC( new wxGCDCImpl( this ) )
1b89a5cd 126{
888dde65
RR
127}
128
9412ee9a
SC
129wxGCDC::~wxGCDC()
130{
131}
132
6c0e710f 133wxGraphicsContext* wxGCDC::GetGraphicsContext() const
888dde65
RR
134{
135 if (!m_pimpl) return NULL;
136 wxGCDCImpl *gc_impl = (wxGCDCImpl*) m_pimpl;
137 return gc_impl->GetGraphicsContext();
1b89a5cd
SC
138}
139
140void wxGCDC::SetGraphicsContext( wxGraphicsContext* ctx )
888dde65
RR
141{
142 if (!m_pimpl) return;
143 wxGCDCImpl *gc_impl = (wxGCDCImpl*) m_pimpl;
144 gc_impl->SetGraphicsContext( ctx );
145}
146
147IMPLEMENT_ABSTRACT_CLASS(wxGCDCImpl, wxDCImpl)
148
149wxGCDCImpl::wxGCDCImpl( wxDC *owner ) :
150 wxDCImpl( owner )
151{
152 Init();
153}
154
155void wxGCDCImpl::SetGraphicsContext( wxGraphicsContext* ctx )
6c0aace2 156{
1b89a5cd
SC
157 delete m_graphicContext;
158 m_graphicContext = ctx;
914fd3f1
SC
159 if ( m_graphicContext )
160 {
161 m_matrixOriginal = m_graphicContext->GetTransform();
162 m_ok = true;
fd791571
SC
163 // apply the stored transformations to the passed in context
164 ComputeScaleAndOrigin();
ad667945
SC
165 m_graphicContext->SetFont( m_font , m_textForegroundColour );
166 m_graphicContext->SetPen( m_pen );
167 m_graphicContext->SetBrush( m_brush);
914fd3f1 168 }
1b89a5cd
SC
169}
170
888dde65
RR
171wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxWindowDC& dc ) :
172 wxDCImpl( owner )
1b89a5cd
SC
173{
174 Init();
914fd3f1 175 SetGraphicsContext( wxGraphicsContext::Create(dc) );
7b98cf02 176 m_window = dc.GetWindow();
1b89a5cd
SC
177}
178
888dde65
RR
179wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxMemoryDC& dc ) :
180 wxDCImpl( owner )
773ccc31
SC
181{
182 Init();
c0e69d72
KO
183 wxGraphicsContext* context;
184#if wxUSE_CAIRO
185 wxGraphicsRenderer* renderer = wxGraphicsRenderer::GetCairoRenderer();
186 context = renderer->CreateContext(dc);
187#else
188 context = wxGraphicsContext::Create(dc);
189#endif
190
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
SC
384
385 if ( col != m_textForegroundColour )
386 {
387 m_textForegroundColour = col;
388 m_graphicContext->SetFont( m_font, m_textForegroundColour );
389 }
390}
391
888dde65 392void wxGCDCImpl::SetTextBackground( const wxColour &col )
1b89a5cd 393{
888dde65 394 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
1b89a5cd
SC
395
396 m_textBackgroundColour = col;
397}
398
89efaf2b 399void wxGCDCImpl::SetMapMode( wxMappingMode mode )
1b89a5cd
SC
400{
401 switch (mode)
402 {
403 case wxMM_TWIPS:
404 SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y );
405 break;
406
407 case wxMM_POINTS:
408 SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y );
409 break;
410
411 case wxMM_METRIC:
412 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
413 break;
414
415 case wxMM_LOMETRIC:
416 SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 );
417 break;
418
419 case wxMM_TEXT:
420 default:
421 SetLogicalScale( 1.0, 1.0 );
422 break;
423 }
424
425 ComputeScaleAndOrigin();
426}
427
888dde65 428wxSize wxGCDCImpl::GetPPI() const
1b89a5cd
SC
429{
430 return wxSize(72, 72);
431}
432
888dde65 433int wxGCDCImpl::GetDepth() const
1b89a5cd
SC
434{
435 return 32;
436}
437
888dde65 438void wxGCDCImpl::ComputeScaleAndOrigin()
b02d4340 439{
2dedef25 440 wxDCImpl::ComputeScaleAndOrigin();
1b89a5cd 441
fd791571
SC
442 if ( m_graphicContext )
443 {
444 m_matrixCurrent = m_graphicContext->CreateMatrix();
08de4403 445
fd791571 446 // the logical origin sets the origin to have new coordinates
08de4403 447 m_matrixCurrent.Translate( m_deviceOriginX - m_logicalOriginX * m_signX * m_scaleX,
d225267e 448 m_deviceOriginY-m_logicalOriginY * m_signY * m_scaleY);
08de4403 449
d225267e 450 m_matrixCurrent.Scale( m_scaleX * m_signX, m_scaleY * m_signY );
08de4403 451
fd791571
SC
452 m_graphicContext->SetTransform( m_matrixOriginal );
453 m_graphicContext->ConcatTransform( m_matrixCurrent );
454 }
1b89a5cd
SC
455}
456
888dde65 457void wxGCDCImpl::SetPalette( const wxPalette& WXUNUSED(palette) )
1b89a5cd
SC
458{
459
460}
461
888dde65 462void wxGCDCImpl::SetBackgroundMode( int mode )
1b89a5cd
SC
463{
464 m_backgroundMode = mode;
465}
466
888dde65 467void wxGCDCImpl::SetFont( const wxFont &font )
1b89a5cd
SC
468{
469 m_font = font;
470 if ( m_graphicContext )
471 {
472 wxFont f = font;
888dde65 473 if ( f.IsOk() )
0ebd9515 474 f.SetPointSize( /*LogicalToDeviceYRel*/(font.GetPointSize()));
1b89a5cd
SC
475 m_graphicContext->SetFont( f, m_textForegroundColour );
476 }
477}
478
888dde65 479void wxGCDCImpl::SetPen( const wxPen &pen )
1b89a5cd
SC
480{
481 if ( m_pen == pen )
482 return;
483
484 m_pen = pen;
485 if ( m_graphicContext )
486 {
0ebd9515 487 m_graphicContext->SetPen( m_pen );
1b89a5cd
SC
488 }
489}
490
888dde65 491void wxGCDCImpl::SetBrush( const wxBrush &brush )
1b89a5cd
SC
492{
493 if (m_brush == brush)
494 return;
495
496 m_brush = brush;
497 if ( m_graphicContext )
498 {
0ebd9515 499 m_graphicContext->SetBrush( m_brush );
1b89a5cd
SC
500 }
501}
b02d4340 502
888dde65 503void wxGCDCImpl::SetBackground( const wxBrush &brush )
1b89a5cd
SC
504{
505 if (m_backgroundBrush == brush)
506 return;
507
508 m_backgroundBrush = brush;
888dde65 509 if (!m_backgroundBrush.IsOk())
1b89a5cd
SC
510 return;
511}
512
89efaf2b 513void wxGCDCImpl::SetLogicalFunction( wxRasterOperationMode function )
1b89a5cd
SC
514{
515 if (m_logicalFunction == function)
516 return;
517
518 m_logicalFunction = function;
03647350 519
fec4e458
VZ
520 wxCompositionMode mode = TranslateRasterOp( function );
521 m_logicalFunctionSupported = mode != wxCOMPOSITION_INVALID;
bf02a7f9
SC
522 if (m_logicalFunctionSupported)
523 m_logicalFunctionSupported = m_graphicContext->SetCompositionMode(mode);
03647350 524
584be856 525 if ( function == wxXOR )
bf02a7f9 526 m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE);
1b89a5cd 527 else
bf02a7f9 528 m_graphicContext->SetAntialiasMode(wxANTIALIAS_DEFAULT);
1b89a5cd
SC
529}
530
888dde65 531bool wxGCDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
03647350 532 const wxColour& WXUNUSED(col),
89efaf2b 533 wxFloodFillStyle WXUNUSED(style))
1b89a5cd
SC
534{
535 return false;
536}
537
888dde65 538bool wxGCDCImpl::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const
1b89a5cd
SC
539{
540 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
541 return false;
542}
543
888dde65 544void wxGCDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
1b89a5cd 545{
888dde65 546 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
1b89a5cd 547
4280b879 548 if ( !m_logicalFunctionSupported )
1b89a5cd 549 return;
1b89a5cd 550
0ebd9515 551 m_graphicContext->StrokeLine(x1,y1,x2,y2);
1b89a5cd
SC
552
553 CalcBoundingBox(x1, y1);
554 CalcBoundingBox(x2, y2);
555}
556
888dde65 557void wxGCDCImpl::DoCrossHair( wxCoord x, wxCoord y )
1b89a5cd 558{
888dde65 559 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
1b89a5cd 560
4280b879 561 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
562 return;
563
564 int w = 0, h = 0;
565
888dde65 566 GetOwner()->GetSize( &w, &h );
1b89a5cd 567
0ebd9515
SC
568 m_graphicContext->StrokeLine(0,y,w,y);
569 m_graphicContext->StrokeLine(x,0,x,h);
1b89a5cd 570
0ebd9515
SC
571 CalcBoundingBox(0, 0);
572 CalcBoundingBox(0+w, 0+h);
1b89a5cd
SC
573}
574
888dde65 575void wxGCDCImpl::DoDrawArc( wxCoord x1, wxCoord y1,
1b89a5cd
SC
576 wxCoord x2, wxCoord y2,
577 wxCoord xc, wxCoord yc )
578{
888dde65 579 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
1b89a5cd 580
4280b879 581 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
582 return;
583
0ebd9515
SC
584 double dx = x1 - xc;
585 double dy = y1 - yc;
1b89a5cd
SC
586 double radius = sqrt((double)(dx * dx + dy * dy));
587 wxCoord rad = (wxCoord)radius;
588 double sa, ea;
0ebd9515 589 if (x1 == x2 && y1 == y2)
1b89a5cd
SC
590 {
591 sa = 0.0;
592 ea = 360.0;
593 }
594 else if (radius == 0.0)
595 {
596 sa = ea = 0.0;
597 }
598 else
599 {
0ebd9515
SC
600 sa = (x1 - xc == 0) ?
601 (y1 - yc < 0) ? 90.0 : -90.0 :
602 -atan2(double(y1 - yc), double(x1 - xc)) * RAD2DEG;
603 ea = (x2 - xc == 0) ?
604 (y2 - yc < 0) ? 90.0 : -90.0 :
605 -atan2(double(y2 - yc), double(x2 - xc)) * RAD2DEG;
1b89a5cd
SC
606 }
607
608 bool fill = m_brush.GetStyle() != wxTRANSPARENT;
609
a4e73390 610 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd 611 if ( fill && ((x1!=x2)||(y1!=y2)) )
0ebd9515 612 path.MoveToPoint( xc, yc );
4bae004c
SC
613 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
614 // get clockwise angles
615 path.AddArc( xc, yc , rad , DegToRad(-sa) , DegToRad(-ea), false );
1b89a5cd 616 if ( fill && ((x1!=x2)||(y1!=y2)) )
0ebd9515 617 path.AddLineToPoint( xc, yc );
1b89a5cd 618 m_graphicContext->DrawPath(path);
1b89a5cd
SC
619}
620
888dde65 621void wxGCDCImpl::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
1b89a5cd
SC
622 double sa, double ea )
623{
888dde65 624 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
1b89a5cd 625
4280b879 626 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
627 return;
628
1b89a5cd 629 m_graphicContext->PushState();
d9485f89 630 m_graphicContext->Translate(x+w/2.0,y+h/2.0);
0ebd9515 631 wxDouble factor = ((wxDouble) w) / h;
1b89a5cd 632 m_graphicContext->Scale( factor , 1.0);
d9485f89 633
1b89a5cd
SC
634 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
635 // get clockwise angles
fcaea2fa
SC
636 if ( m_brush.GetStyle() != wxTRANSPARENT )
637 {
638 wxGraphicsPath path = m_graphicContext->CreatePath();
639 path.MoveToPoint( 0, 0 );
47c1bb95 640 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
fcaea2fa
SC
641 path.AddLineToPoint( 0, 0 );
642 m_graphicContext->FillPath( path );
643
644 path = m_graphicContext->CreatePath();
645 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
fcaea2fa
SC
646 m_graphicContext->StrokePath( path );
647 }
648 else
649 {
650 wxGraphicsPath path = m_graphicContext->CreatePath();
47c1bb95
SC
651 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
652 m_graphicContext->DrawPath( path );
fcaea2fa
SC
653 }
654
1b89a5cd 655 m_graphicContext->PopState();
1b89a5cd
SC
656}
657
888dde65 658void wxGCDCImpl::DoDrawPoint( wxCoord x, wxCoord y )
1b89a5cd 659{
888dde65 660 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
1b89a5cd
SC
661
662 DoDrawLine( x , y , x + 1 , y + 1 );
663}
664
888dde65 665void wxGCDCImpl::DoDrawLines(int n, wxPoint points[],
1b89a5cd
SC
666 wxCoord xoffset, wxCoord yoffset)
667{
888dde65 668 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
1b89a5cd 669
4280b879 670 if ( !m_logicalFunctionSupported )
1b89a5cd 671 return;
1b89a5cd
SC
672
673 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n];
674 for( int i = 0; i < n; ++i)
675 {
0ebd9515
SC
676 pointsD[i].m_x = points[i].x + xoffset;
677 pointsD[i].m_y = points[i].y + yoffset;
1b89a5cd
SC
678 }
679
680 m_graphicContext->StrokeLines( n , pointsD);
681 delete[] pointsD;
682}
683
684#if wxUSE_SPLINES
888dde65 685void wxGCDCImpl::DoDrawSpline(const wxPointList *points)
1b89a5cd 686{
888dde65 687 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
1b89a5cd 688
4280b879 689 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
690 return;
691
a4e73390 692 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd 693
b0d7707b 694 wxPointList::compatibility_iterator node = points->GetFirst();
cb98e78b 695 if ( !node )
1b89a5cd
SC
696 // empty list
697 return;
698
b0d7707b 699 wxPoint *p = node->GetData();
1b89a5cd
SC
700
701 wxCoord x1 = p->x;
702 wxCoord y1 = p->y;
703
704 node = node->GetNext();
b0d7707b 705 p = node->GetData();
1b89a5cd
SC
706
707 wxCoord x2 = p->x;
708 wxCoord y2 = p->y;
709 wxCoord cx1 = ( x1 + x2 ) / 2;
710 wxCoord cy1 = ( y1 + y2 ) / 2;
711
0ebd9515
SC
712 path.MoveToPoint( x1 , y1 );
713 path.AddLineToPoint( cx1 , cy1 );
01871bf6 714#if !wxUSE_STD_CONTAINERS
1b89a5cd
SC
715
716 while ((node = node->GetNext()) != NULL)
717#else
718
719 while ((node = node->GetNext()))
01871bf6 720#endif // !wxUSE_STD_CONTAINERS
1b89a5cd
SC
721
722 {
b0d7707b 723 p = node->GetData();
1b89a5cd
SC
724 x1 = x2;
725 y1 = y2;
726 x2 = p->x;
727 y2 = p->y;
728 wxCoord cx4 = (x1 + x2) / 2;
729 wxCoord cy4 = (y1 + y2) / 2;
730
0ebd9515 731 path.AddQuadCurveToPoint(x1 , y1 ,cx4 , cy4 );
1b89a5cd
SC
732
733 cx1 = cx4;
734 cy1 = cy4;
735 }
736
0ebd9515 737 path.AddLineToPoint( x2 , y2 );
1b89a5cd
SC
738
739 m_graphicContext->StrokePath( path );
1b89a5cd
SC
740}
741#endif // wxUSE_SPLINES
742
888dde65 743void wxGCDCImpl::DoDrawPolygon( int n, wxPoint points[],
89efaf2b
FM
744 wxCoord xoffset, wxCoord yoffset,
745 wxPolygonFillMode fillStyle )
1b89a5cd 746{
888dde65 747 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
1b89a5cd
SC
748
749 if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) )
750 return;
4280b879 751 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
752 return;
753
754 bool closeIt = false;
755 if (points[n-1] != points[0])
756 closeIt = true;
757
758 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)];
759 for( int i = 0; i < n; ++i)
760 {
0ebd9515
SC
761 pointsD[i].m_x = points[i].x + xoffset;
762 pointsD[i].m_y = points[i].y + yoffset;
1b89a5cd
SC
763 }
764 if ( closeIt )
765 pointsD[n] = pointsD[0];
766
767 m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle);
768 delete[] pointsD;
769}
770
888dde65 771void wxGCDCImpl::DoDrawPolyPolygon(int n,
1b89a5cd
SC
772 int count[],
773 wxPoint points[],
774 wxCoord xoffset,
775 wxCoord yoffset,
89efaf2b 776 wxPolygonFillMode fillStyle)
1b89a5cd
SC
777{
778 wxASSERT(n > 1);
a4e73390 779 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd
SC
780
781 int i = 0;
782 for ( int j = 0; j < n; ++j)
783 {
784 wxPoint start = points[i];
0ebd9515 785 path.MoveToPoint( start.x+ xoffset, start.y+ yoffset);
1b89a5cd
SC
786 ++i;
787 int l = count[j];
788 for ( int k = 1; k < l; ++k)
789 {
0ebd9515 790 path.AddLineToPoint( points[i].x+ xoffset, points[i].y+ yoffset);
1b89a5cd
SC
791 ++i;
792 }
793 // close the polygon
794 if ( start != points[i-1])
0ebd9515 795 path.AddLineToPoint( start.x+ xoffset, start.y+ yoffset);
1b89a5cd
SC
796 }
797 m_graphicContext->DrawPath( path , fillStyle);
1b89a5cd
SC
798}
799
888dde65 800void wxGCDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
1b89a5cd 801{
888dde65 802 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
1b89a5cd 803
4280b879 804 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
805 return;
806
1b89a5cd 807 // CMB: draw nothing if transformed w or h is 0
0ebd9515 808 if (w == 0 || h == 0)
1b89a5cd
SC
809 return;
810
5ebfdf41
SC
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
0ebd9515
SC
815 w -= 1;
816 h -= 1;
5ebfdf41 817 }
0ebd9515 818 m_graphicContext->DrawRectangle(x,y,w,h);
1b89a5cd
SC
819}
820
888dde65 821void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
0ebd9515 822 wxCoord w, wxCoord h,
1b89a5cd
SC
823 double radius)
824{
888dde65 825 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1b89a5cd 826
4280b879 827 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
828 return;
829
830 if (radius < 0.0)
0ebd9515 831 radius = - radius * ((w < h) ? w : h);
1b89a5cd
SC
832
833 // CMB: draw nothing if transformed w or h is 0
0ebd9515 834 if (w == 0 || h == 0)
1b89a5cd
SC
835 return;
836
d9485f89
RD
837 if ( m_graphicContext->ShouldOffset() )
838 {
839 // if we are offsetting the entire rectangle is moved 0.5, so the
840 // border line gets off by 1
841 w -= 1;
842 h -= 1;
843 }
0ebd9515 844 m_graphicContext->DrawRoundedRectangle( x,y,w,h,radius);
1b89a5cd
SC
845}
846
888dde65 847void wxGCDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
1b89a5cd 848{
888dde65 849 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
1b89a5cd 850
4280b879 851 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
852 return;
853
d9485f89
RD
854 if ( m_graphicContext->ShouldOffset() )
855 {
856 // if we are offsetting the entire rectangle is moved 0.5, so the
857 // border line gets off by 1
858 w -= 1;
859 h -= 1;
860 }
0ebd9515 861 m_graphicContext->DrawEllipse(x,y,w,h);
1b89a5cd
SC
862}
863
888dde65 864bool wxGCDCImpl::CanDrawBitmap() const
1b89a5cd
SC
865{
866 return true;
867}
868
888dde65 869bool wxGCDCImpl::DoBlit(
1b89a5cd 870 wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
03647350 871 wxDC *source, wxCoord xsrc, wxCoord ysrc,
89efaf2b 872 wxRasterOperationMode logical_func , bool useMask,
1b89a5cd
SC
873 wxCoord xsrcMask, wxCoord ysrcMask )
874{
e3b81044
VZ
875 return DoStretchBlit( xdest, ydest, width, height,
876 source, xsrc, ysrc, width, height, logical_func, useMask,
877 xsrcMask,ysrcMask );
878}
879
888dde65 880bool wxGCDCImpl::DoStretchBlit(
e3b81044
VZ
881 wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight,
882 wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight,
89efaf2b 883 wxRasterOperationMode logical_func , bool useMask,
e3b81044
VZ
884 wxCoord xsrcMask, wxCoord ysrcMask )
885{
888dde65
RR
886 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
887 wxCHECK_MSG( source->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
6c0aace2 888
1b89a5cd
SC
889 if ( logical_func == wxNO_OP )
890 return true;
03647350 891
fec4e458
VZ
892 wxCompositionMode mode = TranslateRasterOp(logical_func);
893 if ( mode == wxCOMPOSITION_INVALID )
c64c9cd3 894 {
bf02a7f9 895 wxFAIL_MSG( wxT("Blitting is not supported with this logical operation.") );
c64c9cd3
KO
896 return false;
897 }
1b89a5cd 898
bf02a7f9 899 bool retval = true;
03647350 900
bf02a7f9
SC
901 wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
902 if (m_graphicContext->SetCompositionMode(mode))
1b89a5cd 903 {
bf02a7f9
SC
904 wxAntialiasMode formerAa = m_graphicContext->GetAntialiasMode();
905 if (mode == wxCOMPOSITION_XOR)
906 {
907 m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE);
908 }
03647350 909
bf02a7f9
SC
910 if (xsrcMask == -1 && ysrcMask == -1)
911 {
912 xsrcMask = xsrc;
913 ysrcMask = ysrc;
914 }
1b89a5cd 915
bf02a7f9
SC
916 wxRect subrect(source->LogicalToDeviceX(xsrc),
917 source->LogicalToDeviceY(ysrc),
918 source->LogicalToDeviceXRel(srcWidth),
919 source->LogicalToDeviceYRel(srcHeight));
cce4a2ce 920
bf02a7f9
SC
921 // if needed clip the subrect down to the size of the source DC
922 wxCoord sw, sh;
923 source->GetSize(&sw, &sh);
924 sw = source->LogicalToDeviceXRel(sw);
925 sh = source->LogicalToDeviceYRel(sh);
926 if (subrect.x + subrect.width > sw)
927 subrect.width = sw - subrect.x;
928 if (subrect.y + subrect.height > sh)
929 subrect.height = sh - subrect.y;
6c0aace2 930
bf02a7f9 931 wxBitmap blit = source->GetAsBitmap( &subrect );
6c0aace2 932
bf02a7f9
SC
933 if ( blit.IsOk() )
934 {
935 if ( !useMask && blit.GetMask() )
936 blit.SetMask(NULL);
08de4403 937
bf02a7f9
SC
938 m_graphicContext->DrawBitmap( blit, xdest, ydest,
939 dstWidth, dstHeight);
940 }
941 else
942 {
943 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
944 retval = false;
945 }
03647350 946
bf02a7f9
SC
947 if (mode == wxCOMPOSITION_XOR)
948 {
949 m_graphicContext->SetAntialiasMode(formerAa);
950 }
1b89a5cd 951 }
bf02a7f9
SC
952 // reset composition
953 m_graphicContext->SetCompositionMode(formerMode);
1b89a5cd 954
bf02a7f9 955 return retval;
1b89a5cd
SC
956}
957
888dde65 958void wxGCDCImpl::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
1b89a5cd
SC
959 double angle)
960{
888dde65 961 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
1b89a5cd 962
6636ef8d 963 if ( str.empty() )
1b89a5cd 964 return;
4280b879 965 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
966 return;
967
068eb463
SC
968 if ( m_backgroundMode == wxTRANSPARENT )
969 m_graphicContext->DrawText( str, x ,y , DegToRad(angle ));
970 else
971 m_graphicContext->DrawText( str, x ,y , DegToRad(angle ), m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) );
1b89a5cd
SC
972}
973
888dde65 974void wxGCDCImpl::DoDrawText(const wxString& str, wxCoord x, wxCoord y)
1b89a5cd 975{
a6afde63
SC
976 // For compatibility with other ports (notably wxGTK) and because it's
977 // genuinely useful, we allow passing multiline strings to DrawText().
978 // However there is no native OSX function to draw them directly so we
979 // instead reuse the generic DrawLabel() method to render them. Of course,
980 // DrawLabel() itself will call back to us but with single line strings
981 // only so there won't be any infinite recursion here.
982 if ( str.find('\n') != wxString::npos )
983 {
984 GetOwner()->DrawLabel(str, wxRect(x, y, 0, 0));
985 return;
986 }
987
08de4403 988 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawText - invalid DC") );
1b89a5cd 989
6636ef8d 990 if ( str.empty() )
1b89a5cd 991 return;
4280b879
SC
992
993 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
994 return;
995
068eb463
SC
996 if ( m_backgroundMode == wxTRANSPARENT )
997 m_graphicContext->DrawText( str, x ,y);
998 else
999 m_graphicContext->DrawText( str, x ,y , m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) );
1b89a5cd
SC
1000}
1001
888dde65 1002bool wxGCDCImpl::CanGetTextExtent() const
1b89a5cd 1003{
888dde65 1004 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
1b89a5cd
SC
1005
1006 return true;
1007}
1008
888dde65 1009void wxGCDCImpl::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
1b89a5cd 1010 wxCoord *descent, wxCoord *externalLeading ,
c94f845b 1011 const wxFont *theFont ) const
1b89a5cd 1012{
d9edff06 1013 wxCHECK_RET( m_graphicContext, wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
1b89a5cd
SC
1014
1015 if ( theFont )
1016 {
1017 m_graphicContext->SetFont( *theFont, m_textForegroundColour );
1018 }
1019
1020 wxDouble h , d , e , w;
1021
1022 m_graphicContext->GetTextExtent( str, &w, &h, &d, &e );
1023
1024 if ( height )
fcaea2fa 1025 *height = (wxCoord)(h+0.5);
1b89a5cd 1026 if ( descent )
fcaea2fa 1027 *descent = (wxCoord)(d+0.5);
1b89a5cd 1028 if ( externalLeading )
fcaea2fa 1029 *externalLeading = (wxCoord)(e+0.5);
1b89a5cd 1030 if ( width )
fcaea2fa 1031 *width = (wxCoord)(w+0.5);
1b89a5cd
SC
1032
1033 if ( theFont )
1034 {
1035 m_graphicContext->SetFont( m_font, m_textForegroundColour );
1036 }
1037}
1038
888dde65 1039bool wxGCDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
1b89a5cd 1040{
d9edff06 1041 wxCHECK_MSG( m_graphicContext, false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
1b89a5cd
SC
1042 widths.Clear();
1043 widths.Add(0,text.Length());
1044 if ( text.IsEmpty() )
1045 return true;
1046
1047 wxArrayDouble widthsD;
1048
1049 m_graphicContext->GetPartialTextExtents( text, widthsD );
1050 for ( size_t i = 0; i < widths.GetCount(); ++i )
0ebd9515 1051 widths[i] = (wxCoord)(widthsD[i] + 0.5);
1b89a5cd
SC
1052
1053 return true;
1054}
1055
888dde65 1056wxCoord wxGCDCImpl::GetCharWidth(void) const
1b89a5cd
SC
1057{
1058 wxCoord width;
1059 DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
1060
1061 return width;
1062}
1063
888dde65 1064wxCoord wxGCDCImpl::GetCharHeight(void) const
1b89a5cd
SC
1065{
1066 wxCoord height;
1067 DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
1068
1069 return height;
1070}
1071
888dde65 1072void wxGCDCImpl::Clear(void)
1b89a5cd 1073{
888dde65 1074 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") );
1b89a5cd
SC
1075 // TODO better implementation / incorporate size info into wxGCDC or context
1076 m_graphicContext->SetBrush( m_backgroundBrush );
1077 wxPen p = *wxTRANSPARENT_PEN;
1078 m_graphicContext->SetPen( p );
954c66fa
SC
1079 wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
1080 m_graphicContext->SetCompositionMode(wxCOMPOSITION_SOURCE);
1b89a5cd 1081 DoDrawRectangle( 0, 0, 32000 , 32000 );
954c66fa 1082 m_graphicContext->SetCompositionMode(formerMode);
6c0aace2 1083 m_graphicContext->SetPen( m_pen );
1b89a5cd
SC
1084 m_graphicContext->SetBrush( m_brush );
1085}
1086
888dde65 1087void wxGCDCImpl::DoGetSize(int *width, int *height) const
1b89a5cd 1088{
1cc7d13a
SC
1089 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoGetSize - invalid DC") );
1090 wxDouble w,h;
1091 m_graphicContext->GetSize( &w, &h );
1092 if ( height )
1093 *height = (int) (h+0.5);
1094 if ( width )
1095 *width = (int) (w+0.5);
1b89a5cd
SC
1096}
1097
888dde65 1098void wxGCDCImpl::DoGradientFillLinear(const wxRect& rect,
1b89a5cd
SC
1099 const wxColour& initialColour,
1100 const wxColour& destColour,
1101 wxDirection nDirection )
1102{
1103 wxPoint start;
1104 wxPoint end;
1105 switch( nDirection)
1106 {
1107 case wxWEST :
1108 start = rect.GetRightBottom();
1109 start.x++;
1110 end = rect.GetLeftBottom();
1111 break;
1112 case wxEAST :
1113 start = rect.GetLeftBottom();
1114 end = rect.GetRightBottom();
1115 end.x++;
1116 break;
1117 case wxNORTH :
1118 start = rect.GetLeftBottom();
1119 start.y++;
1120 end = rect.GetLeftTop();
1121 break;
1122 case wxSOUTH :
1123 start = rect.GetLeftTop();
1124 end = rect.GetLeftBottom();
1125 end.y++;
1126 break;
1127 default :
1128 break;
1129 }
1130
0ebd9515 1131 if (rect.width == 0 || rect.height == 0)
1b89a5cd
SC
1132 return;
1133
0ebd9515
SC
1134 m_graphicContext->SetBrush( m_graphicContext->CreateLinearGradientBrush(
1135 start.x,start.y,end.x,end.y, initialColour, destColour));
1b89a5cd 1136 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
0ebd9515 1137 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd
SC
1138 m_graphicContext->SetPen(m_pen);
1139}
1140
888dde65 1141void wxGCDCImpl::DoGradientFillConcentric(const wxRect& rect,
1b89a5cd
SC
1142 const wxColour& initialColour,
1143 const wxColour& destColour,
1144 const wxPoint& circleCenter)
1145{
1146 //Radius
1147 wxInt32 cx = rect.GetWidth() / 2;
1148 wxInt32 cy = rect.GetHeight() / 2;
1149 wxInt32 nRadius;
1150 if (cx < cy)
1151 nRadius = cx;
1152 else
1153 nRadius = cy;
1154
0ebd9515 1155 // make sure the background is filled (todo move into specific platform implementation ?)
1b89a5cd
SC
1156 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
1157 m_graphicContext->SetBrush( wxBrush( destColour) );
0ebd9515 1158 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd
SC
1159
1160 m_graphicContext->SetBrush( m_graphicContext->CreateRadialGradientBrush(
0ebd9515
SC
1161 rect.x+circleCenter.x,rect.y+circleCenter.y,
1162 rect.x+circleCenter.x,rect.y+circleCenter.y,
1163 nRadius,initialColour,destColour));
1b89a5cd 1164
0ebd9515 1165 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd
SC
1166 m_graphicContext->SetPen(m_pen);
1167}
1168
888dde65 1169void wxGCDCImpl::DoDrawCheckMark(wxCoord x, wxCoord y,
1b89a5cd
SC
1170 wxCoord width, wxCoord height)
1171{
888dde65 1172 wxDCImpl::DoDrawCheckMark(x,y,width,height);
1b89a5cd
SC
1173}
1174
53d4bdbc
VZ
1175#ifdef __WXMSW__
1176wxRect wxGCDCImpl::MSWApplyGDIPlusTransform(const wxRect& r) const
1177{
1178 wxGraphicsContext* const gc = GetGraphicsContext();
1179 wxCHECK_MSG( gc, r, wxT("Invalid wxGCDC") );
1180
1181 double x = 0,
1182 y = 0;
1183 gc->GetTransform().TransformPoint(&x, &y);
1184
1185 wxRect rect(r);
1186 rect.Offset(x, y);
1187
1188 return rect;
1189}
1190#endif // __WXMSW__
1191
1b89a5cd 1192#endif // wxUSE_GRAPHICS_CONTEXT