]>
Commit | Line | Data |
---|---|---|
1b89a5cd SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/common/graphcmn.cpp | |
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 | ||
fcaea2fa SC |
31 | #ifdef __WXMAC__ |
32 | #include "wx/mac/private.h" | |
33 | #endif | |
1b89a5cd SC |
34 | //----------------------------------------------------------------------------- |
35 | // constants | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
38 | static const double RAD2DEG = 180.0 / M_PI; | |
39 | ||
40 | //----------------------------------------------------------------------------- | |
41 | // Local functions | |
42 | //----------------------------------------------------------------------------- | |
43 | ||
44 | static inline double DegToRad(double deg) | |
45 | { | |
46 | return (deg * M_PI) / 180.0; | |
47 | } | |
48 | ||
49 | //----------------------------------------------------------------------------- | |
50 | // wxDC bridge class | |
51 | //----------------------------------------------------------------------------- | |
52 | ||
1b89a5cd | 53 | IMPLEMENT_DYNAMIC_CLASS(wxGCDC, wxDC) |
888dde65 RR |
54 | |
55 | wxGCDC::wxGCDC(const wxWindowDC& dc) | |
56 | { | |
57 | m_pimpl = new wxGCDCImpl( this, dc ); | |
58 | } | |
59 | ||
60 | wxGCDC::wxGCDC( const wxMemoryDC& dc) | |
61 | { | |
62 | m_pimpl = new wxGCDCImpl( this, dc ); | |
63 | } | |
1b89a5cd SC |
64 | |
65 | wxGCDC::wxGCDC() | |
66 | { | |
888dde65 RR |
67 | m_pimpl = new wxGCDCImpl( this ); |
68 | } | |
69 | ||
70 | wxGraphicsContext* wxGCDC::GetGraphicsContext() | |
71 | { | |
72 | if (!m_pimpl) return NULL; | |
73 | wxGCDCImpl *gc_impl = (wxGCDCImpl*) m_pimpl; | |
74 | return gc_impl->GetGraphicsContext(); | |
1b89a5cd SC |
75 | } |
76 | ||
77 | void wxGCDC::SetGraphicsContext( wxGraphicsContext* ctx ) | |
888dde65 RR |
78 | { |
79 | if (!m_pimpl) return; | |
80 | wxGCDCImpl *gc_impl = (wxGCDCImpl*) m_pimpl; | |
81 | gc_impl->SetGraphicsContext( ctx ); | |
82 | } | |
83 | ||
84 | IMPLEMENT_ABSTRACT_CLASS(wxGCDCImpl, wxDCImpl) | |
85 | ||
86 | wxGCDCImpl::wxGCDCImpl( wxDC *owner ) : | |
87 | wxDCImpl( owner ) | |
88 | { | |
89 | Init(); | |
90 | } | |
91 | ||
92 | void wxGCDCImpl::SetGraphicsContext( wxGraphicsContext* ctx ) | |
6c0aace2 | 93 | { |
1b89a5cd SC |
94 | delete m_graphicContext; |
95 | m_graphicContext = ctx; | |
914fd3f1 SC |
96 | if ( m_graphicContext ) |
97 | { | |
98 | m_matrixOriginal = m_graphicContext->GetTransform(); | |
99 | m_ok = true; | |
fd791571 SC |
100 | // apply the stored transformations to the passed in context |
101 | ComputeScaleAndOrigin(); | |
ad667945 SC |
102 | m_graphicContext->SetFont( m_font , m_textForegroundColour ); |
103 | m_graphicContext->SetPen( m_pen ); | |
104 | m_graphicContext->SetBrush( m_brush); | |
914fd3f1 | 105 | } |
1b89a5cd SC |
106 | } |
107 | ||
888dde65 RR |
108 | wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxWindowDC& dc ) : |
109 | wxDCImpl( owner ) | |
1b89a5cd SC |
110 | { |
111 | Init(); | |
914fd3f1 | 112 | SetGraphicsContext( wxGraphicsContext::Create(dc) ); |
1b89a5cd SC |
113 | } |
114 | ||
888dde65 RR |
115 | wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxMemoryDC& dc ) : |
116 | wxDCImpl( owner ) | |
773ccc31 SC |
117 | { |
118 | Init(); | |
119 | SetGraphicsContext( wxGraphicsContext::Create(dc) ); | |
120 | } | |
773ccc31 | 121 | |
888dde65 | 122 | void wxGCDCImpl::Init() |
1b89a5cd SC |
123 | { |
124 | m_ok = false; | |
125 | m_colour = true; | |
126 | m_mm_to_pix_x = mm2pt; | |
127 | m_mm_to_pix_y = mm2pt; | |
128 | ||
129 | m_pen = *wxBLACK_PEN; | |
130 | m_font = *wxNORMAL_FONT; | |
131 | m_brush = *wxWHITE_BRUSH; | |
132 | ||
133 | m_graphicContext = NULL; | |
4280b879 | 134 | m_logicalFunctionSupported = true; |
1b89a5cd SC |
135 | } |
136 | ||
137 | ||
888dde65 | 138 | wxGCDCImpl::~wxGCDCImpl() |
1b89a5cd SC |
139 | { |
140 | delete m_graphicContext; | |
141 | } | |
142 | ||
888dde65 | 143 | void wxGCDCImpl::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool WXUNUSED(useMask) ) |
1b89a5cd | 144 | { |
888dde65 RR |
145 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") ); |
146 | wxCHECK_RET( bmp.IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") ); | |
1b89a5cd | 147 | |
f889bdb3 SC |
148 | if ( bmp.GetDepth() == 1 ) |
149 | { | |
150 | m_graphicContext->SetPen(*wxTRANSPARENT_PEN); | |
151 | m_graphicContext->SetBrush( wxBrush( m_textBackgroundColour , wxSOLID ) ); | |
152 | m_graphicContext->DrawRectangle( x , y , bmp.GetWidth() , bmp.GetHeight() ); | |
153 | m_graphicContext->SetBrush( wxBrush( m_textForegroundColour , wxSOLID ) ); | |
154 | m_graphicContext->DrawBitmap( bmp, x , y , bmp.GetWidth() , bmp.GetHeight() ); | |
155 | m_graphicContext->SetBrush( m_graphicContext->CreateBrush(m_brush)); | |
156 | m_graphicContext->SetPen( m_graphicContext->CreatePen(m_pen)); | |
157 | } | |
158 | else | |
159 | m_graphicContext->DrawBitmap( bmp, x , y , bmp.GetWidth() , bmp.GetHeight() ); | |
1b89a5cd SC |
160 | } |
161 | ||
888dde65 | 162 | void wxGCDCImpl::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) |
1b89a5cd | 163 | { |
888dde65 RR |
164 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") ); |
165 | wxCHECK_RET( icon.IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") ); | |
1b89a5cd | 166 | |
1b89a5cd SC |
167 | wxCoord w = icon.GetWidth(); |
168 | wxCoord h = icon.GetHeight(); | |
1b89a5cd | 169 | |
0ebd9515 | 170 | m_graphicContext->DrawIcon( icon , x, y, w, h ); |
1b89a5cd SC |
171 | } |
172 | ||
888dde65 | 173 | bool wxGCDCImpl::StartDoc( const wxString& WXUNUSED(message) ) |
fcaea2fa SC |
174 | { |
175 | return false; | |
176 | } | |
177 | ||
888dde65 | 178 | void wxGCDCImpl::EndDoc() |
fcaea2fa SC |
179 | { |
180 | } | |
181 | ||
888dde65 | 182 | void wxGCDCImpl::StartPage() |
fcaea2fa SC |
183 | { |
184 | } | |
185 | ||
888dde65 | 186 | void wxGCDCImpl::EndPage() |
fcaea2fa SC |
187 | { |
188 | } | |
189 | ||
888dde65 | 190 | void wxGCDCImpl::Flush() |
fcaea2fa SC |
191 | { |
192 | #ifdef __WXMAC__ | |
193 | CGContextFlush( (CGContextRef) m_graphicContext->GetNativeContext() ); | |
194 | #endif | |
195 | } | |
196 | ||
888dde65 | 197 | void wxGCDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) |
1b89a5cd | 198 | { |
888dde65 | 199 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") ); |
1b89a5cd | 200 | |
0ebd9515 | 201 | m_graphicContext->Clip( x, y, w, h ); |
1b89a5cd SC |
202 | if ( m_clipping ) |
203 | { | |
0ebd9515 SC |
204 | m_clipX1 = wxMax( m_clipX1, x ); |
205 | m_clipY1 = wxMax( m_clipY1, y ); | |
206 | m_clipX2 = wxMin( m_clipX2, (x + w) ); | |
207 | m_clipY2 = wxMin( m_clipY2, (y + h) ); | |
1b89a5cd SC |
208 | } |
209 | else | |
210 | { | |
211 | m_clipping = true; | |
212 | ||
0ebd9515 SC |
213 | m_clipX1 = x; |
214 | m_clipY1 = y; | |
215 | m_clipX2 = x + w; | |
216 | m_clipY2 = y + h; | |
1b89a5cd SC |
217 | } |
218 | } | |
219 | ||
888dde65 | 220 | void wxGCDCImpl::DoSetClippingRegionAsRegion( const wxRegion ®ion ) |
1b89a5cd | 221 | { |
4bae004c | 222 | // region is in device coordinates |
888dde65 | 223 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") ); |
1b89a5cd SC |
224 | |
225 | if (region.Empty()) | |
226 | { | |
fcaea2fa | 227 | //DestroyClippingRegion(); |
1b89a5cd SC |
228 | return; |
229 | } | |
230 | ||
4bae004c | 231 | wxRegion logRegion( region ); |
1b89a5cd | 232 | wxCoord x, y, w, h; |
0ebd9515 | 233 | |
4bae004c SC |
234 | logRegion.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) ); |
235 | logRegion.GetBox( x, y, w, h ); | |
236 | ||
237 | m_graphicContext->Clip( logRegion ); | |
0ebd9515 | 238 | if ( m_clipping ) |
1b89a5cd | 239 | { |
0ebd9515 SC |
240 | m_clipX1 = wxMax( m_clipX1, x ); |
241 | m_clipY1 = wxMax( m_clipY1, y ); | |
242 | m_clipX2 = wxMin( m_clipX2, (x + w) ); | |
243 | m_clipY2 = wxMin( m_clipY2, (y + h) ); | |
1b89a5cd SC |
244 | } |
245 | else | |
246 | { | |
0ebd9515 | 247 | m_clipping = true; |
1b89a5cd | 248 | |
0ebd9515 SC |
249 | m_clipX1 = x; |
250 | m_clipY1 = y; | |
251 | m_clipX2 = x + w; | |
252 | m_clipY2 = y + h; | |
1b89a5cd SC |
253 | } |
254 | } | |
255 | ||
888dde65 | 256 | void wxGCDCImpl::DestroyClippingRegion() |
1b89a5cd SC |
257 | { |
258 | m_graphicContext->ResetClip(); | |
cb6e26b8 SC |
259 | // currently the clip eg of a window extends to the area between the scrollbars |
260 | // so we must explicitely make sure it only covers the area we want it to draw | |
261 | int width, height ; | |
888dde65 | 262 | GetOwner()->GetSize( &width , &height ) ; |
fcaea2fa | 263 | m_graphicContext->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , DeviceToLogicalXRel(width), DeviceToLogicalYRel(height) ); |
cb6e26b8 | 264 | |
1b89a5cd SC |
265 | m_graphicContext->SetPen( m_pen ); |
266 | m_graphicContext->SetBrush( m_brush ); | |
267 | ||
268 | m_clipping = false; | |
269 | } | |
270 | ||
888dde65 | 271 | void wxGCDCImpl::DoGetSizeMM( int* width, int* height ) const |
1b89a5cd SC |
272 | { |
273 | int w = 0, h = 0; | |
274 | ||
888dde65 | 275 | GetOwner()->GetSize( &w, &h ); |
1b89a5cd SC |
276 | if (width) |
277 | *width = long( double(w) / (m_scaleX * m_mm_to_pix_x) ); | |
278 | if (height) | |
279 | *height = long( double(h) / (m_scaleY * m_mm_to_pix_y) ); | |
280 | } | |
281 | ||
888dde65 | 282 | void wxGCDCImpl::SetTextForeground( const wxColour &col ) |
1b89a5cd | 283 | { |
888dde65 | 284 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") ); |
1b89a5cd SC |
285 | |
286 | if ( col != m_textForegroundColour ) | |
287 | { | |
288 | m_textForegroundColour = col; | |
289 | m_graphicContext->SetFont( m_font, m_textForegroundColour ); | |
290 | } | |
291 | } | |
292 | ||
888dde65 | 293 | void wxGCDCImpl::SetTextBackground( const wxColour &col ) |
1b89a5cd | 294 | { |
888dde65 | 295 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") ); |
1b89a5cd SC |
296 | |
297 | m_textBackgroundColour = col; | |
298 | } | |
299 | ||
888dde65 | 300 | void wxGCDCImpl::SetMapMode( int mode ) |
1b89a5cd SC |
301 | { |
302 | switch (mode) | |
303 | { | |
304 | case wxMM_TWIPS: | |
305 | SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y ); | |
306 | break; | |
307 | ||
308 | case wxMM_POINTS: | |
309 | SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y ); | |
310 | break; | |
311 | ||
312 | case wxMM_METRIC: | |
313 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); | |
314 | break; | |
315 | ||
316 | case wxMM_LOMETRIC: | |
317 | SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 ); | |
318 | break; | |
319 | ||
320 | case wxMM_TEXT: | |
321 | default: | |
322 | SetLogicalScale( 1.0, 1.0 ); | |
323 | break; | |
324 | } | |
325 | ||
326 | ComputeScaleAndOrigin(); | |
327 | } | |
328 | ||
888dde65 | 329 | wxSize wxGCDCImpl::GetPPI() const |
1b89a5cd SC |
330 | { |
331 | return wxSize(72, 72); | |
332 | } | |
333 | ||
888dde65 | 334 | int wxGCDCImpl::GetDepth() const |
1b89a5cd SC |
335 | { |
336 | return 32; | |
337 | } | |
338 | ||
888dde65 | 339 | void wxGCDCImpl::ComputeScaleAndOrigin() |
2dedef25 SC |
340 | { |
341 | wxDCImpl::ComputeScaleAndOrigin(); | |
1b89a5cd | 342 | |
fd791571 SC |
343 | if ( m_graphicContext ) |
344 | { | |
345 | m_matrixCurrent = m_graphicContext->CreateMatrix(); | |
346 | m_matrixCurrent.Translate( m_deviceOriginX, m_deviceOriginY ); | |
347 | m_matrixCurrent.Scale( m_scaleX, m_scaleY ); | |
348 | // the logical origin sets the origin to have new coordinates | |
349 | m_matrixCurrent.Translate( -m_logicalOriginX, -m_logicalOriginY ); | |
350 | ||
351 | m_graphicContext->SetTransform( m_matrixOriginal ); | |
352 | m_graphicContext->ConcatTransform( m_matrixCurrent ); | |
353 | } | |
1b89a5cd SC |
354 | } |
355 | ||
888dde65 | 356 | void wxGCDCImpl::SetPalette( const wxPalette& WXUNUSED(palette) ) |
1b89a5cd SC |
357 | { |
358 | ||
359 | } | |
360 | ||
888dde65 | 361 | void wxGCDCImpl::SetBackgroundMode( int mode ) |
1b89a5cd SC |
362 | { |
363 | m_backgroundMode = mode; | |
364 | } | |
365 | ||
888dde65 | 366 | void wxGCDCImpl::SetFont( const wxFont &font ) |
1b89a5cd SC |
367 | { |
368 | m_font = font; | |
369 | if ( m_graphicContext ) | |
370 | { | |
371 | wxFont f = font; | |
888dde65 | 372 | if ( f.IsOk() ) |
0ebd9515 | 373 | f.SetPointSize( /*LogicalToDeviceYRel*/(font.GetPointSize())); |
1b89a5cd SC |
374 | m_graphicContext->SetFont( f, m_textForegroundColour ); |
375 | } | |
376 | } | |
377 | ||
888dde65 | 378 | void wxGCDCImpl::SetPen( const wxPen &pen ) |
1b89a5cd SC |
379 | { |
380 | if ( m_pen == pen ) | |
381 | return; | |
382 | ||
383 | m_pen = pen; | |
384 | if ( m_graphicContext ) | |
385 | { | |
0ebd9515 | 386 | m_graphicContext->SetPen( m_pen ); |
1b89a5cd SC |
387 | } |
388 | } | |
389 | ||
888dde65 | 390 | void wxGCDCImpl::SetBrush( const wxBrush &brush ) |
1b89a5cd SC |
391 | { |
392 | if (m_brush == brush) | |
393 | return; | |
394 | ||
395 | m_brush = brush; | |
396 | if ( m_graphicContext ) | |
397 | { | |
0ebd9515 | 398 | m_graphicContext->SetBrush( m_brush ); |
1b89a5cd SC |
399 | } |
400 | } | |
4280b879 | 401 | |
888dde65 | 402 | void wxGCDCImpl::SetBackground( const wxBrush &brush ) |
1b89a5cd SC |
403 | { |
404 | if (m_backgroundBrush == brush) | |
405 | return; | |
406 | ||
407 | m_backgroundBrush = brush; | |
888dde65 | 408 | if (!m_backgroundBrush.IsOk()) |
1b89a5cd SC |
409 | return; |
410 | } | |
411 | ||
888dde65 | 412 | void wxGCDCImpl::SetLogicalFunction( int function ) |
1b89a5cd SC |
413 | { |
414 | if (m_logicalFunction == function) | |
415 | return; | |
416 | ||
417 | m_logicalFunction = function; | |
4280b879 SC |
418 | if ( m_graphicContext->SetLogicalFunction( function ) ) |
419 | m_logicalFunctionSupported=true; | |
1b89a5cd | 420 | else |
4280b879 | 421 | m_logicalFunctionSupported=false; |
1b89a5cd SC |
422 | } |
423 | ||
888dde65 | 424 | bool wxGCDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), |
1b89a5cd SC |
425 | const wxColour& WXUNUSED(col), int WXUNUSED(style)) |
426 | { | |
427 | return false; | |
428 | } | |
429 | ||
888dde65 | 430 | bool wxGCDCImpl::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const |
1b89a5cd SC |
431 | { |
432 | // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") ); | |
433 | return false; | |
434 | } | |
435 | ||
888dde65 | 436 | void wxGCDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
1b89a5cd | 437 | { |
888dde65 | 438 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") ); |
1b89a5cd | 439 | |
4280b879 | 440 | if ( !m_logicalFunctionSupported ) |
1b89a5cd | 441 | return; |
1b89a5cd | 442 | |
0ebd9515 | 443 | m_graphicContext->StrokeLine(x1,y1,x2,y2); |
1b89a5cd SC |
444 | |
445 | CalcBoundingBox(x1, y1); | |
446 | CalcBoundingBox(x2, y2); | |
447 | } | |
448 | ||
888dde65 | 449 | void wxGCDCImpl::DoCrossHair( wxCoord x, wxCoord y ) |
1b89a5cd | 450 | { |
888dde65 | 451 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") ); |
1b89a5cd | 452 | |
4280b879 | 453 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
454 | return; |
455 | ||
456 | int w = 0, h = 0; | |
457 | ||
888dde65 | 458 | GetOwner()->GetSize( &w, &h ); |
1b89a5cd | 459 | |
0ebd9515 SC |
460 | m_graphicContext->StrokeLine(0,y,w,y); |
461 | m_graphicContext->StrokeLine(x,0,x,h); | |
1b89a5cd | 462 | |
0ebd9515 SC |
463 | CalcBoundingBox(0, 0); |
464 | CalcBoundingBox(0+w, 0+h); | |
1b89a5cd SC |
465 | } |
466 | ||
888dde65 | 467 | void wxGCDCImpl::DoDrawArc( wxCoord x1, wxCoord y1, |
1b89a5cd SC |
468 | wxCoord x2, wxCoord y2, |
469 | wxCoord xc, wxCoord yc ) | |
470 | { | |
888dde65 | 471 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") ); |
1b89a5cd | 472 | |
4280b879 | 473 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
474 | return; |
475 | ||
0ebd9515 SC |
476 | double dx = x1 - xc; |
477 | double dy = y1 - yc; | |
1b89a5cd SC |
478 | double radius = sqrt((double)(dx * dx + dy * dy)); |
479 | wxCoord rad = (wxCoord)radius; | |
480 | double sa, ea; | |
0ebd9515 | 481 | if (x1 == x2 && y1 == y2) |
1b89a5cd SC |
482 | { |
483 | sa = 0.0; | |
484 | ea = 360.0; | |
485 | } | |
486 | else if (radius == 0.0) | |
487 | { | |
488 | sa = ea = 0.0; | |
489 | } | |
490 | else | |
491 | { | |
0ebd9515 SC |
492 | sa = (x1 - xc == 0) ? |
493 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
494 | -atan2(double(y1 - yc), double(x1 - xc)) * RAD2DEG; | |
495 | ea = (x2 - xc == 0) ? | |
496 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
497 | -atan2(double(y2 - yc), double(x2 - xc)) * RAD2DEG; | |
1b89a5cd SC |
498 | } |
499 | ||
500 | bool fill = m_brush.GetStyle() != wxTRANSPARENT; | |
501 | ||
a4e73390 | 502 | wxGraphicsPath path = m_graphicContext->CreatePath(); |
1b89a5cd | 503 | if ( fill && ((x1!=x2)||(y1!=y2)) ) |
0ebd9515 | 504 | path.MoveToPoint( xc, yc ); |
4bae004c SC |
505 | // since these angles (ea,sa) are measured counter-clockwise, we invert them to |
506 | // get clockwise angles | |
507 | path.AddArc( xc, yc , rad , DegToRad(-sa) , DegToRad(-ea), false ); | |
1b89a5cd | 508 | if ( fill && ((x1!=x2)||(y1!=y2)) ) |
0ebd9515 | 509 | path.AddLineToPoint( xc, yc ); |
1b89a5cd | 510 | m_graphicContext->DrawPath(path); |
1b89a5cd SC |
511 | } |
512 | ||
888dde65 | 513 | void wxGCDCImpl::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
1b89a5cd SC |
514 | double sa, double ea ) |
515 | { | |
888dde65 | 516 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") ); |
1b89a5cd | 517 | |
4280b879 | 518 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
519 | return; |
520 | ||
1b89a5cd | 521 | m_graphicContext->PushState(); |
d9485f89 | 522 | m_graphicContext->Translate(x+w/2.0,y+h/2.0); |
0ebd9515 | 523 | wxDouble factor = ((wxDouble) w) / h; |
1b89a5cd | 524 | m_graphicContext->Scale( factor , 1.0); |
d9485f89 | 525 | |
1b89a5cd SC |
526 | // since these angles (ea,sa) are measured counter-clockwise, we invert them to |
527 | // get clockwise angles | |
fcaea2fa SC |
528 | if ( m_brush.GetStyle() != wxTRANSPARENT ) |
529 | { | |
530 | wxGraphicsPath path = m_graphicContext->CreatePath(); | |
531 | path.MoveToPoint( 0, 0 ); | |
532 | path.AddLineToPoint( h / 2.0 * cos(DegToRad(sa)) , h / 2.0 * sin(DegToRad(-sa)) ); | |
533 | path.AddLineToPoint( h / 2.0 * cos(DegToRad(ea)) , h / 2.0 * sin(DegToRad(-ea)) ); | |
534 | path.AddLineToPoint( 0, 0 ); | |
535 | m_graphicContext->FillPath( path ); | |
536 | ||
537 | path = m_graphicContext->CreatePath(); | |
538 | path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); | |
539 | m_graphicContext->FillPath( path ); | |
540 | m_graphicContext->StrokePath( path ); | |
541 | } | |
542 | else | |
543 | { | |
544 | wxGraphicsPath path = m_graphicContext->CreatePath(); | |
d9485f89 | 545 | path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); |
1b89a5cd | 546 | m_graphicContext->DrawPath( path ); |
fcaea2fa SC |
547 | } |
548 | ||
1b89a5cd | 549 | m_graphicContext->PopState(); |
1b89a5cd SC |
550 | } |
551 | ||
888dde65 | 552 | void wxGCDCImpl::DoDrawPoint( wxCoord x, wxCoord y ) |
1b89a5cd | 553 | { |
888dde65 | 554 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") ); |
1b89a5cd SC |
555 | |
556 | DoDrawLine( x , y , x + 1 , y + 1 ); | |
557 | } | |
558 | ||
888dde65 | 559 | void wxGCDCImpl::DoDrawLines(int n, wxPoint points[], |
1b89a5cd SC |
560 | wxCoord xoffset, wxCoord yoffset) |
561 | { | |
888dde65 | 562 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") ); |
1b89a5cd | 563 | |
4280b879 | 564 | if ( !m_logicalFunctionSupported ) |
1b89a5cd | 565 | return; |
1b89a5cd SC |
566 | |
567 | wxPoint2DDouble* pointsD = new wxPoint2DDouble[n]; | |
568 | for( int i = 0; i < n; ++i) | |
569 | { | |
0ebd9515 SC |
570 | pointsD[i].m_x = points[i].x + xoffset; |
571 | pointsD[i].m_y = points[i].y + yoffset; | |
1b89a5cd SC |
572 | } |
573 | ||
574 | m_graphicContext->StrokeLines( n , pointsD); | |
575 | delete[] pointsD; | |
576 | } | |
577 | ||
578 | #if wxUSE_SPLINES | |
888dde65 | 579 | void wxGCDCImpl::DoDrawSpline(const wxPointList *points) |
1b89a5cd | 580 | { |
888dde65 | 581 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") ); |
1b89a5cd | 582 | |
4280b879 | 583 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
584 | return; |
585 | ||
a4e73390 | 586 | wxGraphicsPath path = m_graphicContext->CreatePath(); |
1b89a5cd | 587 | |
b0d7707b RR |
588 | wxPointList::compatibility_iterator node = points->GetFirst(); |
589 | if (node == wxPointList::compatibility_iterator()) | |
1b89a5cd SC |
590 | // empty list |
591 | return; | |
592 | ||
b0d7707b | 593 | wxPoint *p = node->GetData(); |
1b89a5cd SC |
594 | |
595 | wxCoord x1 = p->x; | |
596 | wxCoord y1 = p->y; | |
597 | ||
598 | node = node->GetNext(); | |
b0d7707b | 599 | p = node->GetData(); |
1b89a5cd SC |
600 | |
601 | wxCoord x2 = p->x; | |
602 | wxCoord y2 = p->y; | |
603 | wxCoord cx1 = ( x1 + x2 ) / 2; | |
604 | wxCoord cy1 = ( y1 + y2 ) / 2; | |
605 | ||
0ebd9515 SC |
606 | path.MoveToPoint( x1 , y1 ); |
607 | path.AddLineToPoint( cx1 , cy1 ); | |
1b89a5cd SC |
608 | #if !wxUSE_STL |
609 | ||
610 | while ((node = node->GetNext()) != NULL) | |
611 | #else | |
612 | ||
613 | while ((node = node->GetNext())) | |
614 | #endif // !wxUSE_STL | |
615 | ||
616 | { | |
b0d7707b | 617 | p = node->GetData(); |
1b89a5cd SC |
618 | x1 = x2; |
619 | y1 = y2; | |
620 | x2 = p->x; | |
621 | y2 = p->y; | |
622 | wxCoord cx4 = (x1 + x2) / 2; | |
623 | wxCoord cy4 = (y1 + y2) / 2; | |
624 | ||
0ebd9515 | 625 | path.AddQuadCurveToPoint(x1 , y1 ,cx4 , cy4 ); |
1b89a5cd SC |
626 | |
627 | cx1 = cx4; | |
628 | cy1 = cy4; | |
629 | } | |
630 | ||
0ebd9515 | 631 | path.AddLineToPoint( x2 , y2 ); |
1b89a5cd SC |
632 | |
633 | m_graphicContext->StrokePath( path ); | |
1b89a5cd SC |
634 | } |
635 | #endif // wxUSE_SPLINES | |
636 | ||
888dde65 | 637 | void wxGCDCImpl::DoDrawPolygon( int n, wxPoint points[], |
1b89a5cd SC |
638 | wxCoord xoffset, wxCoord yoffset, |
639 | int fillStyle ) | |
640 | { | |
888dde65 | 641 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") ); |
1b89a5cd SC |
642 | |
643 | if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) ) | |
644 | return; | |
4280b879 | 645 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
646 | return; |
647 | ||
648 | bool closeIt = false; | |
649 | if (points[n-1] != points[0]) | |
650 | closeIt = true; | |
651 | ||
652 | wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)]; | |
653 | for( int i = 0; i < n; ++i) | |
654 | { | |
0ebd9515 SC |
655 | pointsD[i].m_x = points[i].x + xoffset; |
656 | pointsD[i].m_y = points[i].y + yoffset; | |
1b89a5cd SC |
657 | } |
658 | if ( closeIt ) | |
659 | pointsD[n] = pointsD[0]; | |
660 | ||
661 | m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle); | |
662 | delete[] pointsD; | |
663 | } | |
664 | ||
888dde65 | 665 | void wxGCDCImpl::DoDrawPolyPolygon(int n, |
1b89a5cd SC |
666 | int count[], |
667 | wxPoint points[], | |
668 | wxCoord xoffset, | |
669 | wxCoord yoffset, | |
670 | int fillStyle) | |
671 | { | |
672 | wxASSERT(n > 1); | |
a4e73390 | 673 | wxGraphicsPath path = m_graphicContext->CreatePath(); |
1b89a5cd SC |
674 | |
675 | int i = 0; | |
676 | for ( int j = 0; j < n; ++j) | |
677 | { | |
678 | wxPoint start = points[i]; | |
0ebd9515 | 679 | path.MoveToPoint( start.x+ xoffset, start.y+ yoffset); |
1b89a5cd SC |
680 | ++i; |
681 | int l = count[j]; | |
682 | for ( int k = 1; k < l; ++k) | |
683 | { | |
0ebd9515 | 684 | path.AddLineToPoint( points[i].x+ xoffset, points[i].y+ yoffset); |
1b89a5cd SC |
685 | ++i; |
686 | } | |
687 | // close the polygon | |
688 | if ( start != points[i-1]) | |
0ebd9515 | 689 | path.AddLineToPoint( start.x+ xoffset, start.y+ yoffset); |
1b89a5cd SC |
690 | } |
691 | m_graphicContext->DrawPath( path , fillStyle); | |
1b89a5cd SC |
692 | } |
693 | ||
888dde65 | 694 | void wxGCDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) |
1b89a5cd | 695 | { |
888dde65 | 696 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") ); |
1b89a5cd | 697 | |
4280b879 | 698 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
699 | return; |
700 | ||
1b89a5cd | 701 | // CMB: draw nothing if transformed w or h is 0 |
0ebd9515 | 702 | if (w == 0 || h == 0) |
1b89a5cd SC |
703 | return; |
704 | ||
5ebfdf41 SC |
705 | if ( m_graphicContext->ShouldOffset() ) |
706 | { | |
707 | // if we are offsetting the entire rectangle is moved 0.5, so the | |
708 | // border line gets off by 1 | |
0ebd9515 SC |
709 | w -= 1; |
710 | h -= 1; | |
5ebfdf41 | 711 | } |
0ebd9515 | 712 | m_graphicContext->DrawRectangle(x,y,w,h); |
1b89a5cd SC |
713 | } |
714 | ||
888dde65 | 715 | void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, |
0ebd9515 | 716 | wxCoord w, wxCoord h, |
1b89a5cd SC |
717 | double radius) |
718 | { | |
888dde65 | 719 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") ); |
1b89a5cd | 720 | |
4280b879 | 721 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
722 | return; |
723 | ||
724 | if (radius < 0.0) | |
0ebd9515 | 725 | radius = - radius * ((w < h) ? w : h); |
1b89a5cd SC |
726 | |
727 | // CMB: draw nothing if transformed w or h is 0 | |
0ebd9515 | 728 | if (w == 0 || h == 0) |
1b89a5cd SC |
729 | return; |
730 | ||
d9485f89 RD |
731 | if ( m_graphicContext->ShouldOffset() ) |
732 | { | |
733 | // if we are offsetting the entire rectangle is moved 0.5, so the | |
734 | // border line gets off by 1 | |
735 | w -= 1; | |
736 | h -= 1; | |
737 | } | |
0ebd9515 | 738 | m_graphicContext->DrawRoundedRectangle( x,y,w,h,radius); |
1b89a5cd SC |
739 | } |
740 | ||
888dde65 | 741 | void wxGCDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) |
1b89a5cd | 742 | { |
888dde65 | 743 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") ); |
1b89a5cd | 744 | |
4280b879 | 745 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
746 | return; |
747 | ||
d9485f89 RD |
748 | if ( m_graphicContext->ShouldOffset() ) |
749 | { | |
750 | // if we are offsetting the entire rectangle is moved 0.5, so the | |
751 | // border line gets off by 1 | |
752 | w -= 1; | |
753 | h -= 1; | |
754 | } | |
0ebd9515 | 755 | m_graphicContext->DrawEllipse(x,y,w,h); |
1b89a5cd SC |
756 | } |
757 | ||
888dde65 | 758 | bool wxGCDCImpl::CanDrawBitmap() const |
1b89a5cd SC |
759 | { |
760 | return true; | |
761 | } | |
762 | ||
888dde65 | 763 | bool wxGCDCImpl::DoBlit( |
1b89a5cd | 764 | wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
e3b81044 | 765 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask, |
1b89a5cd SC |
766 | wxCoord xsrcMask, wxCoord ysrcMask ) |
767 | { | |
e3b81044 VZ |
768 | return DoStretchBlit( xdest, ydest, width, height, |
769 | source, xsrc, ysrc, width, height, logical_func, useMask, | |
770 | xsrcMask,ysrcMask ); | |
771 | } | |
772 | ||
888dde65 | 773 | bool wxGCDCImpl::DoStretchBlit( |
e3b81044 VZ |
774 | wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight, |
775 | wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight, | |
776 | int logical_func , bool WXUNUSED(useMask), | |
777 | wxCoord xsrcMask, wxCoord ysrcMask ) | |
778 | { | |
888dde65 RR |
779 | wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") ); |
780 | wxCHECK_MSG( source->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") ); | |
6c0aace2 | 781 | |
1b89a5cd SC |
782 | if ( logical_func == wxNO_OP ) |
783 | return true; | |
fcaea2fa SC |
784 | else if ( !m_graphicContext->SetLogicalFunction( logical_func ) ) |
785 | ||
c64c9cd3 KO |
786 | { |
787 | wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") ); | |
788 | return false; | |
789 | } | |
1b89a5cd SC |
790 | |
791 | if (xsrcMask == -1 && ysrcMask == -1) | |
792 | { | |
793 | xsrcMask = xsrc; | |
794 | ysrcMask = ysrc; | |
795 | } | |
796 | ||
cce4a2ce RD |
797 | wxRect subrect(source->LogicalToDeviceX(xsrc), |
798 | source->LogicalToDeviceY(ysrc), | |
e3b81044 VZ |
799 | source->LogicalToDeviceXRel(srcWidth), |
800 | source->LogicalToDeviceYRel(srcHeight)); | |
cce4a2ce RD |
801 | |
802 | // if needed clip the subrect down to the size of the source DC | |
803 | wxCoord sw, sh; | |
804 | source->GetSize(&sw, &sh); | |
805 | sw = source->LogicalToDeviceXRel(sw); | |
806 | sh = source->LogicalToDeviceYRel(sh); | |
807 | if (subrect.x + subrect.width > sw) | |
808 | subrect.width = sw - subrect.x; | |
809 | if (subrect.y + subrect.height > sh) | |
810 | subrect.height = sh - subrect.y; | |
6c0aace2 | 811 | |
64c8307c | 812 | wxBitmap blit = source->GetAsBitmap( &subrect ); |
6c0aace2 | 813 | |
888dde65 | 814 | if ( blit.IsOk() ) |
c64c9cd3 | 815 | { |
cce4a2ce | 816 | m_graphicContext->DrawBitmap( blit, xdest, ydest, |
e3b81044 | 817 | dstWidth, dstHeight); |
c64c9cd3 | 818 | } |
1b89a5cd SC |
819 | else |
820 | { | |
c64c9cd3 | 821 | wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") ); |
1b89a5cd SC |
822 | return false; |
823 | } | |
824 | ||
fcaea2fa SC |
825 | // reset logical function |
826 | m_graphicContext->SetLogicalFunction( m_logicalFunction ); | |
827 | ||
1b89a5cd SC |
828 | return true; |
829 | } | |
830 | ||
888dde65 | 831 | void wxGCDCImpl::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, |
1b89a5cd SC |
832 | double angle) |
833 | { | |
888dde65 | 834 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") ); |
1b89a5cd SC |
835 | |
836 | if ( str.length() == 0 ) | |
837 | return; | |
4280b879 | 838 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
839 | return; |
840 | ||
068eb463 SC |
841 | if ( m_backgroundMode == wxTRANSPARENT ) |
842 | m_graphicContext->DrawText( str, x ,y , DegToRad(angle )); | |
843 | else | |
844 | m_graphicContext->DrawText( str, x ,y , DegToRad(angle ), m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) ); | |
1b89a5cd SC |
845 | } |
846 | ||
888dde65 | 847 | void wxGCDCImpl::DoDrawText(const wxString& str, wxCoord x, wxCoord y) |
1b89a5cd | 848 | { |
888dde65 | 849 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") ); |
1b89a5cd SC |
850 | |
851 | if ( str.length() == 0 ) | |
852 | return; | |
4280b879 SC |
853 | |
854 | if ( !m_logicalFunctionSupported ) | |
1b89a5cd SC |
855 | return; |
856 | ||
068eb463 SC |
857 | if ( m_backgroundMode == wxTRANSPARENT ) |
858 | m_graphicContext->DrawText( str, x ,y); | |
859 | else | |
860 | m_graphicContext->DrawText( str, x ,y , m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) ); | |
1b89a5cd SC |
861 | } |
862 | ||
888dde65 | 863 | bool wxGCDCImpl::CanGetTextExtent() const |
1b89a5cd | 864 | { |
888dde65 | 865 | wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") ); |
1b89a5cd SC |
866 | |
867 | return true; | |
868 | } | |
869 | ||
888dde65 | 870 | void wxGCDCImpl::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height, |
1b89a5cd | 871 | wxCoord *descent, wxCoord *externalLeading , |
c94f845b | 872 | const wxFont *theFont ) const |
1b89a5cd | 873 | { |
888dde65 | 874 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") ); |
1b89a5cd SC |
875 | |
876 | if ( theFont ) | |
877 | { | |
878 | m_graphicContext->SetFont( *theFont, m_textForegroundColour ); | |
879 | } | |
880 | ||
881 | wxDouble h , d , e , w; | |
882 | ||
883 | m_graphicContext->GetTextExtent( str, &w, &h, &d, &e ); | |
884 | ||
885 | if ( height ) | |
fcaea2fa | 886 | *height = (wxCoord)(h+0.5); |
1b89a5cd | 887 | if ( descent ) |
fcaea2fa | 888 | *descent = (wxCoord)(d+0.5); |
1b89a5cd | 889 | if ( externalLeading ) |
fcaea2fa | 890 | *externalLeading = (wxCoord)(e+0.5); |
1b89a5cd | 891 | if ( width ) |
fcaea2fa | 892 | *width = (wxCoord)(w+0.5); |
1b89a5cd SC |
893 | |
894 | if ( theFont ) | |
895 | { | |
896 | m_graphicContext->SetFont( m_font, m_textForegroundColour ); | |
897 | } | |
898 | } | |
899 | ||
888dde65 | 900 | bool wxGCDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const |
1b89a5cd | 901 | { |
888dde65 | 902 | wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") ); |
1b89a5cd SC |
903 | widths.Clear(); |
904 | widths.Add(0,text.Length()); | |
905 | if ( text.IsEmpty() ) | |
906 | return true; | |
907 | ||
908 | wxArrayDouble widthsD; | |
909 | ||
910 | m_graphicContext->GetPartialTextExtents( text, widthsD ); | |
911 | for ( size_t i = 0; i < widths.GetCount(); ++i ) | |
0ebd9515 | 912 | widths[i] = (wxCoord)(widthsD[i] + 0.5); |
1b89a5cd SC |
913 | |
914 | return true; | |
915 | } | |
916 | ||
888dde65 | 917 | wxCoord wxGCDCImpl::GetCharWidth(void) const |
1b89a5cd SC |
918 | { |
919 | wxCoord width; | |
920 | DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL ); | |
921 | ||
922 | return width; | |
923 | } | |
924 | ||
888dde65 | 925 | wxCoord wxGCDCImpl::GetCharHeight(void) const |
1b89a5cd SC |
926 | { |
927 | wxCoord height; | |
928 | DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ); | |
929 | ||
930 | return height; | |
931 | } | |
932 | ||
888dde65 | 933 | void wxGCDCImpl::Clear(void) |
1b89a5cd | 934 | { |
888dde65 | 935 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") ); |
1b89a5cd SC |
936 | // TODO better implementation / incorporate size info into wxGCDC or context |
937 | m_graphicContext->SetBrush( m_backgroundBrush ); | |
938 | wxPen p = *wxTRANSPARENT_PEN; | |
939 | m_graphicContext->SetPen( p ); | |
940 | DoDrawRectangle( 0, 0, 32000 , 32000 ); | |
6c0aace2 | 941 | m_graphicContext->SetPen( m_pen ); |
1b89a5cd SC |
942 | m_graphicContext->SetBrush( m_brush ); |
943 | } | |
944 | ||
888dde65 | 945 | void wxGCDCImpl::DoGetSize(int *width, int *height) const |
1b89a5cd | 946 | { |
fcaea2fa SC |
947 | *width = 10000; |
948 | *height = 10000; | |
1b89a5cd SC |
949 | } |
950 | ||
888dde65 | 951 | void wxGCDCImpl::DoGradientFillLinear(const wxRect& rect, |
1b89a5cd SC |
952 | const wxColour& initialColour, |
953 | const wxColour& destColour, | |
954 | wxDirection nDirection ) | |
955 | { | |
956 | wxPoint start; | |
957 | wxPoint end; | |
958 | switch( nDirection) | |
959 | { | |
960 | case wxWEST : | |
961 | start = rect.GetRightBottom(); | |
962 | start.x++; | |
963 | end = rect.GetLeftBottom(); | |
964 | break; | |
965 | case wxEAST : | |
966 | start = rect.GetLeftBottom(); | |
967 | end = rect.GetRightBottom(); | |
968 | end.x++; | |
969 | break; | |
970 | case wxNORTH : | |
971 | start = rect.GetLeftBottom(); | |
972 | start.y++; | |
973 | end = rect.GetLeftTop(); | |
974 | break; | |
975 | case wxSOUTH : | |
976 | start = rect.GetLeftTop(); | |
977 | end = rect.GetLeftBottom(); | |
978 | end.y++; | |
979 | break; | |
980 | default : | |
981 | break; | |
982 | } | |
983 | ||
0ebd9515 | 984 | if (rect.width == 0 || rect.height == 0) |
1b89a5cd SC |
985 | return; |
986 | ||
0ebd9515 SC |
987 | m_graphicContext->SetBrush( m_graphicContext->CreateLinearGradientBrush( |
988 | start.x,start.y,end.x,end.y, initialColour, destColour)); | |
1b89a5cd | 989 | m_graphicContext->SetPen(*wxTRANSPARENT_PEN); |
0ebd9515 | 990 | m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height); |
1b89a5cd SC |
991 | m_graphicContext->SetPen(m_pen); |
992 | } | |
993 | ||
888dde65 | 994 | void wxGCDCImpl::DoGradientFillConcentric(const wxRect& rect, |
1b89a5cd SC |
995 | const wxColour& initialColour, |
996 | const wxColour& destColour, | |
997 | const wxPoint& circleCenter) | |
998 | { | |
999 | //Radius | |
1000 | wxInt32 cx = rect.GetWidth() / 2; | |
1001 | wxInt32 cy = rect.GetHeight() / 2; | |
1002 | wxInt32 nRadius; | |
1003 | if (cx < cy) | |
1004 | nRadius = cx; | |
1005 | else | |
1006 | nRadius = cy; | |
1007 | ||
0ebd9515 | 1008 | // make sure the background is filled (todo move into specific platform implementation ?) |
1b89a5cd SC |
1009 | m_graphicContext->SetPen(*wxTRANSPARENT_PEN); |
1010 | m_graphicContext->SetBrush( wxBrush( destColour) ); | |
0ebd9515 | 1011 | m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height); |
1b89a5cd SC |
1012 | |
1013 | m_graphicContext->SetBrush( m_graphicContext->CreateRadialGradientBrush( | |
0ebd9515 SC |
1014 | rect.x+circleCenter.x,rect.y+circleCenter.y, |
1015 | rect.x+circleCenter.x,rect.y+circleCenter.y, | |
1016 | nRadius,initialColour,destColour)); | |
1b89a5cd | 1017 | |
0ebd9515 | 1018 | m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height); |
1b89a5cd SC |
1019 | m_graphicContext->SetPen(m_pen); |
1020 | } | |
1021 | ||
888dde65 | 1022 | void wxGCDCImpl::DoDrawCheckMark(wxCoord x, wxCoord y, |
1b89a5cd SC |
1023 | wxCoord width, wxCoord height) |
1024 | { | |
888dde65 | 1025 | wxDCImpl::DoDrawCheckMark(x,y,width,height); |
1b89a5cd SC |
1026 | } |
1027 | ||
1028 | #endif // wxUSE_GRAPHICS_CONTEXT |