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