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