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 wxInterpolationQuality
32 // default interpolation
33 wxINTERPOLATION_DEFAULT
,
36 // fast interpolation, suited for interactivity
40 // best quality, not suited for interactivity
44 enum wxCompositionMode
46 // R = Result, S = Source, D = Destination, premultiplied with alpha
47 // Ra, Sa, Da their alpha components
49 // classic Porter-Duff compositions
50 // http://keithp.com/~keithp/porterduff/p253-porter.pdf
52 wxCOMPOSITION_CLEAR
, /* R = 0 */
53 wxCOMPOSITION_SOURCE
, /* R = S */
54 wxCOMPOSITION_OVER
, /* R = S + D*(1 - Sa) */
55 wxCOMPOSITION_IN
, /* R = S*Da */
56 wxCOMPOSITION_OUT
, /* R = S*(1 - Da) */
57 wxCOMPOSITION_ATOP
, /* R = S*Da + D*(1 - Sa) */
59 wxCOMPOSITION_DEST
, /* R = D, essentially a noop */
60 wxCOMPOSITION_DEST_OVER
, /* R = S*(1 - Da) + D */
61 wxCOMPOSITION_DEST_IN
, /* R = D*Sa */
62 wxCOMPOSITION_DEST_OUT
, /* R = D*(1 - Sa) */
63 wxCOMPOSITION_DEST_ATOP
, /* R = S*(1 - Da) + D*Sa */
64 wxCOMPOSITION_XOR
, /* R = S*(1 - Da) + D*(1 - Sa) */
66 // mathematical compositions
67 wxCOMPOSITION_ADD
, /* R = S + D */
70 class WXDLLIMPEXP_FWD_CORE wxWindowDC
;
71 class WXDLLIMPEXP_FWD_CORE wxMemoryDC
;
72 #if wxUSE_PRINTING_ARCHITECTURE
73 class WXDLLIMPEXP_FWD_CORE wxPrinterDC
;
76 #if wxUSE_ENH_METAFILE
77 class WXDLLIMPEXP_FWD_CORE wxEnhMetaFileDC
;
80 class WXDLLIMPEXP_FWD_CORE wxGraphicsContext
;
81 class WXDLLIMPEXP_FWD_CORE wxGraphicsPath
;
82 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix
;
83 class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure
;
84 class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer
;
85 class WXDLLIMPEXP_FWD_CORE wxGraphicsPen
;
86 class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush
;
87 class WXDLLIMPEXP_FWD_CORE wxGraphicsFont
;
88 class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap
;
91 * notes about the graphics context apis
93 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
94 * in direction of positive y axis.
97 // Base class of all objects used for drawing in the new graphics API, the always point back to their
98 // originating rendering engine, there is no dynamic unloading of a renderer currently allowed,
99 // these references are not counted
102 // The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive
103 // duplication. Any operation on a shared instance that results in a modified state, uncouples this
104 // instance from the other instances that were shared - using copy on write semantics
107 class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData
;
108 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData
;
109 class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData
;
111 class WXDLLIMPEXP_CORE wxGraphicsObject
: public wxObject
115 wxGraphicsObject( wxGraphicsRenderer
* renderer
);
116 virtual ~wxGraphicsObject();
120 // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
121 wxGraphicsRenderer
* GetRenderer() const;
122 wxGraphicsObjectRefData
* GetGraphicsData() const;
124 virtual wxObjectRefData
* CreateRefData() const;
125 virtual wxObjectRefData
* CloneRefData(const wxObjectRefData
* data
) const;
127 DECLARE_DYNAMIC_CLASS(wxGraphicsObject
)
130 class WXDLLIMPEXP_CORE wxGraphicsPen
: public wxGraphicsObject
134 virtual ~wxGraphicsPen() {}
136 DECLARE_DYNAMIC_CLASS(wxGraphicsPen
)
139 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen
) wxNullGraphicsPen
;
141 class WXDLLIMPEXP_CORE wxGraphicsBrush
: public wxGraphicsObject
145 virtual ~wxGraphicsBrush() {}
147 DECLARE_DYNAMIC_CLASS(wxGraphicsBrush
)
150 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush
) wxNullGraphicsBrush
;
152 class WXDLLIMPEXP_CORE wxGraphicsFont
: public wxGraphicsObject
156 virtual ~wxGraphicsFont() {}
158 DECLARE_DYNAMIC_CLASS(wxGraphicsFont
)
161 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont
) wxNullGraphicsFont
;
163 class WXDLLIMPEXP_CORE wxGraphicsBitmap
: public wxGraphicsObject
166 wxGraphicsBitmap() {}
167 virtual ~wxGraphicsBitmap() {}
169 DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap
)
172 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap
) wxNullGraphicsBitmap
;
174 class WXDLLIMPEXP_CORE wxGraphicsMatrix
: public wxGraphicsObject
177 wxGraphicsMatrix() {}
179 virtual ~wxGraphicsMatrix() {}
181 // concatenates the matrix
182 virtual void Concat( const wxGraphicsMatrix
*t
);
183 void Concat( const wxGraphicsMatrix
&t
) { Concat( &t
); }
185 // sets the matrix to the respective values
186 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
187 wxDouble tx
=0.0, wxDouble ty
=0.0);
189 // gets the component valuess of the matrix
190 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
191 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
193 // makes this the inverse matrix
194 virtual void Invert();
196 // returns true if the elements of the transformation matrix are equal ?
197 virtual bool IsEqual( const wxGraphicsMatrix
* t
) const;
198 bool IsEqual( const wxGraphicsMatrix
& t
) const { return IsEqual( &t
); }
200 // return true if this is the identity matrix
201 virtual bool IsIdentity() const;
207 // add the translation to this matrix
208 virtual void Translate( wxDouble dx
, wxDouble dy
);
210 // add the scale to this matrix
211 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
213 // add the rotation to this matrix (radians)
214 virtual void Rotate( wxDouble angle
);
217 // apply the transforms
220 // applies that matrix to the point
221 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
223 // applies the matrix except for translations
224 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
226 // returns the native representation
227 virtual void * GetNativeMatrix() const;
229 const wxGraphicsMatrixData
* GetMatrixData() const
230 { return (const wxGraphicsMatrixData
*) GetRefData(); }
231 wxGraphicsMatrixData
* GetMatrixData()
232 { return (wxGraphicsMatrixData
*) GetRefData(); }
235 DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix
)
238 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix
) wxNullGraphicsMatrix
;
240 class WXDLLIMPEXP_CORE wxGraphicsPath
: public wxGraphicsObject
244 virtual ~wxGraphicsPath() {}
247 // These are the path primitives from which everything else can be constructed
250 // begins a new subpath at (x,y)
251 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
252 void MoveToPoint( const wxPoint2DDouble
& p
);
254 // adds a straight line from the current point to (x,y)
255 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
256 void AddLineToPoint( const wxPoint2DDouble
& p
);
258 // adds a cubic Bezier curve from the current point, using two control points and an end point
259 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
260 void AddCurveToPoint( const wxPoint2DDouble
& c1
, const wxPoint2DDouble
& c2
, const wxPoint2DDouble
& e
);
263 virtual void AddPath( const wxGraphicsPath
& path
);
265 // closes the current sub-path
266 virtual void CloseSubpath();
268 // gets the last point of the current path, (0,0) if not yet set
269 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
270 wxPoint2DDouble
GetCurrentPoint() const;
272 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
273 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
274 void AddArc( const wxPoint2DDouble
& c
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
277 // These are convenience functions which - if not available natively will be assembled
278 // using the primitives from above
281 // adds a quadratic Bezier curve from the current point, using a control point and an end point
282 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
284 // appends a rectangle as a new closed subpath
285 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
287 // appends an ellipsis as a new closed subpath fitting the passed rectangle
288 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
290 // 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)
291 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
293 // appends an ellipse
294 virtual void AddEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
296 // appends a rounded rectangle
297 virtual void AddRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
299 // returns the native path
300 virtual void * GetNativePath() const;
302 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
303 virtual void UnGetNativePath(void *p
)const;
305 // transforms each point of this path by the matrix
306 virtual void Transform( const wxGraphicsMatrix
& matrix
);
308 // gets the bounding box enclosing all points (possibly including control points)
309 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
)const;
310 wxRect2DDouble
GetBox()const;
312 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)const;
313 bool Contains( const wxPoint2DDouble
& c
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)const;
315 const wxGraphicsPathData
* GetPathData() const
316 { return (const wxGraphicsPathData
*) GetRefData(); }
317 wxGraphicsPathData
* GetPathData()
318 { return (wxGraphicsPathData
*) GetRefData(); }
321 DECLARE_DYNAMIC_CLASS(wxGraphicsPath
)
324 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPath
) wxNullGraphicsPath
;
327 // Describes a single gradient stop.
328 class wxGraphicsGradientStop
331 wxGraphicsGradientStop(wxColour col
= wxTransparentColour
,
338 // default copy ctor, assignment operator and dtor are ok
340 const wxColour
& GetColour() const { return m_col
; }
341 void SetColour(const wxColour
& col
) { m_col
= col
; }
343 float GetPosition() const { return m_pos
; }
344 void SetPosition(float pos
)
346 wxASSERT_MSG( pos
>= 0 && pos
<= 1, "invalid gradient stop position" );
352 // The colour of this gradient band.
355 // Its starting position: 0 is the beginning and 1 is the end.
359 // A collection of gradient stops ordered by their positions (from lowest to
360 // highest). The first stop (index 0, position 0.0) is always the starting
361 // colour and the last one (index GetCount() - 1, position 1.0) is the end
363 class WXDLLIMPEXP_CORE wxGraphicsGradientStops
366 wxGraphicsGradientStops(wxColour startCol
= wxTransparentColour
,
367 wxColour endCol
= wxTransparentColour
)
369 // we can't use Add() here as it relies on having start/end stops as
370 // first/last array elements so do it manually
371 m_stops
.push_back(wxGraphicsGradientStop(startCol
, 0.f
));
372 m_stops
.push_back(wxGraphicsGradientStop(endCol
, 1.f
));
375 // default copy ctor, assignment operator and dtor are ok for this class
378 // Add a stop in correct order.
379 void Add(const wxGraphicsGradientStop
& stop
);
380 void Add(wxColour col
, float pos
) { Add(wxGraphicsGradientStop(col
, pos
)); }
382 // Get the number of stops.
383 unsigned GetCount() const { return m_stops
.size(); }
385 // Return the stop at the given index (which must be valid).
386 wxGraphicsGradientStop
Item(unsigned n
) const { return m_stops
.at(n
); }
388 // Get/set start and end colours.
389 void SetStartColour(wxColour col
)
390 { m_stops
[0].SetColour(col
); }
391 wxColour
GetStartColour() const
392 { return m_stops
[0].GetColour(); }
393 void SetEndColour(wxColour col
)
394 { m_stops
[m_stops
.size() - 1].SetColour(col
); }
395 wxColour
GetEndColour() const
396 { return m_stops
[m_stops
.size() - 1].GetColour(); }
399 // All the stops stored in ascending order of positions.
400 wxVector
<wxGraphicsGradientStop
> m_stops
;
403 class WXDLLIMPEXP_CORE wxGraphicsContext
: public wxGraphicsObject
406 wxGraphicsContext(wxGraphicsRenderer
* renderer
);
408 virtual ~wxGraphicsContext();
410 static wxGraphicsContext
* Create( const wxWindowDC
& dc
);
411 static wxGraphicsContext
* Create( const wxMemoryDC
& dc
);
412 #if wxUSE_PRINTING_ARCHITECTURE
413 static wxGraphicsContext
* Create( const wxPrinterDC
& dc
);
416 #if wxUSE_ENH_METAFILE
417 static wxGraphicsContext
* Create( const wxEnhMetaFileDC
& dc
);
421 static wxGraphicsContext
* CreateFromNative( void * context
);
423 static wxGraphicsContext
* CreateFromNativeWindow( void * window
);
425 static wxGraphicsContext
* Create( wxWindow
* window
);
427 // create a context that can be used for measuring texts only, no drawing allowed
428 static wxGraphicsContext
* Create();
430 // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown
431 virtual bool StartDoc( const wxString
& message
);
433 // done with that document (relevant only for printing / pdf etc)
434 virtual void EndDoc();
436 // opens a new page (relevant only for printing / pdf etc) with the given size in points
437 // (if both are null the default page size will be used)
438 virtual void StartPage( wxDouble width
= 0, wxDouble height
= 0 );
440 // ends the current page (relevant only for printing / pdf etc)
441 virtual void EndPage();
443 // make sure that the current content of this context is immediately visible
444 virtual void Flush();
446 wxGraphicsPath
CreatePath() const;
448 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) const;
450 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) const;
452 // sets the brush to a linear gradient, starting at (x1,y1) and ending at
453 // (x2,y2) with the given boundary colours or the specified stops
455 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
456 wxDouble x2
, wxDouble y2
,
457 const wxColour
& c1
, const wxColour
& c2
) const;
459 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
460 wxDouble x2
, wxDouble y2
,
461 const wxGraphicsGradientStops
& stops
) const;
463 // sets the brush to a radial gradient originating at (xo,yc) and ending
464 // on a circle around (xc,yc) with the given radius; the colours may be
465 // specified by just the two extremes or the full array of gradient stops
467 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
468 wxDouble xc
, wxDouble yc
, wxDouble radius
,
469 const wxColour
& oColor
, const wxColour
& cColor
) const;
472 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
473 wxDouble xc
, wxDouble yc
, wxDouble radius
,
474 const wxGraphicsGradientStops
& stops
) const;
477 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) const;
479 // create a native bitmap representation
480 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) const;
482 // create a native bitmap representation
483 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) const;
485 // create a 'native' matrix corresponding to these values
486 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
487 wxDouble tx
=0.0, wxDouble ty
=0.0) const;
489 // push the current state of the context, ie the transformation matrix on a stack
490 virtual void PushState() = 0;
492 // pops a stored state from the stack
493 virtual void PopState() = 0;
495 // clips drawings to the region intersected with the current clipping region
496 virtual void Clip( const wxRegion
®ion
) = 0;
498 // clips drawings to the rect intersected with the current clipping region
499 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
501 // resets the clipping to original extent
502 virtual void ResetClip() = 0;
504 // returns the native context
505 virtual void * GetNativeContext() = 0;
507 // returns the current shape antialiasing mode
508 virtual wxAntialiasMode
GetAntialiasMode() const { return m_antialias
; }
510 // sets the antialiasing mode, returns true if it supported
511 virtual bool SetAntialiasMode(wxAntialiasMode antialias
) = 0;
513 // returns the current interpolation quality
514 virtual wxInterpolationQuality
GetInterpolationQuality() const { return m_interpolation
; }
516 // sets the interpolation quality, returns true if it supported
517 virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation
) = 0;
519 // returns the current compositing operator
520 virtual wxCompositionMode
GetCompositionMode() const { return m_composition
; }
522 // sets the compositing operator, returns true if it supported
523 virtual bool SetCompositionMode(wxCompositionMode op
) = 0;
525 // returns the size of the graphics context in device coordinates
526 void GetSize(wxDouble
* width
, wxDouble
* height
)
534 // returns the resolution of the graphics context in device points per inch
535 virtual void GetDPI( wxDouble
* dpiX
, wxDouble
* dpiY
);
538 // sets the current alpha on this context
539 virtual void SetAlpha( wxDouble alpha
);
541 // returns the alpha on this context
542 virtual wxDouble
GetAlpha() const;
545 // all rendering is done into a fully transparent temporary context
546 virtual void BeginLayer(wxDouble opacity
) = 0;
548 // composites back the drawings into the context with the opacity given at
549 // the BeginLayer call
550 virtual void EndLayer() = 0;
553 // transformation : changes the current transformation matrix CTM of the context
557 virtual void Translate( wxDouble dx
, wxDouble dy
) = 0;
560 virtual void Scale( wxDouble xScale
, wxDouble yScale
) = 0;
563 virtual void Rotate( wxDouble angle
) = 0;
565 // concatenates this transform with the current transform of this context
566 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
) = 0;
568 // sets the transform of this context
569 virtual void SetTransform( const wxGraphicsMatrix
& matrix
) = 0;
571 // gets the matrix of this context
572 virtual wxGraphicsMatrix
GetTransform() const = 0;
578 virtual void SetPen( const wxGraphicsPen
& pen
);
580 void SetPen( const wxPen
& pen
);
582 // sets the brush for filling
583 virtual void SetBrush( const wxGraphicsBrush
& brush
);
585 void SetBrush( const wxBrush
& brush
);
588 virtual void SetFont( const wxGraphicsFont
& font
);
590 void SetFont( const wxFont
& font
, const wxColour
& colour
);
593 // strokes along a path with the current pen
594 virtual void StrokePath( const wxGraphicsPath
& path
) = 0;
596 // fills a path with the current brush
597 virtual void FillPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) = 0;
599 // draws a path by first filling and then stroking
600 virtual void DrawPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
606 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
607 { DoDrawText(str
, x
, y
); }
609 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
610 { DoDrawRotatedText(str
, x
, y
, angle
); }
612 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
,
613 const wxGraphicsBrush
& backgroundBrush
)
614 { DoDrawFilledText(str
, x
, y
, backgroundBrush
); }
616 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
,
617 wxDouble angle
, const wxGraphicsBrush
& backgroundBrush
)
618 { DoDrawRotatedFilledText(str
, x
, y
, angle
, backgroundBrush
); }
621 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
622 wxDouble
*descent
= NULL
, wxDouble
*externalLeading
= NULL
) const = 0;
624 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const = 0;
630 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
632 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
634 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
637 // convenience methods
640 // strokes a single line
641 virtual void StrokeLine( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
643 // stroke lines connecting each of the points
644 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
646 // stroke disconnected lines from begin to end points
647 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*beginPoints
, const wxPoint2DDouble
*endPoints
);
650 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
653 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
656 virtual void DrawEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
658 // draws a rounded rectangle
659 virtual void DrawRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
661 // wrappers using wxPoint2DDouble TODO
663 // helper to determine if a 0.5 offset should be applied for the drawing operation
664 virtual bool ShouldOffset() const { return false; }
666 // indicates whether the context should try to offset for pixel boundaries, this only makes sense on
667 // bitmap devices like screen, by default this is turned off
668 virtual void EnableOffset(bool enable
= true);
670 void DisableOffset() { EnableOffset(false); }
671 bool OffsetEnabled() { return m_enableOffset
; }
674 // These fields must be initialized in the derived class ctors.
679 wxGraphicsBrush m_brush
;
680 wxGraphicsFont m_font
;
681 wxAntialiasMode m_antialias
;
682 wxCompositionMode m_composition
;
683 wxInterpolationQuality m_interpolation
;
687 // implementations of overloaded public functions: we use different names
688 // for them to avoid the virtual function hiding problems in the derived
690 virtual void DoDrawText(const wxString
& str
, wxDouble x
, wxDouble y
) = 0;
691 virtual void DoDrawRotatedText(const wxString
& str
, wxDouble x
, wxDouble y
,
693 virtual void DoDrawFilledText(const wxString
& str
, wxDouble x
, wxDouble y
,
694 const wxGraphicsBrush
& backgroundBrush
);
695 virtual void DoDrawRotatedFilledText(const wxString
& str
,
696 wxDouble x
, wxDouble y
,
698 const wxGraphicsBrush
& backgroundBrush
);
700 wxDECLARE_NO_COPY_CLASS(wxGraphicsContext
);
701 DECLARE_ABSTRACT_CLASS(wxGraphicsContext
)
707 // A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements
710 class WXDLLIMPEXP_CORE wxGraphicsFigure
: public wxGraphicsObject
713 wxGraphicsFigure(wxGraphicsRenderer
* renderer
);
715 virtual ~wxGraphicsFigure();
717 void SetPath( wxGraphicsMatrix
* matrix
);
719 void SetMatrix( wxGraphicsPath
* path
);
721 // draws this object on the context
722 virtual void Draw( wxGraphicsContext
* cg
);
724 // returns the path of this object
725 wxGraphicsPath
* GetPath() { return m_path
; }
727 // returns the transformation matrix of this object, may be null if there is no transformation necessary
728 wxGraphicsMatrix
* GetMatrix() { return m_matrix
; }
731 wxGraphicsMatrix
* m_matrix
;
732 wxGraphicsPath
* m_path
;
734 DECLARE_DYNAMIC_CLASS(wxGraphicsFigure
)
740 // The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer
741 // instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional
742 // paths at any point from a given matrix etc.
745 class WXDLLIMPEXP_CORE wxGraphicsRenderer
: public wxObject
748 wxGraphicsRenderer() {}
750 virtual ~wxGraphicsRenderer() {}
752 static wxGraphicsRenderer
* GetDefaultRenderer();
754 static wxGraphicsRenderer
* GetCairoRenderer();
757 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
) = 0;
758 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
) = 0;
759 #if wxUSE_PRINTING_ARCHITECTURE
760 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
) = 0;
763 #if wxUSE_ENH_METAFILE
764 virtual wxGraphicsContext
* CreateContext( const wxEnhMetaFileDC
& dc
) = 0;
768 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
) = 0;
770 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
) = 0;
772 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
) = 0;
774 // create a context that can be used for measuring texts only, no drawing allowed
775 virtual wxGraphicsContext
* CreateMeasuringContext() = 0;
779 virtual wxGraphicsPath
CreatePath() = 0;
783 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
784 wxDouble tx
=0.0, wxDouble ty
=0.0) = 0;
788 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) = 0;
790 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) = 0;
792 // Gradient brush creation functions may not honour all the stops specified
793 // stops and use just its boundary colours (this is currently the case
795 virtual wxGraphicsBrush
796 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
797 wxDouble x2
, wxDouble y2
,
798 const wxGraphicsGradientStops
& stops
) = 0;
800 virtual wxGraphicsBrush
801 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
802 wxDouble xc
, wxDouble yc
,
804 const wxGraphicsGradientStops
& stops
) = 0;
807 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) = 0;
809 // create a native bitmap representation
810 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) = 0;
812 // create a graphics bitmap from a native bitmap
813 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
) = 0;
815 // create a subimage from a native image representation
816 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
819 wxDECLARE_NO_COPY_CLASS(wxGraphicsRenderer
);
820 DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer
)
825 #endif // _WX_GRAPHICS_H_