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