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