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