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