]>
Commit | Line | Data |
---|---|---|
50581042 SC |
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 | ||
8acd14d1 SC |
15 | #if wxUSE_GRAPHICS_CONTEXT |
16 | ||
50581042 | 17 | #include "wx/geometry.h" |
50581042 SC |
18 | #include "wx/dynarray.h" |
19 | ||
774f4d12 SC |
20 | class WXDLLEXPORT wxWindowDC; |
21 | ||
50581042 SC |
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 | |
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); | |
774f4d12 | 85 | |
50581042 SC |
86 | DECLARE_NO_COPY_CLASS(wxGraphicsPath) |
87 | }; | |
88 | ||
774f4d12 SC |
89 | /* |
90 | class WXDLLEXPORT wxGraphicsMatrix | |
91 | { | |
92 | public : | |
93 | wxGraphicsMatrix() {} | |
94 | ||
95 | virtual ~wxGraphicsMatrix() {} | |
96 | ||
97 | wxGraphicsMatrix* Concat( const wxGraphicsMatrix *t ) const; | |
98 | ||
99 | // returns the inverse matrix | |
100 | wxGraphicsMatrix* Invert() const; | |
101 | ||
102 | // returns true if the elements of the transformation matrix are equal ? | |
103 | bool operator==(const wxGraphicsMatrix& t) const; | |
104 | ||
105 | // return true if this is the identity matrix | |
106 | bool IsIdentity(); | |
107 | ||
108 | // | |
109 | // transformation | |
110 | // | |
111 | ||
112 | // translate | |
113 | virtual void Translate( wxDouble dx , wxDouble dy ) = 0; | |
114 | ||
115 | // scale | |
116 | virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0; | |
117 | ||
118 | // rotate (radians) | |
119 | virtual void Rotate( wxDouble angle ) = 0; | |
120 | } ; | |
121 | */ | |
122 | ||
50581042 SC |
123 | class WXDLLEXPORT wxGraphicsContext |
124 | { | |
125 | public: | |
126 | wxGraphicsContext() {} | |
774f4d12 | 127 | |
50581042 SC |
128 | virtual ~wxGraphicsContext() {} |
129 | ||
130 | static wxGraphicsContext* Create( const wxWindowDC& dc) ; | |
774f4d12 | 131 | |
bf2185eb | 132 | static wxGraphicsContext* CreateFromNative( void * context ) ; |
774f4d12 | 133 | |
bf2185eb SC |
134 | #ifdef __WXMAC__ |
135 | static wxGraphicsContext* CreateFromNativeWindow( void * window ) ; | |
136 | #endif | |
774f4d12 | 137 | static wxGraphicsContext* Create( wxWindow* window ) ; |
50581042 SC |
138 | |
139 | // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ... | |
140 | virtual wxGraphicsPath * CreatePath() = 0; | |
774f4d12 SC |
141 | |
142 | /* | |
143 | // create a 'native' matrix corresponding to these values | |
144 | virtual wxGraphicsMatrix* CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, | |
145 | wxDouble tx=0.0, wxDouble ty=0.0) = 0; | |
146 | */ | |
147 | ||
50581042 SC |
148 | // push the current state of the context, ie the transformation matrix on a stack |
149 | virtual void PushState() = 0; | |
150 | ||
151 | // pops a stored state from the stack | |
152 | virtual void PopState() = 0; | |
153 | ||
774f4d12 | 154 | // clips drawings to the region, combined to current clipping region |
50581042 SC |
155 | virtual void Clip( const wxRegion ®ion ) = 0; |
156 | ||
774f4d12 SC |
157 | // clips drawings to the rect |
158 | virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; | |
159 | ||
160 | // resets the clipping to original extent | |
161 | virtual void ResetClip() = 0 ; | |
162 | ||
163 | // returns the native context | |
164 | virtual void * GetNativeContext() = 0; | |
165 | ||
50581042 | 166 | // |
774f4d12 | 167 | // transformation : changes the current transformation matrix CTM of the context |
50581042 SC |
168 | // |
169 | ||
170 | // translate | |
171 | virtual void Translate( wxDouble dx , wxDouble dy ) = 0; | |
172 | ||
173 | // scale | |
174 | virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0; | |
175 | ||
176 | // rotate (radians) | |
177 | virtual void Rotate( wxDouble angle ) = 0; | |
178 | ||
179 | // | |
180 | // setting the paint | |
181 | // | |
182 | ||
183 | // sets the pan | |
184 | virtual void SetPen( const wxPen &pen ) = 0; | |
185 | ||
186 | // sets the brush for filling | |
187 | virtual void SetBrush( const wxBrush &brush ) = 0; | |
188 | ||
189 | // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2 | |
190 | virtual void SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, | |
191 | const wxColour&c1, const wxColour&c2) = 0; | |
192 | ||
193 | // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc) | |
194 | // with radius r and color cColor | |
195 | virtual void SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, | |
196 | const wxColour &oColor, const wxColour &cColor) = 0; | |
197 | ||
198 | // sets the font | |
199 | virtual void SetFont( const wxFont &font ) = 0; | |
200 | ||
201 | // sets the text color | |
202 | virtual void SetTextColor( const wxColour &col ) = 0; | |
203 | ||
204 | // strokes along a path with the current pen | |
205 | virtual void StrokePath( const wxGraphicsPath *path ) = 0; | |
206 | ||
207 | // fills a path with the current brush | |
208 | virtual void FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ) = 0; | |
209 | ||
210 | // draws a path by first filling and then stroking | |
211 | virtual void DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ); | |
774f4d12 | 212 | |
50581042 SC |
213 | // |
214 | // text | |
215 | // | |
216 | ||
217 | virtual void DrawText( const wxString &str, wxDouble x, wxDouble y ) = 0; | |
218 | ||
219 | virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ); | |
220 | ||
221 | virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height, | |
222 | wxDouble *descent, wxDouble *externalLeading ) const = 0; | |
223 | ||
224 | virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const = 0; | |
225 | ||
226 | // | |
227 | // image support | |
228 | // | |
229 | ||
230 | virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; | |
231 | ||
232 | virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; | |
233 | ||
234 | // | |
235 | // convenience methods | |
236 | // | |
237 | ||
238 | // strokes a single line | |
239 | virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2); | |
240 | ||
241 | // stroke lines connecting each of the points | |
242 | virtual void StrokeLines( size_t n, const wxPoint2DDouble *points); | |
243 | ||
244 | // stroke disconnected lines from begin to end points | |
245 | virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints); | |
246 | ||
247 | // draws a polygon | |
248 | virtual void DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle = wxWINDING_RULE ); | |
249 | ||
250 | // draws a polygon | |
251 | virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h); | |
252 | ||
253 | // draws an ellipse | |
254 | virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h); | |
255 | ||
256 | // draws a rounded rectangle | |
257 | virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius); | |
258 | ||
259 | // wrappers using wxPoint2DDouble TODO | |
260 | ||
261 | DECLARE_NO_COPY_CLASS(wxGraphicsContext) | |
262 | }; | |
263 | ||
774f4d12 | 264 | #endif |
50581042 | 265 | |
8acd14d1 | 266 | #endif // _WX_GRAPHICS_H_ |