]> git.saurik.com Git - wxWidgets.git/blob - src/common/graphcmn.cpp
use HandleWindowEvent() in Close() as it can be called from a GTK+ callback (#9565)
[wxWidgets.git] / src / common / graphcmn.cpp
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
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if defined(__BORLANDC__)
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_GRAPHICS_CONTEXT
20
21 #include "wx/private/graphics.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/icon.h"
25 #include "wx/bitmap.h"
26 #include "wx/dcmemory.h"
27 #include "wx/region.h"
28 #include "wx/log.h"
29 #endif
30
31 //-----------------------------------------------------------------------------
32 // constants
33 //-----------------------------------------------------------------------------
34
35 static const double RAD2DEG = 180.0 / M_PI;
36
37 //-----------------------------------------------------------------------------
38 // Local functions
39 //-----------------------------------------------------------------------------
40
41 static inline double DegToRad(double deg)
42 {
43 return (deg * M_PI) / 180.0;
44 }
45
46 //-----------------------------------------------------------------------------
47
48 //-----------------------------------------------------------------------------
49 // wxGraphicsObject
50 //-----------------------------------------------------------------------------
51
52 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsObject, wxObject)
53
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 }
62 wxGraphicsRenderer* wxGraphicsObjectRefData::GetRenderer() const
63 {
64 return m_renderer ;
65 }
66
67 wxGraphicsObjectRefData* wxGraphicsObjectRefData::Clone() const
68 {
69 return new wxGraphicsObjectRefData(this);
70 }
71
72 wxGraphicsObject::wxGraphicsObject()
73 {
74 }
75
76 wxGraphicsObject::wxGraphicsObject( wxGraphicsRenderer* renderer )
77 {
78 SetRefData( new wxGraphicsObjectRefData(renderer));
79 }
80
81 wxGraphicsObject::~wxGraphicsObject()
82 {
83 }
84
85 bool wxGraphicsObject::IsNull() const
86 {
87 return m_refData == NULL;
88 }
89
90 wxGraphicsRenderer* wxGraphicsObject::GetRenderer() const
91 {
92 return ( IsNull() ? NULL : GetGraphicsData()->GetRenderer() );
93 }
94
95 wxGraphicsObjectRefData* wxGraphicsObject::GetGraphicsData() const
96 {
97 return (wxGraphicsObjectRefData*) m_refData;
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)
119 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBitmap, wxGraphicsObject)
120
121 WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen;
122 WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush;
123 WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont;
124 WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap;
125
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
141 void wxGraphicsMatrix::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
142 wxDouble tx, wxDouble ty)
143 {
144 AllocExclusive();
145 GetMatrixData()->Set(a,b,c,d,tx,ty);
146 }
147
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
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);
193 }
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 }
210
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)
222 WXDLLIMPEXP_DATA_CORE(wxGraphicsPath) wxNullGraphicsPath;
223
224 // convenience functions, for using wxPoint2DDouble etc
225
226 wxPoint2DDouble wxGraphicsPath::GetCurrentPoint() const
227 {
228 wxDouble x,y;
229 GetCurrentPoint(&x,&y);
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
253 wxRect2DDouble wxGraphicsPath::GetBox() const
254 {
255 wxDouble x,y,w,h;
256 GetBox(&x,&y,&w,&h);
257 return wxRect2DDouble( x,y,w,h );
258 }
259
260 bool wxGraphicsPath::Contains( const wxPoint2DDouble& c, int fillStyle ) const
261 {
262 return Contains( c.m_x, c.m_y, fillStyle);
263 }
264
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
274 // adds a straight line from the current point to (x,y)
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
315 //
316 // These are convenience functions which - if not available natively will be assembled
317 // using the primitives from above
318 //
319
320 // adds a quadratic Bezier curve from the current point, using a control point and an end point
321 void wxGraphicsPath::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y )
322 {
323 AllocExclusive();
324 GetPathData()->AddQuadCurveToPoint(cx,cy,x,y);
325 }
326
327 // appends a rectangle as a new closed subpath
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)
342 void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r )
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
386 bool wxGraphicsPath::Contains( wxDouble x, wxDouble y, int fillStyle ) const
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 )
396 {
397 // calculate using degree elevation to a cubic bezier
398 wxPoint2DDouble c1;
399 wxPoint2DDouble c2;
400
401 wxPoint2DDouble start;
402 GetCurrentPoint(&start.m_x,&start.m_y);
403 wxPoint2DDouble end(x,y);
404 wxPoint2DDouble c(cx,cy);
405 c1 = wxDouble(1/3.0) * start + wxDouble(2/3.0) * c;
406 c2 = wxDouble(2/3.0) * c + wxDouble(1/3.0) * end;
407 AddCurveToPoint(c1.m_x,c1.m_y,c2.m_x,c2.m_y,x,y);
408 }
409
410 void wxGraphicsPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
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
419 void wxGraphicsPathData::AddCircle( wxDouble x, wxDouble y, wxDouble r )
420 {
421 MoveToPoint(x+r,y);
422 AddArc( x,y,r,0,2*M_PI,false);
423 CloseSubpath();
424 }
425
426 void wxGraphicsPathData::AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
427 {
428 wxDouble rw = w/2;
429 wxDouble rh = h/2;
430 wxDouble xc = x + rw;
431 wxDouble yc = y + rh;
432 wxGraphicsMatrix m = GetRenderer()->CreateMatrix();
433 m.Translate(xc,yc);
434 m.Scale(rw/rh,1.0);
435 wxGraphicsPath p = GetRenderer()->CreatePath();
436 p.AddCircle(0,0,rh);
437 p.Transform(m);
438 AddPath(p.GetPathData());
439 }
440
441 void wxGraphicsPathData::AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius)
442 {
443 if ( radius == 0 )
444 AddRectangle(x,y,w,h);
445 else
446 {
447 MoveToPoint( x + w, y + h / 2);
448 AddArcToPoint(x + w, y + h, x + w / 2, y + h, radius);
449 AddArcToPoint(x, y + h, x, y + h / 2, radius);
450 AddArcToPoint(x, y , x + w / 2, y, radius);
451 AddArcToPoint(x + w, y, x + w, y + h / 2, radius);
452 CloseSubpath();
453 }
454 }
455
456 // 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)
457 void wxGraphicsPathData::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r )
458 {
459 wxPoint2DDouble current;
460 GetCurrentPoint(&current.m_x,&current.m_y);
461 wxPoint2DDouble p1(x1,y1);
462 wxPoint2DDouble p2(x2,y2);
463
464 wxPoint2DDouble v1 = current - p1;
465 v1.Normalize();
466 wxPoint2DDouble v2 = p2 - p1;
467 v2.Normalize();
468
469 wxDouble alpha = v1.GetVectorAngle() - v2.GetVectorAngle();
470
471 if ( alpha < 0 )
472 alpha = 360 + alpha;
473 // TODO obtuse angles
474
475 alpha = DegToRad(alpha);
476
477 wxDouble dist = r / sin(alpha/2) * cos(alpha/2);
478 // calculate tangential points
479 wxPoint2DDouble t1 = dist*v1 + p1;
480 wxPoint2DDouble t2 = dist*v2 + p1;
481
482 wxPoint2DDouble nv1 = v1;
483 nv1.SetVectorAngle(v1.GetVectorAngle()-90);
484 wxPoint2DDouble c = t1 + r*nv1;
485
486 wxDouble a1 = v1.GetVectorAngle()+90;
487 wxDouble a2 = v2.GetVectorAngle()-90;
488
489 AddLineToPoint(t1.m_x,t1.m_y);
490 AddArc(c.m_x,c.m_y,r,DegToRad(a1),DegToRad(a2),true);
491 AddLineToPoint(p2.m_x,p2.m_y);
492 }
493
494 //-----------------------------------------------------------------------------
495 // wxGraphicsContext Convenience Methods
496 //-----------------------------------------------------------------------------
497
498 IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext, wxObject)
499
500
501 wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) : wxGraphicsObject(renderer)
502 {
503 m_logicalFunction = wxCOPY;
504 }
505
506 wxGraphicsContext::~wxGraphicsContext()
507 {
508 }
509
510 bool wxGraphicsContext::StartDoc(const wxString& WXUNUSED(message))
511 {
512 return true;
513 }
514
515 void wxGraphicsContext::EndDoc()
516 {
517 }
518
519 void wxGraphicsContext::StartPage(wxDouble WXUNUSED(width),
520 wxDouble WXUNUSED(height))
521 {
522 }
523
524 void wxGraphicsContext::EndPage()
525 {
526 }
527
528 void wxGraphicsContext::Flush()
529 {
530 }
531
532 #if 0
533 void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) )
534 {
535 }
536
537 wxDouble wxGraphicsContext::GetAlpha() const
538 {
539 return 1.0;
540 }
541 #endif
542
543 void wxGraphicsContext::GetSize( wxDouble* width, wxDouble* height)
544 {
545 *width = 10000.0;
546 *height = 10000.0;
547 }
548
549 void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY)
550 {
551 *dpiX = 72.0;
552 *dpiY = 72.0;
553 }
554
555 // sets the pen
556 void wxGraphicsContext::SetPen( const wxGraphicsPen& pen )
557 {
558 m_pen = pen;
559 }
560
561 void wxGraphicsContext::SetPen( const wxPen& pen )
562 {
563 if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
564 SetPen( wxNullGraphicsPen );
565 else
566 SetPen( CreatePen( pen ) );
567 }
568
569 // sets the brush for filling
570 void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush )
571 {
572 m_brush = brush;
573 }
574
575 void wxGraphicsContext::SetBrush( const wxBrush& brush )
576 {
577 if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
578 SetBrush( wxNullGraphicsBrush );
579 else
580 SetBrush( CreateBrush( brush ) );
581 }
582
583 // sets the brush for filling
584 void wxGraphicsContext::SetFont( const wxGraphicsFont& font )
585 {
586 m_font = font;
587 }
588
589 bool wxGraphicsContext::SetLogicalFunction( int function )
590 {
591 if ( function == wxCOPY )
592 {
593 m_logicalFunction = function;
594 return true;
595 }
596 return false;
597 }
598
599 void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour )
600 {
601 if ( font.Ok() )
602 SetFont( CreateFont( font, colour ) );
603 else
604 SetFont( wxNullGraphicsFont );
605 }
606
607 void wxGraphicsContext::DrawPath( const wxGraphicsPath& path, int fillStyle )
608 {
609 FillPath( path , fillStyle );
610 StrokePath( path );
611 }
612
613 void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle )
614 {
615 Translate(x,y);
616 Rotate( -angle );
617 DrawText( str , 0, 0 );
618 Rotate( angle );
619 Translate(-x,-y);
620 }
621
622 void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush& backgroundBrush )
623 {
624 wxGraphicsBrush formerBrush = m_brush;
625 wxGraphicsPen formerPen = m_pen;
626 wxDouble width;
627 wxDouble height;
628 wxDouble descent;
629 wxDouble externalLeading;
630 GetTextExtent( str , &width, &height, &descent, &externalLeading );
631 SetBrush( backgroundBrush );
632 // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
633 SetPen( wxNullGraphicsPen );
634
635 wxGraphicsPath path = CreatePath();
636 path.AddRectangle( x , y, width, height );
637 FillPath( path );
638
639 DrawText( str, x ,y);
640 SetBrush( formerBrush );
641 SetPen( formerPen );
642 }
643
644 void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush )
645 {
646 wxGraphicsBrush formerBrush = m_brush;
647 wxGraphicsPen formerPen = m_pen;
648
649 wxDouble width;
650 wxDouble height;
651 wxDouble descent;
652 wxDouble externalLeading;
653 GetTextExtent( str , &width, &height, &descent, &externalLeading );
654 SetBrush( backgroundBrush );
655 // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
656 SetPen( wxNullGraphicsPen );
657
658 wxGraphicsPath path = CreatePath();
659 path.MoveToPoint( x , y );
660 path.AddLineToPoint( (int) (x + sin(angle) * height) , (int) (y + cos(angle) * height) );
661 path.AddLineToPoint(
662 (int) (x + sin(angle) * height + cos(angle) * width) ,
663 (int) (y + cos(angle) * height - sin(angle) * width));
664 path.AddLineToPoint((int) (x + cos(angle) * width) , (int) (y - sin(angle) * width) );
665 FillPath( path );
666 DrawText( str, x ,y, angle);
667 SetBrush( formerBrush );
668 SetPen( formerPen );
669 }
670
671 void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2)
672 {
673 wxGraphicsPath path = CreatePath();
674 path.MoveToPoint(x1, y1);
675 path.AddLineToPoint( x2, y2 );
676 StrokePath( path );
677 }
678
679 void wxGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
680 {
681 wxGraphicsPath path = CreatePath();
682 path.AddRectangle( x , y , w , h );
683 DrawPath( path );
684 }
685
686 void wxGraphicsContext::DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
687 {
688 wxGraphicsPath path = CreatePath();
689 path.AddEllipse(x,y,w,h);
690 DrawPath(path);
691 }
692
693 void wxGraphicsContext::DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius)
694 {
695 wxGraphicsPath path = CreatePath();
696 path.AddRoundedRectangle(x,y,w,h,radius);
697 DrawPath(path);
698 }
699
700 void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *points)
701 {
702 wxASSERT(n > 1);
703 wxGraphicsPath path = CreatePath();
704 path.MoveToPoint(points[0].m_x, points[0].m_y);
705 for ( size_t i = 1; i < n; ++i)
706 path.AddLineToPoint( points[i].m_x, points[i].m_y );
707 StrokePath( path );
708 }
709
710 void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle)
711 {
712 wxASSERT(n > 1);
713 wxGraphicsPath path = CreatePath();
714 path.MoveToPoint(points[0].m_x, points[0].m_y);
715 for ( size_t i = 1; i < n; ++i)
716 path.AddLineToPoint( points[i].m_x, points[i].m_y );
717 DrawPath( path , fillStyle);
718 }
719
720 void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints)
721 {
722 wxASSERT(n > 0);
723 wxGraphicsPath path = CreatePath();
724 for ( size_t i = 0; i < n; ++i)
725 {
726 path.MoveToPoint(beginPoints[i].m_x, beginPoints[i].m_y);
727 path.AddLineToPoint( endPoints[i].m_x, endPoints[i].m_y );
728 }
729 StrokePath( path );
730 }
731
732 // create a 'native' matrix corresponding to these values
733 wxGraphicsMatrix wxGraphicsContext::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d,
734 wxDouble tx, wxDouble ty) const
735 {
736 return GetRenderer()->CreateMatrix(a,b,c,d,tx,ty);
737 }
738
739 wxGraphicsPath wxGraphicsContext::CreatePath() const
740 {
741 return GetRenderer()->CreatePath();
742 }
743
744 wxGraphicsPen wxGraphicsContext::CreatePen(const wxPen& pen) const
745 {
746 return GetRenderer()->CreatePen(pen);
747 }
748
749 wxGraphicsBrush wxGraphicsContext::CreateBrush(const wxBrush& brush ) const
750 {
751 return GetRenderer()->CreateBrush(brush);
752 }
753
754 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
755 wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
756 const wxColour&c1, const wxColour&c2) const
757 {
758 return GetRenderer()->CreateLinearGradientBrush(x1,y1,x2,y2,c1,c2);
759 }
760
761 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
762 // with radius r and color cColor
763 wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
764 const wxColour &oColor, const wxColour &cColor) const
765 {
766 return GetRenderer()->CreateRadialGradientBrush(xo,yo,xc,yc,radius,oColor,cColor);
767 }
768
769 // sets the font
770 wxGraphicsFont wxGraphicsContext::CreateFont( const wxFont &font , const wxColour &col ) const
771 {
772 return GetRenderer()->CreateFont(font,col);
773 }
774
775 wxGraphicsBitmap wxGraphicsContext::CreateBitmap( const wxBitmap& bmp ) const
776 {
777 #ifndef __WXGTK20__
778 return GetRenderer()->CreateBitmap(bmp);
779 #else
780 return wxNullGraphicsBitmap;
781 #endif
782 }
783
784 wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) const
785 {
786 #ifndef __WXGTK20__
787 return GetRenderer()->CreateSubBitmap(bmp,x,y,w,h);
788 #else
789 return wxNullGraphicsBitmap;
790 #endif
791 }
792
793 /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc)
794 {
795 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
796 }
797
798 /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxMemoryDC& dc)
799 {
800 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
801 }
802
803 /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxPrinterDC& dc)
804 {
805 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
806 }
807
808 wxGraphicsContext* wxGraphicsContext::CreateFromNative( void * context )
809 {
810 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeContext(context);
811 }
812
813 wxGraphicsContext* wxGraphicsContext::CreateFromNativeWindow( void * window )
814 {
815 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeWindow(window);
816 }
817
818 wxGraphicsContext* wxGraphicsContext::Create( wxWindow* window )
819 {
820 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window);
821 }
822
823 wxGraphicsContext* wxGraphicsContext::Create()
824 {
825 return wxGraphicsRenderer::GetDefaultRenderer()->CreateMeasuringContext();
826 }
827
828 //-----------------------------------------------------------------------------
829 // wxGraphicsRenderer
830 //-----------------------------------------------------------------------------
831
832 IMPLEMENT_ABSTRACT_CLASS(wxGraphicsRenderer, wxObject)
833
834 #endif // wxUSE_GRAPHICS_CONTEXT