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