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