]>
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 | { |
0b6a49c2 | 268 | #ifdef __WXOSX_OR_COCOA__ |
fcaea2fa SC |
269 | CGContextFlush( (CGContextRef) m_graphicContext->GetNativeContext() ); |
270 | #endif | |
271 | } | |
272 | ||
888dde65 | 273 | void wxGCDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) |
1b89a5cd | 274 | { |
888dde65 | 275 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") ); |
1b89a5cd | 276 | |
0ebd9515 | 277 | m_graphicContext->Clip( x, y, w, h ); |
1b89a5cd SC |
278 | if ( m_clipping ) |
279 | { | |
0ebd9515 SC |
280 | m_clipX1 = wxMax( m_clipX1, x ); |
281 | m_clipY1 = wxMax( m_clipY1, y ); | |
282 | m_clipX2 = wxMin( m_clipX2, (x + w) ); | |
283 | m_clipY2 = wxMin( m_clipY2, (y + h) ); | |
1b89a5cd SC |
284 | } |
285 | else | |
286 | { | |
287 | m_clipping = true; | |
288 | ||
0ebd9515 SC |
289 | m_clipX1 = x; |
290 | m_clipY1 = y; | |
291 | m_clipX2 = x + w; | |
292 | m_clipY2 = y + h; | |
1b89a5cd SC |
293 | } |
294 | } | |
295 | ||
fdaad94e | 296 | void wxGCDCImpl::DoSetDeviceClippingRegion( const wxRegion ®ion ) |
1b89a5cd | 297 | { |
4bae004c | 298 | // region is in device coordinates |
fdaad94e | 299 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetDeviceClippingRegion - invalid DC") ); |
1b89a5cd SC |
300 | |
301 | if (region.Empty()) | |
302 | { | |
fcaea2fa | 303 | //DestroyClippingRegion(); |
1b89a5cd SC |
304 | return; |
305 | } | |
306 | ||
4bae004c | 307 | wxRegion logRegion( region ); |
1b89a5cd | 308 | wxCoord x, y, w, h; |
0ebd9515 | 309 | |
4bae004c SC |
310 | logRegion.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) ); |
311 | logRegion.GetBox( x, y, w, h ); | |
312 | ||
313 | m_graphicContext->Clip( logRegion ); | |
0ebd9515 | 314 | if ( m_clipping ) |
1b89a5cd | 315 | { |
0ebd9515 SC |
316 | m_clipX1 = wxMax( m_clipX1, x ); |
317 | m_clipY1 = wxMax( m_clipY1, y ); | |
318 | m_clipX2 = wxMin( m_clipX2, (x + w) ); | |
319 | m_clipY2 = wxMin( m_clipY2, (y + h) ); | |
1b89a5cd SC |
320 | } |
321 | else | |
322 | { | |
0ebd9515 | 323 | m_clipping = true; |
1b89a5cd | 324 | |
0ebd9515 SC |
325 | m_clipX1 = x; |
326 | m_clipY1 = y; | |
327 | m_clipX2 = x + w; | |
328 | m_clipY2 = y + h; | |
1b89a5cd SC |
329 | } |
330 | } | |
331 | ||
888dde65 | 332 | void wxGCDCImpl::DestroyClippingRegion() |
1b89a5cd SC |
333 | { |
334 | m_graphicContext->ResetClip(); | |
cb6e26b8 SC |
335 | // currently the clip eg of a window extends to the area between the scrollbars |
336 | // so we must explicitely make sure it only covers the area we want it to draw | |
337 | int width, height ; | |
888dde65 | 338 | GetOwner()->GetSize( &width , &height ) ; |
fcaea2fa | 339 | m_graphicContext->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , DeviceToLogicalXRel(width), DeviceToLogicalYRel(height) ); |
b02d4340 | 340 | |
1b89a5cd SC |
341 | m_graphicContext->SetPen( m_pen ); |
342 | m_graphicContext->SetBrush( m_brush ); | |
343 | ||
344 | m_clipping = false; | |
345 | } | |
346 | ||
888dde65 | 347 | void wxGCDCImpl::DoGetSizeMM( int* width, int* height ) const |
1b89a5cd SC |
348 | { |
349 | int w = 0, h = 0; | |
350 | ||
888dde65 | 351 | GetOwner()->GetSize( &w, &h ); |
1b89a5cd SC |
352 | if (width) |
353 | *width = long( double(w) / (m_scaleX * m_mm_to_pix_x) ); | |
354 | if (height) | |
355 | *height = long( double(h) / (m_scaleY * m_mm_to_pix_y) ); | |
356 | } | |
357 | ||
888dde65 | 358 | void wxGCDCImpl::SetTextForeground( const wxColour &col ) |
1b89a5cd | 359 | { |
888dde65 | 360 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") ); |
1b89a5cd SC |
361 | |
362 | if ( col != m_textForegroundColour ) | |
363 | { | |
364 | m_textForegroundColour = col; | |
365 | m_graphicContext->SetFont( m_font, m_textForegroundColour ); | |
366 | } | |
367 | } | |
368 | ||
888dde65 | 369 | void wxGCDCImpl::SetTextBackground( const wxColour &col ) |
1b89a5cd | 370 | { |
888dde65 | 371 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") ); |
1b89a5cd SC |
372 | |
373 | m_textBackgroundColour = col; | |
374 | } | |
375 | ||
89efaf2b | 376 | void wxGCDCImpl::SetMapMode( wxMappingMode mode ) |
1b89a5cd SC |
377 | { |
378 | switch (mode) | |
379 | { | |
380 | case wxMM_TWIPS: | |
381 | SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y ); | |
382 | break; | |
383 | ||
384 | case wxMM_POINTS: | |
385 | SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y ); | |
386 | break; | |
387 | ||
388 | case wxMM_METRIC: | |
389 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); | |
390 | break; | |
391 | ||
392 | case wxMM_LOMETRIC: | |
393 | SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 ); | |
394 | break; | |
395 | ||
396 | case wxMM_TEXT: | |
397 | default: | |
398 | SetLogicalScale( 1.0, 1.0 ); | |
399 | break; | |
400 | } | |
401 | ||
402 | ComputeScaleAndOrigin(); | |
403 | } | |
404 | ||
888dde65 | 405 | wxSize wxGCDCImpl::GetPPI() const |
1b89a5cd SC |
406 | { |
407 | return wxSize(72, 72); | |
408 | } | |
409 | ||
888dde65 | 410 | int wxGCDCImpl::GetDepth() const |
1b89a5cd SC |
411 | { |
412 | return 32; | |
413 | } | |
414 | ||
888dde65 | 415 | void wxGCDCImpl::ComputeScaleAndOrigin() |
b02d4340 | 416 | { |
2dedef25 | 417 | wxDCImpl::ComputeScaleAndOrigin(); |
1b89a5cd | 418 | |
fd791571 SC |
419 | if ( m_graphicContext ) |
420 | { | |
421 | m_matrixCurrent = m_graphicContext->CreateMatrix(); | |
08de4403 | 422 | |
fd791571 | 423 | // the logical origin sets the origin to have new coordinates |
08de4403 | 424 | m_matrixCurrent.Translate( m_deviceOriginX - m_logicalOriginX * m_signX * m_scaleX, |
d225267e | 425 | m_deviceOriginY-m_logicalOriginY * m_signY * m_scaleY); |
08de4403 | 426 | |
d225267e | 427 | m_matrixCurrent.Scale( m_scaleX * m_signX, m_scaleY * m_signY ); |
08de4403 | 428 | |
fd791571 SC |
429 | m_graphicContext->SetTransform( m_matrixOriginal ); |
430 | m_graphicContext->ConcatTransform( m_matrixCurrent ); | |
431 | } | |
1b89a5cd SC |
432 | } |
433 | ||
888dde65 | 434 | void wxGCDCImpl::SetPalette( const wxPalette& WXUNUSED(palette) ) |
1b89a5cd SC |
435 | { |
436 | ||
437 | } | |
438 | ||
888dde65 | 439 | void wxGCDCImpl::SetBackgroundMode( int mode ) |
1b89a5cd SC |
440 | { |
441 | m_backgroundMode = mode; | |
442 | } | |
443 | ||
888dde65 | 444 | void wxGCDCImpl::SetFont( const wxFont &font ) |
1b89a5cd SC |
445 | { |
446 | m_font = font; | |
447 | if ( m_graphicContext ) | |
448 | { | |
449 | wxFont f = font; | |
888dde65 | 450 | if ( f.IsOk() ) |
0ebd9515 | 451 | f.SetPointSize( /*LogicalToDeviceYRel*/(font.GetPointSize())); |
1b89a5cd | 452 | m_graphicContext->SetFont( f, m_textForegroundColour ); |
92a94260 | 453 | #if defined(__WXGTK__) || defined(__WXOSX__) |
03647350 | 454 | if ( m_font.IsOk() && m_font.GetNoAntiAliasing() ) |
92a94260 SC |
455 | { |
456 | m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE); | |
457 | } | |
458 | #endif | |
1b89a5cd SC |
459 | } |
460 | } | |
461 | ||
888dde65 | 462 | void wxGCDCImpl::SetPen( const wxPen &pen ) |
1b89a5cd SC |
463 | { |
464 | if ( m_pen == pen ) | |
465 | return; | |
466 | ||
467 | m_pen = pen; | |
468 | if ( m_graphicContext ) | |
469 | { | |
0ebd9515 | 470 | m_graphicContext->SetPen( m_pen ); |
1b89a5cd SC |
471 | } |
472 | } | |
473 | ||
888dde65 | 474 | void wxGCDCImpl::SetBrush( const wxBrush &brush ) |
1b89a5cd SC |
475 | { |
476 | if (m_brush == brush) | |
477 | return; | |
478 | ||
479 | m_brush = brush; | |
480 | if ( m_graphicContext ) | |
481 | { | |
0ebd9515 | 482 | m_graphicContext->SetBrush( m_brush ); |
1b89a5cd SC |
483 | } |
484 | } | |
b02d4340 | 485 | |
888dde65 | 486 | void wxGCDCImpl::SetBackground( const wxBrush &brush ) |
1b89a5cd SC |
487 | { |
488 | if (m_backgroundBrush == brush) | |
489 | return; | |
490 | ||
491 | m_backgroundBrush = brush; | |
888dde65 | 492 | if (!m_backgroundBrush.IsOk()) |
1b89a5cd SC |
493 | return; |
494 | } | |
495 | ||
89efaf2b | 496 | void wxGCDCImpl::SetLogicalFunction( wxRasterOperationMode function ) |
1b89a5cd SC |
497 | { |
498 | if (m_logicalFunction == function) | |
499 | return; | |
500 | ||
501 | m_logicalFunction = function; | |
03647350 | 502 | |
bf02a7f9 SC |
503 | wxCompositionMode mode; |
504 | m_logicalFunctionSupported = TranslateRasterOp( function, &mode); | |
505 | if (m_logicalFunctionSupported) | |
506 | m_logicalFunctionSupported = m_graphicContext->SetCompositionMode(mode); | |
03647350 | 507 | |
bf02a7f9 SC |
508 | if (mode == wxCOMPOSITION_XOR) |
509 | m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE); | |
1b89a5cd | 510 | else |
bf02a7f9 | 511 | m_graphicContext->SetAntialiasMode(wxANTIALIAS_DEFAULT); |
1b89a5cd SC |
512 | } |
513 | ||
888dde65 | 514 | bool wxGCDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), |
03647350 | 515 | const wxColour& WXUNUSED(col), |
89efaf2b | 516 | wxFloodFillStyle WXUNUSED(style)) |
1b89a5cd SC |
517 | { |
518 | return false; | |
519 | } | |
520 | ||
888dde65 | 521 | bool wxGCDCImpl::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const |
1b89a5cd SC |
522 | { |
523 | // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") ); | |
524 | return false; | |
525 | } | |
526 | ||
888dde65 | 527 | void wxGCDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
1b89a5cd | 528 | { |
888dde65 | 529 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") ); |
1b89a5cd | 530 | |
4280b879 | 531 | if ( !m_logicalFunctionSupported ) |
1b89a5cd | 532 | return; |
1b89a5cd | 533 | |
0ebd9515 | 534 | m_graphicContext->StrokeLine(x1,y1,x2,y2); |
1b89a5cd SC |
535 | |
536 | CalcBoundingBox(x1, y1); | |
537 | CalcBoundingBox(x2, y2); | |
538 | } | |
539 | ||
888dde65 | 540 | void wxGCDCImpl::DoCrossHair( wxCoord x, wxCoord y ) |
1b89a5cd | 541 | { |
888dde65 | 542 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") ); |
1b89a5cd | 543 | |
4280b879 | 544 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
545 | return; |
546 | ||
547 | int w = 0, h = 0; | |
548 | ||
888dde65 | 549 | GetOwner()->GetSize( &w, &h ); |
1b89a5cd | 550 | |
0ebd9515 SC |
551 | m_graphicContext->StrokeLine(0,y,w,y); |
552 | m_graphicContext->StrokeLine(x,0,x,h); | |
1b89a5cd | 553 | |
0ebd9515 SC |
554 | CalcBoundingBox(0, 0); |
555 | CalcBoundingBox(0+w, 0+h); | |
1b89a5cd SC |
556 | } |
557 | ||
888dde65 | 558 | void wxGCDCImpl::DoDrawArc( wxCoord x1, wxCoord y1, |
1b89a5cd SC |
559 | wxCoord x2, wxCoord y2, |
560 | wxCoord xc, wxCoord yc ) | |
561 | { | |
888dde65 | 562 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") ); |
1b89a5cd | 563 | |
4280b879 | 564 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
565 | return; |
566 | ||
0ebd9515 SC |
567 | double dx = x1 - xc; |
568 | double dy = y1 - yc; | |
1b89a5cd SC |
569 | double radius = sqrt((double)(dx * dx + dy * dy)); |
570 | wxCoord rad = (wxCoord)radius; | |
571 | double sa, ea; | |
0ebd9515 | 572 | if (x1 == x2 && y1 == y2) |
1b89a5cd SC |
573 | { |
574 | sa = 0.0; | |
575 | ea = 360.0; | |
576 | } | |
577 | else if (radius == 0.0) | |
578 | { | |
579 | sa = ea = 0.0; | |
580 | } | |
581 | else | |
582 | { | |
0ebd9515 SC |
583 | sa = (x1 - xc == 0) ? |
584 | (y1 - yc < 0) ? 90.0 : -90.0 : | |
585 | -atan2(double(y1 - yc), double(x1 - xc)) * RAD2DEG; | |
586 | ea = (x2 - xc == 0) ? | |
587 | (y2 - yc < 0) ? 90.0 : -90.0 : | |
588 | -atan2(double(y2 - yc), double(x2 - xc)) * RAD2DEG; | |
1b89a5cd SC |
589 | } |
590 | ||
591 | bool fill = m_brush.GetStyle() != wxTRANSPARENT; | |
592 | ||
a4e73390 | 593 | wxGraphicsPath path = m_graphicContext->CreatePath(); |
1b89a5cd | 594 | if ( fill && ((x1!=x2)||(y1!=y2)) ) |
0ebd9515 | 595 | path.MoveToPoint( xc, yc ); |
4bae004c SC |
596 | // since these angles (ea,sa) are measured counter-clockwise, we invert them to |
597 | // get clockwise angles | |
598 | path.AddArc( xc, yc , rad , DegToRad(-sa) , DegToRad(-ea), false ); | |
1b89a5cd | 599 | if ( fill && ((x1!=x2)||(y1!=y2)) ) |
0ebd9515 | 600 | path.AddLineToPoint( xc, yc ); |
1b89a5cd | 601 | m_graphicContext->DrawPath(path); |
1b89a5cd SC |
602 | } |
603 | ||
888dde65 | 604 | void wxGCDCImpl::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
1b89a5cd SC |
605 | double sa, double ea ) |
606 | { | |
888dde65 | 607 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") ); |
1b89a5cd | 608 | |
4280b879 | 609 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
610 | return; |
611 | ||
1b89a5cd | 612 | m_graphicContext->PushState(); |
d9485f89 | 613 | m_graphicContext->Translate(x+w/2.0,y+h/2.0); |
0ebd9515 | 614 | wxDouble factor = ((wxDouble) w) / h; |
1b89a5cd | 615 | m_graphicContext->Scale( factor , 1.0); |
d9485f89 | 616 | |
1b89a5cd SC |
617 | // since these angles (ea,sa) are measured counter-clockwise, we invert them to |
618 | // get clockwise angles | |
fcaea2fa SC |
619 | if ( m_brush.GetStyle() != wxTRANSPARENT ) |
620 | { | |
621 | wxGraphicsPath path = m_graphicContext->CreatePath(); | |
622 | path.MoveToPoint( 0, 0 ); | |
47c1bb95 | 623 | path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); |
fcaea2fa SC |
624 | path.AddLineToPoint( 0, 0 ); |
625 | m_graphicContext->FillPath( path ); | |
626 | ||
627 | path = m_graphicContext->CreatePath(); | |
628 | path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); | |
fcaea2fa SC |
629 | m_graphicContext->StrokePath( path ); |
630 | } | |
631 | else | |
632 | { | |
633 | wxGraphicsPath path = m_graphicContext->CreatePath(); | |
47c1bb95 SC |
634 | path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); |
635 | m_graphicContext->DrawPath( path ); | |
fcaea2fa SC |
636 | } |
637 | ||
1b89a5cd | 638 | m_graphicContext->PopState(); |
1b89a5cd SC |
639 | } |
640 | ||
888dde65 | 641 | void wxGCDCImpl::DoDrawPoint( wxCoord x, wxCoord y ) |
1b89a5cd | 642 | { |
888dde65 | 643 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") ); |
1b89a5cd SC |
644 | |
645 | DoDrawLine( x , y , x + 1 , y + 1 ); | |
646 | } | |
647 | ||
888dde65 | 648 | void wxGCDCImpl::DoDrawLines(int n, wxPoint points[], |
1b89a5cd SC |
649 | wxCoord xoffset, wxCoord yoffset) |
650 | { | |
888dde65 | 651 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") ); |
1b89a5cd | 652 | |
4280b879 | 653 | if ( !m_logicalFunctionSupported ) |
1b89a5cd | 654 | return; |
1b89a5cd SC |
655 | |
656 | wxPoint2DDouble* pointsD = new wxPoint2DDouble[n]; | |
657 | for( int i = 0; i < n; ++i) | |
658 | { | |
0ebd9515 SC |
659 | pointsD[i].m_x = points[i].x + xoffset; |
660 | pointsD[i].m_y = points[i].y + yoffset; | |
1b89a5cd SC |
661 | } |
662 | ||
663 | m_graphicContext->StrokeLines( n , pointsD); | |
664 | delete[] pointsD; | |
665 | } | |
666 | ||
667 | #if wxUSE_SPLINES | |
888dde65 | 668 | void wxGCDCImpl::DoDrawSpline(const wxPointList *points) |
1b89a5cd | 669 | { |
888dde65 | 670 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") ); |
1b89a5cd | 671 | |
4280b879 | 672 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
673 | return; |
674 | ||
a4e73390 | 675 | wxGraphicsPath path = m_graphicContext->CreatePath(); |
1b89a5cd | 676 | |
b0d7707b RR |
677 | wxPointList::compatibility_iterator node = points->GetFirst(); |
678 | if (node == wxPointList::compatibility_iterator()) | |
1b89a5cd SC |
679 | // empty list |
680 | return; | |
681 | ||
b0d7707b | 682 | wxPoint *p = node->GetData(); |
1b89a5cd SC |
683 | |
684 | wxCoord x1 = p->x; | |
685 | wxCoord y1 = p->y; | |
686 | ||
687 | node = node->GetNext(); | |
b0d7707b | 688 | p = node->GetData(); |
1b89a5cd SC |
689 | |
690 | wxCoord x2 = p->x; | |
691 | wxCoord y2 = p->y; | |
692 | wxCoord cx1 = ( x1 + x2 ) / 2; | |
693 | wxCoord cy1 = ( y1 + y2 ) / 2; | |
694 | ||
0ebd9515 SC |
695 | path.MoveToPoint( x1 , y1 ); |
696 | path.AddLineToPoint( cx1 , cy1 ); | |
1b89a5cd SC |
697 | #if !wxUSE_STL |
698 | ||
699 | while ((node = node->GetNext()) != NULL) | |
700 | #else | |
701 | ||
702 | while ((node = node->GetNext())) | |
703 | #endif // !wxUSE_STL | |
704 | ||
705 | { | |
b0d7707b | 706 | p = node->GetData(); |
1b89a5cd SC |
707 | x1 = x2; |
708 | y1 = y2; | |
709 | x2 = p->x; | |
710 | y2 = p->y; | |
711 | wxCoord cx4 = (x1 + x2) / 2; | |
712 | wxCoord cy4 = (y1 + y2) / 2; | |
713 | ||
0ebd9515 | 714 | path.AddQuadCurveToPoint(x1 , y1 ,cx4 , cy4 ); |
1b89a5cd SC |
715 | |
716 | cx1 = cx4; | |
717 | cy1 = cy4; | |
718 | } | |
719 | ||
0ebd9515 | 720 | path.AddLineToPoint( x2 , y2 ); |
1b89a5cd SC |
721 | |
722 | m_graphicContext->StrokePath( path ); | |
1b89a5cd SC |
723 | } |
724 | #endif // wxUSE_SPLINES | |
725 | ||
888dde65 | 726 | void wxGCDCImpl::DoDrawPolygon( int n, wxPoint points[], |
89efaf2b FM |
727 | wxCoord xoffset, wxCoord yoffset, |
728 | wxPolygonFillMode fillStyle ) | |
1b89a5cd | 729 | { |
888dde65 | 730 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") ); |
1b89a5cd SC |
731 | |
732 | if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) ) | |
733 | return; | |
4280b879 | 734 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
735 | return; |
736 | ||
737 | bool closeIt = false; | |
738 | if (points[n-1] != points[0]) | |
739 | closeIt = true; | |
740 | ||
741 | wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)]; | |
742 | for( int i = 0; i < n; ++i) | |
743 | { | |
0ebd9515 SC |
744 | pointsD[i].m_x = points[i].x + xoffset; |
745 | pointsD[i].m_y = points[i].y + yoffset; | |
1b89a5cd SC |
746 | } |
747 | if ( closeIt ) | |
748 | pointsD[n] = pointsD[0]; | |
749 | ||
750 | m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle); | |
751 | delete[] pointsD; | |
752 | } | |
753 | ||
888dde65 | 754 | void wxGCDCImpl::DoDrawPolyPolygon(int n, |
1b89a5cd SC |
755 | int count[], |
756 | wxPoint points[], | |
757 | wxCoord xoffset, | |
758 | wxCoord yoffset, | |
89efaf2b | 759 | wxPolygonFillMode fillStyle) |
1b89a5cd SC |
760 | { |
761 | wxASSERT(n > 1); | |
a4e73390 | 762 | wxGraphicsPath path = m_graphicContext->CreatePath(); |
1b89a5cd SC |
763 | |
764 | int i = 0; | |
765 | for ( int j = 0; j < n; ++j) | |
766 | { | |
767 | wxPoint start = points[i]; | |
0ebd9515 | 768 | path.MoveToPoint( start.x+ xoffset, start.y+ yoffset); |
1b89a5cd SC |
769 | ++i; |
770 | int l = count[j]; | |
771 | for ( int k = 1; k < l; ++k) | |
772 | { | |
0ebd9515 | 773 | path.AddLineToPoint( points[i].x+ xoffset, points[i].y+ yoffset); |
1b89a5cd SC |
774 | ++i; |
775 | } | |
776 | // close the polygon | |
777 | if ( start != points[i-1]) | |
0ebd9515 | 778 | path.AddLineToPoint( start.x+ xoffset, start.y+ yoffset); |
1b89a5cd SC |
779 | } |
780 | m_graphicContext->DrawPath( path , fillStyle); | |
1b89a5cd SC |
781 | } |
782 | ||
888dde65 | 783 | void wxGCDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) |
1b89a5cd | 784 | { |
888dde65 | 785 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") ); |
1b89a5cd | 786 | |
4280b879 | 787 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
788 | return; |
789 | ||
1b89a5cd | 790 | // CMB: draw nothing if transformed w or h is 0 |
0ebd9515 | 791 | if (w == 0 || h == 0) |
1b89a5cd SC |
792 | return; |
793 | ||
5ebfdf41 SC |
794 | if ( m_graphicContext->ShouldOffset() ) |
795 | { | |
796 | // if we are offsetting the entire rectangle is moved 0.5, so the | |
797 | // border line gets off by 1 | |
0ebd9515 SC |
798 | w -= 1; |
799 | h -= 1; | |
5ebfdf41 | 800 | } |
0ebd9515 | 801 | m_graphicContext->DrawRectangle(x,y,w,h); |
1b89a5cd SC |
802 | } |
803 | ||
888dde65 | 804 | void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, |
0ebd9515 | 805 | wxCoord w, wxCoord h, |
1b89a5cd SC |
806 | double radius) |
807 | { | |
888dde65 | 808 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") ); |
1b89a5cd | 809 | |
4280b879 | 810 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
811 | return; |
812 | ||
813 | if (radius < 0.0) | |
0ebd9515 | 814 | radius = - radius * ((w < h) ? w : h); |
1b89a5cd SC |
815 | |
816 | // CMB: draw nothing if transformed w or h is 0 | |
0ebd9515 | 817 | if (w == 0 || h == 0) |
1b89a5cd SC |
818 | return; |
819 | ||
d9485f89 RD |
820 | if ( m_graphicContext->ShouldOffset() ) |
821 | { | |
822 | // if we are offsetting the entire rectangle is moved 0.5, so the | |
823 | // border line gets off by 1 | |
824 | w -= 1; | |
825 | h -= 1; | |
826 | } | |
0ebd9515 | 827 | m_graphicContext->DrawRoundedRectangle( x,y,w,h,radius); |
1b89a5cd SC |
828 | } |
829 | ||
888dde65 | 830 | void wxGCDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) |
1b89a5cd | 831 | { |
888dde65 | 832 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") ); |
1b89a5cd | 833 | |
4280b879 | 834 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
835 | return; |
836 | ||
d9485f89 RD |
837 | if ( m_graphicContext->ShouldOffset() ) |
838 | { | |
839 | // if we are offsetting the entire rectangle is moved 0.5, so the | |
840 | // border line gets off by 1 | |
841 | w -= 1; | |
842 | h -= 1; | |
843 | } | |
0ebd9515 | 844 | m_graphicContext->DrawEllipse(x,y,w,h); |
1b89a5cd SC |
845 | } |
846 | ||
888dde65 | 847 | bool wxGCDCImpl::CanDrawBitmap() const |
1b89a5cd SC |
848 | { |
849 | return true; | |
850 | } | |
851 | ||
888dde65 | 852 | bool wxGCDCImpl::DoBlit( |
1b89a5cd | 853 | wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
03647350 | 854 | wxDC *source, wxCoord xsrc, wxCoord ysrc, |
89efaf2b | 855 | wxRasterOperationMode logical_func , bool useMask, |
1b89a5cd SC |
856 | wxCoord xsrcMask, wxCoord ysrcMask ) |
857 | { | |
e3b81044 VZ |
858 | return DoStretchBlit( xdest, ydest, width, height, |
859 | source, xsrc, ysrc, width, height, logical_func, useMask, | |
860 | xsrcMask,ysrcMask ); | |
861 | } | |
862 | ||
888dde65 | 863 | bool wxGCDCImpl::DoStretchBlit( |
e3b81044 VZ |
864 | wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight, |
865 | wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight, | |
89efaf2b | 866 | wxRasterOperationMode logical_func , bool useMask, |
e3b81044 VZ |
867 | wxCoord xsrcMask, wxCoord ysrcMask ) |
868 | { | |
888dde65 RR |
869 | wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") ); |
870 | wxCHECK_MSG( source->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") ); | |
6c0aace2 | 871 | |
1b89a5cd SC |
872 | if ( logical_func == wxNO_OP ) |
873 | return true; | |
03647350 | 874 | |
bf02a7f9 SC |
875 | wxCompositionMode mode; |
876 | if ( !TranslateRasterOp(logical_func, &mode) ) | |
c64c9cd3 | 877 | { |
bf02a7f9 | 878 | wxFAIL_MSG( wxT("Blitting is not supported with this logical operation.") ); |
c64c9cd3 KO |
879 | return false; |
880 | } | |
1b89a5cd | 881 | |
bf02a7f9 | 882 | bool retval = true; |
03647350 | 883 | |
bf02a7f9 SC |
884 | wxCompositionMode formerMode = m_graphicContext->GetCompositionMode(); |
885 | if (m_graphicContext->SetCompositionMode(mode)) | |
1b89a5cd | 886 | { |
bf02a7f9 SC |
887 | wxAntialiasMode formerAa = m_graphicContext->GetAntialiasMode(); |
888 | if (mode == wxCOMPOSITION_XOR) | |
889 | { | |
890 | m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE); | |
891 | } | |
03647350 | 892 | |
bf02a7f9 SC |
893 | if (xsrcMask == -1 && ysrcMask == -1) |
894 | { | |
895 | xsrcMask = xsrc; | |
896 | ysrcMask = ysrc; | |
897 | } | |
1b89a5cd | 898 | |
bf02a7f9 SC |
899 | wxRect subrect(source->LogicalToDeviceX(xsrc), |
900 | source->LogicalToDeviceY(ysrc), | |
901 | source->LogicalToDeviceXRel(srcWidth), | |
902 | source->LogicalToDeviceYRel(srcHeight)); | |
cce4a2ce | 903 | |
bf02a7f9 SC |
904 | // if needed clip the subrect down to the size of the source DC |
905 | wxCoord sw, sh; | |
906 | source->GetSize(&sw, &sh); | |
907 | sw = source->LogicalToDeviceXRel(sw); | |
908 | sh = source->LogicalToDeviceYRel(sh); | |
909 | if (subrect.x + subrect.width > sw) | |
910 | subrect.width = sw - subrect.x; | |
911 | if (subrect.y + subrect.height > sh) | |
912 | subrect.height = sh - subrect.y; | |
6c0aace2 | 913 | |
bf02a7f9 | 914 | wxBitmap blit = source->GetAsBitmap( &subrect ); |
6c0aace2 | 915 | |
bf02a7f9 SC |
916 | if ( blit.IsOk() ) |
917 | { | |
918 | if ( !useMask && blit.GetMask() ) | |
919 | blit.SetMask(NULL); | |
08de4403 | 920 | |
bf02a7f9 SC |
921 | m_graphicContext->DrawBitmap( blit, xdest, ydest, |
922 | dstWidth, dstHeight); | |
923 | } | |
924 | else | |
925 | { | |
926 | wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") ); | |
927 | retval = false; | |
928 | } | |
03647350 | 929 | |
bf02a7f9 SC |
930 | if (mode == wxCOMPOSITION_XOR) |
931 | { | |
932 | m_graphicContext->SetAntialiasMode(formerAa); | |
933 | } | |
1b89a5cd | 934 | } |
bf02a7f9 SC |
935 | // reset composition |
936 | m_graphicContext->SetCompositionMode(formerMode); | |
1b89a5cd | 937 | |
bf02a7f9 | 938 | return retval; |
1b89a5cd SC |
939 | } |
940 | ||
888dde65 | 941 | void wxGCDCImpl::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, |
1b89a5cd SC |
942 | double angle) |
943 | { | |
888dde65 | 944 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") ); |
1b89a5cd SC |
945 | |
946 | if ( str.length() == 0 ) | |
947 | return; | |
4280b879 | 948 | if ( !m_logicalFunctionSupported ) |
1b89a5cd SC |
949 | return; |
950 | ||
068eb463 SC |
951 | if ( m_backgroundMode == wxTRANSPARENT ) |
952 | m_graphicContext->DrawText( str, x ,y , DegToRad(angle )); | |
953 | else | |
954 | m_graphicContext->DrawText( str, x ,y , DegToRad(angle ), m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) ); | |
1b89a5cd SC |
955 | } |
956 | ||
888dde65 | 957 | void wxGCDCImpl::DoDrawText(const wxString& str, wxCoord x, wxCoord y) |
1b89a5cd | 958 | { |
08de4403 | 959 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawText - invalid DC") ); |
1b89a5cd SC |
960 | |
961 | if ( str.length() == 0 ) | |
962 | return; | |
4280b879 SC |
963 | |
964 | if ( !m_logicalFunctionSupported ) | |
1b89a5cd SC |
965 | return; |
966 | ||
068eb463 SC |
967 | if ( m_backgroundMode == wxTRANSPARENT ) |
968 | m_graphicContext->DrawText( str, x ,y); | |
969 | else | |
970 | m_graphicContext->DrawText( str, x ,y , m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) ); | |
1b89a5cd SC |
971 | } |
972 | ||
888dde65 | 973 | bool wxGCDCImpl::CanGetTextExtent() const |
1b89a5cd | 974 | { |
888dde65 | 975 | wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") ); |
1b89a5cd SC |
976 | |
977 | return true; | |
978 | } | |
979 | ||
888dde65 | 980 | void wxGCDCImpl::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height, |
1b89a5cd | 981 | wxCoord *descent, wxCoord *externalLeading , |
c94f845b | 982 | const wxFont *theFont ) const |
1b89a5cd | 983 | { |
888dde65 | 984 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") ); |
1b89a5cd SC |
985 | |
986 | if ( theFont ) | |
987 | { | |
988 | m_graphicContext->SetFont( *theFont, m_textForegroundColour ); | |
989 | } | |
990 | ||
991 | wxDouble h , d , e , w; | |
992 | ||
993 | m_graphicContext->GetTextExtent( str, &w, &h, &d, &e ); | |
994 | ||
995 | if ( height ) | |
fcaea2fa | 996 | *height = (wxCoord)(h+0.5); |
1b89a5cd | 997 | if ( descent ) |
fcaea2fa | 998 | *descent = (wxCoord)(d+0.5); |
1b89a5cd | 999 | if ( externalLeading ) |
fcaea2fa | 1000 | *externalLeading = (wxCoord)(e+0.5); |
1b89a5cd | 1001 | if ( width ) |
fcaea2fa | 1002 | *width = (wxCoord)(w+0.5); |
1b89a5cd SC |
1003 | |
1004 | if ( theFont ) | |
1005 | { | |
1006 | m_graphicContext->SetFont( m_font, m_textForegroundColour ); | |
1007 | } | |
1008 | } | |
1009 | ||
888dde65 | 1010 | bool wxGCDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const |
1b89a5cd | 1011 | { |
888dde65 | 1012 | wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") ); |
1b89a5cd SC |
1013 | widths.Clear(); |
1014 | widths.Add(0,text.Length()); | |
1015 | if ( text.IsEmpty() ) | |
1016 | return true; | |
1017 | ||
1018 | wxArrayDouble widthsD; | |
1019 | ||
1020 | m_graphicContext->GetPartialTextExtents( text, widthsD ); | |
1021 | for ( size_t i = 0; i < widths.GetCount(); ++i ) | |
0ebd9515 | 1022 | widths[i] = (wxCoord)(widthsD[i] + 0.5); |
1b89a5cd SC |
1023 | |
1024 | return true; | |
1025 | } | |
1026 | ||
888dde65 | 1027 | wxCoord wxGCDCImpl::GetCharWidth(void) const |
1b89a5cd SC |
1028 | { |
1029 | wxCoord width; | |
1030 | DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL ); | |
1031 | ||
1032 | return width; | |
1033 | } | |
1034 | ||
888dde65 | 1035 | wxCoord wxGCDCImpl::GetCharHeight(void) const |
1b89a5cd SC |
1036 | { |
1037 | wxCoord height; | |
1038 | DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ); | |
1039 | ||
1040 | return height; | |
1041 | } | |
1042 | ||
888dde65 | 1043 | void wxGCDCImpl::Clear(void) |
1b89a5cd | 1044 | { |
888dde65 | 1045 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") ); |
1b89a5cd SC |
1046 | // TODO better implementation / incorporate size info into wxGCDC or context |
1047 | m_graphicContext->SetBrush( m_backgroundBrush ); | |
1048 | wxPen p = *wxTRANSPARENT_PEN; | |
1049 | m_graphicContext->SetPen( p ); | |
1050 | DoDrawRectangle( 0, 0, 32000 , 32000 ); | |
6c0aace2 | 1051 | m_graphicContext->SetPen( m_pen ); |
1b89a5cd SC |
1052 | m_graphicContext->SetBrush( m_brush ); |
1053 | } | |
1054 | ||
888dde65 | 1055 | void wxGCDCImpl::DoGetSize(int *width, int *height) const |
1b89a5cd | 1056 | { |
1cc7d13a SC |
1057 | wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoGetSize - invalid DC") ); |
1058 | wxDouble w,h; | |
1059 | m_graphicContext->GetSize( &w, &h ); | |
1060 | if ( height ) | |
1061 | *height = (int) (h+0.5); | |
1062 | if ( width ) | |
1063 | *width = (int) (w+0.5); | |
1b89a5cd SC |
1064 | } |
1065 | ||
888dde65 | 1066 | void wxGCDCImpl::DoGradientFillLinear(const wxRect& rect, |
1b89a5cd SC |
1067 | const wxColour& initialColour, |
1068 | const wxColour& destColour, | |
1069 | wxDirection nDirection ) | |
1070 | { | |
1071 | wxPoint start; | |
1072 | wxPoint end; | |
1073 | switch( nDirection) | |
1074 | { | |
1075 | case wxWEST : | |
1076 | start = rect.GetRightBottom(); | |
1077 | start.x++; | |
1078 | end = rect.GetLeftBottom(); | |
1079 | break; | |
1080 | case wxEAST : | |
1081 | start = rect.GetLeftBottom(); | |
1082 | end = rect.GetRightBottom(); | |
1083 | end.x++; | |
1084 | break; | |
1085 | case wxNORTH : | |
1086 | start = rect.GetLeftBottom(); | |
1087 | start.y++; | |
1088 | end = rect.GetLeftTop(); | |
1089 | break; | |
1090 | case wxSOUTH : | |
1091 | start = rect.GetLeftTop(); | |
1092 | end = rect.GetLeftBottom(); | |
1093 | end.y++; | |
1094 | break; | |
1095 | default : | |
1096 | break; | |
1097 | } | |
1098 | ||
0ebd9515 | 1099 | if (rect.width == 0 || rect.height == 0) |
1b89a5cd SC |
1100 | return; |
1101 | ||
0ebd9515 SC |
1102 | m_graphicContext->SetBrush( m_graphicContext->CreateLinearGradientBrush( |
1103 | start.x,start.y,end.x,end.y, initialColour, destColour)); | |
1b89a5cd | 1104 | m_graphicContext->SetPen(*wxTRANSPARENT_PEN); |
0ebd9515 | 1105 | m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height); |
1b89a5cd SC |
1106 | m_graphicContext->SetPen(m_pen); |
1107 | } | |
1108 | ||
888dde65 | 1109 | void wxGCDCImpl::DoGradientFillConcentric(const wxRect& rect, |
1b89a5cd SC |
1110 | const wxColour& initialColour, |
1111 | const wxColour& destColour, | |
1112 | const wxPoint& circleCenter) | |
1113 | { | |
1114 | //Radius | |
1115 | wxInt32 cx = rect.GetWidth() / 2; | |
1116 | wxInt32 cy = rect.GetHeight() / 2; | |
1117 | wxInt32 nRadius; | |
1118 | if (cx < cy) | |
1119 | nRadius = cx; | |
1120 | else | |
1121 | nRadius = cy; | |
1122 | ||
0ebd9515 | 1123 | // make sure the background is filled (todo move into specific platform implementation ?) |
1b89a5cd SC |
1124 | m_graphicContext->SetPen(*wxTRANSPARENT_PEN); |
1125 | m_graphicContext->SetBrush( wxBrush( destColour) ); | |
0ebd9515 | 1126 | m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height); |
1b89a5cd SC |
1127 | |
1128 | m_graphicContext->SetBrush( m_graphicContext->CreateRadialGradientBrush( | |
0ebd9515 SC |
1129 | rect.x+circleCenter.x,rect.y+circleCenter.y, |
1130 | rect.x+circleCenter.x,rect.y+circleCenter.y, | |
1131 | nRadius,initialColour,destColour)); | |
1b89a5cd | 1132 | |
0ebd9515 | 1133 | m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height); |
1b89a5cd SC |
1134 | m_graphicContext->SetPen(m_pen); |
1135 | } | |
1136 | ||
888dde65 | 1137 | void wxGCDCImpl::DoDrawCheckMark(wxCoord x, wxCoord y, |
1b89a5cd SC |
1138 | wxCoord width, wxCoord height) |
1139 | { | |
888dde65 | 1140 | wxDCImpl::DoDrawCheckMark(x,y,width,height); |
1b89a5cd SC |
1141 | } |
1142 | ||
1143 | #endif // wxUSE_GRAPHICS_CONTEXT |