]> git.saurik.com Git - wxWidgets.git/blob - include/wx/graphics.h
using common code
[wxWidgets.git] / include / wx / graphics.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/graphics.h
3 // Purpose: graphics context header
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created:
7 // Copyright: (c) Stefan Csomor
8 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GRAPHICS_H_
13 #define _WX_GRAPHICS_H_
14
15 #if wxUSE_GRAPHICS_CONTEXT
16
17 #include "wx/geometry.h"
18 #include "wx/dynarray.h"
19
20 class WXDLLIMPEXP_FWD_CORE wxWindowDC;
21 class WXDLLIMPEXP_FWD_CORE wxMemoryDC;
22 class WXDLLIMPEXP_FWD_CORE wxGraphicsContext;
23 class WXDLLIMPEXP_FWD_CORE wxGraphicsPath;
24 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix;
25 class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure;
26 class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer;
27 class WXDLLIMPEXP_FWD_CORE wxGraphicsPen;
28 class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush;
29 class WXDLLIMPEXP_FWD_CORE wxGraphicsFont;
30
31 /*
32 * notes about the graphics context apis
33 *
34 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
35 * in direction of positive y axis.
36 */
37
38 // Base class of all objects used for drawing in the new graphics API, the always point back to their
39 // originating rendering engine, there is no dynamic unloading of a renderer currently allowed,
40 // these references are not counted
41
42 //
43 // The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive
44 // duplication. Any operation on a shared instance that results in a modified state, uncouples this
45 // instance from the other instances that were shared - using copy on write semantics
46 //
47
48 class WXDLLIMPEXP_CORE wxGraphicsObjectRefData : public wxObjectRefData
49 {
50 public :
51 wxGraphicsObjectRefData( wxGraphicsRenderer* renderer );
52 wxGraphicsObjectRefData( const wxGraphicsObjectRefData* data );
53 wxGraphicsRenderer* GetRenderer() const ;
54 virtual wxGraphicsObjectRefData* Clone() const ;
55
56 protected :
57 wxGraphicsRenderer* m_renderer;
58 } ;
59
60 class WXDLLIMPEXP_CORE wxGraphicsObject : public wxObject
61 {
62 public :
63 wxGraphicsObject() ;
64 wxGraphicsObject( wxGraphicsRenderer* renderer ) ;
65 virtual ~wxGraphicsObject() ;
66
67 bool IsNull() const ;
68
69 // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
70 wxGraphicsRenderer* GetRenderer() const ;
71 wxGraphicsObjectRefData* GetGraphicsData() const ;
72 protected :
73 virtual wxObjectRefData* CreateRefData() const;
74 virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const;
75
76 DECLARE_DYNAMIC_CLASS(wxGraphicsObject)
77 } ;
78
79 class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject
80 {
81 public :
82 wxGraphicsPen() {}
83 virtual ~wxGraphicsPen() {}
84 private :
85 DECLARE_DYNAMIC_CLASS(wxGraphicsPen)
86 } ;
87
88 extern WXDLLEXPORT_DATA(wxGraphicsPen) wxNullGraphicsPen;
89
90 class WXDLLIMPEXP_CORE wxGraphicsBrush : public wxGraphicsObject
91 {
92 public :
93 wxGraphicsBrush() {}
94 virtual ~wxGraphicsBrush() {}
95 private :
96 DECLARE_DYNAMIC_CLASS(wxGraphicsBrush)
97 } ;
98
99 extern WXDLLEXPORT_DATA(wxGraphicsBrush) wxNullGraphicsBrush;
100
101 class WXDLLIMPEXP_CORE wxGraphicsFont : public wxGraphicsObject
102 {
103 public :
104 wxGraphicsFont() {}
105 virtual ~wxGraphicsFont() {}
106 private :
107 DECLARE_DYNAMIC_CLASS(wxGraphicsFont)
108 } ;
109
110 extern WXDLLEXPORT_DATA(wxGraphicsFont) wxNullGraphicsFont;
111
112
113 class WXDLLIMPEXP_CORE wxGraphicsMatrixData : public wxGraphicsObjectRefData
114 {
115 public :
116 wxGraphicsMatrixData( wxGraphicsRenderer* renderer) :
117 wxGraphicsObjectRefData(renderer) {}
118
119 virtual ~wxGraphicsMatrixData() {}
120
121 // concatenates the matrix
122 virtual void Concat( const wxGraphicsMatrixData *t ) = 0;
123
124 // sets the matrix to the respective values
125 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
126 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
127
128 // gets the component valuess of the matrix
129 virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
130 wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const = 0;
131
132 // makes this the inverse matrix
133 virtual void Invert() = 0;
134
135 // returns true if the elements of the transformation matrix are equal ?
136 virtual bool IsEqual( const wxGraphicsMatrixData* t) const = 0;
137
138 // return true if this is the identity matrix
139 virtual bool IsIdentity() const = 0;
140
141 //
142 // transformation
143 //
144
145 // add the translation to this matrix
146 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
147
148 // add the scale to this matrix
149 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
150
151 // add the rotation to this matrix (radians)
152 virtual void Rotate( wxDouble angle ) = 0;
153
154 //
155 // apply the transforms
156 //
157
158 // applies that matrix to the point
159 virtual void TransformPoint( wxDouble *x, wxDouble *y ) const = 0;
160
161 // applies the matrix except for translations
162 virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const =0;
163
164 // returns the native representation
165 virtual void * GetNativeMatrix() const = 0;
166 } ;
167
168 class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject
169 {
170 public :
171 wxGraphicsMatrix() {}
172
173 virtual ~wxGraphicsMatrix() {}
174
175 // concatenates the matrix
176 virtual void Concat( const wxGraphicsMatrix *t );
177 void Concat( const wxGraphicsMatrix &t ) { Concat( &t ); }
178
179 // sets the matrix to the respective values
180 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
181 wxDouble tx=0.0, wxDouble ty=0.0);
182
183 // gets the component valuess of the matrix
184 virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
185 wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const;
186
187 // makes this the inverse matrix
188 virtual void Invert();
189
190 // returns true if the elements of the transformation matrix are equal ?
191 virtual bool IsEqual( const wxGraphicsMatrix* t) const;
192 bool IsEqual( const wxGraphicsMatrix& t) const { return IsEqual( &t ); }
193
194 // return true if this is the identity matrix
195 virtual bool IsIdentity() const;
196
197 //
198 // transformation
199 //
200
201 // add the translation to this matrix
202 virtual void Translate( wxDouble dx , wxDouble dy );
203
204 // add the scale to this matrix
205 virtual void Scale( wxDouble xScale , wxDouble yScale );
206
207 // add the rotation to this matrix (radians)
208 virtual void Rotate( wxDouble angle );
209
210 //
211 // apply the transforms
212 //
213
214 // applies that matrix to the point
215 virtual void TransformPoint( wxDouble *x, wxDouble *y ) const;
216
217 // applies the matrix except for translations
218 virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const;
219
220 // returns the native representation
221 virtual void * GetNativeMatrix() const;
222
223 const wxGraphicsMatrixData* GetMatrixData() const
224 { return (const wxGraphicsMatrixData*) GetRefData(); }
225 wxGraphicsMatrixData* GetMatrixData()
226 { return (wxGraphicsMatrixData*) GetRefData(); }
227
228 private :
229 DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix)
230 } ;
231
232 extern WXDLLEXPORT_DATA(wxGraphicsMatrix) wxNullGraphicsMatrix;
233
234 class WXDLLIMPEXP_CORE wxGraphicsPathData : public wxGraphicsObjectRefData
235 {
236 public :
237 wxGraphicsPathData(wxGraphicsRenderer* renderer) : wxGraphicsObjectRefData(renderer) {}
238 virtual ~wxGraphicsPathData() {}
239
240 //
241 // These are the path primitives from which everything else can be constructed
242 //
243
244 // begins a new subpath at (x,y)
245 virtual void MoveToPoint( wxDouble x, wxDouble y ) = 0;
246
247 // adds a straight line from the current point to (x,y)
248 virtual void AddLineToPoint( wxDouble x, wxDouble y ) = 0;
249
250 // adds a cubic Bezier curve from the current point, using two control points and an end point
251 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) = 0;
252
253 // adds another path
254 virtual void AddPath( const wxGraphicsPathData* path ) =0;
255
256 // closes the current sub-path
257 virtual void CloseSubpath() = 0;
258
259 // gets the last point of the current path, (0,0) if not yet set
260 virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const = 0;
261
262 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
263 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) = 0;
264
265 //
266 // These are convenience functions which - if not available natively will be assembled
267 // using the primitives from above
268 //
269
270 // adds a quadratic Bezier curve from the current point, using a control point and an end point
271 virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
272
273 // appends a rectangle as a new closed subpath
274 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
275
276 // appends an ellipsis as a new closed subpath fitting the passed rectangle
277 virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
278
279 // 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)
280 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
281
282 // appends an ellipse
283 virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
284
285 // appends a rounded rectangle
286 virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
287
288 // returns the native path
289 virtual void * GetNativePath() const = 0;
290
291 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
292 virtual void UnGetNativePath(void *p) const= 0;
293
294 // transforms each point of this path by the matrix
295 virtual void Transform( const wxGraphicsMatrixData* matrix ) =0;
296
297 // gets the bounding box enclosing all points (possibly including control points)
298 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const=0;
299
300 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE) const=0;
301 };
302
303 class WXDLLIMPEXP_CORE wxGraphicsPath : public wxGraphicsObject
304 {
305 public :
306 wxGraphicsPath() {}
307 virtual ~wxGraphicsPath() {}
308
309 //
310 // These are the path primitives from which everything else can be constructed
311 //
312
313 // begins a new subpath at (x,y)
314 virtual void MoveToPoint( wxDouble x, wxDouble y );
315 void MoveToPoint( const wxPoint2DDouble& p);
316
317 // adds a straight line from the current point to (x,y)
318 virtual void AddLineToPoint( wxDouble x, wxDouble y );
319 void AddLineToPoint( const wxPoint2DDouble& p);
320
321 // adds a cubic Bezier curve from the current point, using two control points and an end point
322 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) ;
323 void AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e);
324
325 // adds another path
326 virtual void AddPath( const wxGraphicsPath& path );
327
328 // closes the current sub-path
329 virtual void CloseSubpath() ;
330
331 // gets the last point of the current path, (0,0) if not yet set
332 virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const;
333 wxPoint2DDouble GetCurrentPoint() const;
334
335 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
336 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) ;
337 void AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
338
339 //
340 // These are convenience functions which - if not available natively will be assembled
341 // using the primitives from above
342 //
343
344 // adds a quadratic Bezier curve from the current point, using a control point and an end point
345 virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
346
347 // appends a rectangle as a new closed subpath
348 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
349
350 // appends an ellipsis as a new closed subpath fitting the passed rectangle
351 virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
352
353 // 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)
354 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
355
356 // appends an ellipse
357 virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
358
359 // appends a rounded rectangle
360 virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
361
362 // returns the native path
363 virtual void * GetNativePath() const;
364
365 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
366 virtual void UnGetNativePath(void *p)const;
367
368 // transforms each point of this path by the matrix
369 virtual void Transform( const wxGraphicsMatrix& matrix );
370
371 // gets the bounding box enclosing all points (possibly including control points)
372 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)const;
373 wxRect2DDouble GetBox()const;
374
375 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE)const;
376 bool Contains( const wxPoint2DDouble& c, int fillStyle = wxODDEVEN_RULE)const;
377
378 const wxGraphicsPathData* GetPathData() const
379 { return (const wxGraphicsPathData*) GetRefData(); }
380 wxGraphicsPathData* GetPathData()
381 { return (wxGraphicsPathData*) GetRefData(); }
382
383 private :
384 DECLARE_DYNAMIC_CLASS(wxGraphicsPath)
385 } ;
386
387 extern WXDLLEXPORT_DATA(wxGraphicsPath) wxNullGraphicsPath;
388
389
390 class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject
391 {
392 public:
393 wxGraphicsContext(wxGraphicsRenderer* renderer);
394
395 virtual ~wxGraphicsContext();
396
397 static wxGraphicsContext* Create( const wxWindowDC& dc) ;
398 static wxGraphicsContext * Create( const wxMemoryDC& dc) ;
399
400 static wxGraphicsContext* CreateFromNative( void * context ) ;
401
402 static wxGraphicsContext* CreateFromNativeWindow( void * window ) ;
403
404 static wxGraphicsContext* Create( wxWindow* window ) ;
405
406 // create a context that can be used for measuring texts only, no drawing allowed
407 static wxGraphicsContext * Create();
408
409 // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown
410 virtual bool StartDoc( const wxString& message ) ;
411
412 // done with that document (relevant only for printing / pdf etc)
413 virtual void EndDoc();
414
415 // opens a new page (relevant only for printing / pdf etc) with the given size in points
416 // (if both are null the default page size will be used)
417 virtual void StartPage( wxDouble width = 0, wxDouble height = 0 );
418
419 // ends the current page (relevant only for printing / pdf etc)
420 virtual void EndPage();
421
422 // make sure that the current content of this context is immediately visible
423 virtual void Flush();
424
425 wxGraphicsPath CreatePath() const;
426
427 virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
428
429 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) const;
430
431 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
432 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
433 const wxColour&c1, const wxColour&c2) const;
434
435 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
436 // with radius r and color cColor
437 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
438 const wxColour &oColor, const wxColour &cColor) const;
439
440 // sets the font
441 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) const;
442
443 // create a 'native' matrix corresponding to these values
444 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
445 wxDouble tx=0.0, wxDouble ty=0.0) const;
446
447 // push the current state of the context, ie the transformation matrix on a stack
448 virtual void PushState() = 0;
449
450 // pops a stored state from the stack
451 virtual void PopState() = 0;
452
453 // clips drawings to the region intersected with the current clipping region
454 virtual void Clip( const wxRegion &region ) = 0;
455
456 // clips drawings to the rect intersected with the current clipping region
457 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
458
459 // resets the clipping to original extent
460 virtual void ResetClip() = 0 ;
461
462 // returns the native context
463 virtual void * GetNativeContext() = 0;
464
465 // returns the current logical function
466 virtual int GetLogicalFunction() const { return m_logicalFunction; }
467
468 // sets the current logical function, returns true if it supported
469 virtual bool SetLogicalFunction(int function) ;
470
471 // returns the size of the graphics context in device coordinates
472 virtual void GetSize( wxDouble* width, wxDouble* height);
473
474 // returns the resolution of the graphics context in device points per inch
475 virtual void GetDPI( wxDouble* dpiX, wxDouble* dpiY);
476
477 #if 0
478 // sets the current alpha on this context
479 virtual void SetAlpha( wxDouble alpha );
480
481 // returns the alpha on this context
482 virtual wxDouble GetAlpha() const;
483 #endif
484 //
485 // transformation : changes the current transformation matrix CTM of the context
486 //
487
488 // translate
489 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
490
491 // scale
492 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
493
494 // rotate (radians)
495 virtual void Rotate( wxDouble angle ) = 0;
496
497 // concatenates this transform with the current transform of this context
498 virtual void ConcatTransform( const wxGraphicsMatrix& matrix ) = 0;
499
500 // sets the transform of this context
501 virtual void SetTransform( const wxGraphicsMatrix& matrix ) = 0;
502
503 // gets the matrix of this context
504 virtual wxGraphicsMatrix GetTransform() const = 0;
505 //
506 // setting the paint
507 //
508
509 // sets the pen
510 virtual void SetPen( const wxGraphicsPen& pen );
511
512 void SetPen( const wxPen& pen );
513
514 // sets the brush for filling
515 virtual void SetBrush( const wxGraphicsBrush& brush );
516
517 void SetBrush( const wxBrush& brush );
518
519 // sets the font
520 virtual void SetFont( const wxGraphicsFont& font );
521
522 void SetFont( const wxFont& font, const wxColour& colour );
523
524
525 // strokes along a path with the current pen
526 virtual void StrokePath( const wxGraphicsPath& path ) = 0;
527
528 // fills a path with the current brush
529 virtual void FillPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ) = 0;
530
531 // draws a path by first filling and then stroking
532 virtual void DrawPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE );
533
534 //
535 // text
536 //
537
538 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y ) = 0;
539
540 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle );
541
542 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush& backgroundBrush ) ;
543
544 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush );
545
546 virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height,
547 wxDouble *descent, wxDouble *externalLeading ) const = 0;
548
549 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const = 0;
550
551 //
552 // image support
553 //
554
555 virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
556
557 virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
558
559 //
560 // convenience methods
561 //
562
563 // strokes a single line
564 virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2);
565
566 // stroke lines connecting each of the points
567 virtual void StrokeLines( size_t n, const wxPoint2DDouble *points);
568
569 // stroke disconnected lines from begin to end points
570 virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints);
571
572 // draws a polygon
573 virtual void DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle = wxODDEVEN_RULE );
574
575 // draws a polygon
576 virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
577
578 // draws an ellipse
579 virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
580
581 // draws a rounded rectangle
582 virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
583
584 // wrappers using wxPoint2DDouble TODO
585
586 // helper to determine if a 0.5 offset should be applied for the drawing operation
587 virtual bool ShouldOffset() const { return false; }
588
589 protected :
590
591 wxGraphicsPen m_pen;
592 wxGraphicsBrush m_brush;
593 wxGraphicsFont m_font;
594 int m_logicalFunction;
595
596 private :
597 DECLARE_NO_COPY_CLASS(wxGraphicsContext)
598 DECLARE_ABSTRACT_CLASS(wxGraphicsContext)
599 };
600
601 #if 0
602
603 //
604 // A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements
605 //
606
607 class WXDLLIMPEXP_CORE wxGraphicsFigure : public wxGraphicsObject
608 {
609 public :
610 wxGraphicsFigure(wxGraphicsRenderer* renderer) ;
611
612 virtual ~wxGraphicsFigure() ;
613
614 void SetPath( wxGraphicsMatrix* matrix );
615
616 void SetMatrix( wxGraphicsPath* path);
617
618 // draws this object on the context
619 virtual void Draw( wxGraphicsContext* cg );
620
621 // returns the path of this object
622 wxGraphicsPath* GetPath() { return m_path; }
623
624 // returns the transformation matrix of this object, may be null if there is no transformation necessary
625 wxGraphicsMatrix* GetMatrix() { return m_matrix; }
626
627 private :
628 wxGraphicsMatrix* m_matrix;
629 wxGraphicsPath* m_path;
630
631 DECLARE_DYNAMIC_CLASS(wxGraphicsFigure)
632 } ;
633
634 #endif
635
636 //
637 // The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer
638 // instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional
639 // paths at any point from a given matrix etc.
640 //
641
642 class WXDLLIMPEXP_CORE wxGraphicsRenderer : public wxObject
643 {
644 public :
645 wxGraphicsRenderer() {}
646
647 virtual ~wxGraphicsRenderer() {}
648
649 static wxGraphicsRenderer* GetDefaultRenderer();
650
651 // Context
652
653 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) = 0 ;
654 virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc) = 0 ;
655
656 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0;
657
658 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0;
659
660 virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0;
661
662 // create a context that can be used for measuring texts only, no drawing allowed
663 virtual wxGraphicsContext * CreateMeasuringContext() = 0;
664
665 // Path
666
667 virtual wxGraphicsPath CreatePath() = 0;
668
669 // Matrix
670
671 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
672 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
673
674 // Paints
675
676 virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0 ;
677
678 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) = 0 ;
679
680 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
681 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
682 const wxColour&c1, const wxColour&c2) = 0;
683
684 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
685 // with radius r and color cColor
686 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
687 const wxColour &oColor, const wxColour &cColor) = 0;
688
689 // sets the font
690 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) = 0;
691
692 private :
693 DECLARE_NO_COPY_CLASS(wxGraphicsRenderer)
694 DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer)
695 } ;
696
697 #endif
698
699 #endif // _WX_GRAPHICS_H_