]> git.saurik.com Git - wxWidgets.git/blob - include/wx/graphics.h
Pass the config object into the wxHtmlHelpFrame so it has the config
[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 #if wxUSE_GRAPHICS_CONTEXT
16
17 #include "wx/geometry.h"
18 #include "wx/dynarray.h"
19
20 class WXDLLEXPORT wxWindowDC;
21
22 /*
23 * notes about the graphics context apis
24 *
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.
27 */
28
29 class WXDLLEXPORT wxGraphicsPath : public wxObject
30 {
31 public :
32 wxGraphicsPath() {}
33 virtual ~wxGraphicsPath() {}
34
35 //
36 // These are the path primitives from which everything else can be constructed
37 //
38
39 // begins a new subpath at (x,y)
40 virtual void MoveToPoint( wxDouble x, wxDouble y ) = 0;
41
42 // adds a straight line from the current point to (x,y)
43 virtual void AddLineToPoint( wxDouble x, wxDouble y ) = 0;
44
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;
47
48 // closes the current sub-path
49 virtual void CloseSubpath() = 0;
50
51 // gets the last point of the current path, (0,0) if not yet set
52 virtual void GetCurrentPoint( wxDouble& x, wxDouble&y) = 0;
53
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;
56
57 //
58 // These are convenience functions which - if not available natively will be assembled
59 // using the primitives from above
60 //
61
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 );
64
65 // appends a rectangle as a new closed subpath
66 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
67
68 // appends an ellipsis as a new closed subpath fitting the passed rectangle
69 virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
70
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 ) ;
73
74 // wrappers using wxPoint2DDoubles
75
76 wxPoint2DDouble GetCurrentPoint();
77
78 void MoveToPoint( const wxPoint2DDouble& p);
79
80 void AddLineToPoint( const wxPoint2DDouble& p);
81
82 void AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e);
83
84 void AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
85
86 // returns the native path
87 virtual void * GetNativePath() const = 0;
88
89 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
90 virtual void UnGetNativePath(void *p) = 0;
91
92 DECLARE_NO_COPY_CLASS(wxGraphicsPath)
93 DECLARE_ABSTRACT_CLASS(wxGraphicsPath)
94 };
95
96 /*
97 class WXDLLEXPORT wxGraphicsMatrix
98 {
99 public :
100 wxGraphicsMatrix() {}
101
102 virtual ~wxGraphicsMatrix() {}
103
104 wxGraphicsMatrix* Concat( const wxGraphicsMatrix *t ) const;
105
106 // returns the inverse matrix
107 wxGraphicsMatrix* Invert() const;
108
109 // returns true if the elements of the transformation matrix are equal ?
110 bool operator==(const wxGraphicsMatrix& t) const;
111
112 // return true if this is the identity matrix
113 bool IsIdentity();
114
115 //
116 // transformation
117 //
118
119 // translate
120 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
121
122 // scale
123 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
124
125 // rotate (radians)
126 virtual void Rotate( wxDouble angle ) = 0;
127 } ;
128 */
129
130 class WXDLLEXPORT wxGraphicsContext : public wxObject
131 {
132 public:
133 wxGraphicsContext() {}
134
135 virtual ~wxGraphicsContext() {}
136
137 static wxGraphicsContext* Create( const wxWindowDC& dc) ;
138
139 static wxGraphicsContext* CreateFromNative( void * context ) ;
140
141 #ifdef __WXMAC__
142 static wxGraphicsContext* CreateFromNativeWindow( void * window ) ;
143 #endif
144 static wxGraphicsContext* Create( wxWindow* window ) ;
145
146 // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
147 virtual wxGraphicsPath * CreatePath() = 0;
148
149 /*
150 // create a 'native' matrix corresponding to these values
151 virtual wxGraphicsMatrix* CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
152 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
153 */
154
155 // push the current state of the context, ie the transformation matrix on a stack
156 virtual void PushState() = 0;
157
158 // pops a stored state from the stack
159 virtual void PopState() = 0;
160
161 // clips drawings to the region, combined to current clipping region
162 virtual void Clip( const wxRegion &region ) = 0;
163
164 // clips drawings to the rect
165 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
166
167 // resets the clipping to original extent
168 virtual void ResetClip() = 0 ;
169
170 // returns the native context
171 virtual void * GetNativeContext() = 0;
172
173 //
174 // transformation : changes the current transformation matrix CTM of the context
175 //
176
177 // translate
178 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
179
180 // scale
181 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
182
183 // rotate (radians)
184 virtual void Rotate( wxDouble angle ) = 0;
185
186 //
187 // setting the paint
188 //
189
190 // sets the pan
191 virtual void SetPen( const wxPen &pen ) = 0;
192
193 // sets the brush for filling
194 virtual void SetBrush( const wxBrush &brush ) = 0;
195
196 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
197 virtual void SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
198 const wxColour&c1, const wxColour&c2) = 0;
199
200 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
201 // with radius r and color cColor
202 virtual void SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
203 const wxColour &oColor, const wxColour &cColor) = 0;
204
205 // sets the font
206 virtual void SetFont( const wxFont &font ) = 0;
207
208 // sets the text color
209 virtual void SetTextColor( const wxColour &col ) = 0;
210
211 // strokes along a path with the current pen
212 virtual void StrokePath( const wxGraphicsPath *path ) = 0;
213
214 // fills a path with the current brush
215 virtual void FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ) = 0;
216
217 // draws a path by first filling and then stroking
218 virtual void DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE );
219
220 //
221 // text
222 //
223
224 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y ) = 0;
225
226 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle );
227
228 virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height,
229 wxDouble *descent, wxDouble *externalLeading ) const = 0;
230
231 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const = 0;
232
233 //
234 // image support
235 //
236
237 virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
238
239 virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
240
241 //
242 // convenience methods
243 //
244
245 // strokes a single line
246 virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2);
247
248 // stroke lines connecting each of the points
249 virtual void StrokeLines( size_t n, const wxPoint2DDouble *points);
250
251 // stroke disconnected lines from begin to end points
252 virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints);
253
254 // draws a polygon
255 virtual void DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle = wxWINDING_RULE );
256
257 // draws a polygon
258 virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
259
260 // draws an ellipse
261 virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
262
263 // draws a rounded rectangle
264 virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
265
266 // wrappers using wxPoint2DDouble TODO
267
268 DECLARE_NO_COPY_CLASS(wxGraphicsContext)
269 DECLARE_ABSTRACT_CLASS(wxGraphicsContext)
270 };
271
272 #endif
273
274 #endif // _WX_GRAPHICS_H_