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_
15 #if wxUSE_GRAPHICS_CONTEXT
17 #include "wx/geometry.h"
18 #include "wx/dynarray.h"
20 class WXDLLEXPORT wxWindowDC
;
23 * notes about the graphics context apis
25 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
26 * in direction of positive y axis.
29 class WXDLLEXPORT wxGraphicsPath
: public wxObject
33 virtual ~wxGraphicsPath() {}
36 // These are the path primitives from which everything else can be constructed
39 // begins a new subpath at (x,y)
40 virtual void MoveToPoint( wxDouble x
, wxDouble y
) = 0;
42 // adds a straight line from the current point to (x,y)
43 virtual void AddLineToPoint( wxDouble x
, wxDouble y
) = 0;
45 // adds a cubic Bezier curve from the current point, using two control points and an end point
46 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
) = 0;
48 // closes the current sub-path
49 virtual void CloseSubpath() = 0;
51 // gets the last point of the current path, (0,0) if not yet set
52 virtual void GetCurrentPoint( wxDouble
& x
, wxDouble
&y
) = 0;
54 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
55 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) = 0;
58 // These are convenience functions which - if not available natively will be assembled
59 // using the primitives from above
62 // adds a quadratic Bezier curve from the current point, using a control point and an end point
63 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
65 // appends a rectangle as a new closed subpath
66 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
68 // appends an ellipsis as a new closed subpath fitting the passed rectangle
69 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
71 // draws 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)
72 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
) ;
74 // wrappers using wxPoint2DDoubles
76 wxPoint2DDouble
GetCurrentPoint();
78 void MoveToPoint( const wxPoint2DDouble
& p
);
80 void AddLineToPoint( const wxPoint2DDouble
& p
);
82 void AddCurveToPoint( const wxPoint2DDouble
& c1
, const wxPoint2DDouble
& c2
, const wxPoint2DDouble
& e
);
84 void AddArc( const wxPoint2DDouble
& c
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
87 // returns the native path
88 virtual void * GetNativePath() = 0;
90 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
91 virtual void UnGetNativePath(void *p) = 0;
94 DECLARE_NO_COPY_CLASS(wxGraphicsPath
)
95 DECLARE_ABSTRACT_CLASS(wxGraphicsPath
)
99 class WXDLLEXPORT wxGraphicsMatrix
102 wxGraphicsMatrix() {}
104 virtual ~wxGraphicsMatrix() {}
106 wxGraphicsMatrix* Concat( const wxGraphicsMatrix *t ) const;
108 // returns the inverse matrix
109 wxGraphicsMatrix* Invert() const;
111 // returns true if the elements of the transformation matrix are equal ?
112 bool operator==(const wxGraphicsMatrix& t) const;
114 // return true if this is the identity matrix
122 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
125 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
128 virtual void Rotate( wxDouble angle ) = 0;
132 class WXDLLEXPORT wxGraphicsContext
: public wxObject
135 wxGraphicsContext() {}
137 virtual ~wxGraphicsContext() {}
139 static wxGraphicsContext
* Create( const wxWindowDC
& dc
) ;
141 static wxGraphicsContext
* CreateFromNative( void * context
) ;
144 static wxGraphicsContext
* CreateFromNativeWindow( void * window
) ;
146 static wxGraphicsContext
* Create( wxWindow
* window
) ;
148 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
149 virtual wxGraphicsPath
* CreatePath() = 0;
152 // create a 'native' matrix corresponding to these values
153 virtual wxGraphicsMatrix* CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
154 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
157 // push the current state of the context, ie the transformation matrix on a stack
158 virtual void PushState() = 0;
160 // pops a stored state from the stack
161 virtual void PopState() = 0;
163 // clips drawings to the region, combined to current clipping region
164 virtual void Clip( const wxRegion
®ion
) = 0;
166 // clips drawings to the rect
167 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
169 // resets the clipping to original extent
170 virtual void ResetClip() = 0 ;
172 // returns the native context
173 virtual void * GetNativeContext() = 0;
176 // transformation : changes the current transformation matrix CTM of the context
180 virtual void Translate( wxDouble dx
, wxDouble dy
) = 0;
183 virtual void Scale( wxDouble xScale
, wxDouble yScale
) = 0;
186 virtual void Rotate( wxDouble angle
) = 0;
193 virtual void SetPen( const wxPen
&pen
) = 0;
195 // sets the brush for filling
196 virtual void SetBrush( const wxBrush
&brush
) = 0;
198 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
199 virtual void SetLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
200 const wxColour
&c1
, const wxColour
&c2
) = 0;
202 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
203 // with radius r and color cColor
204 virtual void SetRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
205 const wxColour
&oColor
, const wxColour
&cColor
) = 0;
208 virtual void SetFont( const wxFont
&font
) = 0;
210 // sets the text color
211 virtual void SetTextColor( const wxColour
&col
) = 0;
213 // strokes along a path with the current pen
214 virtual void StrokePath( const wxGraphicsPath
*path
) = 0;
216 // fills a path with the current brush
217 virtual void FillPath( const wxGraphicsPath
*path
, int fillStyle
= wxWINDING_RULE
) = 0;
219 // draws a path by first filling and then stroking
220 virtual void DrawPath( const wxGraphicsPath
*path
, int fillStyle
= wxWINDING_RULE
);
226 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
) = 0;
228 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
230 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
231 wxDouble
*descent
, wxDouble
*externalLeading
) const = 0;
233 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const = 0;
239 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
241 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
244 // convenience methods
247 // strokes a single line
248 virtual void StrokeLine( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
250 // stroke lines connecting each of the points
251 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
253 // stroke disconnected lines from begin to end points
254 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*beginPoints
, const wxPoint2DDouble
*endPoints
);
257 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, int fillStyle
= wxWINDING_RULE
);
260 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
263 virtual void DrawEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
265 // draws a rounded rectangle
266 virtual void DrawRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
268 // wrappers using wxPoint2DDouble TODO
270 DECLARE_NO_COPY_CLASS(wxGraphicsContext
)
271 DECLARE_ABSTRACT_CLASS(wxGraphicsContext
)
276 #endif // _WX_GRAPHICS_H_