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