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