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