]>
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: | |
caa42c43 | 6 | // Created: |
50581042 SC |
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 | ||
66bc98cc | 21 | #include "wx/private/graphics.h" |
50581042 | 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" |
4f40354a | 28 | #include "wx/log.h" |
539872ae SC |
29 | #endif |
30 | ||
d94228a2 SC |
31 | //----------------------------------------------------------------------------- |
32 | // constants | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
9fd707a5 | 35 | static const double RAD2DEG = 180.0 / M_PI; |
d94228a2 SC |
36 | |
37 | //----------------------------------------------------------------------------- | |
38 | // Local functions | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
d94228a2 SC |
41 | static inline double DegToRad(double deg) |
42 | { | |
43 | return (deg * M_PI) / 180.0; | |
44 | } | |
d94228a2 | 45 | |
9fd707a5 | 46 | //----------------------------------------------------------------------------- |
d94228a2 | 47 | |
2c820406 SC |
48 | //----------------------------------------------------------------------------- |
49 | // wxGraphicsObject | |
50 | //----------------------------------------------------------------------------- | |
51 | ||
facbe363 SC |
52 | IMPLEMENT_DYNAMIC_CLASS(wxGraphicsObject, wxObject) |
53 | ||
2c820406 SC |
54 | wxGraphicsObjectRefData::wxGraphicsObjectRefData( wxGraphicsRenderer* renderer ) |
55 | { | |
56 | m_renderer = renderer; | |
57 | } | |
58 | wxGraphicsObjectRefData::wxGraphicsObjectRefData( const wxGraphicsObjectRefData* data ) | |
59 | { | |
60 | m_renderer = data->m_renderer; | |
61 | } | |
caa42c43 VZ |
62 | wxGraphicsRenderer* wxGraphicsObjectRefData::GetRenderer() const |
63 | { | |
64 | return m_renderer ; | |
2c820406 | 65 | } |
facbe363 | 66 | |
caa42c43 | 67 | wxGraphicsObjectRefData* wxGraphicsObjectRefData::Clone() const |
2c820406 SC |
68 | { |
69 | return new wxGraphicsObjectRefData(this); | |
70 | } | |
facbe363 | 71 | |
caa42c43 | 72 | wxGraphicsObject::wxGraphicsObject() |
2c820406 SC |
73 | { |
74 | } | |
facbe363 | 75 | |
caa42c43 | 76 | wxGraphicsObject::wxGraphicsObject( wxGraphicsRenderer* renderer ) |
2c820406 SC |
77 | { |
78 | SetRefData( new wxGraphicsObjectRefData(renderer)); | |
79 | } | |
facbe363 | 80 | |
caa42c43 | 81 | wxGraphicsObject::~wxGraphicsObject() |
2c820406 SC |
82 | { |
83 | } | |
facbe363 | 84 | |
caa42c43 VZ |
85 | bool wxGraphicsObject::IsNull() const |
86 | { | |
87 | return m_refData == NULL; | |
2c820406 SC |
88 | } |
89 | ||
caa42c43 VZ |
90 | wxGraphicsRenderer* wxGraphicsObject::GetRenderer() const |
91 | { | |
92 | return ( IsNull() ? NULL : GetGraphicsData()->GetRenderer() ); | |
2c820406 SC |
93 | } |
94 | ||
caa42c43 VZ |
95 | wxGraphicsObjectRefData* wxGraphicsObject::GetGraphicsData() const |
96 | { | |
97 | return (wxGraphicsObjectRefData*) m_refData; | |
2c820406 SC |
98 | } |
99 | ||
100 | wxObjectRefData* wxGraphicsObject::CreateRefData() const | |
101 | { | |
102 | wxLogDebug(wxT("A Null Object cannot be changed")); | |
103 | return NULL; | |
104 | } | |
105 | ||
106 | wxObjectRefData* wxGraphicsObject::CloneRefData(const wxObjectRefData* data) const | |
107 | { | |
108 | const wxGraphicsObjectRefData* ptr = (const wxGraphicsObjectRefData*) data; | |
109 | return ptr->Clone(); | |
110 | } | |
111 | ||
112 | //----------------------------------------------------------------------------- | |
113 | // pens etc. | |
114 | //----------------------------------------------------------------------------- | |
115 | ||
116 | IMPLEMENT_DYNAMIC_CLASS(wxGraphicsPen, wxGraphicsObject) | |
117 | IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBrush, wxGraphicsObject) | |
118 | IMPLEMENT_DYNAMIC_CLASS(wxGraphicsFont, wxGraphicsObject) | |
9786ef01 | 119 | IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBitmap, wxGraphicsObject) |
a4e73390 | 120 | |
2c820406 SC |
121 | WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen; |
122 | WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush; | |
123 | WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont; | |
9786ef01 | 124 | WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap; |
2c820406 | 125 | |
a4e73390 SC |
126 | //----------------------------------------------------------------------------- |
127 | // matrix | |
128 | //----------------------------------------------------------------------------- | |
129 | ||
130 | IMPLEMENT_DYNAMIC_CLASS(wxGraphicsMatrix, wxGraphicsObject) | |
131 | WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix; | |
132 | ||
133 | // concatenates the matrix | |
134 | void wxGraphicsMatrix::Concat( const wxGraphicsMatrix *t ) | |
135 | { | |
136 | AllocExclusive(); | |
137 | GetMatrixData()->Concat(t->GetMatrixData()); | |
138 | } | |
139 | ||
140 | // sets the matrix to the respective values | |
caa42c43 | 141 | void wxGraphicsMatrix::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d, |
a4e73390 SC |
142 | wxDouble tx, wxDouble ty) |
143 | { | |
144 | AllocExclusive(); | |
145 | GetMatrixData()->Set(a,b,c,d,tx,ty); | |
146 | } | |
147 | ||
248802d0 RD |
148 | // gets the component valuess of the matrix |
149 | void wxGraphicsMatrix::Get(wxDouble* a, wxDouble* b, wxDouble* c, | |
150 | wxDouble* d, wxDouble* tx, wxDouble* ty) const | |
151 | { | |
152 | GetMatrixData()->Get(a, b, c, d, tx, ty); | |
153 | } | |
154 | ||
a4e73390 SC |
155 | // makes this the inverse matrix |
156 | void wxGraphicsMatrix::Invert() | |
157 | { | |
158 | AllocExclusive(); | |
159 | GetMatrixData()->Invert(); | |
160 | } | |
161 | ||
162 | // returns true if the elements of the transformation matrix are equal ? | |
163 | bool wxGraphicsMatrix::IsEqual( const wxGraphicsMatrix* t) const | |
164 | { | |
165 | return GetMatrixData()->IsEqual(t->GetMatrixData()); | |
166 | } | |
167 | ||
168 | // return true if this is the identity matrix | |
169 | bool wxGraphicsMatrix::IsIdentity() const | |
170 | { | |
171 | return GetMatrixData()->IsIdentity(); | |
172 | } | |
173 | ||
174 | // add the translation to this matrix | |
175 | void wxGraphicsMatrix::Translate( wxDouble dx , wxDouble dy ) | |
176 | { | |
177 | AllocExclusive(); | |
178 | GetMatrixData()->Translate(dx,dy); | |
179 | } | |
180 | ||
181 | // add the scale to this matrix | |
182 | void wxGraphicsMatrix::Scale( wxDouble xScale , wxDouble yScale ) | |
183 | { | |
184 | AllocExclusive(); | |
185 | GetMatrixData()->Scale(xScale,yScale); | |
186 | } | |
187 | ||
188 | // add the rotation to this matrix (radians) | |
189 | void wxGraphicsMatrix::Rotate( wxDouble angle ) | |
190 | { | |
191 | AllocExclusive(); | |
192 | GetMatrixData()->Rotate(angle); | |
caa42c43 | 193 | } |
a4e73390 SC |
194 | |
195 | // | |
196 | // apply the transforms | |
197 | // | |
198 | ||
199 | // applies that matrix to the point | |
200 | void wxGraphicsMatrix::TransformPoint( wxDouble *x, wxDouble *y ) const | |
201 | { | |
202 | GetMatrixData()->TransformPoint(x,y); | |
203 | } | |
204 | ||
205 | // applies the matrix except for translations | |
206 | void wxGraphicsMatrix::TransformDistance( wxDouble *dx, wxDouble *dy ) const | |
207 | { | |
208 | GetMatrixData()->TransformDistance(dx,dy); | |
209 | } | |
8ddf8e82 | 210 | |
a4e73390 SC |
211 | // returns the native representation |
212 | void * wxGraphicsMatrix::GetNativeMatrix() const | |
213 | { | |
214 | return GetMatrixData()->GetNativeMatrix(); | |
215 | } | |
216 | ||
217 | //----------------------------------------------------------------------------- | |
218 | // path | |
219 | //----------------------------------------------------------------------------- | |
220 | ||
221 | IMPLEMENT_DYNAMIC_CLASS(wxGraphicsPath, wxGraphicsObject) | |
1ea0eb4e | 222 | WXDLLIMPEXP_DATA_CORE(wxGraphicsPath) wxNullGraphicsPath; |
a4e73390 SC |
223 | |
224 | // convenience functions, for using wxPoint2DDouble etc | |
225 | ||
226 | wxPoint2DDouble wxGraphicsPath::GetCurrentPoint() const | |
50581042 | 227 | { |
a2d6d210 | 228 | wxDouble x,y; |
a4e73390 | 229 | GetCurrentPoint(&x,&y); |
50581042 SC |
230 | return wxPoint2DDouble(x,y); |
231 | } | |
232 | ||
233 | void wxGraphicsPath::MoveToPoint( const wxPoint2DDouble& p) | |
234 | { | |
235 | MoveToPoint( p.m_x , p.m_y); | |
236 | } | |
237 | ||
238 | void wxGraphicsPath::AddLineToPoint( const wxPoint2DDouble& p) | |
239 | { | |
240 | AddLineToPoint( p.m_x , p.m_y); | |
241 | } | |
242 | ||
243 | void wxGraphicsPath::AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e) | |
244 | { | |
245 | AddCurveToPoint(c1.m_x, c1.m_y, c2.m_x, c2.m_y, e.m_x, e.m_y); | |
246 | } | |
247 | ||
248 | void wxGraphicsPath::AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise) | |
249 | { | |
250 | AddArc(c.m_x, c.m_y, r, startAngle, endAngle, clockwise); | |
251 | } | |
252 | ||
a4e73390 | 253 | wxRect2DDouble wxGraphicsPath::GetBox() const |
facbe363 | 254 | { |
caa42c43 VZ |
255 | wxDouble x,y,w,h; |
256 | GetBox(&x,&y,&w,&h); | |
257 | return wxRect2DDouble( x,y,w,h ); | |
facbe363 SC |
258 | } |
259 | ||
94a007ec | 260 | bool wxGraphicsPath::Contains( const wxPoint2DDouble& c, wxPolygonFillMode fillStyle ) const |
c907796b RD |
261 | { |
262 | return Contains( c.m_x, c.m_y, fillStyle); | |
263 | } | |
264 | ||
a4e73390 SC |
265 | // true redirections |
266 | ||
267 | // begins a new subpath at (x,y) | |
268 | void wxGraphicsPath::MoveToPoint( wxDouble x, wxDouble y ) | |
269 | { | |
270 | AllocExclusive(); | |
271 | GetPathData()->MoveToPoint(x,y); | |
272 | } | |
273 | ||
caa42c43 | 274 | // adds a straight line from the current point to (x,y) |
a4e73390 SC |
275 | void wxGraphicsPath::AddLineToPoint( wxDouble x, wxDouble y ) |
276 | { | |
277 | AllocExclusive(); | |
278 | GetPathData()->AddLineToPoint(x,y); | |
279 | } | |
280 | ||
281 | // adds a cubic Bezier curve from the current point, using two control points and an end point | |
282 | void wxGraphicsPath::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) | |
283 | { | |
284 | AllocExclusive(); | |
285 | GetPathData()->AddCurveToPoint(cx1,cy1,cx2,cy2,x,y); | |
286 | } | |
287 | ||
288 | // adds another path | |
289 | void wxGraphicsPath::AddPath( const wxGraphicsPath& path ) | |
290 | { | |
291 | AllocExclusive(); | |
292 | GetPathData()->AddPath(path.GetPathData()); | |
293 | } | |
294 | ||
295 | // closes the current sub-path | |
296 | void wxGraphicsPath::CloseSubpath() | |
297 | { | |
298 | AllocExclusive(); | |
299 | GetPathData()->CloseSubpath(); | |
300 | } | |
301 | ||
302 | // gets the last point of the current path, (0,0) if not yet set | |
303 | void wxGraphicsPath::GetCurrentPoint( wxDouble* x, wxDouble* y) const | |
304 | { | |
305 | GetPathData()->GetCurrentPoint(x,y); | |
306 | } | |
307 | ||
308 | // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle | |
309 | void wxGraphicsPath::AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) | |
310 | { | |
311 | AllocExclusive(); | |
312 | GetPathData()->AddArc(x,y,r,startAngle,endAngle,clockwise); | |
313 | } | |
314 | ||
50581042 | 315 | // |
caa42c43 | 316 | // These are convenience functions which - if not available natively will be assembled |
a4e73390 | 317 | // using the primitives from above |
50581042 SC |
318 | // |
319 | ||
a4e73390 | 320 | // adds a quadratic Bezier curve from the current point, using a control point and an end point |
50581042 | 321 | void wxGraphicsPath::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ) |
a4e73390 SC |
322 | { |
323 | AllocExclusive(); | |
324 | GetPathData()->AddQuadCurveToPoint(cx,cy,x,y); | |
325 | } | |
326 | ||
caa42c43 | 327 | // appends a rectangle as a new closed subpath |
a4e73390 SC |
328 | void wxGraphicsPath::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
329 | { | |
330 | AllocExclusive(); | |
331 | GetPathData()->AddRectangle(x,y,w,h); | |
332 | } | |
333 | ||
334 | // appends an ellipsis as a new closed subpath fitting the passed rectangle | |
335 | void wxGraphicsPath::AddCircle( wxDouble x, wxDouble y, wxDouble r ) | |
336 | { | |
337 | AllocExclusive(); | |
338 | GetPathData()->AddCircle(x,y,r); | |
339 | } | |
340 | ||
341 | // appends 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) | |
caa42c43 | 342 | void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) |
a4e73390 SC |
343 | { |
344 | GetPathData()->AddArcToPoint(x1,y1,x2,y2,r); | |
345 | } | |
346 | ||
347 | // appends an ellipse | |
348 | void wxGraphicsPath::AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h) | |
349 | { | |
350 | AllocExclusive(); | |
351 | GetPathData()->AddEllipse(x,y,w,h); | |
352 | } | |
353 | ||
354 | // appends a rounded rectangle | |
355 | void wxGraphicsPath::AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius) | |
356 | { | |
357 | AllocExclusive(); | |
358 | GetPathData()->AddRoundedRectangle(x,y,w,h,radius); | |
359 | } | |
360 | ||
361 | // returns the native path | |
362 | void * wxGraphicsPath::GetNativePath() const | |
363 | { | |
364 | return GetPathData()->GetNativePath(); | |
365 | } | |
366 | ||
367 | // give the native path returned by GetNativePath() back (there might be some deallocations necessary) | |
368 | void wxGraphicsPath::UnGetNativePath(void *p)const | |
369 | { | |
370 | GetPathData()->UnGetNativePath(p); | |
371 | } | |
372 | ||
373 | // transforms each point of this path by the matrix | |
374 | void wxGraphicsPath::Transform( const wxGraphicsMatrix& matrix ) | |
375 | { | |
376 | AllocExclusive(); | |
377 | GetPathData()->Transform(matrix.GetMatrixData()); | |
378 | } | |
379 | ||
380 | // gets the bounding box enclosing all points (possibly including control points) | |
381 | void wxGraphicsPath::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const | |
382 | { | |
383 | GetPathData()->GetBox(x,y,w,h); | |
384 | } | |
385 | ||
94a007ec | 386 | bool wxGraphicsPath::Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle ) const |
a4e73390 SC |
387 | { |
388 | return GetPathData()->Contains(x,y,fillStyle); | |
389 | } | |
390 | ||
391 | // | |
392 | // Emulations, these mus be implemented in the ...Data classes in order to allow for proper overrides | |
393 | // | |
394 | ||
395 | void wxGraphicsPathData::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ) | |
50581042 SC |
396 | { |
397 | // calculate using degree elevation to a cubic bezier | |
a2d6d210 VZ |
398 | wxPoint2DDouble c1; |
399 | wxPoint2DDouble c2; | |
50581042 | 400 | |
a4e73390 SC |
401 | wxPoint2DDouble start; |
402 | GetCurrentPoint(&start.m_x,&start.m_y); | |
50581042 SC |
403 | wxPoint2DDouble end(x,y); |
404 | wxPoint2DDouble c(cx,cy); | |
5ce3abfb | 405 | c1 = wxDouble(1/3.0) * start + wxDouble(2/3.0) * c; |
a2d6d210 | 406 | c2 = wxDouble(2/3.0) * c + wxDouble(1/3.0) * end; |
50581042 SC |
407 | AddCurveToPoint(c1.m_x,c1.m_y,c2.m_x,c2.m_y,x,y); |
408 | } | |
409 | ||
a4e73390 | 410 | void wxGraphicsPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) |
50581042 SC |
411 | { |
412 | MoveToPoint(x,y); | |
413 | AddLineToPoint(x,y+h); | |
414 | AddLineToPoint(x+w,y+h); | |
415 | AddLineToPoint(x+w,y); | |
416 | CloseSubpath(); | |
417 | } | |
418 | ||
a4e73390 | 419 | void wxGraphicsPathData::AddCircle( wxDouble x, wxDouble y, wxDouble r ) |
50581042 SC |
420 | { |
421 | MoveToPoint(x+r,y); | |
422 | AddArc( x,y,r,0,2*M_PI,false); | |
423 | CloseSubpath(); | |
424 | } | |
425 | ||
a4e73390 | 426 | void wxGraphicsPathData::AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h) |
59720690 | 427 | { |
d9468a20 RR |
428 | if (w <= 0. || h <= 0.) |
429 | return; | |
caa42c43 | 430 | |
59720690 SC |
431 | wxDouble rw = w/2; |
432 | wxDouble rh = h/2; | |
433 | wxDouble xc = x + rw; | |
434 | wxDouble yc = y + rh; | |
a4e73390 SC |
435 | wxGraphicsMatrix m = GetRenderer()->CreateMatrix(); |
436 | m.Translate(xc,yc); | |
437 | m.Scale(rw/rh,1.0); | |
438 | wxGraphicsPath p = GetRenderer()->CreatePath(); | |
439 | p.AddCircle(0,0,rh); | |
440 | p.Transform(m); | |
441 | AddPath(p.GetPathData()); | |
59720690 SC |
442 | } |
443 | ||
a4e73390 | 444 | void wxGraphicsPathData::AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius) |
59720690 SC |
445 | { |
446 | if ( radius == 0 ) | |
447 | AddRectangle(x,y,w,h); | |
448 | else | |
449 | { | |
450 | MoveToPoint( x + w, y + h / 2); | |
451 | AddArcToPoint(x + w, y + h, x + w / 2, y + h, radius); | |
452 | AddArcToPoint(x, y + h, x, y + h / 2, radius); | |
453 | AddArcToPoint(x, y , x + w / 2, y, radius); | |
454 | AddArcToPoint(x + w, y, x + w, y + h / 2, radius); | |
455 | CloseSubpath(); | |
456 | } | |
457 | } | |
458 | ||
d94228a2 | 459 | // 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) |
a4e73390 | 460 | void wxGraphicsPathData::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) |
caa42c43 | 461 | { |
a4e73390 SC |
462 | wxPoint2DDouble current; |
463 | GetCurrentPoint(¤t.m_x,¤t.m_y); | |
d94228a2 SC |
464 | wxPoint2DDouble p1(x1,y1); |
465 | wxPoint2DDouble p2(x2,y2); | |
466 | ||
a2d6d210 | 467 | wxPoint2DDouble v1 = current - p1; |
d94228a2 | 468 | v1.Normalize(); |
a2d6d210 | 469 | wxPoint2DDouble v2 = p2 - p1; |
d94228a2 SC |
470 | v2.Normalize(); |
471 | ||
472 | wxDouble alpha = v1.GetVectorAngle() - v2.GetVectorAngle(); | |
473 | ||
474 | if ( alpha < 0 ) | |
a2d6d210 | 475 | alpha = 360 + alpha; |
d94228a2 SC |
476 | // TODO obtuse angles |
477 | ||
478 | alpha = DegToRad(alpha); | |
479 | ||
a2d6d210 | 480 | wxDouble dist = r / sin(alpha/2) * cos(alpha/2); |
d94228a2 | 481 | // calculate tangential points |
a2d6d210 VZ |
482 | wxPoint2DDouble t1 = dist*v1 + p1; |
483 | wxPoint2DDouble t2 = dist*v2 + p1; | |
d94228a2 | 484 | |
a2d6d210 | 485 | wxPoint2DDouble nv1 = v1; |
d94228a2 SC |
486 | nv1.SetVectorAngle(v1.GetVectorAngle()-90); |
487 | wxPoint2DDouble c = t1 + r*nv1; | |
488 | ||
a2d6d210 VZ |
489 | wxDouble a1 = v1.GetVectorAngle()+90; |
490 | wxDouble a2 = v2.GetVectorAngle()-90; | |
d94228a2 | 491 | |
a4e73390 | 492 | AddLineToPoint(t1.m_x,t1.m_y); |
d94228a2 | 493 | AddArc(c.m_x,c.m_y,r,DegToRad(a1),DegToRad(a2),true); |
a4e73390 | 494 | AddLineToPoint(p2.m_x,p2.m_y); |
d94228a2 SC |
495 | } |
496 | ||
50581042 SC |
497 | //----------------------------------------------------------------------------- |
498 | // wxGraphicsContext Convenience Methods | |
499 | //----------------------------------------------------------------------------- | |
500 | ||
8ddf8e82 SC |
501 | IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext, wxObject) |
502 | ||
facbe363 | 503 | |
03647350 | 504 | wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) : |
bf02a7f9 SC |
505 | wxGraphicsObject(renderer), |
506 | m_antialias(wxANTIALIAS_DEFAULT), | |
507 | m_composition(wxCOMPOSITION_OVER) | |
facbe363 | 508 | { |
facbe363 SC |
509 | } |
510 | ||
caa42c43 | 511 | wxGraphicsContext::~wxGraphicsContext() |
facbe363 | 512 | { |
facbe363 SC |
513 | } |
514 | ||
caa42c43 | 515 | bool wxGraphicsContext::StartDoc(const wxString& WXUNUSED(message)) |
fcaea2fa SC |
516 | { |
517 | return true; | |
518 | } | |
caa42c43 | 519 | |
fcaea2fa SC |
520 | void wxGraphicsContext::EndDoc() |
521 | { | |
522 | } | |
523 | ||
c29bdd5f VZ |
524 | void wxGraphicsContext::StartPage(wxDouble WXUNUSED(width), |
525 | wxDouble WXUNUSED(height)) | |
fcaea2fa SC |
526 | { |
527 | } | |
caa42c43 | 528 | |
fcaea2fa SC |
529 | void wxGraphicsContext::EndPage() |
530 | { | |
531 | } | |
532 | ||
533 | void wxGraphicsContext::Flush() | |
534 | { | |
535 | } | |
536 | ||
537 | #if 0 | |
538 | void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) ) | |
539 | { | |
540 | } | |
caa42c43 | 541 | |
fcaea2fa SC |
542 | wxDouble wxGraphicsContext::GetAlpha() const |
543 | { | |
544 | return 1.0; | |
545 | } | |
546 | #endif | |
547 | ||
548 | void wxGraphicsContext::GetSize( wxDouble* width, wxDouble* height) | |
549 | { | |
550 | *width = 10000.0; | |
551 | *height = 10000.0; | |
552 | } | |
553 | ||
554 | void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY) | |
555 | { | |
556 | *dpiX = 72.0; | |
557 | *dpiY = 72.0; | |
558 | } | |
559 | ||
facbe363 | 560 | // sets the pen |
caa42c43 | 561 | void wxGraphicsContext::SetPen( const wxGraphicsPen& pen ) |
facbe363 | 562 | { |
facbe363 | 563 | m_pen = pen; |
facbe363 SC |
564 | } |
565 | ||
566 | void wxGraphicsContext::SetPen( const wxPen& pen ) | |
567 | { | |
ad667945 | 568 | if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT ) |
2c820406 | 569 | SetPen( wxNullGraphicsPen ); |
facbe363 SC |
570 | else |
571 | SetPen( CreatePen( pen ) ); | |
572 | } | |
caa42c43 | 573 | |
facbe363 | 574 | // sets the brush for filling |
caa42c43 | 575 | void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush ) |
facbe363 | 576 | { |
facbe363 | 577 | m_brush = brush; |
facbe363 SC |
578 | } |
579 | ||
580 | void wxGraphicsContext::SetBrush( const wxBrush& brush ) | |
581 | { | |
ad667945 | 582 | if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT ) |
2c820406 | 583 | SetBrush( wxNullGraphicsBrush ); |
facbe363 SC |
584 | else |
585 | SetBrush( CreateBrush( brush ) ); | |
586 | } | |
587 | ||
588 | // sets the brush for filling | |
caa42c43 | 589 | void wxGraphicsContext::SetFont( const wxGraphicsFont& font ) |
facbe363 | 590 | { |
facbe363 | 591 | m_font = font; |
facbe363 SC |
592 | } |
593 | ||
594 | void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour ) | |
595 | { | |
2c820406 SC |
596 | if ( font.Ok() ) |
597 | SetFont( CreateFont( font, colour ) ); | |
598 | else | |
599 | SetFont( wxNullGraphicsFont ); | |
facbe363 SC |
600 | } |
601 | ||
94a007ec | 602 | void wxGraphicsContext::DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle ) |
50581042 SC |
603 | { |
604 | FillPath( path , fillStyle ); | |
605 | StrokePath( path ); | |
606 | } | |
607 | ||
0b7dce54 VZ |
608 | void |
609 | wxGraphicsContext::DoDrawRotatedText(const wxString &str, | |
610 | wxDouble x, | |
611 | wxDouble y, | |
612 | wxDouble angle) | |
50581042 | 613 | { |
a2d6d210 | 614 | Translate(x,y); |
50581042 SC |
615 | Rotate( -angle ); |
616 | DrawText( str , 0, 0 ); | |
617 | Rotate( angle ); | |
a2d6d210 | 618 | Translate(-x,-y); |
50581042 SC |
619 | } |
620 | ||
0b7dce54 VZ |
621 | void |
622 | wxGraphicsContext::DoDrawFilledText(const wxString &str, | |
623 | wxDouble x, | |
624 | wxDouble y, | |
625 | const wxGraphicsBrush& backgroundBrush) | |
068eb463 SC |
626 | { |
627 | wxGraphicsBrush formerBrush = m_brush; | |
caa42c43 | 628 | wxGraphicsPen formerPen = m_pen; |
068eb463 SC |
629 | wxDouble width; |
630 | wxDouble height; | |
631 | wxDouble descent; | |
632 | wxDouble externalLeading; | |
633 | GetTextExtent( str , &width, &height, &descent, &externalLeading ); | |
634 | SetBrush( backgroundBrush ); | |
caa42c43 VZ |
635 | // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape |
636 | SetPen( wxNullGraphicsPen ); | |
068eb463 SC |
637 | |
638 | wxGraphicsPath path = CreatePath(); | |
639 | path.AddRectangle( x , y, width, height ); | |
640 | FillPath( path ); | |
641 | ||
642 | DrawText( str, x ,y); | |
643 | SetBrush( formerBrush ); | |
caa42c43 | 644 | SetPen( formerPen ); |
068eb463 SC |
645 | } |
646 | ||
0b7dce54 VZ |
647 | void |
648 | wxGraphicsContext::DoDrawRotatedFilledText(const wxString &str, | |
649 | wxDouble x, wxDouble y, | |
650 | wxDouble angle, | |
651 | const wxGraphicsBrush& backgroundBrush) | |
068eb463 SC |
652 | { |
653 | wxGraphicsBrush formerBrush = m_brush; | |
caa42c43 | 654 | wxGraphicsPen formerPen = m_pen; |
068eb463 SC |
655 | |
656 | wxDouble width; | |
657 | wxDouble height; | |
658 | wxDouble descent; | |
659 | wxDouble externalLeading; | |
660 | GetTextExtent( str , &width, &height, &descent, &externalLeading ); | |
661 | SetBrush( backgroundBrush ); | |
caa42c43 VZ |
662 | // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape |
663 | SetPen( wxNullGraphicsPen ); | |
068eb463 SC |
664 | |
665 | wxGraphicsPath path = CreatePath(); | |
666 | path.MoveToPoint( x , y ); | |
667 | path.AddLineToPoint( (int) (x + sin(angle) * height) , (int) (y + cos(angle) * height) ); | |
668 | path.AddLineToPoint( | |
669 | (int) (x + sin(angle) * height + cos(angle) * width) , | |
670 | (int) (y + cos(angle) * height - sin(angle) * width)); | |
671 | path.AddLineToPoint((int) (x + cos(angle) * width) , (int) (y - sin(angle) * width) ); | |
672 | FillPath( path ); | |
673 | DrawText( str, x ,y, angle); | |
674 | SetBrush( formerBrush ); | |
caa42c43 | 675 | SetPen( formerPen ); |
068eb463 SC |
676 | } |
677 | ||
50581042 SC |
678 | void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2) |
679 | { | |
a4e73390 SC |
680 | wxGraphicsPath path = CreatePath(); |
681 | path.MoveToPoint(x1, y1); | |
682 | path.AddLineToPoint( x2, y2 ); | |
50581042 | 683 | StrokePath( path ); |
50581042 SC |
684 | } |
685 | ||
686 | void wxGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h) | |
687 | { | |
a4e73390 SC |
688 | wxGraphicsPath path = CreatePath(); |
689 | path.AddRectangle( x , y , w , h ); | |
50581042 | 690 | DrawPath( path ); |
50581042 SC |
691 | } |
692 | ||
693 | void wxGraphicsContext::DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h) | |
694 | { | |
a4e73390 SC |
695 | wxGraphicsPath path = CreatePath(); |
696 | path.AddEllipse(x,y,w,h); | |
59720690 | 697 | DrawPath(path); |
50581042 SC |
698 | } |
699 | ||
700 | void wxGraphicsContext::DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius) | |
701 | { | |
a4e73390 SC |
702 | wxGraphicsPath path = CreatePath(); |
703 | path.AddRoundedRectangle(x,y,w,h,radius); | |
59720690 | 704 | DrawPath(path); |
50581042 SC |
705 | } |
706 | ||
707 | void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *points) | |
708 | { | |
709 | wxASSERT(n > 1); | |
a4e73390 SC |
710 | wxGraphicsPath path = CreatePath(); |
711 | path.MoveToPoint(points[0].m_x, points[0].m_y); | |
a2d6d210 | 712 | for ( size_t i = 1; i < n; ++i) |
a4e73390 | 713 | path.AddLineToPoint( points[i].m_x, points[i].m_y ); |
50581042 | 714 | StrokePath( path ); |
50581042 SC |
715 | } |
716 | ||
94a007ec | 717 | void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle) |
50581042 SC |
718 | { |
719 | wxASSERT(n > 1); | |
a4e73390 SC |
720 | wxGraphicsPath path = CreatePath(); |
721 | path.MoveToPoint(points[0].m_x, points[0].m_y); | |
a2d6d210 | 722 | for ( size_t i = 1; i < n; ++i) |
a4e73390 | 723 | path.AddLineToPoint( points[i].m_x, points[i].m_y ); |
50581042 | 724 | DrawPath( path , fillStyle); |
50581042 SC |
725 | } |
726 | ||
727 | void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints) | |
728 | { | |
729 | wxASSERT(n > 0); | |
a4e73390 | 730 | wxGraphicsPath path = CreatePath(); |
a2d6d210 | 731 | for ( size_t i = 0; i < n; ++i) |
50581042 | 732 | { |
a4e73390 SC |
733 | path.MoveToPoint(beginPoints[i].m_x, beginPoints[i].m_y); |
734 | path.AddLineToPoint( endPoints[i].m_x, endPoints[i].m_y ); | |
50581042 SC |
735 | } |
736 | StrokePath( path ); | |
50581042 SC |
737 | } |
738 | ||
facbe363 | 739 | // create a 'native' matrix corresponding to these values |
caa42c43 | 740 | wxGraphicsMatrix wxGraphicsContext::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d, |
a4e73390 | 741 | wxDouble tx, wxDouble ty) const |
50581042 | 742 | { |
facbe363 | 743 | return GetRenderer()->CreateMatrix(a,b,c,d,tx,ty); |
50581042 SC |
744 | } |
745 | ||
a4e73390 | 746 | wxGraphicsPath wxGraphicsContext::CreatePath() const |
06b9edb7 SC |
747 | { |
748 | return GetRenderer()->CreatePath(); | |
749 | } | |
750 | ||
a4e73390 | 751 | wxGraphicsPen wxGraphicsContext::CreatePen(const wxPen& pen) const |
06b9edb7 SC |
752 | { |
753 | return GetRenderer()->CreatePen(pen); | |
754 | } | |
755 | ||
a4e73390 | 756 | wxGraphicsBrush wxGraphicsContext::CreateBrush(const wxBrush& brush ) const |
06b9edb7 SC |
757 | { |
758 | return GetRenderer()->CreateBrush(brush); | |
759 | } | |
760 | ||
761 | // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2 | |
caa42c43 | 762 | wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, |
a4e73390 | 763 | const wxColour&c1, const wxColour&c2) const |
06b9edb7 SC |
764 | { |
765 | return GetRenderer()->CreateLinearGradientBrush(x1,y1,x2,y2,c1,c2); | |
766 | } | |
767 | ||
caa42c43 | 768 | // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc) |
06b9edb7 | 769 | // with radius r and color cColor |
2c820406 | 770 | wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, |
a4e73390 | 771 | const wxColour &oColor, const wxColour &cColor) const |
06b9edb7 SC |
772 | { |
773 | return GetRenderer()->CreateRadialGradientBrush(xo,yo,xc,yc,radius,oColor,cColor); | |
774 | } | |
775 | ||
776 | // sets the font | |
a4e73390 | 777 | wxGraphicsFont wxGraphicsContext::CreateFont( const wxFont &font , const wxColour &col ) const |
06b9edb7 SC |
778 | { |
779 | return GetRenderer()->CreateFont(font,col); | |
780 | } | |
781 | ||
9786ef01 SC |
782 | wxGraphicsBitmap wxGraphicsContext::CreateBitmap( const wxBitmap& bmp ) const |
783 | { | |
784 | return GetRenderer()->CreateBitmap(bmp); | |
785 | } | |
786 | ||
787 | wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) const | |
788 | { | |
789 | return GetRenderer()->CreateSubBitmap(bmp,x,y,w,h); | |
790 | } | |
791 | ||
caa42c43 | 792 | /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc) |
06b9edb7 SC |
793 | { |
794 | return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc); | |
795 | } | |
888dde65 | 796 | |
caa42c43 | 797 | /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxMemoryDC& dc) |
0b822969 RR |
798 | { |
799 | return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc); | |
800 | } | |
801 | ||
6d0d8455 | 802 | #if wxUSE_PRINTING_ARCHITECTURE |
caa42c43 | 803 | /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxPrinterDC& dc) |
773ccc31 SC |
804 | { |
805 | return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc); | |
806 | } | |
6d0d8455 | 807 | #endif |
06b9edb7 SC |
808 | |
809 | wxGraphicsContext* wxGraphicsContext::CreateFromNative( void * context ) | |
810 | { | |
811 | return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeContext(context); | |
812 | } | |
813 | ||
814 | wxGraphicsContext* wxGraphicsContext::CreateFromNativeWindow( void * window ) | |
815 | { | |
816 | return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeWindow(window); | |
817 | } | |
818 | ||
819 | wxGraphicsContext* wxGraphicsContext::Create( wxWindow* window ) | |
820 | { | |
821 | return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window); | |
822 | } | |
823 | ||
ad667945 SC |
824 | wxGraphicsContext* wxGraphicsContext::Create() |
825 | { | |
826 | return wxGraphicsRenderer::GetDefaultRenderer()->CreateMeasuringContext(); | |
827 | } | |
828 | ||
a4e73390 SC |
829 | //----------------------------------------------------------------------------- |
830 | // wxGraphicsRenderer | |
831 | //----------------------------------------------------------------------------- | |
832 | ||
833 | IMPLEMENT_ABSTRACT_CLASS(wxGraphicsRenderer, wxObject) | |
834 | ||
9fd707a5 | 835 | #endif // wxUSE_GRAPHICS_CONTEXT |