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