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