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