1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: graphics context header
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GRAPHICS_H_
13 #define _WX_GRAPHICS_H_
17 #if wxUSE_GRAPHICS_CONTEXT
19 #include "wx/geometry.h"
20 #include "wx/dynarray.h"
22 #include "wx/vector.h"
26 wxANTIALIAS_NONE
, // should be 0
30 enum wxCompositionMode
32 // R = Result, S = Source, D = Destination, premultiplied with alpha
33 // Ra, Sa, Da their alpha components
35 // classic Porter-Duff compositions
36 // http://keithp.com/~keithp/porterduff/p253-porter.pdf
38 wxCOMPOSITION_CLEAR
, /* R = 0 */
39 wxCOMPOSITION_SOURCE
, /* R = S */
40 wxCOMPOSITION_OVER
, /* R = S + D*(1 - Sa) */
41 wxCOMPOSITION_IN
, /* R = S*Da */
42 wxCOMPOSITION_OUT
, /* R = S*(1 - Da) */
43 wxCOMPOSITION_ATOP
, /* R = S*Da + D*(1 - Sa) */
45 wxCOMPOSITION_DEST
, /* R = D, essentially a noop */
46 wxCOMPOSITION_DEST_OVER
, /* R = S*(1 - Da) + D */
47 wxCOMPOSITION_DEST_IN
, /* R = D*Sa */
48 wxCOMPOSITION_DEST_OUT
, /* R = D*(1 - Sa) */
49 wxCOMPOSITION_DEST_ATOP
, /* R = S*(1 - Da) + D*Sa */
50 wxCOMPOSITION_XOR
, /* R = S*(1 - Da) + D*(1 - Sa) */
52 // mathematical compositions
53 wxCOMPOSITION_ADD
, /* R = S + D */
56 class WXDLLIMPEXP_FWD_CORE wxWindowDC
;
57 class WXDLLIMPEXP_FWD_CORE wxMemoryDC
;
58 #if wxUSE_PRINTING_ARCHITECTURE
59 class WXDLLIMPEXP_FWD_CORE wxPrinterDC
;
62 #if wxUSE_ENH_METAFILE
63 class WXDLLIMPEXP_FWD_CORE wxEnhMetaFileDC
;
66 class WXDLLIMPEXP_FWD_CORE wxGraphicsContext
;
67 class WXDLLIMPEXP_FWD_CORE wxGraphicsPath
;
68 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix
;
69 class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure
;
70 class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer
;
71 class WXDLLIMPEXP_FWD_CORE wxGraphicsPen
;
72 class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush
;
73 class WXDLLIMPEXP_FWD_CORE wxGraphicsFont
;
74 class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap
;
77 * notes about the graphics context apis
79 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
80 * in direction of positive y axis.
83 // Base class of all objects used for drawing in the new graphics API, the always point back to their
84 // originating rendering engine, there is no dynamic unloading of a renderer currently allowed,
85 // these references are not counted
88 // The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive
89 // duplication. Any operation on a shared instance that results in a modified state, uncouples this
90 // instance from the other instances that were shared - using copy on write semantics
93 class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData
;
94 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData
;
95 class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData
;
97 class WXDLLIMPEXP_CORE wxGraphicsObject
: public wxObject
101 wxGraphicsObject( wxGraphicsRenderer
* renderer
);
102 virtual ~wxGraphicsObject();
106 // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
107 wxGraphicsRenderer
* GetRenderer() const;
108 wxGraphicsObjectRefData
* GetGraphicsData() const;
110 virtual wxObjectRefData
* CreateRefData() const;
111 virtual wxObjectRefData
* CloneRefData(const wxObjectRefData
* data
) const;
113 DECLARE_DYNAMIC_CLASS(wxGraphicsObject
)
116 class WXDLLIMPEXP_CORE wxGraphicsPen
: public wxGraphicsObject
120 virtual ~wxGraphicsPen() {}
122 DECLARE_DYNAMIC_CLASS(wxGraphicsPen
)
125 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen
) wxNullGraphicsPen
;
127 class WXDLLIMPEXP_CORE wxGraphicsBrush
: public wxGraphicsObject
131 virtual ~wxGraphicsBrush() {}
133 DECLARE_DYNAMIC_CLASS(wxGraphicsBrush
)
136 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush
) wxNullGraphicsBrush
;
138 class WXDLLIMPEXP_CORE wxGraphicsFont
: public wxGraphicsObject
142 virtual ~wxGraphicsFont() {}
144 DECLARE_DYNAMIC_CLASS(wxGraphicsFont
)
147 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont
) wxNullGraphicsFont
;
149 class WXDLLIMPEXP_CORE wxGraphicsBitmap
: public wxGraphicsObject
152 wxGraphicsBitmap() {}
153 virtual ~wxGraphicsBitmap() {}
155 DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap
)
158 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap
) wxNullGraphicsBitmap
;
160 class WXDLLIMPEXP_CORE wxGraphicsMatrix
: public wxGraphicsObject
163 wxGraphicsMatrix() {}
165 virtual ~wxGraphicsMatrix() {}
167 // concatenates the matrix
168 virtual void Concat( const wxGraphicsMatrix
*t
);
169 void Concat( const wxGraphicsMatrix
&t
) { Concat( &t
); }
171 // sets the matrix to the respective values
172 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
173 wxDouble tx
=0.0, wxDouble ty
=0.0);
175 // gets the component valuess of the matrix
176 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
177 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
179 // makes this the inverse matrix
180 virtual void Invert();
182 // returns true if the elements of the transformation matrix are equal ?
183 virtual bool IsEqual( const wxGraphicsMatrix
* t
) const;
184 bool IsEqual( const wxGraphicsMatrix
& t
) const { return IsEqual( &t
); }
186 // return true if this is the identity matrix
187 virtual bool IsIdentity() const;
193 // add the translation to this matrix
194 virtual void Translate( wxDouble dx
, wxDouble dy
);
196 // add the scale to this matrix
197 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
199 // add the rotation to this matrix (radians)
200 virtual void Rotate( wxDouble angle
);
203 // apply the transforms
206 // applies that matrix to the point
207 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
209 // applies the matrix except for translations
210 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
212 // returns the native representation
213 virtual void * GetNativeMatrix() const;
215 const wxGraphicsMatrixData
* GetMatrixData() const
216 { return (const wxGraphicsMatrixData
*) GetRefData(); }
217 wxGraphicsMatrixData
* GetMatrixData()
218 { return (wxGraphicsMatrixData
*) GetRefData(); }
221 DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix
)
224 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix
) wxNullGraphicsMatrix
;
226 class WXDLLIMPEXP_CORE wxGraphicsPath
: public wxGraphicsObject
230 virtual ~wxGraphicsPath() {}
233 // These are the path primitives from which everything else can be constructed
236 // begins a new subpath at (x,y)
237 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
238 void MoveToPoint( const wxPoint2DDouble
& p
);
240 // adds a straight line from the current point to (x,y)
241 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
242 void AddLineToPoint( const wxPoint2DDouble
& p
);
244 // adds a cubic Bezier curve from the current point, using two control points and an end point
245 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
246 void AddCurveToPoint( const wxPoint2DDouble
& c1
, const wxPoint2DDouble
& c2
, const wxPoint2DDouble
& e
);
249 virtual void AddPath( const wxGraphicsPath
& path
);
251 // closes the current sub-path
252 virtual void CloseSubpath();
254 // gets the last point of the current path, (0,0) if not yet set
255 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
256 wxPoint2DDouble
GetCurrentPoint() const;
258 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
259 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
260 void AddArc( const wxPoint2DDouble
& c
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
263 // These are convenience functions which - if not available natively will be assembled
264 // using the primitives from above
267 // adds a quadratic Bezier curve from the current point, using a control point and an end point
268 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
270 // appends a rectangle as a new closed subpath
271 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
273 // appends an ellipsis as a new closed subpath fitting the passed rectangle
274 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
276 // 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)
277 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
279 // appends an ellipse
280 virtual void AddEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
282 // appends a rounded rectangle
283 virtual void AddRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
285 // returns the native path
286 virtual void * GetNativePath() const;
288 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
289 virtual void UnGetNativePath(void *p
)const;
291 // transforms each point of this path by the matrix
292 virtual void Transform( const wxGraphicsMatrix
& matrix
);
294 // gets the bounding box enclosing all points (possibly including control points)
295 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
)const;
296 wxRect2DDouble
GetBox()const;
298 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)const;
299 bool Contains( const wxPoint2DDouble
& c
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)const;
301 const wxGraphicsPathData
* GetPathData() const
302 { return (const wxGraphicsPathData
*) GetRefData(); }
303 wxGraphicsPathData
* GetPathData()
304 { return (wxGraphicsPathData
*) GetRefData(); }
307 DECLARE_DYNAMIC_CLASS(wxGraphicsPath
)
310 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPath
) wxNullGraphicsPath
;
313 // Describes a single gradient stop.
314 class wxGraphicsGradientStop
317 wxGraphicsGradientStop(wxColour col
= wxTransparentColour
,
324 // default copy ctor, assignment operator and dtor are ok
326 const wxColour
& GetColour() const { return m_col
; }
327 void SetColour(const wxColour
& col
) { m_col
= col
; }
329 float GetPosition() const { return m_pos
; }
330 void SetPosition(float pos
)
332 wxASSERT_MSG( pos
>= 0 && pos
<= 1, "invalid gradient stop position" );
338 // The colour of this gradient band.
341 // Its starting position: 0 is the beginning and 1 is the end.
345 // A collection of gradient stops ordered by their positions (from lowest to
346 // highest). The first stop (index 0, position 0.0) is always the starting
347 // colour and the last one (index GetCount() - 1, position 1.0) is the end
349 class WXDLLIMPEXP_CORE wxGraphicsGradientStops
352 wxGraphicsGradientStops(wxColour startCol
= wxTransparentColour
,
353 wxColour endCol
= wxTransparentColour
)
355 // we can't use Add() here as it relies on having start/end stops as
356 // first/last array elements so do it manually
357 m_stops
.push_back(wxGraphicsGradientStop(startCol
, 0.f
));
358 m_stops
.push_back(wxGraphicsGradientStop(endCol
, 1.f
));
361 // default copy ctor, assignment operator and dtor are ok for this class
364 // Add a stop in correct order.
365 void Add(const wxGraphicsGradientStop
& stop
);
366 void Add(wxColour col
, float pos
) { Add(wxGraphicsGradientStop(col
, pos
)); }
368 // Get the number of stops.
369 unsigned GetCount() const { return m_stops
.size(); }
371 // Return the stop at the given index (which must be valid).
372 wxGraphicsGradientStop
Item(unsigned n
) const { return m_stops
.at(n
); }
374 // Get/set start and end colours.
375 void SetStartColour(wxColour col
)
376 { m_stops
[0].SetColour(col
); }
377 wxColour
GetStartColour() const
378 { return m_stops
[0].GetColour(); }
379 void SetEndColour(wxColour col
)
380 { m_stops
[m_stops
.size() - 1].SetColour(col
); }
381 wxColour
GetEndColour() const
382 { return m_stops
[m_stops
.size() - 1].GetColour(); }
385 // All the stops stored in ascending order of positions.
386 wxVector
<wxGraphicsGradientStop
> m_stops
;
389 class WXDLLIMPEXP_CORE wxGraphicsContext
: public wxGraphicsObject
392 wxGraphicsContext(wxGraphicsRenderer
* renderer
);
394 virtual ~wxGraphicsContext();
396 static wxGraphicsContext
* Create( const wxWindowDC
& dc
);
397 static wxGraphicsContext
* Create( const wxMemoryDC
& dc
);
398 #if wxUSE_PRINTING_ARCHITECTURE
399 static wxGraphicsContext
* Create( const wxPrinterDC
& dc
);
402 #if wxUSE_ENH_METAFILE
403 static wxGraphicsContext
* Create( const wxEnhMetaFileDC
& dc
);
407 static wxGraphicsContext
* CreateFromNative( void * context
);
409 static wxGraphicsContext
* CreateFromNativeWindow( void * window
);
411 static wxGraphicsContext
* Create( wxWindow
* window
);
413 // create a context that can be used for measuring texts only, no drawing allowed
414 static wxGraphicsContext
* Create();
416 // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown
417 virtual bool StartDoc( const wxString
& message
);
419 // done with that document (relevant only for printing / pdf etc)
420 virtual void EndDoc();
422 // opens a new page (relevant only for printing / pdf etc) with the given size in points
423 // (if both are null the default page size will be used)
424 virtual void StartPage( wxDouble width
= 0, wxDouble height
= 0 );
426 // ends the current page (relevant only for printing / pdf etc)
427 virtual void EndPage();
429 // make sure that the current content of this context is immediately visible
430 virtual void Flush();
432 wxGraphicsPath
CreatePath() const;
434 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) const;
436 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) const;
438 // sets the brush to a linear gradient, starting at (x1,y1) and ending at
439 // (x2,y2) with the given boundary colours or the specified stops
441 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
442 wxDouble x2
, wxDouble y2
,
443 const wxColour
& c1
, const wxColour
& c2
) const;
445 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
446 wxDouble x2
, wxDouble y2
,
447 const wxGraphicsGradientStops
& stops
) const;
449 // sets the brush to a radial gradient originating at (xo,yc) and ending
450 // on a circle around (xc,yc) with the given radius; the colours may be
451 // specified by just the two extremes or the full array of gradient stops
453 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
454 wxDouble xc
, wxDouble yc
, wxDouble radius
,
455 const wxColour
& oColor
, const wxColour
& cColor
) const;
458 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
459 wxDouble xc
, wxDouble yc
, wxDouble radius
,
460 const wxGraphicsGradientStops
& stops
) const;
463 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) const;
465 // create a native bitmap representation
466 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) const;
468 // create a native bitmap representation
469 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) const;
471 // create a 'native' matrix corresponding to these values
472 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
473 wxDouble tx
=0.0, wxDouble ty
=0.0) const;
475 // push the current state of the context, ie the transformation matrix on a stack
476 virtual void PushState() = 0;
478 // pops a stored state from the stack
479 virtual void PopState() = 0;
481 // clips drawings to the region intersected with the current clipping region
482 virtual void Clip( const wxRegion
®ion
) = 0;
484 // clips drawings to the rect intersected with the current clipping region
485 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
487 // resets the clipping to original extent
488 virtual void ResetClip() = 0;
490 // returns the native context
491 virtual void * GetNativeContext() = 0;
493 // returns the current shape antialiasing mode
494 virtual wxAntialiasMode
GetAntialiasMode() const { return m_antialias
; }
496 // sets the antialiasing mode, returns true if it supported
497 virtual bool SetAntialiasMode(wxAntialiasMode antialias
) = 0;
499 // returns the current compositing operator
500 virtual wxCompositionMode
GetCompositionMode() const { return m_composition
; }
502 // sets the compositing operator, returns true if it supported
503 virtual bool SetCompositionMode(wxCompositionMode op
) = 0;
505 // returns the size of the graphics context in device coordinates
506 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
508 // returns the resolution of the graphics context in device points per inch
509 virtual void GetDPI( wxDouble
* dpiX
, wxDouble
* dpiY
);
512 // sets the current alpha on this context
513 virtual void SetAlpha( wxDouble alpha
);
515 // returns the alpha on this context
516 virtual wxDouble
GetAlpha() const;
519 // all rendering is done into a fully transparent temporary context
520 virtual void BeginLayer(wxDouble opacity
) = 0;
522 // composites back the drawings into the context with the opacity given at
523 // the BeginLayer call
524 virtual void EndLayer() = 0;
527 // transformation : changes the current transformation matrix CTM of the context
531 virtual void Translate( wxDouble dx
, wxDouble dy
) = 0;
534 virtual void Scale( wxDouble xScale
, wxDouble yScale
) = 0;
537 virtual void Rotate( wxDouble angle
) = 0;
539 // concatenates this transform with the current transform of this context
540 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
) = 0;
542 // sets the transform of this context
543 virtual void SetTransform( const wxGraphicsMatrix
& matrix
) = 0;
545 // gets the matrix of this context
546 virtual wxGraphicsMatrix
GetTransform() const = 0;
552 virtual void SetPen( const wxGraphicsPen
& pen
);
554 void SetPen( const wxPen
& pen
);
556 // sets the brush for filling
557 virtual void SetBrush( const wxGraphicsBrush
& brush
);
559 void SetBrush( const wxBrush
& brush
);
562 virtual void SetFont( const wxGraphicsFont
& font
);
564 void SetFont( const wxFont
& font
, const wxColour
& colour
);
567 // strokes along a path with the current pen
568 virtual void StrokePath( const wxGraphicsPath
& path
) = 0;
570 // fills a path with the current brush
571 virtual void FillPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) = 0;
573 // draws a path by first filling and then stroking
574 virtual void DrawPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
580 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
581 { DoDrawText(str
, x
, y
); }
583 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
584 { DoDrawRotatedText(str
, x
, y
, angle
); }
586 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
,
587 const wxGraphicsBrush
& backgroundBrush
)
588 { DoDrawFilledText(str
, x
, y
, backgroundBrush
); }
590 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
,
591 wxDouble angle
, const wxGraphicsBrush
& backgroundBrush
)
592 { DoDrawRotatedFilledText(str
, x
, y
, angle
, backgroundBrush
); }
595 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
596 wxDouble
*descent
= NULL
, wxDouble
*externalLeading
= NULL
) const = 0;
598 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const = 0;
604 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
606 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
608 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
611 // convenience methods
614 // strokes a single line
615 virtual void StrokeLine( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
617 // stroke lines connecting each of the points
618 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
620 // stroke disconnected lines from begin to end points
621 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*beginPoints
, const wxPoint2DDouble
*endPoints
);
624 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
627 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
630 virtual void DrawEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
632 // draws a rounded rectangle
633 virtual void DrawRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
635 // wrappers using wxPoint2DDouble TODO
637 // helper to determine if a 0.5 offset should be applied for the drawing operation
638 virtual bool ShouldOffset() const { return false; }
643 wxGraphicsBrush m_brush
;
644 wxGraphicsFont m_font
;
645 wxAntialiasMode m_antialias
;
646 wxCompositionMode m_composition
;
649 // implementations of overloaded public functions: we use different names
650 // for them to avoid the virtual function hiding problems in the derived
652 virtual void DoDrawText(const wxString
& str
, wxDouble x
, wxDouble y
) = 0;
653 virtual void DoDrawRotatedText(const wxString
& str
, wxDouble x
, wxDouble y
,
655 virtual void DoDrawFilledText(const wxString
& str
, wxDouble x
, wxDouble y
,
656 const wxGraphicsBrush
& backgroundBrush
);
657 virtual void DoDrawRotatedFilledText(const wxString
& str
,
658 wxDouble x
, wxDouble y
,
660 const wxGraphicsBrush
& backgroundBrush
);
662 wxDECLARE_NO_COPY_CLASS(wxGraphicsContext
);
663 DECLARE_ABSTRACT_CLASS(wxGraphicsContext
)
669 // A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements
672 class WXDLLIMPEXP_CORE wxGraphicsFigure
: public wxGraphicsObject
675 wxGraphicsFigure(wxGraphicsRenderer
* renderer
);
677 virtual ~wxGraphicsFigure();
679 void SetPath( wxGraphicsMatrix
* matrix
);
681 void SetMatrix( wxGraphicsPath
* path
);
683 // draws this object on the context
684 virtual void Draw( wxGraphicsContext
* cg
);
686 // returns the path of this object
687 wxGraphicsPath
* GetPath() { return m_path
; }
689 // returns the transformation matrix of this object, may be null if there is no transformation necessary
690 wxGraphicsMatrix
* GetMatrix() { return m_matrix
; }
693 wxGraphicsMatrix
* m_matrix
;
694 wxGraphicsPath
* m_path
;
696 DECLARE_DYNAMIC_CLASS(wxGraphicsFigure
)
702 // The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer
703 // instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional
704 // paths at any point from a given matrix etc.
707 class WXDLLIMPEXP_CORE wxGraphicsRenderer
: public wxObject
710 wxGraphicsRenderer() {}
712 virtual ~wxGraphicsRenderer() {}
714 static wxGraphicsRenderer
* GetDefaultRenderer();
716 static wxGraphicsRenderer
* GetCairoRenderer();
719 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
) = 0;
720 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
) = 0;
721 #if wxUSE_PRINTING_ARCHITECTURE
722 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
) = 0;
725 #if wxUSE_ENH_METAFILE
726 virtual wxGraphicsContext
* CreateContext( const wxEnhMetaFileDC
& dc
) = 0;
730 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
) = 0;
732 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
) = 0;
734 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
) = 0;
736 // create a context that can be used for measuring texts only, no drawing allowed
737 virtual wxGraphicsContext
* CreateMeasuringContext() = 0;
741 virtual wxGraphicsPath
CreatePath() = 0;
745 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
746 wxDouble tx
=0.0, wxDouble ty
=0.0) = 0;
750 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) = 0;
752 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) = 0;
754 // Gradient brush creation functions may not honour all the stops specified
755 // stops and use just its boundary colours (this is currently the case
757 virtual wxGraphicsBrush
758 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
759 wxDouble x2
, wxDouble y2
,
760 const wxGraphicsGradientStops
& stops
) = 0;
762 virtual wxGraphicsBrush
763 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
764 wxDouble xc
, wxDouble yc
,
766 const wxGraphicsGradientStops
& stops
) = 0;
769 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) = 0;
771 // create a native bitmap representation
772 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) = 0;
774 // create a graphics bitmap from a native bitmap
775 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
) = 0;
777 // create a subimage from a native image representation
778 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
781 wxDECLARE_NO_COPY_CLASS(wxGraphicsRenderer
);
782 DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer
)
787 #endif // _WX_GRAPHICS_H_