]>
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 | ||
15 | #if wxMAC_USE_CORE_GRAPHICS | |
16 | #undef wxUSE_GRAPHICS_CONTEXT | |
17 | #define wxUSE_GRAPHICS_CONTEXT 1 | |
18 | #endif | |
19 | ||
20 | #ifndef wxUSE_GRAPHICS_CONTEXT | |
21 | #define wxUSE_GRAPHICS_CONTEXT 0 | |
22 | #endif | |
23 | ||
24 | #if wxUSE_GRAPHICS_CONTEXT | |
25 | ||
26 | // --------------------------------------------------------------------------- | |
27 | // macros | |
28 | // --------------------------------------------------------------------------- | |
29 | ||
30 | #include "wx/geometry.h" | |
31 | #include "wx/dcclient.h" | |
32 | #include "wx/dynarray.h" | |
33 | ||
34 | /* | |
35 | * notes about the graphics context apis | |
36 | * | |
37 | * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being | |
38 | * in direction of positive y axis. | |
39 | */ | |
40 | ||
41 | class WXDLLEXPORT wxGraphicsPath | |
42 | { | |
43 | public : | |
44 | wxGraphicsPath() {} | |
45 | virtual ~wxGraphicsPath() {} | |
46 | ||
47 | // | |
48 | // These are the path primitives from which everything else can be constructed | |
49 | // | |
50 | ||
51 | // begins a new subpath at (x,y) | |
52 | virtual void MoveToPoint( wxDouble x, wxDouble y ) = 0; | |
53 | ||
54 | // adds a straight line from the current point to (x,y) | |
55 | virtual void AddLineToPoint( wxDouble x, wxDouble y ) = 0; | |
56 | ||
57 | // adds a cubic Bezier curve from the current point, using two control points and an end point | |
58 | virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) = 0; | |
59 | ||
60 | // closes the current sub-path | |
61 | virtual void CloseSubpath() = 0; | |
62 | ||
63 | // gets the last point of the current path, (0,0) if not yet set | |
64 | virtual void GetCurrentPoint( wxDouble& x, wxDouble&y) = 0; | |
65 | ||
66 | // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle | |
67 | virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) = 0; | |
68 | ||
69 | // | |
70 | // These are convenience functions which - if not available natively will be assembled | |
71 | // using the primitives from above | |
72 | // | |
73 | ||
74 | // adds a quadratic Bezier curve from the current point, using a control point and an end point | |
75 | virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ); | |
76 | ||
77 | // appends a rectangle as a new closed subpath | |
78 | virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ); | |
79 | ||
80 | // appends an ellipsis as a new closed subpath fitting the passed rectangle | |
81 | virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r ); | |
82 | ||
83 | // 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) | |
84 | virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ; | |
85 | ||
86 | // wrappers using wxPoint2DDoubles | |
87 | ||
88 | wxPoint2DDouble GetCurrentPoint(); | |
89 | ||
90 | void MoveToPoint( const wxPoint2DDouble& p); | |
91 | ||
92 | void AddLineToPoint( const wxPoint2DDouble& p); | |
93 | ||
94 | void AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e); | |
95 | ||
96 | void AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise); | |
97 | ||
98 | DECLARE_NO_COPY_CLASS(wxGraphicsPath) | |
99 | }; | |
100 | ||
101 | class WXDLLEXPORT wxGraphicsContext | |
102 | { | |
103 | public: | |
104 | wxGraphicsContext() {} | |
105 | virtual ~wxGraphicsContext() {} | |
106 | ||
107 | static wxGraphicsContext* Create( const wxWindowDC& dc) ; | |
108 | ||
109 | // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ... | |
110 | virtual wxGraphicsPath * CreatePath() = 0; | |
111 | ||
112 | // push the current state of the context, ie the transformation matrix on a stack | |
113 | virtual void PushState() = 0; | |
114 | ||
115 | // pops a stored state from the stack | |
116 | virtual void PopState() = 0; | |
117 | ||
118 | // clips drawings to the region | |
119 | virtual void Clip( const wxRegion ®ion ) = 0; | |
120 | ||
121 | // | |
122 | // transformation | |
123 | // | |
124 | ||
125 | // translate | |
126 | virtual void Translate( wxDouble dx , wxDouble dy ) = 0; | |
127 | ||
128 | // scale | |
129 | virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0; | |
130 | ||
131 | // rotate (radians) | |
132 | virtual void Rotate( wxDouble angle ) = 0; | |
133 | ||
134 | // | |
135 | // setting the paint | |
136 | // | |
137 | ||
138 | // sets the pan | |
139 | virtual void SetPen( const wxPen &pen ) = 0; | |
140 | ||
141 | // sets the brush for filling | |
142 | virtual void SetBrush( const wxBrush &brush ) = 0; | |
143 | ||
144 | // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2 | |
145 | virtual void SetLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, | |
146 | const wxColour&c1, const wxColour&c2) = 0; | |
147 | ||
148 | // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc) | |
149 | // with radius r and color cColor | |
150 | virtual void SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, | |
151 | const wxColour &oColor, const wxColour &cColor) = 0; | |
152 | ||
153 | // sets the font | |
154 | virtual void SetFont( const wxFont &font ) = 0; | |
155 | ||
156 | // sets the text color | |
157 | virtual void SetTextColor( const wxColour &col ) = 0; | |
158 | ||
159 | // strokes along a path with the current pen | |
160 | virtual void StrokePath( const wxGraphicsPath *path ) = 0; | |
161 | ||
162 | // fills a path with the current brush | |
163 | virtual void FillPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ) = 0; | |
164 | ||
165 | // draws a path by first filling and then stroking | |
166 | virtual void DrawPath( const wxGraphicsPath *path, int fillStyle = wxWINDING_RULE ); | |
167 | ||
168 | // | |
169 | // text | |
170 | // | |
171 | ||
172 | virtual void DrawText( const wxString &str, wxDouble x, wxDouble y ) = 0; | |
173 | ||
174 | virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ); | |
175 | ||
176 | virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height, | |
177 | wxDouble *descent, wxDouble *externalLeading ) const = 0; | |
178 | ||
179 | virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const = 0; | |
180 | ||
181 | // | |
182 | // image support | |
183 | // | |
184 | ||
185 | virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; | |
186 | ||
187 | virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; | |
188 | ||
189 | // | |
190 | // convenience methods | |
191 | // | |
192 | ||
193 | // strokes a single line | |
194 | virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2); | |
195 | ||
196 | // stroke lines connecting each of the points | |
197 | virtual void StrokeLines( size_t n, const wxPoint2DDouble *points); | |
198 | ||
199 | // stroke disconnected lines from begin to end points | |
200 | virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints); | |
201 | ||
202 | // draws a polygon | |
203 | virtual void DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle = wxWINDING_RULE ); | |
204 | ||
205 | // draws a polygon | |
206 | virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h); | |
207 | ||
208 | // draws an ellipse | |
209 | virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h); | |
210 | ||
211 | // draws a rounded rectangle | |
212 | virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius); | |
213 | ||
214 | // wrappers using wxPoint2DDouble TODO | |
215 | ||
216 | DECLARE_NO_COPY_CLASS(wxGraphicsContext) | |
217 | }; | |
218 | ||
219 | class WXDLLEXPORT wxGCDC: public wxDC | |
220 | { | |
221 | DECLARE_DYNAMIC_CLASS(wxGCDC) | |
222 | DECLARE_NO_COPY_CLASS(wxGCDC) | |
223 | ||
224 | public: | |
225 | wxGCDC(const wxWindowDC& dc); | |
226 | wxGCDC(); | |
227 | virtual ~wxGCDC(); | |
228 | ||
229 | void Init(); | |
230 | ||
231 | ||
232 | // implement base class pure virtuals | |
233 | // ---------------------------------- | |
234 | ||
235 | virtual void Clear(); | |
236 | ||
237 | virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return true; } | |
238 | virtual void EndDoc(void) {} | |
239 | ||
240 | virtual void StartPage(void) {} | |
241 | virtual void EndPage(void) {} | |
242 | ||
243 | virtual void SetFont(const wxFont& font); | |
244 | virtual void SetPen(const wxPen& pen); | |
245 | virtual void SetBrush(const wxBrush& brush); | |
246 | virtual void SetBackground(const wxBrush& brush); | |
247 | virtual void SetBackgroundMode(int mode); | |
248 | virtual void SetPalette(const wxPalette& palette); | |
249 | ||
250 | virtual void DestroyClippingRegion(); | |
251 | ||
252 | virtual wxCoord GetCharHeight() const; | |
253 | virtual wxCoord GetCharWidth() const; | |
254 | ||
255 | virtual bool CanDrawBitmap() const; | |
256 | virtual bool CanGetTextExtent() const; | |
257 | virtual int GetDepth() const; | |
258 | virtual wxSize GetPPI() const; | |
259 | ||
260 | virtual void SetMapMode(int mode); | |
261 | virtual void SetUserScale(double x, double y); | |
262 | ||
263 | virtual void SetLogicalScale(double x, double y); | |
264 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); | |
265 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); | |
266 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); | |
267 | virtual void SetLogicalFunction(int function); | |
268 | ||
269 | virtual void SetTextForeground(const wxColour& colour); | |
270 | virtual void SetTextBackground(const wxColour& colour); | |
271 | ||
272 | virtual void ComputeScaleAndOrigin(); | |
273 | ||
274 | wxGraphicsContext* GetGraphicContext() { return m_graphicContext; } | |
275 | ||
276 | protected: | |
277 | // the true implementations | |
278 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
279 | int style = wxFLOOD_SURFACE); | |
280 | ||
281 | virtual void DoGradientFillLinear(const wxRect& rect, | |
282 | const wxColour& initialColour, | |
283 | const wxColour& destColour, | |
284 | wxDirection nDirection = wxEAST); | |
285 | ||
286 | virtual void DoGradientFillConcentric(const wxRect& rect, | |
287 | const wxColour& initialColour, | |
288 | const wxColour& destColour, | |
289 | const wxPoint& circleCenter); | |
290 | ||
291 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; | |
292 | ||
293 | virtual void DoDrawPoint(wxCoord x, wxCoord y); | |
294 | ||
295 | #if wxUSE_SPLINES | |
296 | virtual void DoDrawSpline(wxList *points); | |
297 | #endif | |
298 | ||
299 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); | |
300 | ||
301 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, | |
302 | wxCoord x2, wxCoord y2, | |
303 | wxCoord xc, wxCoord yc); | |
304 | ||
305 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, | |
306 | wxCoord width, wxCoord height); | |
307 | ||
308 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
309 | double sa, double ea); | |
310 | ||
311 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
312 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
313 | wxCoord width, wxCoord height, | |
314 | double radius); | |
315 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
316 | ||
317 | virtual void DoCrossHair(wxCoord x, wxCoord y); | |
318 | ||
319 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); | |
320 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
321 | bool useMask = false); | |
322 | ||
323 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); | |
324 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, | |
325 | double angle); | |
326 | ||
327 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
328 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
329 | int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1); | |
330 | ||
331 | virtual void DoGetSize(int *,int *) const; | |
332 | virtual void DoGetSizeMM(int* width, int* height) const; | |
333 | ||
334 | virtual void DoDrawLines(int n, wxPoint points[], | |
335 | wxCoord xoffset, wxCoord yoffset); | |
336 | virtual void DoDrawPolygon(int n, wxPoint points[], | |
337 | wxCoord xoffset, wxCoord yoffset, | |
338 | int fillStyle = wxODDEVEN_RULE); | |
339 | virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], | |
340 | wxCoord xoffset, wxCoord yoffset, | |
341 | int fillStyle); | |
342 | ||
343 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region); | |
344 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, | |
345 | wxCoord width, wxCoord height); | |
346 | ||
347 | virtual void DoGetTextExtent(const wxString& string, | |
348 | wxCoord *x, wxCoord *y, | |
349 | wxCoord *descent = NULL, | |
350 | wxCoord *externalLeading = NULL, | |
351 | wxFont *theFont = NULL) const; | |
352 | ||
353 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; | |
354 | ||
355 | protected: | |
356 | // scaling variables | |
357 | double m_mm_to_pix_x, m_mm_to_pix_y; | |
358 | ||
359 | wxGraphicsContext* m_graphicContext; | |
360 | }; | |
361 | #endif | |
362 | ||
363 | #endif | |
364 | // _WX_GRID_H_BASE_ |