]>
Commit | Line | Data |
---|---|---|
50581042 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/common/graphcmn.cpp | |
3 | // Purpose: graphics context methods common to all platforms | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
50581042 SC |
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 | ||
9fd707a5 PC |
19 | #if wxUSE_GRAPHICS_CONTEXT |
20 | ||
50581042 SC |
21 | #include "wx/graphics.h" |
22 | ||
539872ae SC |
23 | #ifndef WX_PRECOMP |
24 | #include "wx/icon.h" | |
25 | #include "wx/bitmap.h" | |
26 | #include "wx/dcmemory.h" | |
9fd707a5 | 27 | #include "wx/region.h" |
539872ae SC |
28 | #endif |
29 | ||
2f34cf60 RD |
30 | #if !defined(wxMAC_USE_CORE_GRAPHICS_BLEND_MODES) |
31 | #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0 | |
32 | #endif | |
33 | ||
d94228a2 SC |
34 | //----------------------------------------------------------------------------- |
35 | // constants | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
9fd707a5 | 38 | static const double RAD2DEG = 180.0 / M_PI; |
d94228a2 SC |
39 | |
40 | //----------------------------------------------------------------------------- | |
41 | // Local functions | |
42 | //----------------------------------------------------------------------------- | |
43 | ||
d94228a2 SC |
44 | static inline double DegToRad(double deg) |
45 | { | |
46 | return (deg * M_PI) / 180.0; | |
47 | } | |
d94228a2 | 48 | |
9fd707a5 | 49 | //----------------------------------------------------------------------------- |
d94228a2 | 50 | |
50581042 SC |
51 | wxPoint2DDouble wxGraphicsPath::GetCurrentPoint() |
52 | { | |
a2d6d210 | 53 | wxDouble x,y; |
50581042 SC |
54 | GetCurrentPoint(x,y); |
55 | return wxPoint2DDouble(x,y); | |
56 | } | |
57 | ||
58 | void wxGraphicsPath::MoveToPoint( const wxPoint2DDouble& p) | |
59 | { | |
60 | MoveToPoint( p.m_x , p.m_y); | |
61 | } | |
62 | ||
63 | void wxGraphicsPath::AddLineToPoint( const wxPoint2DDouble& p) | |
64 | { | |
65 | AddLineToPoint( p.m_x , p.m_y); | |
66 | } | |
67 | ||
68 | void wxGraphicsPath::AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e) | |
69 | { | |
70 | AddCurveToPoint(c1.m_x, c1.m_y, c2.m_x, c2.m_y, e.m_x, e.m_y); | |
71 | } | |
72 | ||
73 | void wxGraphicsPath::AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise) | |
74 | { | |
75 | AddArc(c.m_x, c.m_y, r, startAngle, endAngle, clockwise); | |
76 | } | |
77 | ||
78 | // | |
79 | // Emulations | |
80 | // | |
81 | ||
82 | void wxGraphicsPath::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ) | |
83 | { | |
84 | // calculate using degree elevation to a cubic bezier | |
a2d6d210 VZ |
85 | wxPoint2DDouble c1; |
86 | wxPoint2DDouble c2; | |
50581042 | 87 | |
a2d6d210 | 88 | wxPoint2DDouble start = GetCurrentPoint(); |
50581042 SC |
89 | wxPoint2DDouble end(x,y); |
90 | wxPoint2DDouble c(cx,cy); | |
5ce3abfb | 91 | c1 = wxDouble(1/3.0) * start + wxDouble(2/3.0) * c; |
a2d6d210 | 92 | c2 = wxDouble(2/3.0) * c + wxDouble(1/3.0) * end; |
50581042 SC |
93 | AddCurveToPoint(c1.m_x,c1.m_y,c2.m_x,c2.m_y,x,y); |
94 | } | |
95 | ||
96 | void wxGraphicsPath::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) | |
97 | { | |
98 | MoveToPoint(x,y); | |
99 | AddLineToPoint(x,y+h); | |
100 | AddLineToPoint(x+w,y+h); | |
101 | AddLineToPoint(x+w,y); | |
102 | CloseSubpath(); | |
103 | } | |
104 | ||
105 | void wxGraphicsPath::AddCircle( wxDouble x, wxDouble y, wxDouble r ) | |
106 | { | |
107 | MoveToPoint(x+r,y); | |
108 | AddArc( x,y,r,0,2*M_PI,false); | |
109 | CloseSubpath(); | |
110 | } | |
111 | ||
d94228a2 SC |
112 | // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1) |
113 | void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) | |
114 | { | |
115 | wxPoint2DDouble current = GetCurrentPoint(); | |
116 | wxPoint2DDouble p1(x1,y1); | |
117 | wxPoint2DDouble p2(x2,y2); | |
118 | ||
a2d6d210 | 119 | wxPoint2DDouble v1 = current - p1; |
d94228a2 | 120 | v1.Normalize(); |
a2d6d210 | 121 | wxPoint2DDouble v2 = p2 - p1; |
d94228a2 SC |
122 | v2.Normalize(); |
123 | ||
124 | wxDouble alpha = v1.GetVectorAngle() - v2.GetVectorAngle(); | |
125 | ||
126 | if ( alpha < 0 ) | |
a2d6d210 | 127 | alpha = 360 + alpha; |
d94228a2 SC |
128 | // TODO obtuse angles |
129 | ||
130 | alpha = DegToRad(alpha); | |
131 | ||
a2d6d210 | 132 | wxDouble dist = r / sin(alpha/2) * cos(alpha/2); |
d94228a2 | 133 | // calculate tangential points |
a2d6d210 VZ |
134 | wxPoint2DDouble t1 = dist*v1 + p1; |
135 | wxPoint2DDouble t2 = dist*v2 + p1; | |
d94228a2 | 136 | |
a2d6d210 | 137 | wxPoint2DDouble nv1 = v1; |
d94228a2 SC |
138 | nv1.SetVectorAngle(v1.GetVectorAngle()-90); |
139 | wxPoint2DDouble c = t1 + r*nv1; | |
140 | ||
a2d6d210 VZ |
141 | wxDouble a1 = v1.GetVectorAngle()+90; |
142 | wxDouble a2 = v2.GetVectorAngle()-90; | |
d94228a2 SC |
143 | |
144 | AddLineToPoint(t1); | |
145 | AddArc(c.m_x,c.m_y,r,DegToRad(a1),DegToRad(a2),true); | |
146 | AddLineToPoint(p2); | |
147 | } | |
148 | ||
50581042 SC |
149 | //----------------------------------------------------------------------------- |
150 | // wxGraphicsContext Convenience Methods | |
151 | //----------------------------------------------------------------------------- | |
152 | ||
153 | void wxGraphicsContext::DrawPath( const wxGraphicsPath *path, int fillStyle ) | |
154 | { | |
155 | FillPath( path , fillStyle ); | |
156 | StrokePath( path ); | |
157 | } | |
158 | ||
159 | void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ) | |
160 | { | |
a2d6d210 | 161 | Translate(x,y); |
50581042 SC |
162 | Rotate( -angle ); |
163 | DrawText( str , 0, 0 ); | |
164 | Rotate( angle ); | |
a2d6d210 | 165 | Translate(-x,-y); |
50581042 SC |
166 | } |
167 | ||
168 | void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2) | |
169 | { | |
170 | wxGraphicsPath* path = CreatePath(); | |
a2d6d210 | 171 | path->MoveToPoint(x1, y1); |
50581042 SC |
172 | path->AddLineToPoint( x2, y2 ); |
173 | StrokePath( path ); | |
174 | delete path; | |
175 | } | |
176 | ||
177 | void wxGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h) | |
178 | { | |
179 | wxGraphicsPath* path = CreatePath(); | |
180 | path->AddRectangle( x , y , w , h ); | |
181 | DrawPath( path ); | |
182 | delete path; | |
183 | } | |
184 | ||
185 | void wxGraphicsContext::DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h) | |
186 | { | |
187 | wxGraphicsPath* path = CreatePath(); | |
188 | if ( w == h ) | |
189 | { | |
190 | path->AddCircle( x+w/2,y+w/2,w/2); | |
191 | DrawPath(path); | |
192 | } | |
193 | else | |
194 | { | |
195 | PushState(); | |
196 | Translate(x+w/2,y+h/2); | |
a2d6d210 VZ |
197 | wxDouble factor = ((wxDouble) w) / h; |
198 | Scale( factor , 1.0); | |
50581042 SC |
199 | path->AddCircle(0,0,h/2); |
200 | DrawPath(path); | |
201 | PopState(); | |
202 | } | |
203 | delete path; | |
204 | } | |
205 | ||
206 | void wxGraphicsContext::DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius) | |
207 | { | |
208 | wxGraphicsPath* path = CreatePath(); | |
209 | if ( radius == 0) | |
210 | { | |
211 | path->AddRectangle( x , y , w , h ); | |
212 | DrawPath( path ); | |
213 | } | |
214 | else | |
215 | { | |
216 | PushState(); | |
217 | Translate( x , y ); | |
218 | ||
50581042 SC |
219 | path->MoveToPoint(w, h / 2); |
220 | path->AddArcToPoint(w, h, w / 2, h, radius); | |
221 | path->AddArcToPoint(0, h, 0, h / 2, radius); | |
222 | path->AddArcToPoint(0, 0, w / 2, 0, radius); | |
223 | path->AddArcToPoint(w, 0, w, h / 2, radius); | |
224 | path->CloseSubpath(); | |
225 | DrawPath( path ); | |
226 | PopState(); | |
227 | } | |
228 | delete path; | |
229 | } | |
230 | ||
231 | void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *points) | |
232 | { | |
233 | wxASSERT(n > 1); | |
234 | wxGraphicsPath* path = CreatePath(); | |
a2d6d210 VZ |
235 | path->MoveToPoint(points[0].m_x, points[0].m_y); |
236 | for ( size_t i = 1; i < n; ++i) | |
50581042 SC |
237 | path->AddLineToPoint( points[i].m_x, points[i].m_y ); |
238 | StrokePath( path ); | |
239 | delete path; | |
240 | } | |
241 | ||
242 | void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle) | |
243 | { | |
244 | wxASSERT(n > 1); | |
245 | wxGraphicsPath* path = CreatePath(); | |
a2d6d210 VZ |
246 | path->MoveToPoint(points[0].m_x, points[0].m_y); |
247 | for ( size_t i = 1; i < n; ++i) | |
50581042 SC |
248 | path->AddLineToPoint( points[i].m_x, points[i].m_y ); |
249 | DrawPath( path , fillStyle); | |
250 | delete path; | |
251 | } | |
252 | ||
253 | void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints) | |
254 | { | |
255 | wxASSERT(n > 0); | |
256 | wxGraphicsPath* path = CreatePath(); | |
a2d6d210 | 257 | for ( size_t i = 0; i < n; ++i) |
50581042 | 258 | { |
a2d6d210 | 259 | path->MoveToPoint(beginPoints[i].m_x, beginPoints[i].m_y); |
50581042 SC |
260 | path->AddLineToPoint( endPoints[i].m_x, endPoints[i].m_y ); |
261 | } | |
262 | StrokePath( path ); | |
263 | delete path; | |
264 | } | |
265 | ||
50581042 SC |
266 | IMPLEMENT_ABSTRACT_CLASS(wxGCDC, wxObject) |
267 | ||
50581042 SC |
268 | //----------------------------------------------------------------------------- |
269 | // wxDC bridge class | |
270 | //----------------------------------------------------------------------------- | |
271 | ||
272 | wxGCDC::wxGCDC() | |
273 | { | |
274 | Init(); | |
275 | } | |
276 | ||
277 | ||
278 | wxGCDC::wxGCDC(const wxWindowDC& dc) | |
279 | { | |
280 | Init(); | |
281 | m_graphicContext = wxGraphicsContext::Create(dc); | |
282 | m_ok = true; | |
d94228a2 SC |
283 | if ( dc.GetFont().Ok()) |
284 | m_graphicContext->SetFont(dc.GetFont()); | |
af863805 SC |
285 | if ( dc.GetPen().Ok()) |
286 | m_graphicContext->SetPen(dc.GetPen()); | |
287 | if ( dc.GetBrush().Ok()) | |
288 | m_graphicContext->SetBrush(dc.GetBrush()); | |
289 | m_graphicContext->SetTextColor(dc.GetTextForeground()); | |
50581042 SC |
290 | } |
291 | ||
292 | void wxGCDC::Init() | |
293 | { | |
294 | m_ok = false; | |
295 | m_colour = true; | |
296 | m_mm_to_pix_x = mm2pt; | |
297 | m_mm_to_pix_y = mm2pt; | |
298 | ||
299 | m_pen = *wxBLACK_PEN; | |
300 | m_font = *wxNORMAL_FONT; | |
301 | m_brush = *wxWHITE_BRUSH; | |
302 | ||
303 | m_graphicContext = NULL; | |
304 | } | |
305 | ||
306 | ||
307 | wxGCDC::~wxGCDC() | |
308 | { | |
309 | delete m_graphicContext; | |
310 | } | |
311 | ||
12f72836 | 312 | void wxGCDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool WXUNUSED(useMask) ) |
50581042 SC |
313 | { |
314 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") ); | |
315 | wxCHECK_RET( bmp.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") ); | |
316 | ||
317 | wxCoord xx = LogicalToDeviceX(x); | |
318 | wxCoord yy = LogicalToDeviceY(y); | |
319 | wxCoord w = bmp.GetWidth(); | |
320 | wxCoord h = bmp.GetHeight(); | |
321 | wxCoord ww = LogicalToDeviceXRel(w); | |
322 | wxCoord hh = LogicalToDeviceYRel(h); | |
323 | ||
324 | m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh ); | |
325 | } | |
326 | ||
327 | void wxGCDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) | |
328 | { | |
329 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") ); | |
330 | wxCHECK_RET( icon.Ok(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") ); | |
331 | ||
332 | wxCoord xx = LogicalToDeviceX(x); | |
333 | wxCoord yy = LogicalToDeviceY(y); | |
334 | wxCoord w = icon.GetWidth(); | |
335 | wxCoord h = icon.GetHeight(); | |
336 | wxCoord ww = LogicalToDeviceXRel(w); | |
337 | wxCoord hh = LogicalToDeviceYRel(h); | |
338 | ||
339 | m_graphicContext->DrawIcon( icon , xx, yy, ww, hh ); | |
340 | } | |
341 | ||
f2ee37d5 | 342 | void wxGCDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
50581042 | 343 | { |
50581042 SC |
344 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") ); |
345 | ||
346 | wxCoord xx, yy, ww, hh; | |
347 | xx = LogicalToDeviceX(x); | |
348 | yy = LogicalToDeviceY(y); | |
349 | ww = LogicalToDeviceXRel(width); | |
350 | hh = LogicalToDeviceYRel(height); | |
351 | ||
a2d6d210 | 352 | m_graphicContext->Clip( xx, yy, ww, hh ); |
50581042 SC |
353 | if ( m_clipping ) |
354 | { | |
355 | m_clipX1 = wxMax( m_clipX1, xx ); | |
356 | m_clipY1 = wxMax( m_clipY1, yy ); | |
357 | m_clipX2 = wxMin( m_clipX2, (xx + ww) ); | |
358 | m_clipY2 = wxMin( m_clipY2, (yy + hh) ); | |
359 | } | |
360 | else | |
361 | { | |
362 | m_clipping = true; | |
363 | ||
364 | m_clipX1 = xx; | |
365 | m_clipY1 = yy; | |
366 | m_clipX2 = xx + ww; | |
367 | m_clipY2 = yy + hh; | |
368 | } | |
50581042 SC |
369 | } |
370 | ||
371 | void wxGCDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) | |
372 | { | |
373 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoSetClippingRegionAsRegion - invalid DC") ); | |
374 | ||
375 | if (region.Empty()) | |
376 | { | |
377 | DestroyClippingRegion(); | |
378 | return; | |
379 | } | |
380 | ||
381 | wxCoord x, y, w, h; | |
382 | region.GetBox( x, y, w, h ); | |
383 | wxCoord xx, yy, ww, hh; | |
384 | xx = LogicalToDeviceX(x); | |
385 | yy = LogicalToDeviceY(y); | |
386 | ww = LogicalToDeviceXRel(w); | |
387 | hh = LogicalToDeviceYRel(h); | |
388 | ||
389 | // if we have a scaling that we cannot map onto native regions | |
390 | // we must use the box | |
391 | if ( ww != w || hh != h ) | |
392 | { | |
393 | wxGCDC::DoSetClippingRegion( x, y, w, h ); | |
394 | } | |
395 | else | |
396 | { | |
a2d6d210 VZ |
397 | m_graphicContext->Clip( region ); |
398 | if ( m_clipping ) | |
399 | { | |
400 | m_clipX1 = wxMax( m_clipX1, xx ); | |
401 | m_clipY1 = wxMax( m_clipY1, yy ); | |
402 | m_clipX2 = wxMin( m_clipX2, (xx + ww) ); | |
403 | m_clipY2 = wxMin( m_clipY2, (yy + hh) ); | |
404 | } | |
405 | else | |
406 | { | |
407 | m_clipping = true; | |
408 | ||
409 | m_clipX1 = xx; | |
410 | m_clipY1 = yy; | |
411 | m_clipX2 = xx + ww; | |
412 | m_clipY2 = yy + hh; | |
413 | } | |
414 | } | |
50581042 SC |
415 | } |
416 | ||
417 | void wxGCDC::DestroyClippingRegion() | |
418 | { | |
a2d6d210 VZ |
419 | m_graphicContext->ResetClip(); |
420 | m_graphicContext->SetPen( m_pen ); | |
421 | m_graphicContext->SetBrush( m_brush ); | |
50581042 SC |
422 | |
423 | m_clipping = false; | |
50581042 SC |
424 | } |
425 | ||
426 | void wxGCDC::DoGetSizeMM( int* width, int* height ) const | |
427 | { | |
428 | int w = 0, h = 0; | |
429 | ||
430 | GetSize( &w, &h ); | |
431 | if (width) | |
432 | *width = long( double(w) / (m_scaleX * m_mm_to_pix_x) ); | |
433 | if (height) | |
434 | *height = long( double(h) / (m_scaleY * m_mm_to_pix_y) ); | |
435 | } | |
436 | ||
437 | void wxGCDC::SetTextForeground( const wxColour &col ) | |
438 | { | |
439 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") ); | |
440 | ||
441 | if ( col != m_textForegroundColour ) | |
442 | { | |
443 | m_textForegroundColour = col; | |
444 | m_graphicContext->SetTextColor( col ); | |
445 | } | |
446 | } | |
447 | ||
448 | void wxGCDC::SetTextBackground( const wxColour &col ) | |
449 | { | |
450 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") ); | |
451 | ||
452 | m_textBackgroundColour = col; | |
453 | } | |
454 | ||
455 | void wxGCDC::SetMapMode( int mode ) | |
456 | { | |
457 | switch (mode) | |
458 | { | |
459 | case wxMM_TWIPS: | |
460 | SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y ); | |
461 | break; | |
462 | ||
463 | case wxMM_POINTS: | |
464 | SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y ); | |
465 | break; | |
466 | ||
467 | case wxMM_METRIC: | |
468 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); | |
469 | break; | |
470 | ||
471 | case wxMM_LOMETRIC: | |
472 | SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 ); | |
473 | break; | |
474 | ||
475 | case wxMM_TEXT: | |
476 | default: | |
477 | SetLogicalScale( 1.0, 1.0 ); | |
478 | break; | |
479 | } | |
480 | ||
481 | ComputeScaleAndOrigin(); | |
482 | } | |
483 | ||
484 | void wxGCDC::SetUserScale( double x, double y ) | |
485 | { | |
486 | // allow negative ? -> no | |
f2ee37d5 | 487 | |
50581042 SC |
488 | m_userScaleX = x; |
489 | m_userScaleY = y; | |
a2d6d210 | 490 | ComputeScaleAndOrigin(); |
50581042 SC |
491 | } |
492 | ||
493 | void wxGCDC::SetLogicalScale( double x, double y ) | |
494 | { | |
495 | // allow negative ? | |
496 | m_logicalScaleX = x; | |
497 | m_logicalScaleY = y; | |
498 | ComputeScaleAndOrigin(); | |
499 | } | |
500 | ||
501 | void wxGCDC::SetLogicalOrigin( wxCoord x, wxCoord y ) | |
502 | { | |
503 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
504 | m_logicalOriginY = y * m_signY; | |
505 | ComputeScaleAndOrigin(); | |
506 | } | |
507 | ||
508 | void wxGCDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
509 | { | |
510 | m_deviceOriginX = x; | |
511 | m_deviceOriginY = y; | |
512 | ComputeScaleAndOrigin(); | |
513 | } | |
514 | ||
515 | void wxGCDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
516 | { | |
517 | m_signX = (xLeftRight ? 1 : -1); | |
518 | m_signY = (yBottomUp ? -1 : 1); | |
519 | ComputeScaleAndOrigin(); | |
520 | } | |
521 | ||
522 | wxSize wxGCDC::GetPPI() const | |
523 | { | |
524 | return wxSize(72, 72); | |
525 | } | |
526 | ||
527 | int wxGCDC::GetDepth() const | |
528 | { | |
529 | return 32; | |
530 | } | |
531 | ||
532 | void wxGCDC::ComputeScaleAndOrigin() | |
533 | { | |
f2ee37d5 SC |
534 | // CMB: copy scale to see if it changes |
535 | double origScaleX = m_scaleX; | |
536 | double origScaleY = m_scaleY; | |
537 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
538 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
539 | m_deviceOriginX = m_deviceOriginX + m_logicalOriginX; | |
540 | m_deviceOriginY = m_deviceOriginY + m_logicalOriginY; | |
50581042 | 541 | |
f2ee37d5 SC |
542 | // CMB: if scale has changed call SetPen to recalulate the line width |
543 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) | |
544 | { | |
545 | // this is a bit artificial, but we need to force wxDC to think | |
546 | // the pen has changed | |
547 | wxPen pen(GetPen()); | |
548 | m_pen = wxNullPen; | |
549 | SetPen(pen); | |
a2d6d210 | 550 | SetFont(m_font); |
f2ee37d5 | 551 | } |
50581042 SC |
552 | } |
553 | ||
12f72836 SC |
554 | void wxGCDC::SetPalette( const wxPalette& WXUNUSED(palette) ) |
555 | { | |
556 | ||
557 | } | |
50581042 SC |
558 | |
559 | void wxGCDC::SetBackgroundMode( int mode ) | |
560 | { | |
561 | m_backgroundMode = mode; | |
562 | } | |
563 | ||
564 | void wxGCDC::SetFont( const wxFont &font ) | |
565 | { | |
566 | m_font = font; | |
567 | if ( m_graphicContext ) | |
a2d6d210 VZ |
568 | { |
569 | wxFont f = font; | |
570 | if ( f.Ok() ) | |
571 | f.SetPointSize( LogicalToDeviceYRel(font.GetPointSize())); | |
f2ee37d5 | 572 | m_graphicContext->SetFont( f ); |
a2d6d210 | 573 | } |
50581042 SC |
574 | } |
575 | ||
576 | void wxGCDC::SetPen( const wxPen &pen ) | |
577 | { | |
578 | if ( m_pen == pen ) | |
579 | return; | |
580 | ||
581 | m_pen = pen; | |
582 | if ( m_graphicContext ) | |
583 | { | |
584 | if ( m_pen.GetStyle() == wxSOLID || m_pen.GetStyle() == wxTRANSPARENT ) | |
585 | { | |
586 | m_graphicContext->SetPen( m_pen ); | |
587 | } | |
588 | else | |
589 | { | |
590 | // we have to compensate for moved device origins etc. otherwise patterned pens are standing still | |
591 | // eg when using a wxScrollWindow and scrolling around | |
592 | int origX = LogicalToDeviceX( 0 ); | |
593 | int origY = LogicalToDeviceY( 0 ); | |
594 | m_graphicContext->Translate( origX , origY ); | |
595 | m_graphicContext->SetPen( m_pen ); | |
596 | m_graphicContext->Translate( -origX , -origY ); | |
597 | } | |
598 | } | |
599 | } | |
600 | ||
601 | void wxGCDC::SetBrush( const wxBrush &brush ) | |
602 | { | |
603 | if (m_brush == brush) | |
604 | return; | |
605 | ||
606 | m_brush = brush; | |
607 | if ( m_graphicContext ) | |
608 | { | |
609 | if ( brush.GetStyle() == wxSOLID || brush.GetStyle() == wxTRANSPARENT ) | |
610 | { | |
611 | m_graphicContext->SetBrush( m_brush ); | |
612 | } | |
613 | else | |
614 | { | |
615 | // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still | |
616 | // eg when using a wxScrollWindow and scrolling around | |
617 | // TODO on MSW / GDIPlus this still occurs with hatched brushes | |
618 | int origX = LogicalToDeviceX(0); | |
619 | int origY = LogicalToDeviceY(0); | |
620 | m_graphicContext->Translate( origX , origY ); | |
621 | m_graphicContext->SetBrush( m_brush ); | |
622 | m_graphicContext->Translate( -origX , -origY ); | |
623 | } | |
624 | } | |
625 | } | |
626 | ||
627 | void wxGCDC::SetBackground( const wxBrush &brush ) | |
628 | { | |
629 | if (m_backgroundBrush == brush) | |
630 | return; | |
631 | ||
632 | m_backgroundBrush = brush; | |
633 | if (!m_backgroundBrush.Ok()) | |
634 | return; | |
635 | } | |
636 | ||
637 | void wxGCDC::SetLogicalFunction( int function ) | |
638 | { | |
639 | if (m_logicalFunction == function) | |
640 | return; | |
641 | ||
642 | m_logicalFunction = function; | |
643 | #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES | |
644 | ||
645 | CGContextRef cgContext = ((wxCairoContext*)(m_graphicContext))->GetNativeContext(); | |
646 | if ( m_logicalFunction == wxCOPY ) | |
647 | CGContextSetBlendMode( cgContext, kCGBlendModeNormal ); | |
648 | else if ( m_logicalFunction == wxINVERT ) | |
649 | CGContextSetBlendMode( cgContext, kCGBlendModeExclusion ); | |
650 | else | |
651 | CGContextSetBlendMode( cgContext, kCGBlendModeNormal ); | |
652 | #endif | |
653 | ||
654 | } | |
655 | ||
12f72836 SC |
656 | bool wxGCDC::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), |
657 | const wxColour& WXUNUSED(col), int WXUNUSED(style)) | |
50581042 | 658 | { |
50581042 SC |
659 | return false; |
660 | } | |
661 | ||
12f72836 | 662 | bool wxGCDC::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const |
50581042 SC |
663 | { |
664 | // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") ); | |
665 | return false; | |
666 | } | |
667 | ||
668 | void wxGCDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) | |
669 | { | |
670 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") ); | |
671 | ||
672 | #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES | |
673 | ||
674 | if ( m_logicalFunction != wxCOPY ) | |
675 | return; | |
676 | #endif | |
677 | ||
678 | wxCoord xx1 = LogicalToDeviceX(x1); | |
679 | wxCoord yy1 = LogicalToDeviceY(y1); | |
680 | wxCoord xx2 = LogicalToDeviceX(x2); | |
681 | wxCoord yy2 = LogicalToDeviceY(y2); | |
682 | ||
683 | m_graphicContext->StrokeLine(xx1,yy1,xx2,yy2); | |
684 | ||
685 | CalcBoundingBox(x1, y1); | |
686 | CalcBoundingBox(x2, y2); | |
687 | } | |
688 | ||
689 | void wxGCDC::DoCrossHair( wxCoord x, wxCoord y ) | |
690 | { | |
691 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") ); | |
692 | ||
693 | if ( m_logicalFunction != wxCOPY ) | |
694 | return; | |
695 | ||
696 | int w = 0, h = 0; | |
697 | ||
698 | GetSize( &w, &h ); | |
699 | ||
700 | wxCoord xx = LogicalToDeviceX(x); | |
701 | wxCoord yy = LogicalToDeviceY(y); | |
702 | wxCoord xw = LogicalToDeviceX(w); | |
703 | wxCoord x0 = LogicalToDeviceX(0); | |
704 | wxCoord y0 = LogicalToDeviceY(0); | |
705 | wxCoord yh = LogicalToDeviceY(h); | |
706 | ||
707 | m_graphicContext->StrokeLine(x0,yy,xw,yy); | |
708 | m_graphicContext->StrokeLine(xx,y0,xx,yh); | |
709 | ||
710 | CalcBoundingBox(x0, y0); | |
711 | CalcBoundingBox(x0+xw, y0+yh); | |
712 | } | |
713 | ||
714 | void wxGCDC::DoDrawArc( wxCoord x1, wxCoord y1, | |
715 | wxCoord x2, wxCoord y2, | |
716 | wxCoord xc, wxCoord yc ) | |
717 | { | |
718 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") ); | |
719 | ||
720 | if ( m_logicalFunction != wxCOPY ) | |
721 | return; | |
722 | ||
723 | wxCoord xx1 = LogicalToDeviceX(x1); | |
724 | wxCoord yy1 = LogicalToDeviceY(y1); | |
725 | wxCoord xx2 = LogicalToDeviceX(x2); | |
726 | wxCoord yy2 = LogicalToDeviceY(y2); | |
727 | wxCoord xxc = LogicalToDeviceX(xc); | |
728 | wxCoord yyc = LogicalToDeviceY(yc); | |
729 | ||
730 | double dx = xx1 - xxc; | |
731 | double dy = yy1 - yyc; | |
732 | double radius = sqrt((double)(dx * dx + dy * dy)); | |
733 | wxCoord rad = (wxCoord)radius; | |
734 | double sa, ea; | |
735 | if (xx1 == xx2 && yy1 == yy2) | |
736 | { | |
737 | sa = 0.0; | |
738 | ea = 360.0; | |
739 | } | |
740 | else if (radius == 0.0) | |
741 | { | |
742 | sa = ea = 0.0; | |
743 | } | |
744 | else | |
745 | { | |
746 | sa = (xx1 - xxc == 0) ? | |
747 | (yy1 - yyc < 0) ? 90.0 : -90.0 : | |
748 | -atan2(double(yy1 - yyc), double(xx1 - xxc)) * RAD2DEG; | |
749 | ea = (xx2 - xxc == 0) ? | |
750 | (yy2 - yyc < 0) ? 90.0 : -90.0 : | |
751 | -atan2(double(yy2 - yyc), double(xx2 - xxc)) * RAD2DEG; | |
752 | } | |
753 | ||
754 | bool fill = m_brush.GetStyle() != wxTRANSPARENT; | |
755 | ||
756 | wxGraphicsPath* path = m_graphicContext->CreatePath(); | |
757 | if ( fill && ((x1!=x2)||(y1!=y2)) ) | |
758 | path->MoveToPoint( xxc, yyc ); | |
759 | path->AddArc( xxc, yyc , rad , DegToRad(sa) , DegToRad(ea), false ); | |
760 | if ( fill && ((x1!=x2)||(y1!=y2)) ) | |
761 | path->AddLineToPoint( xxc, yyc ); | |
762 | m_graphicContext->DrawPath(path); | |
763 | delete path; | |
764 | } | |
765 | ||
766 | void wxGCDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
767 | double sa, double ea ) | |
768 | { | |
769 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") ); | |
770 | ||
771 | if ( m_logicalFunction != wxCOPY ) | |
772 | return; | |
773 | ||
774 | wxCoord xx = LogicalToDeviceX(x); | |
775 | wxCoord yy = LogicalToDeviceY(y); | |
776 | wxCoord ww = m_signX * LogicalToDeviceXRel(w); | |
777 | wxCoord hh = m_signY * LogicalToDeviceYRel(h); | |
778 | ||
779 | // handle -ve width and/or height | |
780 | if (ww < 0) | |
781 | { | |
782 | ww = -ww; | |
783 | xx = xx - ww; | |
784 | } | |
785 | if (hh < 0) | |
786 | { | |
787 | hh = -hh; | |
788 | yy = yy - hh; | |
789 | } | |
790 | ||
791 | bool fill = m_brush.GetStyle() != wxTRANSPARENT; | |
792 | ||
793 | wxGraphicsPath* path = m_graphicContext->CreatePath(); | |
794 | m_graphicContext->PushState(); | |
795 | m_graphicContext->Translate(xx+ww/2,yy+hh/2); | |
a2d6d210 VZ |
796 | wxDouble factor = ((wxDouble) ww) / hh; |
797 | m_graphicContext->Scale( factor , 1.0); | |
50581042 SC |
798 | if ( fill && (sa!=ea) ) |
799 | path->MoveToPoint(0,0); | |
d94228a2 SC |
800 | // since these angles (ea,sa) are measured counter-clockwise, we invert them to |
801 | // get clockwise angles | |
802 | path->AddArc( 0, 0, hh/2 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); | |
50581042 SC |
803 | if ( fill && (sa!=ea) ) |
804 | path->AddLineToPoint(0,0); | |
805 | m_graphicContext->DrawPath( path ); | |
806 | m_graphicContext->PopState(); | |
807 | delete path; | |
808 | } | |
809 | ||
810 | void wxGCDC::DoDrawPoint( wxCoord x, wxCoord y ) | |
811 | { | |
812 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") ); | |
813 | ||
814 | DoDrawLine( x , y , x + 1 , y + 1 ); | |
815 | } | |
816 | ||
817 | void wxGCDC::DoDrawLines(int n, wxPoint points[], | |
818 | wxCoord xoffset, wxCoord yoffset) | |
819 | { | |
820 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") ); | |
821 | ||
822 | #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES | |
823 | ||
824 | if ( m_logicalFunction != wxCOPY ) | |
825 | return; | |
826 | #endif | |
827 | ||
a2d6d210 VZ |
828 | wxPoint2DDouble* pointsD = new wxPoint2DDouble[n]; |
829 | for( int i = 0; i < n; ++i) | |
50581042 SC |
830 | { |
831 | pointsD[i].m_x = LogicalToDeviceX(points[i].x + xoffset); | |
832 | pointsD[i].m_y = LogicalToDeviceY(points[i].y + yoffset); | |
833 | } | |
834 | ||
a2d6d210 | 835 | m_graphicContext->StrokeLines( n , pointsD); |
50581042 SC |
836 | delete[] pointsD; |
837 | } | |
838 | ||
839 | #if wxUSE_SPLINES | |
840 | void wxGCDC::DoDrawSpline(wxList *points) | |
841 | { | |
842 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") ); | |
843 | ||
844 | if ( m_logicalFunction != wxCOPY ) | |
845 | return; | |
846 | ||
847 | wxGraphicsPath* path = m_graphicContext->CreatePath(); | |
848 | ||
849 | wxList::compatibility_iterator node = points->GetFirst(); | |
850 | if (node == wxList::compatibility_iterator()) | |
851 | // empty list | |
852 | return; | |
853 | ||
854 | wxPoint *p = (wxPoint *)node->GetData(); | |
855 | ||
856 | wxCoord x1 = p->x; | |
857 | wxCoord y1 = p->y; | |
858 | ||
859 | node = node->GetNext(); | |
860 | p = (wxPoint *)node->GetData(); | |
861 | ||
862 | wxCoord x2 = p->x; | |
863 | wxCoord y2 = p->y; | |
864 | wxCoord cx1 = ( x1 + x2 ) / 2; | |
865 | wxCoord cy1 = ( y1 + y2 ) / 2; | |
866 | ||
867 | path->MoveToPoint( LogicalToDeviceX( x1 ) , LogicalToDeviceY( y1 ) ); | |
868 | path->AddLineToPoint( LogicalToDeviceX( cx1 ) , LogicalToDeviceY( cy1 ) ); | |
869 | #if !wxUSE_STL | |
870 | ||
871 | while ((node = node->GetNext()) != NULL) | |
872 | #else | |
873 | ||
874 | while ((node = node->GetNext())) | |
875 | #endif // !wxUSE_STL | |
876 | ||
877 | { | |
878 | p = (wxPoint *)node->GetData(); | |
879 | x1 = x2; | |
880 | y1 = y2; | |
881 | x2 = p->x; | |
882 | y2 = p->y; | |
883 | wxCoord cx4 = (x1 + x2) / 2; | |
884 | wxCoord cy4 = (y1 + y2) / 2; | |
885 | ||
886 | path->AddQuadCurveToPoint( | |
887 | LogicalToDeviceX( x1 ) , LogicalToDeviceY( y1 ) , | |
888 | LogicalToDeviceX( cx4 ) , LogicalToDeviceY( cy4 ) ); | |
889 | ||
890 | cx1 = cx4; | |
891 | cy1 = cy4; | |
892 | } | |
893 | ||
894 | path->AddLineToPoint( LogicalToDeviceX( x2 ) , LogicalToDeviceY( y2 ) ); | |
895 | ||
896 | m_graphicContext->StrokePath( path ); | |
897 | delete path; | |
898 | } | |
9fd707a5 | 899 | #endif // wxUSE_SPLINES |
50581042 SC |
900 | |
901 | void wxGCDC::DoDrawPolygon( int n, wxPoint points[], | |
902 | wxCoord xoffset, wxCoord yoffset, | |
903 | int fillStyle ) | |
904 | { | |
905 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") ); | |
906 | ||
907 | if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) ) | |
908 | return; | |
909 | if ( m_logicalFunction != wxCOPY ) | |
910 | return; | |
911 | ||
a2d6d210 | 912 | bool closeIt = false; |
50581042 | 913 | if (points[n-1] != points[0]) |
a2d6d210 | 914 | closeIt = true; |
50581042 | 915 | |
a2d6d210 VZ |
916 | wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)]; |
917 | for( int i = 0; i < n; ++i) | |
50581042 SC |
918 | { |
919 | pointsD[i].m_x = LogicalToDeviceX(points[i].x + xoffset); | |
920 | pointsD[i].m_y = LogicalToDeviceY(points[i].y + yoffset); | |
921 | } | |
922 | if ( closeIt ) | |
923 | pointsD[n] = pointsD[0]; | |
924 | ||
a2d6d210 | 925 | m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle); |
50581042 SC |
926 | delete[] pointsD; |
927 | } | |
928 | ||
929 | void wxGCDC::DoDrawPolyPolygon(int n, | |
930 | int count[], | |
931 | wxPoint points[], | |
932 | wxCoord xoffset, | |
933 | wxCoord yoffset, | |
934 | int fillStyle) | |
935 | { | |
936 | wxASSERT(n > 1); | |
937 | wxGraphicsPath* path = m_graphicContext->CreatePath(); | |
938 | ||
a2d6d210 VZ |
939 | int i = 0; |
940 | for ( int j = 0; j < n; ++j) | |
50581042 SC |
941 | { |
942 | wxPoint start = points[i]; | |
a2d6d210 | 943 | path->MoveToPoint(LogicalToDeviceX(start.x+ xoffset), LogicalToDeviceY(start.y+ yoffset)); |
50581042 SC |
944 | ++i; |
945 | int l = count[j]; | |
a2d6d210 | 946 | for ( int k = 1; k < l; ++k) |
50581042 SC |
947 | { |
948 | path->AddLineToPoint( LogicalToDeviceX(points[i].x+ xoffset), LogicalToDeviceY(points[i].y+ yoffset)); | |
a2d6d210 | 949 | ++i; |
50581042 SC |
950 | } |
951 | // close the polygon | |
952 | if ( start != points[i-1]) | |
953 | path->AddLineToPoint( LogicalToDeviceX(start.x+ xoffset), LogicalToDeviceY(start.y+ yoffset)); | |
954 | } | |
955 | m_graphicContext->DrawPath( path , fillStyle); | |
956 | delete path; | |
957 | } | |
958 | ||
959 | void wxGCDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
960 | { | |
961 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") ); | |
962 | ||
963 | if ( m_logicalFunction != wxCOPY ) | |
964 | return; | |
965 | ||
966 | wxCoord xx = LogicalToDeviceX(x); | |
967 | wxCoord yy = LogicalToDeviceY(y); | |
968 | wxCoord ww = m_signX * LogicalToDeviceXRel(width); | |
969 | wxCoord hh = m_signY * LogicalToDeviceYRel(height); | |
970 | ||
971 | // CMB: draw nothing if transformed w or h is 0 | |
972 | if (ww == 0 || hh == 0) | |
973 | return; | |
974 | ||
975 | // CMB: handle -ve width and/or height | |
976 | if (ww < 0) | |
977 | { | |
978 | ww = -ww; | |
979 | xx = xx - ww; | |
980 | } | |
981 | if (hh < 0) | |
982 | { | |
983 | hh = -hh; | |
984 | yy = yy - hh; | |
985 | } | |
986 | m_graphicContext->DrawRectangle( xx,yy,ww,hh); | |
987 | } | |
988 | ||
989 | void wxGCDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
990 | wxCoord width, wxCoord height, | |
991 | double radius) | |
992 | { | |
993 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") ); | |
994 | ||
995 | if ( m_logicalFunction != wxCOPY ) | |
996 | return; | |
997 | ||
998 | if (radius < 0.0) | |
999 | radius = - radius * ((width < height) ? width : height); | |
1000 | wxCoord xx = LogicalToDeviceX(x); | |
1001 | wxCoord yy = LogicalToDeviceY(y); | |
1002 | wxCoord ww = m_signX * LogicalToDeviceXRel(width); | |
1003 | wxCoord hh = m_signY * LogicalToDeviceYRel(height); | |
1004 | ||
1005 | // CMB: draw nothing if transformed w or h is 0 | |
1006 | if (ww == 0 || hh == 0) | |
1007 | return; | |
1008 | ||
1009 | // CMB: handle -ve width and/or height | |
1010 | if (ww < 0) | |
1011 | { | |
1012 | ww = -ww; | |
1013 | xx = xx - ww; | |
1014 | } | |
1015 | if (hh < 0) | |
1016 | { | |
1017 | hh = -hh; | |
1018 | yy = yy - hh; | |
1019 | } | |
1020 | ||
1021 | m_graphicContext->DrawRoundedRectangle( xx,yy,ww,hh,radius); | |
1022 | } | |
1023 | ||
1024 | void wxGCDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1025 | { | |
1026 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") ); | |
1027 | ||
1028 | if ( m_logicalFunction != wxCOPY ) | |
1029 | return; | |
1030 | ||
a2d6d210 VZ |
1031 | wxDouble xx = LogicalToDeviceX(x); |
1032 | wxDouble yy = LogicalToDeviceY(y); | |
50581042 | 1033 | wxDouble ww = m_signX * LogicalToDeviceXRel(width); |
a2d6d210 | 1034 | wxDouble hh = m_signY * LogicalToDeviceYRel(height); |
50581042 SC |
1035 | |
1036 | // CMB: draw nothing if transformed w or h is 0 | |
1037 | if (ww == 0 || hh == 0) | |
1038 | return; | |
1039 | ||
1040 | // CMB: handle -ve width and/or height | |
1041 | if (ww < 0) | |
1042 | { | |
1043 | ww = -ww; | |
1044 | xx = xx - ww; | |
1045 | } | |
1046 | if (hh < 0) | |
1047 | { | |
1048 | hh = -hh; | |
1049 | yy = yy - hh; | |
1050 | } | |
1051 | ||
1052 | m_graphicContext->DrawEllipse(xx,yy,ww,hh); | |
1053 | } | |
1054 | ||
1055 | bool wxGCDC::CanDrawBitmap() const | |
1056 | { | |
1057 | return true; | |
1058 | } | |
1059 | ||
1060 | bool wxGCDC::DoBlit( | |
f2ee37d5 | 1061 | wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
0b1cc7bf | 1062 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool WXUNUSED(useMask), |
f2ee37d5 | 1063 | wxCoord xsrcMask, wxCoord ysrcMask ) |
50581042 SC |
1064 | { |
1065 | wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") ); | |
1066 | wxCHECK_MSG( source->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") ); | |
1067 | ||
1068 | if ( logical_func == wxNO_OP ) | |
1069 | return true; | |
1070 | ||
1071 | if (xsrcMask == -1 && ysrcMask == -1) | |
1072 | { | |
1073 | xsrcMask = xsrc; | |
1074 | ysrcMask = ysrc; | |
1075 | } | |
1076 | ||
1077 | wxCoord yysrc = source-> LogicalToDeviceY(ysrc); | |
1078 | wxCoord xxsrc = source-> LogicalToDeviceX(xsrc); | |
1079 | wxCoord wwsrc = source-> LogicalToDeviceXRel(width); | |
1080 | wxCoord hhsrc = source-> LogicalToDeviceYRel(height); | |
1081 | ||
1082 | wxCoord yydest = LogicalToDeviceY(ydest); | |
1083 | wxCoord xxdest = LogicalToDeviceX(xdest); | |
1084 | wxCoord wwdest = LogicalToDeviceXRel(width); | |
1085 | wxCoord hhdest = LogicalToDeviceYRel(height); | |
1086 | ||
1087 | wxMemoryDC* memdc = dynamic_cast<wxMemoryDC*>(source); | |
1088 | if ( memdc && logical_func == wxCOPY ) | |
1089 | { | |
0b1cc7bf | 1090 | wxBitmap blit = memdc->GetSelectedBitmap(); |
50581042 SC |
1091 | |
1092 | wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") ); | |
1093 | ||
1094 | wxCoord bmpwidth = blit.GetWidth(); | |
1095 | wxCoord bmpheight = blit.GetHeight(); | |
1096 | ||
1097 | if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc ) | |
1098 | { | |
1099 | wwsrc = wxMin( wwsrc , bmpwidth - xxsrc ); | |
1100 | hhsrc = wxMin( hhsrc , bmpheight - yysrc ); | |
1101 | if ( wwsrc > 0 && hhsrc > 0 ) | |
1102 | { | |
1103 | if ( xxsrc >= 0 && yysrc >= 0 ) | |
1104 | { | |
1105 | wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc ); | |
1106 | // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons | |
1107 | blit = blit.GetSubBitmap( subrect ); | |
1108 | } | |
1109 | else | |
1110 | { | |
1111 | // in this case we'd probably have to adjust the different coordinates, but | |
1112 | // we have to find out proper contract first | |
1113 | blit = wxNullBitmap; | |
1114 | } | |
1115 | } | |
1116 | else | |
1117 | { | |
1118 | blit = wxNullBitmap; | |
1119 | } | |
1120 | } | |
1121 | ||
1122 | if ( blit.Ok() ) | |
1123 | { | |
1124 | m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest ); | |
1125 | } | |
50581042 SC |
1126 | } |
1127 | else | |
1128 | { | |
1129 | wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ); | |
1130 | return false; | |
1131 | } | |
1132 | ||
f2ee37d5 | 1133 | return true; |
50581042 SC |
1134 | } |
1135 | ||
1136 | void wxGCDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, | |
1137 | double angle) | |
1138 | { | |
1139 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") ); | |
1140 | ||
1141 | if ( str.length() == 0 ) | |
1142 | return; | |
1143 | if ( m_logicalFunction != wxCOPY ) | |
1144 | return; | |
1145 | ||
1146 | int drawX = LogicalToDeviceX(x); | |
1147 | int drawY = LogicalToDeviceY(y); | |
1148 | ||
1149 | m_graphicContext->DrawText( str, drawX ,drawY , DegToRad(angle )); | |
1150 | } | |
1151 | ||
1152 | void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y) | |
1153 | { | |
1154 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") ); | |
1155 | ||
1156 | if ( str.length() == 0 ) | |
1157 | return; | |
1158 | if ( m_logicalFunction != wxCOPY ) | |
1159 | return; | |
1160 | ||
1161 | int drawX = LogicalToDeviceX(x); | |
1162 | int drawY = LogicalToDeviceY(y); | |
1163 | ||
1164 | m_graphicContext->DrawText( str, drawX ,drawY); | |
1165 | } | |
1166 | ||
1167 | bool wxGCDC::CanGetTextExtent() const | |
1168 | { | |
1169 | wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") ); | |
1170 | ||
1171 | return true; | |
1172 | } | |
1173 | ||
1174 | void wxGCDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height, | |
1175 | wxCoord *descent, wxCoord *externalLeading , | |
1176 | wxFont *theFont ) const | |
1177 | { | |
1178 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") ); | |
1179 | ||
50581042 SC |
1180 | if ( theFont ) |
1181 | { | |
1182 | m_graphicContext->SetFont( *theFont ); | |
1183 | } | |
1184 | ||
1185 | wxDouble h , d , e , w; | |
1186 | ||
1187 | m_graphicContext->GetTextExtent( str, &w, &h, &d, &e ); | |
1188 | ||
1189 | if ( height ) | |
a2d6d210 | 1190 | *height = DeviceToLogicalYRel((wxCoord)h); |
50581042 | 1191 | if ( descent ) |
a2d6d210 | 1192 | *descent = DeviceToLogicalYRel((wxCoord)d); |
50581042 | 1193 | if ( externalLeading ) |
a2d6d210 | 1194 | *externalLeading = DeviceToLogicalYRel((wxCoord)e); |
50581042 | 1195 | if ( width ) |
a2d6d210 | 1196 | *width = DeviceToLogicalXRel((wxCoord)w); |
50581042 SC |
1197 | |
1198 | if ( theFont ) | |
1199 | { | |
1200 | m_graphicContext->SetFont( m_font ); | |
1201 | } | |
1202 | } | |
1203 | ||
1204 | bool wxGCDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const | |
1205 | { | |
1206 | wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") ); | |
1207 | widths.Clear(); | |
1208 | widths.Add(0,text.Length()); | |
1209 | if ( text.IsEmpty() ) | |
a2d6d210 | 1210 | return true; |
50581042 | 1211 | |
a2d6d210 | 1212 | wxArrayDouble widthsD; |
50581042 SC |
1213 | |
1214 | m_graphicContext->GetPartialTextExtents( text, widthsD ); | |
1215 | for ( size_t i = 0; i < widths.GetCount(); ++i ) | |
a2d6d210 | 1216 | widths[i] = DeviceToLogicalXRel((wxCoord)(widthsD[i] + 0.5)); |
50581042 SC |
1217 | |
1218 | return true; | |
1219 | } | |
1220 | ||
1221 | wxCoord wxGCDC::GetCharWidth(void) const | |
1222 | { | |
1223 | wxCoord width; | |
1224 | DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL ); | |
1225 | ||
1226 | return width; | |
1227 | } | |
1228 | ||
1229 | wxCoord wxGCDC::GetCharHeight(void) const | |
1230 | { | |
1231 | wxCoord height; | |
1232 | DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ); | |
1233 | ||
1234 | return height; | |
1235 | } | |
1236 | ||
1237 | void wxGCDC::Clear(void) | |
1238 | { | |
1239 | wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::Clear - invalid DC") ); | |
f2ee37d5 | 1240 | // TODO better implementation / incorporate size info into wxGCDC or context |
a2d6d210 VZ |
1241 | m_graphicContext->SetBrush( m_backgroundBrush ); |
1242 | wxPen p = *wxTRANSPARENT_PEN; | |
1243 | m_graphicContext->SetPen( p ); | |
1244 | DoDrawRectangle( 0, 0, 32000 , 32000 ); | |
1245 | m_graphicContext->SetPen( m_pen ); | |
1246 | m_graphicContext->SetBrush( m_brush ); | |
50581042 SC |
1247 | } |
1248 | ||
1249 | void wxGCDC::DoGetSize(int *width, int *height) const | |
1250 | { | |
1251 | *width = 1000; | |
1252 | *height = 1000; | |
1253 | } | |
1254 | ||
1255 | void wxGCDC::DoGradientFillLinear(const wxRect& rect, | |
1256 | const wxColour& initialColour, | |
1257 | const wxColour& destColour, | |
1258 | wxDirection nDirection ) | |
1259 | { | |
a2d6d210 VZ |
1260 | wxPoint start; |
1261 | wxPoint end; | |
50581042 SC |
1262 | switch( nDirection) |
1263 | { | |
1264 | case wxWEST : | |
1265 | start = rect.GetRightBottom(); | |
1266 | start.x++; | |
1267 | end = rect.GetLeftBottom(); | |
a2d6d210 | 1268 | break; |
50581042 SC |
1269 | case wxEAST : |
1270 | start = rect.GetLeftBottom(); | |
1271 | end = rect.GetRightBottom(); | |
1272 | end.x++; | |
a2d6d210 | 1273 | break; |
50581042 SC |
1274 | case wxNORTH : |
1275 | start = rect.GetLeftBottom(); | |
1276 | start.y++; | |
1277 | end = rect.GetLeftTop(); | |
a2d6d210 | 1278 | break; |
50581042 SC |
1279 | case wxSOUTH : |
1280 | start = rect.GetLeftTop(); | |
1281 | end = rect.GetLeftBottom(); | |
1282 | end.y++; | |
a2d6d210 VZ |
1283 | break; |
1284 | default : | |
1285 | break; | |
50581042 SC |
1286 | } |
1287 | ||
1288 | m_graphicContext->SetLinearGradientBrush( | |
1289 | LogicalToDeviceX(start.x),LogicalToDeviceY(start.y), | |
1290 | LogicalToDeviceX(end.x),LogicalToDeviceY(end.y), initialColour, destColour); | |
1291 | ||
a2d6d210 VZ |
1292 | wxDouble xx = LogicalToDeviceX(rect.x); |
1293 | wxDouble yy = LogicalToDeviceY(rect.y); | |
50581042 | 1294 | wxDouble ww = m_signX * LogicalToDeviceXRel(rect.width); |
a2d6d210 | 1295 | wxDouble hh = m_signY * LogicalToDeviceYRel(rect.height); |
50581042 SC |
1296 | |
1297 | if (ww == 0 || hh == 0) | |
1298 | return; | |
1299 | ||
1300 | if (ww < 0) | |
1301 | { | |
1302 | ww = -ww; | |
1303 | xx = xx - ww; | |
1304 | } | |
1305 | if (hh < 0) | |
1306 | { | |
1307 | hh = -hh; | |
1308 | yy = yy - hh; | |
1309 | } | |
1310 | ||
1311 | m_graphicContext->SetPen(*wxTRANSPARENT_PEN); | |
1312 | m_graphicContext->DrawRectangle(xx,yy,ww,hh); | |
1313 | m_graphicContext->SetPen(m_pen); | |
1314 | } | |
1315 | ||
1316 | void wxGCDC::DoGradientFillConcentric(const wxRect& rect, | |
1317 | const wxColour& initialColour, | |
1318 | const wxColour& destColour, | |
1319 | const wxPoint& circleCenter) | |
1320 | { | |
1321 | //Radius | |
1322 | wxInt32 cx = rect.GetWidth() / 2; | |
1323 | wxInt32 cy = rect.GetHeight() / 2; | |
1324 | wxInt32 nRadius; | |
1325 | if (cx < cy) | |
1326 | nRadius = cx; | |
1327 | else | |
1328 | nRadius = cy; | |
1329 | ||
a2d6d210 VZ |
1330 | wxDouble xx = LogicalToDeviceX(rect.x); |
1331 | wxDouble yy = LogicalToDeviceY(rect.y); | |
50581042 | 1332 | wxDouble ww = m_signX * LogicalToDeviceXRel(rect.width); |
a2d6d210 | 1333 | wxDouble hh = m_signY * LogicalToDeviceYRel(rect.height); |
50581042 SC |
1334 | |
1335 | if (ww == 0 || hh == 0) | |
1336 | return; | |
1337 | ||
1338 | if (ww < 0) | |
1339 | { | |
1340 | ww = -ww; | |
1341 | xx = xx - ww; | |
1342 | } | |
1343 | if (hh < 0) | |
1344 | { | |
1345 | hh = -hh; | |
1346 | yy = yy - hh; | |
1347 | } | |
1348 | ||
1349 | m_graphicContext->SetPen(*wxTRANSPARENT_PEN); | |
a2d6d210 | 1350 | m_graphicContext->SetBrush( wxBrush( destColour) ); |
50581042 SC |
1351 | m_graphicContext->DrawRectangle( xx,yy,ww,hh); |
1352 | ||
1353 | m_graphicContext->SetRadialGradientBrush( | |
1354 | xx+LogicalToDeviceX(circleCenter.x),yy+LogicalToDeviceY(circleCenter.y), | |
1355 | xx+LogicalToDeviceX(circleCenter.x),yy+LogicalToDeviceY(circleCenter.y), | |
1356 | LogicalToDeviceXRel(nRadius), | |
1357 | initialColour,destColour); | |
1358 | ||
1359 | m_graphicContext->DrawRectangle( xx,yy,ww,hh); | |
1360 | m_graphicContext->SetPen(m_pen); | |
1361 | } | |
1362 | ||
1363 | void wxGCDC::DoDrawCheckMark(wxCoord x, wxCoord y, | |
1364 | wxCoord width, wxCoord height) | |
1365 | { | |
1366 | wxDCBase::DoDrawCheckMark(x,y,width,height); | |
1367 | } | |
1368 | ||
9fd707a5 | 1369 | #endif // wxUSE_GRAPHICS_CONTEXT |