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