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