]> git.saurik.com Git - wxWidgets.git/blob - src/common/graphcmn.cpp
Move code removing "-psn_xxx" command line arguments to common code.
[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 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #if defined(__BORLANDC__)
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_GRAPHICS_CONTEXT
19
20 #include "wx/graphics.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/icon.h"
24 #include "wx/bitmap.h"
25 #include "wx/dcmemory.h"
26 #include "wx/region.h"
27 #include "wx/log.h"
28 #endif
29
30 #include "wx/private/graphics.h"
31
32 //-----------------------------------------------------------------------------
33 // Local functions
34 //-----------------------------------------------------------------------------
35
36 static inline double DegToRad(double deg)
37 {
38 return (deg * M_PI) / 180.0;
39 }
40
41 //-----------------------------------------------------------------------------
42
43 //-----------------------------------------------------------------------------
44 // wxGraphicsObject
45 //-----------------------------------------------------------------------------
46
47 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsObject, wxObject)
48
49 wxGraphicsObjectRefData::wxGraphicsObjectRefData( wxGraphicsRenderer* renderer )
50 {
51 m_renderer = renderer;
52 }
53 wxGraphicsObjectRefData::wxGraphicsObjectRefData( const wxGraphicsObjectRefData* data )
54 {
55 m_renderer = data->m_renderer;
56 }
57 wxGraphicsRenderer* wxGraphicsObjectRefData::GetRenderer() const
58 {
59 return m_renderer ;
60 }
61
62 wxGraphicsObjectRefData* wxGraphicsObjectRefData::Clone() const
63 {
64 return new wxGraphicsObjectRefData(this);
65 }
66
67 wxGraphicsObject::wxGraphicsObject()
68 {
69 }
70
71 wxGraphicsObject::wxGraphicsObject( wxGraphicsRenderer* renderer )
72 {
73 SetRefData( new wxGraphicsObjectRefData(renderer));
74 }
75
76 wxGraphicsObject::~wxGraphicsObject()
77 {
78 }
79
80 bool wxGraphicsObject::IsNull() const
81 {
82 return m_refData == NULL;
83 }
84
85 wxGraphicsRenderer* wxGraphicsObject::GetRenderer() const
86 {
87 return ( IsNull() ? NULL : GetGraphicsData()->GetRenderer() );
88 }
89
90 wxGraphicsObjectRefData* wxGraphicsObject::GetGraphicsData() const
91 {
92 return (wxGraphicsObjectRefData*) m_refData;
93 }
94
95 wxObjectRefData* wxGraphicsObject::CreateRefData() const
96 {
97 wxLogDebug(wxT("A Null Object cannot be changed"));
98 return NULL;
99 }
100
101 wxObjectRefData* wxGraphicsObject::CloneRefData(const wxObjectRefData* data) const
102 {
103 const wxGraphicsObjectRefData* ptr = (const wxGraphicsObjectRefData*) data;
104 return ptr->Clone();
105 }
106
107 //-----------------------------------------------------------------------------
108 // pens etc.
109 //-----------------------------------------------------------------------------
110
111 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsPen, wxGraphicsObject)
112 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBrush, wxGraphicsObject)
113 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsFont, wxGraphicsObject)
114 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBitmap, wxGraphicsObject)
115
116 WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen;
117 WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush;
118 WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont;
119 WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap;
120
121 //-----------------------------------------------------------------------------
122 // matrix
123 //-----------------------------------------------------------------------------
124
125 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsMatrix, wxGraphicsObject)
126 WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix;
127
128 // concatenates the matrix
129 void wxGraphicsMatrix::Concat( const wxGraphicsMatrix *t )
130 {
131 AllocExclusive();
132 GetMatrixData()->Concat(t->GetMatrixData());
133 }
134
135 // sets the matrix to the respective values
136 void wxGraphicsMatrix::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
137 wxDouble tx, wxDouble ty)
138 {
139 AllocExclusive();
140 GetMatrixData()->Set(a,b,c,d,tx,ty);
141 }
142
143 // gets the component valuess of the matrix
144 void wxGraphicsMatrix::Get(wxDouble* a, wxDouble* b, wxDouble* c,
145 wxDouble* d, wxDouble* tx, wxDouble* ty) const
146 {
147 GetMatrixData()->Get(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 WXDLLIMPEXP_DATA_CORE(wxGraphicsPath) wxNullGraphicsPath;
218
219 // convenience functions, for using wxPoint2DDouble etc
220
221 wxPoint2DDouble wxGraphicsPath::GetCurrentPoint() const
222 {
223 wxDouble x,y;
224 GetCurrentPoint(&x,&y);
225 return wxPoint2DDouble(x,y);
226 }
227
228 void wxGraphicsPath::MoveToPoint( const wxPoint2DDouble& p)
229 {
230 MoveToPoint( p.m_x , p.m_y);
231 }
232
233 void wxGraphicsPath::AddLineToPoint( const wxPoint2DDouble& p)
234 {
235 AddLineToPoint( p.m_x , p.m_y);
236 }
237
238 void 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
243 void 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
248 wxRect2DDouble wxGraphicsPath::GetBox() const
249 {
250 wxDouble x,y,w,h;
251 GetBox(&x,&y,&w,&h);
252 return wxRect2DDouble( x,y,w,h );
253 }
254
255 bool wxGraphicsPath::Contains( const wxPoint2DDouble& c, wxPolygonFillMode fillStyle ) const
256 {
257 return Contains( c.m_x, c.m_y, fillStyle);
258 }
259
260 // true redirections
261
262 // begins a new subpath at (x,y)
263 void 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)
270 void 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
277 void 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
284 void wxGraphicsPath::AddPath( const wxGraphicsPath& path )
285 {
286 AllocExclusive();
287 GetPathData()->AddPath(path.GetPathData());
288 }
289
290 // closes the current sub-path
291 void 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
298 void 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
304 void 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
310 //
311 // These are convenience functions which - if not available natively will be assembled
312 // using the primitives from above
313 //
314
315 // adds a quadratic Bezier curve from the current point, using a control point and an end point
316 void wxGraphicsPath::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y )
317 {
318 AllocExclusive();
319 GetPathData()->AddQuadCurveToPoint(cx,cy,x,y);
320 }
321
322 // appends a rectangle as a new closed subpath
323 void 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
330 void 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)
337 void 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
343 void 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
350 void 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
357 void * 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)
363 void wxGraphicsPath::UnGetNativePath(void *p)const
364 {
365 GetPathData()->UnGetNativePath(p);
366 }
367
368 // transforms each point of this path by the matrix
369 void 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)
376 void wxGraphicsPath::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const
377 {
378 GetPathData()->GetBox(x,y,w,h);
379 }
380
381 bool wxGraphicsPath::Contains( wxDouble x, wxDouble y, wxPolygonFillMode 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
390 void wxGraphicsPathData::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y )
391 {
392 // calculate using degree elevation to a cubic bezier
393 wxPoint2DDouble c1;
394 wxPoint2DDouble c2;
395
396 wxPoint2DDouble start;
397 GetCurrentPoint(&start.m_x,&start.m_y);
398 wxPoint2DDouble end(x,y);
399 wxPoint2DDouble c(cx,cy);
400 c1 = wxDouble(1/3.0) * start + wxDouble(2/3.0) * c;
401 c2 = wxDouble(2/3.0) * c + wxDouble(1/3.0) * end;
402 AddCurveToPoint(c1.m_x,c1.m_y,c2.m_x,c2.m_y,x,y);
403 }
404
405 void wxGraphicsPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
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
414 void wxGraphicsPathData::AddCircle( wxDouble x, wxDouble y, wxDouble r )
415 {
416 MoveToPoint(x+r,y);
417 AddArc( x,y,r,0,2*M_PI,false);
418 CloseSubpath();
419 }
420
421 void wxGraphicsPathData::AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
422 {
423 if (w <= 0. || h <= 0.)
424 return;
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
479 wxPoint2DDouble nv1 = v1;
480 nv1.SetVectorAngle(v1.GetVectorAngle()-90);
481 wxPoint2DDouble c = t1 + r*nv1;
482
483 wxDouble a1 = v1.GetVectorAngle()+90;
484 wxDouble a2 = v2.GetVectorAngle()-90;
485
486 AddLineToPoint(t1.m_x,t1.m_y);
487 AddArc(c.m_x,c.m_y,r,DegToRad(a1),DegToRad(a2),true);
488 AddLineToPoint(p2.m_x,p2.m_y);
489 }
490
491 //-----------------------------------------------------------------------------
492 // wxGraphicsGradientStops
493 //-----------------------------------------------------------------------------
494
495 void wxGraphicsGradientStops::Add(const wxGraphicsGradientStop& stop)
496 {
497 for ( wxVector<wxGraphicsGradientStop>::iterator it = m_stops.begin();
498 it != m_stops.end();
499 ++it )
500 {
501 if ( stop.GetPosition() < it->GetPosition() )
502 {
503 if ( it != m_stops.begin() )
504 {
505 m_stops.insert(it, stop);
506 }
507 else // we shouldn't be inserting it at the beginning
508 {
509 wxFAIL_MSG( "invalid gradient stop position < 0" );
510 }
511
512 return;
513 }
514 }
515
516 if ( stop.GetPosition() == 1. )
517 {
518 m_stops.insert(m_stops.end() - 1, stop);
519 }
520 else
521 {
522 wxFAIL_MSG( "invalid gradient stop position > 1" );
523 }
524 }
525
526 void * wxGraphicsBitmap::GetNativeBitmap() const
527 {
528 return GetBitmapData()->GetNativeBitmap();
529 }
530
531 //-----------------------------------------------------------------------------
532 // wxGraphicsContext Convenience Methods
533 //-----------------------------------------------------------------------------
534
535 IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext, wxObject)
536
537
538 wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) :
539 wxGraphicsObject(renderer),
540 m_antialias(wxANTIALIAS_DEFAULT),
541 m_composition(wxCOMPOSITION_OVER),
542 m_enableOffset(false)
543 {
544 }
545
546 wxGraphicsContext::~wxGraphicsContext()
547 {
548 }
549
550 bool wxGraphicsContext::StartDoc(const wxString& WXUNUSED(message))
551 {
552 return true;
553 }
554
555 void wxGraphicsContext::EndDoc()
556 {
557 }
558
559 void wxGraphicsContext::StartPage(wxDouble WXUNUSED(width),
560 wxDouble WXUNUSED(height))
561 {
562 }
563
564 void wxGraphicsContext::EndPage()
565 {
566 }
567
568 void wxGraphicsContext::Flush()
569 {
570 }
571
572 void wxGraphicsContext::EnableOffset(bool enable)
573 {
574 m_enableOffset = enable;
575 }
576
577 #if 0
578 void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) )
579 {
580 }
581
582 wxDouble wxGraphicsContext::GetAlpha() const
583 {
584 return 1.0;
585 }
586 #endif
587
588 void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY)
589 {
590 *dpiX = 72.0;
591 *dpiY = 72.0;
592 }
593
594 // sets the pen
595 void wxGraphicsContext::SetPen( const wxGraphicsPen& pen )
596 {
597 m_pen = pen;
598 }
599
600 void wxGraphicsContext::SetPen( const wxPen& pen )
601 {
602 if ( !pen.IsOk() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT )
603 SetPen( wxNullGraphicsPen );
604 else
605 SetPen( CreatePen( pen ) );
606 }
607
608 // sets the brush for filling
609 void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush )
610 {
611 m_brush = brush;
612 }
613
614 void wxGraphicsContext::SetBrush( const wxBrush& brush )
615 {
616 if ( !brush.IsOk() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT )
617 SetBrush( wxNullGraphicsBrush );
618 else
619 SetBrush( CreateBrush( brush ) );
620 }
621
622 // sets the brush for filling
623 void wxGraphicsContext::SetFont( const wxGraphicsFont& font )
624 {
625 m_font = font;
626 }
627
628 void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour )
629 {
630 if ( font.IsOk() )
631 SetFont( CreateFont( font, colour ) );
632 else
633 SetFont( wxNullGraphicsFont );
634 }
635
636 void wxGraphicsContext::DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle )
637 {
638 FillPath( path , fillStyle );
639 StrokePath( path );
640 }
641
642 void
643 wxGraphicsContext::DoDrawRotatedText(const wxString &str,
644 wxDouble x,
645 wxDouble y,
646 wxDouble angle)
647 {
648 Translate(x,y);
649 Rotate( -angle );
650 DrawText( str , 0, 0 );
651 Rotate( angle );
652 Translate(-x,-y);
653 }
654
655 void
656 wxGraphicsContext::DoDrawFilledText(const wxString &str,
657 wxDouble x,
658 wxDouble y,
659 const wxGraphicsBrush& backgroundBrush)
660 {
661 wxGraphicsBrush formerBrush = m_brush;
662 wxGraphicsPen formerPen = m_pen;
663 wxDouble width;
664 wxDouble height;
665 wxDouble descent;
666 wxDouble externalLeading;
667 GetTextExtent( str , &width, &height, &descent, &externalLeading );
668 SetBrush( backgroundBrush );
669 // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
670 SetPen( wxNullGraphicsPen );
671
672 DrawRectangle(x , y, width, height);
673
674 DrawText( str, x ,y);
675 SetBrush( formerBrush );
676 SetPen( formerPen );
677 }
678
679 void
680 wxGraphicsContext::DoDrawRotatedFilledText(const wxString &str,
681 wxDouble x, wxDouble y,
682 wxDouble angle,
683 const wxGraphicsBrush& backgroundBrush)
684 {
685 wxGraphicsBrush formerBrush = m_brush;
686 wxGraphicsPen formerPen = m_pen;
687
688 wxDouble width;
689 wxDouble height;
690 wxDouble descent;
691 wxDouble externalLeading;
692 GetTextExtent( str , &width, &height, &descent, &externalLeading );
693 SetBrush( backgroundBrush );
694 // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
695 SetPen( wxNullGraphicsPen );
696
697 wxGraphicsPath path = CreatePath();
698 path.MoveToPoint( x , y );
699 path.AddLineToPoint( (int) (x + sin(angle) * height) , (int) (y + cos(angle) * height) );
700 path.AddLineToPoint(
701 (int) (x + sin(angle) * height + cos(angle) * width) ,
702 (int) (y + cos(angle) * height - sin(angle) * width));
703 path.AddLineToPoint((int) (x + cos(angle) * width) , (int) (y - sin(angle) * width) );
704 FillPath( path );
705 DrawText( str, x ,y, angle);
706 SetBrush( formerBrush );
707 SetPen( formerPen );
708 }
709
710 void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2)
711 {
712 wxGraphicsPath path = CreatePath();
713 path.MoveToPoint(x1, y1);
714 path.AddLineToPoint( x2, y2 );
715 StrokePath( path );
716 }
717
718 void wxGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
719 {
720 wxGraphicsPath path = CreatePath();
721 path.AddRectangle( x , y , w , h );
722 DrawPath( path );
723 }
724
725 void wxGraphicsContext::DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
726 {
727 wxGraphicsPath path = CreatePath();
728 path.AddEllipse(x,y,w,h);
729 DrawPath(path);
730 }
731
732 void wxGraphicsContext::DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius)
733 {
734 wxGraphicsPath path = CreatePath();
735 path.AddRoundedRectangle(x,y,w,h,radius);
736 DrawPath(path);
737 }
738
739 void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *points)
740 {
741 wxASSERT(n > 1);
742 wxGraphicsPath path = CreatePath();
743 path.MoveToPoint(points[0].m_x, points[0].m_y);
744 for ( size_t i = 1; i < n; ++i)
745 path.AddLineToPoint( points[i].m_x, points[i].m_y );
746 StrokePath( path );
747 }
748
749 void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle)
750 {
751 wxASSERT(n > 1);
752 wxGraphicsPath path = CreatePath();
753 path.MoveToPoint(points[0].m_x, points[0].m_y);
754 for ( size_t i = 1; i < n; ++i)
755 path.AddLineToPoint( points[i].m_x, points[i].m_y );
756 DrawPath( path , fillStyle);
757 }
758
759 void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints)
760 {
761 wxASSERT(n > 0);
762 wxGraphicsPath path = CreatePath();
763 for ( size_t i = 0; i < n; ++i)
764 {
765 path.MoveToPoint(beginPoints[i].m_x, beginPoints[i].m_y);
766 path.AddLineToPoint( endPoints[i].m_x, endPoints[i].m_y );
767 }
768 StrokePath( path );
769 }
770
771 // create a 'native' matrix corresponding to these values
772 wxGraphicsMatrix wxGraphicsContext::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d,
773 wxDouble tx, wxDouble ty) const
774 {
775 return GetRenderer()->CreateMatrix(a,b,c,d,tx,ty);
776 }
777
778 wxGraphicsPath wxGraphicsContext::CreatePath() const
779 {
780 return GetRenderer()->CreatePath();
781 }
782
783 wxGraphicsPen wxGraphicsContext::CreatePen(const wxPen& pen) const
784 {
785 return GetRenderer()->CreatePen(pen);
786 }
787
788 wxGraphicsBrush wxGraphicsContext::CreateBrush(const wxBrush& brush ) const
789 {
790 return GetRenderer()->CreateBrush(brush);
791 }
792
793 wxGraphicsBrush
794 wxGraphicsContext::CreateLinearGradientBrush(
795 wxDouble x1, wxDouble y1,
796 wxDouble x2, wxDouble y2,
797 const wxColour& c1, const wxColour& c2) const
798 {
799 return GetRenderer()->CreateLinearGradientBrush
800 (
801 x1, y1,
802 x2, y2,
803 wxGraphicsGradientStops(c1,c2)
804 );
805 }
806
807 wxGraphicsBrush
808 wxGraphicsContext::CreateLinearGradientBrush(
809 wxDouble x1, wxDouble y1,
810 wxDouble x2, wxDouble y2,
811 const wxGraphicsGradientStops& gradientStops) const
812 {
813 return GetRenderer()->CreateLinearGradientBrush(x1,y1,x2,y2, gradientStops);
814 }
815
816 wxGraphicsBrush
817 wxGraphicsContext::CreateRadialGradientBrush(
818 wxDouble xo, wxDouble yo,
819 wxDouble xc, wxDouble yc, wxDouble radius,
820 const wxColour &oColor, const wxColour &cColor) const
821 {
822 return GetRenderer()->CreateRadialGradientBrush
823 (
824 xo, yo,
825 xc, yc, radius,
826 wxGraphicsGradientStops(oColor, cColor)
827 );
828 }
829
830 wxGraphicsBrush
831 wxGraphicsContext::CreateRadialGradientBrush(
832 wxDouble xo, wxDouble yo,
833 wxDouble xc, wxDouble yc, wxDouble radius,
834 const wxGraphicsGradientStops& gradientStops) const
835 {
836 return GetRenderer()->CreateRadialGradientBrush
837 (
838 xo, yo,
839 xc, yc, radius,
840 gradientStops
841 );
842 }
843
844 wxGraphicsFont wxGraphicsContext::CreateFont( const wxFont &font , const wxColour &col ) const
845 {
846 return GetRenderer()->CreateFont(font,col);
847 }
848
849 wxGraphicsFont
850 wxGraphicsContext::CreateFont(double size,
851 const wxString& facename,
852 int flags,
853 const wxColour& col) const
854 {
855 return GetRenderer()->CreateFont(size, facename, flags, col);
856 }
857
858 wxGraphicsBitmap wxGraphicsContext::CreateBitmap( const wxBitmap& bmp ) const
859 {
860 return GetRenderer()->CreateBitmap(bmp);
861 }
862
863 #if wxUSE_IMAGE
864 wxGraphicsBitmap wxGraphicsContext::CreateBitmapFromImage(const wxImage& image) const
865 {
866 return GetRenderer()->CreateBitmapFromImage(image);
867 }
868 #endif // wxUSE_IMAGE
869
870 wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) const
871 {
872 return GetRenderer()->CreateSubBitmap(bmp,x,y,w,h);
873 }
874
875 /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc)
876 {
877 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
878 }
879
880 /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxMemoryDC& dc)
881 {
882 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
883 }
884
885 #if wxUSE_PRINTING_ARCHITECTURE
886 /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxPrinterDC& dc)
887 {
888 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
889 }
890 #endif
891
892 #ifdef __WXMSW__
893 #if wxUSE_ENH_METAFILE
894 /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxEnhMetaFileDC& dc)
895 {
896 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
897 }
898 #endif
899 #endif
900
901 wxGraphicsContext* wxGraphicsContext::CreateFromNative( void * context )
902 {
903 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeContext(context);
904 }
905
906 wxGraphicsContext* wxGraphicsContext::CreateFromNativeWindow( void * window )
907 {
908 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeWindow(window);
909 }
910
911 wxGraphicsContext* wxGraphicsContext::Create( wxWindow* window )
912 {
913 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window);
914 }
915
916 #if wxUSE_IMAGE
917 /* static */ wxGraphicsContext* wxGraphicsContext::Create(wxImage& image)
918 {
919 return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromImage(image);
920 }
921 #endif // wxUSE_IMAGE
922
923 wxGraphicsContext* wxGraphicsContext::Create()
924 {
925 return wxGraphicsRenderer::GetDefaultRenderer()->CreateMeasuringContext();
926 }
927
928 //-----------------------------------------------------------------------------
929 // wxGraphicsRenderer
930 //-----------------------------------------------------------------------------
931
932 IMPLEMENT_ABSTRACT_CLASS(wxGraphicsRenderer, wxObject)
933
934 #endif // wxUSE_GRAPHICS_CONTEXT