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
;
61 #if wxUSE_ENH_METAFILE
62 class WXDLLIMPEXP_FWD_CORE wxEnhMetaFileDC
;
64 class WXDLLIMPEXP_FWD_CORE wxGraphicsContext
;
65 class WXDLLIMPEXP_FWD_CORE wxGraphicsPath
;
66 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix
;
67 class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure
;
68 class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer
;
69 class WXDLLIMPEXP_FWD_CORE wxGraphicsPen
;
70 class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush
;
71 class WXDLLIMPEXP_FWD_CORE wxGraphicsFont
;
72 class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap
;
75 * notes about the graphics context apis
77 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
78 * in direction of positive y axis.
81 // Base class of all objects used for drawing in the new graphics API, the always point back to their
82 // originating rendering engine, there is no dynamic unloading of a renderer currently allowed,
83 // these references are not counted
86 // The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive
87 // duplication. Any operation on a shared instance that results in a modified state, uncouples this
88 // instance from the other instances that were shared - using copy on write semantics
91 class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData
;
92 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData
;
93 class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData
;
95 class WXDLLIMPEXP_CORE wxGraphicsObject
: public wxObject
99 wxGraphicsObject( wxGraphicsRenderer
* renderer
);
100 virtual ~wxGraphicsObject();
104 // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
105 wxGraphicsRenderer
* GetRenderer() const;
106 wxGraphicsObjectRefData
* GetGraphicsData() const;
108 virtual wxObjectRefData
* CreateRefData() const;
109 virtual wxObjectRefData
* CloneRefData(const wxObjectRefData
* data
) const;
111 DECLARE_DYNAMIC_CLASS(wxGraphicsObject
)
114 class WXDLLIMPEXP_CORE wxGraphicsPen
: public wxGraphicsObject
118 virtual ~wxGraphicsPen() {}
120 DECLARE_DYNAMIC_CLASS(wxGraphicsPen
)
123 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen
) wxNullGraphicsPen
;
125 class WXDLLIMPEXP_CORE wxGraphicsBrush
: public wxGraphicsObject
129 virtual ~wxGraphicsBrush() {}
131 DECLARE_DYNAMIC_CLASS(wxGraphicsBrush
)
134 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush
) wxNullGraphicsBrush
;
136 class WXDLLIMPEXP_CORE wxGraphicsFont
: public wxGraphicsObject
140 virtual ~wxGraphicsFont() {}
142 DECLARE_DYNAMIC_CLASS(wxGraphicsFont
)
145 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont
) wxNullGraphicsFont
;
147 class WXDLLIMPEXP_CORE wxGraphicsBitmap
: public wxGraphicsObject
150 wxGraphicsBitmap() {}
151 virtual ~wxGraphicsBitmap() {}
153 DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap
)
156 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap
) wxNullGraphicsBitmap
;
158 class WXDLLIMPEXP_CORE wxGraphicsMatrix
: public wxGraphicsObject
161 wxGraphicsMatrix() {}
163 virtual ~wxGraphicsMatrix() {}
165 // concatenates the matrix
166 virtual void Concat( const wxGraphicsMatrix
*t
);
167 void Concat( const wxGraphicsMatrix
&t
) { Concat( &t
); }
169 // sets the matrix to the respective values
170 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
171 wxDouble tx
=0.0, wxDouble ty
=0.0);
173 // gets the component valuess of the matrix
174 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
175 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
177 // makes this the inverse matrix
178 virtual void Invert();
180 // returns true if the elements of the transformation matrix are equal ?
181 virtual bool IsEqual( const wxGraphicsMatrix
* t
) const;
182 bool IsEqual( const wxGraphicsMatrix
& t
) const { return IsEqual( &t
); }
184 // return true if this is the identity matrix
185 virtual bool IsIdentity() const;
191 // add the translation to this matrix
192 virtual void Translate( wxDouble dx
, wxDouble dy
);
194 // add the scale to this matrix
195 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
197 // add the rotation to this matrix (radians)
198 virtual void Rotate( wxDouble angle
);
201 // apply the transforms
204 // applies that matrix to the point
205 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
207 // applies the matrix except for translations
208 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
210 // returns the native representation
211 virtual void * GetNativeMatrix() const;
213 const wxGraphicsMatrixData
* GetMatrixData() const
214 { return (const wxGraphicsMatrixData
*) GetRefData(); }
215 wxGraphicsMatrixData
* GetMatrixData()
216 { return (wxGraphicsMatrixData
*) GetRefData(); }
219 DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix
)
222 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix
) wxNullGraphicsMatrix
;
224 class WXDLLIMPEXP_CORE wxGraphicsPath
: public wxGraphicsObject
228 virtual ~wxGraphicsPath() {}
231 // These are the path primitives from which everything else can be constructed
234 // begins a new subpath at (x,y)
235 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
236 void MoveToPoint( const wxPoint2DDouble
& p
);
238 // adds a straight line from the current point to (x,y)
239 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
240 void AddLineToPoint( const wxPoint2DDouble
& p
);
242 // adds a cubic Bezier curve from the current point, using two control points and an end point
243 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
244 void AddCurveToPoint( const wxPoint2DDouble
& c1
, const wxPoint2DDouble
& c2
, const wxPoint2DDouble
& e
);
247 virtual void AddPath( const wxGraphicsPath
& path
);
249 // closes the current sub-path
250 virtual void CloseSubpath();
252 // gets the last point of the current path, (0,0) if not yet set
253 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
254 wxPoint2DDouble
GetCurrentPoint() const;
256 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
257 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
258 void AddArc( const wxPoint2DDouble
& c
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
261 // These are convenience functions which - if not available natively will be assembled
262 // using the primitives from above
265 // adds a quadratic Bezier curve from the current point, using a control point and an end point
266 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
268 // appends a rectangle as a new closed subpath
269 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
271 // appends an ellipsis as a new closed subpath fitting the passed rectangle
272 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
274 // 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)
275 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
277 // appends an ellipse
278 virtual void AddEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
280 // appends a rounded rectangle
281 virtual void AddRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
283 // returns the native path
284 virtual void * GetNativePath() const;
286 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
287 virtual void UnGetNativePath(void *p
)const;
289 // transforms each point of this path by the matrix
290 virtual void Transform( const wxGraphicsMatrix
& matrix
);
292 // gets the bounding box enclosing all points (possibly including control points)
293 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
)const;
294 wxRect2DDouble
GetBox()const;
296 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)const;
297 bool Contains( const wxPoint2DDouble
& c
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)const;
299 const wxGraphicsPathData
* GetPathData() const
300 { return (const wxGraphicsPathData
*) GetRefData(); }
301 wxGraphicsPathData
* GetPathData()
302 { return (wxGraphicsPathData
*) GetRefData(); }
305 DECLARE_DYNAMIC_CLASS(wxGraphicsPath
)
308 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPath
) wxNullGraphicsPath
;
311 // Describes a single gradient stop.
312 class wxGraphicsGradientStop
315 wxGraphicsGradientStop(wxColour col
= wxTransparentColour
,
322 // default copy ctor, assignment operator and dtor are ok
324 const wxColour
& GetColour() const { return m_col
; }
325 void SetColour(const wxColour
& col
) { m_col
= col
; }
327 float GetPosition() const { return m_pos
; }
328 void SetPosition(float pos
)
330 wxASSERT_MSG( pos
>= 0 && pos
<= 1, "invalid gradient stop position" );
336 // The colour of this gradient band.
339 // Its starting position: 0 is the beginning and 1 is the end.
343 // A collection of gradient stops ordered by their positions (from lowest to
344 // highest). The first stop (index 0, position 0.0) is always the starting
345 // colour and the last one (index GetCount() - 1, position 1.0) is the end
347 class WXDLLIMPEXP_CORE wxGraphicsGradientStops
350 wxGraphicsGradientStops(wxColour startCol
= wxTransparentColour
,
351 wxColour endCol
= wxTransparentColour
)
353 // we can't use Add() here as it relies on having start/end stops as
354 // first/last array elements so do it manually
355 m_stops
.push_back(wxGraphicsGradientStop(startCol
, 0.f
));
356 m_stops
.push_back(wxGraphicsGradientStop(endCol
, 1.f
));
359 // default copy ctor, assignment operator and dtor are ok for this class
362 // Add a stop in correct order.
363 void Add(const wxGraphicsGradientStop
& stop
);
364 void Add(wxColour col
, float pos
) { Add(wxGraphicsGradientStop(col
, pos
)); }
366 // Get the number of stops.
367 unsigned GetCount() const { return m_stops
.size(); }
369 // Return the stop at the given index (which must be valid).
370 wxGraphicsGradientStop
Item(unsigned n
) const { return m_stops
.at(n
); }
372 // Get/set start and end colours.
373 void SetStartColour(wxColour col
)
374 { m_stops
[0].SetColour(col
); }
375 wxColour
GetStartColour() const
376 { return m_stops
[0].GetColour(); }
377 void SetEndColour(wxColour col
)
378 { m_stops
[m_stops
.size() - 1].SetColour(col
); }
379 wxColour
GetEndColour() const
380 { return m_stops
[m_stops
.size() - 1].GetColour(); }
383 // All the stops stored in ascending order of positions.
384 wxVector
<wxGraphicsGradientStop
> m_stops
;
387 class WXDLLIMPEXP_CORE wxGraphicsContext
: public wxGraphicsObject
390 wxGraphicsContext(wxGraphicsRenderer
* renderer
);
392 virtual ~wxGraphicsContext();
394 static wxGraphicsContext
* Create( const wxWindowDC
& dc
);
395 static wxGraphicsContext
* Create( const wxMemoryDC
& dc
);
396 #if wxUSE_PRINTING_ARCHITECTURE
397 static wxGraphicsContext
* Create( const wxPrinterDC
& dc
);
399 #if wxUSE_ENH_METAFILE
400 static wxGraphicsContext
* Create( const wxEnhMetaFileDC
& dc
);
403 static wxGraphicsContext
* CreateFromNative( void * context
);
405 static wxGraphicsContext
* CreateFromNativeWindow( void * window
);
407 static wxGraphicsContext
* Create( wxWindow
* window
);
409 // create a context that can be used for measuring texts only, no drawing allowed
410 static wxGraphicsContext
* Create();
412 // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown
413 virtual bool StartDoc( const wxString
& message
);
415 // done with that document (relevant only for printing / pdf etc)
416 virtual void EndDoc();
418 // opens a new page (relevant only for printing / pdf etc) with the given size in points
419 // (if both are null the default page size will be used)
420 virtual void StartPage( wxDouble width
= 0, wxDouble height
= 0 );
422 // ends the current page (relevant only for printing / pdf etc)
423 virtual void EndPage();
425 // make sure that the current content of this context is immediately visible
426 virtual void Flush();
428 wxGraphicsPath
CreatePath() const;
430 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) const;
432 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) const;
434 // sets the brush to a linear gradient, starting at (x1,y1) and ending at
435 // (x2,y2) with the given boundary colours or the specified stops
437 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
438 wxDouble x2
, wxDouble y2
,
439 const wxColour
& c1
, const wxColour
& c2
) const;
441 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
442 wxDouble x2
, wxDouble y2
,
443 const wxGraphicsGradientStops
& stops
) const;
445 // sets the brush to a radial gradient originating at (xo,yc) and ending
446 // on a circle around (xc,yc) with the given radius; the colours may be
447 // specified by just the two extremes or the full array of gradient stops
449 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
450 wxDouble xc
, wxDouble yc
, wxDouble radius
,
451 const wxColour
& oColor
, const wxColour
& cColor
) const;
454 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
455 wxDouble xc
, wxDouble yc
, wxDouble radius
,
456 const wxGraphicsGradientStops
& stops
) const;
459 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) const;
461 // create a native bitmap representation
462 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) const;
464 // create a native bitmap representation
465 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) const;
467 // create a 'native' matrix corresponding to these values
468 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
469 wxDouble tx
=0.0, wxDouble ty
=0.0) const;
471 // push the current state of the context, ie the transformation matrix on a stack
472 virtual void PushState() = 0;
474 // pops a stored state from the stack
475 virtual void PopState() = 0;
477 // clips drawings to the region intersected with the current clipping region
478 virtual void Clip( const wxRegion
®ion
) = 0;
480 // clips drawings to the rect intersected with the current clipping region
481 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
483 // resets the clipping to original extent
484 virtual void ResetClip() = 0;
486 // returns the native context
487 virtual void * GetNativeContext() = 0;
489 // returns the current shape antialiasing mode
490 virtual wxAntialiasMode
GetAntialiasMode() const { return m_antialias
; }
492 // sets the antialiasing mode, returns true if it supported
493 virtual bool SetAntialiasMode(wxAntialiasMode antialias
) = 0;
495 // returns the current compositing operator
496 virtual wxCompositionMode
GetCompositionMode() const { return m_composition
; }
498 // sets the compositing operator, returns true if it supported
499 virtual bool SetCompositionMode(wxCompositionMode op
) = 0;
501 // returns the size of the graphics context in device coordinates
502 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
504 // returns the resolution of the graphics context in device points per inch
505 virtual void GetDPI( wxDouble
* dpiX
, wxDouble
* dpiY
);
508 // sets the current alpha on this context
509 virtual void SetAlpha( wxDouble alpha
);
511 // returns the alpha on this context
512 virtual wxDouble
GetAlpha() const;
515 // all rendering is done into a fully transparent temporary context
516 virtual void BeginLayer(wxDouble opacity
) = 0;
518 // composites back the drawings into the context with the opacity given at
519 // the BeginLayer call
520 virtual void EndLayer() = 0;
523 // transformation : changes the current transformation matrix CTM of the context
527 virtual void Translate( wxDouble dx
, wxDouble dy
) = 0;
530 virtual void Scale( wxDouble xScale
, wxDouble yScale
) = 0;
533 virtual void Rotate( wxDouble angle
) = 0;
535 // concatenates this transform with the current transform of this context
536 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
) = 0;
538 // sets the transform of this context
539 virtual void SetTransform( const wxGraphicsMatrix
& matrix
) = 0;
541 // gets the matrix of this context
542 virtual wxGraphicsMatrix
GetTransform() const = 0;
548 virtual void SetPen( const wxGraphicsPen
& pen
);
550 void SetPen( const wxPen
& pen
);
552 // sets the brush for filling
553 virtual void SetBrush( const wxGraphicsBrush
& brush
);
555 void SetBrush( const wxBrush
& brush
);
558 virtual void SetFont( const wxGraphicsFont
& font
);
560 void SetFont( const wxFont
& font
, const wxColour
& colour
);
563 // strokes along a path with the current pen
564 virtual void StrokePath( const wxGraphicsPath
& path
) = 0;
566 // fills a path with the current brush
567 virtual void FillPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) = 0;
569 // draws a path by first filling and then stroking
570 virtual void DrawPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
576 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
577 { DoDrawText(str
, x
, y
); }
579 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
580 { DoDrawRotatedText(str
, x
, y
, angle
); }
582 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
,
583 const wxGraphicsBrush
& backgroundBrush
)
584 { DoDrawFilledText(str
, x
, y
, backgroundBrush
); }
586 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
,
587 wxDouble angle
, const wxGraphicsBrush
& backgroundBrush
)
588 { DoDrawRotatedFilledText(str
, x
, y
, angle
, backgroundBrush
); }
591 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
592 wxDouble
*descent
= NULL
, wxDouble
*externalLeading
= NULL
) const = 0;
594 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const = 0;
600 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
602 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
604 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
607 // convenience methods
610 // strokes a single line
611 virtual void StrokeLine( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
613 // stroke lines connecting each of the points
614 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
616 // stroke disconnected lines from begin to end points
617 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*beginPoints
, const wxPoint2DDouble
*endPoints
);
620 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
623 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
626 virtual void DrawEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
628 // draws a rounded rectangle
629 virtual void DrawRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
631 // wrappers using wxPoint2DDouble TODO
633 // helper to determine if a 0.5 offset should be applied for the drawing operation
634 virtual bool ShouldOffset() const { return false; }
639 wxGraphicsBrush m_brush
;
640 wxGraphicsFont m_font
;
641 wxAntialiasMode m_antialias
;
642 wxCompositionMode m_composition
;
645 // implementations of overloaded public functions: we use different names
646 // for them to avoid the virtual function hiding problems in the derived
648 virtual void DoDrawText(const wxString
& str
, wxDouble x
, wxDouble y
) = 0;
649 virtual void DoDrawRotatedText(const wxString
& str
, wxDouble x
, wxDouble y
,
651 virtual void DoDrawFilledText(const wxString
& str
, wxDouble x
, wxDouble y
,
652 const wxGraphicsBrush
& backgroundBrush
);
653 virtual void DoDrawRotatedFilledText(const wxString
& str
,
654 wxDouble x
, wxDouble y
,
656 const wxGraphicsBrush
& backgroundBrush
);
658 wxDECLARE_NO_COPY_CLASS(wxGraphicsContext
);
659 DECLARE_ABSTRACT_CLASS(wxGraphicsContext
)
665 // A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements
668 class WXDLLIMPEXP_CORE wxGraphicsFigure
: public wxGraphicsObject
671 wxGraphicsFigure(wxGraphicsRenderer
* renderer
);
673 virtual ~wxGraphicsFigure();
675 void SetPath( wxGraphicsMatrix
* matrix
);
677 void SetMatrix( wxGraphicsPath
* path
);
679 // draws this object on the context
680 virtual void Draw( wxGraphicsContext
* cg
);
682 // returns the path of this object
683 wxGraphicsPath
* GetPath() { return m_path
; }
685 // returns the transformation matrix of this object, may be null if there is no transformation necessary
686 wxGraphicsMatrix
* GetMatrix() { return m_matrix
; }
689 wxGraphicsMatrix
* m_matrix
;
690 wxGraphicsPath
* m_path
;
692 DECLARE_DYNAMIC_CLASS(wxGraphicsFigure
)
698 // The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer
699 // instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional
700 // paths at any point from a given matrix etc.
703 class WXDLLIMPEXP_CORE wxGraphicsRenderer
: public wxObject
706 wxGraphicsRenderer() {}
708 virtual ~wxGraphicsRenderer() {}
710 static wxGraphicsRenderer
* GetDefaultRenderer();
712 static wxGraphicsRenderer
* GetCairoRenderer();
715 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
) = 0;
716 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
) = 0;
717 #if wxUSE_PRINTING_ARCHITECTURE
718 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
) = 0;
720 #if wxUSE_ENH_METAFILE
721 virtual wxGraphicsContext
* CreateContext( const wxEnhMetaFileDC
& dc
) = 0;
724 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
) = 0;
726 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
) = 0;
728 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
) = 0;
730 // create a context that can be used for measuring texts only, no drawing allowed
731 virtual wxGraphicsContext
* CreateMeasuringContext() = 0;
735 virtual wxGraphicsPath
CreatePath() = 0;
739 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
740 wxDouble tx
=0.0, wxDouble ty
=0.0) = 0;
744 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) = 0;
746 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) = 0;
748 // Gradient brush creation functions may not honour all the stops specified
749 // stops and use just its boundary colours (this is currently the case
751 virtual wxGraphicsBrush
752 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
753 wxDouble x2
, wxDouble y2
,
754 const wxGraphicsGradientStops
& stops
) = 0;
756 virtual wxGraphicsBrush
757 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
758 wxDouble xc
, wxDouble yc
,
760 const wxGraphicsGradientStops
& stops
) = 0;
763 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) = 0;
765 // create a native bitmap representation
766 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) = 0;
768 // create a graphics bitmap from a native bitmap
769 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
) = 0;
771 // create a subimage from a native image representation
772 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
775 wxDECLARE_NO_COPY_CLASS(wxGraphicsRenderer
);
776 DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer
)
781 #endif // _WX_GRAPHICS_H_