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