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