]>
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 | ||
f07d9b97 MR |
15 | #include "wx/defs.h" |
16 | ||
8acd14d1 SC |
17 | #if wxUSE_GRAPHICS_CONTEXT |
18 | ||
50581042 | 19 | #include "wx/geometry.h" |
50581042 | 20 | #include "wx/dynarray.h" |
79bd5e98 | 21 | #include "wx/dc.h" |
50581042 | 22 | |
b5dbe15d VS |
23 | class WXDLLIMPEXP_FWD_CORE wxWindowDC; |
24 | class WXDLLIMPEXP_FWD_CORE wxMemoryDC; | |
220d37c8 | 25 | #if wxUSE_PRINTING_ARCHITECTURE |
0b822969 | 26 | class WXDLLIMPEXP_FWD_CORE wxPrinterDC; |
220d37c8 | 27 | #endif |
b5dbe15d VS |
28 | class WXDLLIMPEXP_FWD_CORE wxGraphicsContext; |
29 | class WXDLLIMPEXP_FWD_CORE wxGraphicsPath; | |
30 | class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix; | |
31 | class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure; | |
32 | class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer; | |
33 | class WXDLLIMPEXP_FWD_CORE wxGraphicsPen; | |
34 | class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush; | |
35 | class WXDLLIMPEXP_FWD_CORE wxGraphicsFont; | |
1796d384 | 36 | class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap; |
774f4d12 | 37 | |
50581042 SC |
38 | /* |
39 | * notes about the graphics context apis | |
40 | * | |
0b7dce54 | 41 | * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being |
50581042 SC |
42 | * in direction of positive y axis. |
43 | */ | |
0b7dce54 | 44 | |
9e605538 | 45 | // Base class of all objects used for drawing in the new graphics API, the always point back to their |
0b7dce54 | 46 | // originating rendering engine, there is no dynamic unloading of a renderer currently allowed, |
9e605538 | 47 | // these references are not counted |
2c820406 SC |
48 | |
49 | // | |
50 | // The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive | |
51 | // duplication. Any operation on a shared instance that results in a modified state, uncouples this | |
52 | // instance from the other instances that were shared - using copy on write semantics | |
53 | // | |
0b7dce54 | 54 | |
3c419e81 SC |
55 | class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData; |
56 | class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData; | |
57 | class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData; | |
2c820406 | 58 | |
9e605538 SC |
59 | class WXDLLIMPEXP_CORE wxGraphicsObject : public wxObject |
60 | { | |
0b7dce54 VZ |
61 | public: |
62 | wxGraphicsObject(); | |
63 | wxGraphicsObject( wxGraphicsRenderer* renderer ); | |
64 | virtual ~wxGraphicsObject(); | |
65 | ||
66 | bool IsNull() const; | |
2c820406 SC |
67 | |
68 | // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet | |
0b7dce54 VZ |
69 | wxGraphicsRenderer* GetRenderer() const; |
70 | wxGraphicsObjectRefData* GetGraphicsData() const; | |
71 | protected: | |
2c820406 SC |
72 | virtual wxObjectRefData* CreateRefData() const; |
73 | virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const; | |
74 | ||
39013ba0 | 75 | DECLARE_DYNAMIC_CLASS(wxGraphicsObject) |
0b7dce54 | 76 | }; |
9e605538 SC |
77 | |
78 | class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject | |
79 | { | |
0b7dce54 | 80 | public: |
2c820406 | 81 | wxGraphicsPen() {} |
9e605538 | 82 | virtual ~wxGraphicsPen() {} |
0b7dce54 | 83 | private: |
2c820406 | 84 | DECLARE_DYNAMIC_CLASS(wxGraphicsPen) |
0b7dce54 | 85 | }; |
9e605538 | 86 | |
53a2db12 | 87 | extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen; |
2c820406 | 88 | |
9e605538 SC |
89 | class WXDLLIMPEXP_CORE wxGraphicsBrush : public wxGraphicsObject |
90 | { | |
0b7dce54 | 91 | public: |
2c820406 | 92 | wxGraphicsBrush() {} |
9e605538 | 93 | virtual ~wxGraphicsBrush() {} |
0b7dce54 | 94 | private: |
2c820406 | 95 | DECLARE_DYNAMIC_CLASS(wxGraphicsBrush) |
0b7dce54 | 96 | }; |
9e605538 | 97 | |
53a2db12 | 98 | extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush; |
2c820406 | 99 | |
9e605538 | 100 | class WXDLLIMPEXP_CORE wxGraphicsFont : public wxGraphicsObject |
50581042 | 101 | { |
0b7dce54 | 102 | public: |
2c820406 | 103 | wxGraphicsFont() {} |
9e605538 | 104 | virtual ~wxGraphicsFont() {} |
0b7dce54 | 105 | private: |
2c820406 | 106 | DECLARE_DYNAMIC_CLASS(wxGraphicsFont) |
0b7dce54 | 107 | }; |
9e605538 | 108 | |
53a2db12 | 109 | extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont; |
2c820406 | 110 | |
1796d384 SC |
111 | class WXDLLIMPEXP_CORE wxGraphicsBitmap : public wxGraphicsObject |
112 | { | |
0b7dce54 | 113 | public: |
1796d384 SC |
114 | wxGraphicsBitmap() {} |
115 | virtual ~wxGraphicsBitmap() {} | |
0b7dce54 | 116 | private: |
1796d384 | 117 | DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap) |
0b7dce54 VZ |
118 | }; |
119 | ||
53a2db12 | 120 | extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap; |
1796d384 | 121 | |
a4e73390 SC |
122 | class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject |
123 | { | |
0b7dce54 | 124 | public: |
a4e73390 SC |
125 | wxGraphicsMatrix() {} |
126 | ||
127 | virtual ~wxGraphicsMatrix() {} | |
128 | ||
129 | // concatenates the matrix | |
130 | virtual void Concat( const wxGraphicsMatrix *t ); | |
131 | void Concat( const wxGraphicsMatrix &t ) { Concat( &t ); } | |
132 | ||
133 | // sets the matrix to the respective values | |
0b7dce54 | 134 | virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, |
a4e73390 SC |
135 | wxDouble tx=0.0, wxDouble ty=0.0); |
136 | ||
248802d0 RD |
137 | // gets the component valuess of the matrix |
138 | virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL, | |
139 | wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const; | |
0b7dce54 | 140 | |
a4e73390 SC |
141 | // makes this the inverse matrix |
142 | virtual void Invert(); | |
143 | ||
144 | // returns true if the elements of the transformation matrix are equal ? | |
145 | virtual bool IsEqual( const wxGraphicsMatrix* t) const; | |
146 | bool IsEqual( const wxGraphicsMatrix& t) const { return IsEqual( &t ); } | |
147 | ||
148 | // return true if this is the identity matrix | |
149 | virtual bool IsIdentity() const; | |
150 | ||
151 | // | |
152 | // transformation | |
153 | // | |
154 | ||
155 | // add the translation to this matrix | |
156 | virtual void Translate( wxDouble dx , wxDouble dy ); | |
157 | ||
158 | // add the scale to this matrix | |
159 | virtual void Scale( wxDouble xScale , wxDouble yScale ); | |
160 | ||
161 | // add the rotation to this matrix (radians) | |
0b7dce54 | 162 | virtual void Rotate( wxDouble angle ); |
a4e73390 SC |
163 | |
164 | // | |
165 | // apply the transforms | |
166 | // | |
167 | ||
168 | // applies that matrix to the point | |
169 | virtual void TransformPoint( wxDouble *x, wxDouble *y ) const; | |
170 | ||
171 | // applies the matrix except for translations | |
172 | virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const; | |
173 | ||
174 | // returns the native representation | |
175 | virtual void * GetNativeMatrix() const; | |
176 | ||
0b7dce54 | 177 | const wxGraphicsMatrixData* GetMatrixData() const |
a4e73390 | 178 | { return (const wxGraphicsMatrixData*) GetRefData(); } |
0b7dce54 | 179 | wxGraphicsMatrixData* GetMatrixData() |
a4e73390 SC |
180 | { return (wxGraphicsMatrixData*) GetRefData(); } |
181 | ||
0b7dce54 | 182 | private: |
a4e73390 | 183 | DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix) |
0b7dce54 | 184 | }; |
a4e73390 | 185 | |
53a2db12 | 186 | extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix; |
a4e73390 | 187 | |
a4e73390 | 188 | class WXDLLIMPEXP_CORE wxGraphicsPath : public wxGraphicsObject |
774f4d12 | 189 | { |
0b7dce54 | 190 | public: |
a4e73390 SC |
191 | wxGraphicsPath() {} |
192 | virtual ~wxGraphicsPath() {} | |
0b7dce54 | 193 | |
a4e73390 SC |
194 | // |
195 | // These are the path primitives from which everything else can be constructed | |
196 | // | |
9e605538 | 197 | |
a4e73390 SC |
198 | // begins a new subpath at (x,y) |
199 | virtual void MoveToPoint( wxDouble x, wxDouble y ); | |
200 | void MoveToPoint( const wxPoint2DDouble& p); | |
0d3675a6 | 201 | |
0b7dce54 | 202 | // adds a straight line from the current point to (x,y) |
a4e73390 SC |
203 | virtual void AddLineToPoint( wxDouble x, wxDouble y ); |
204 | void AddLineToPoint( const wxPoint2DDouble& p); | |
0d3675a6 | 205 | |
a4e73390 | 206 | // adds a cubic Bezier curve from the current point, using two control points and an end point |
0b7dce54 | 207 | virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ); |
a4e73390 | 208 | void AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e); |
0b7dce54 | 209 | |
a4e73390 SC |
210 | // adds another path |
211 | virtual void AddPath( const wxGraphicsPath& path ); | |
212 | ||
213 | // closes the current sub-path | |
0b7dce54 | 214 | virtual void CloseSubpath(); |
a4e73390 SC |
215 | |
216 | // gets the last point of the current path, (0,0) if not yet set | |
217 | virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const; | |
218 | wxPoint2DDouble GetCurrentPoint() const; | |
219 | ||
220 | // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle | |
0b7dce54 | 221 | virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ); |
a4e73390 SC |
222 | void AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise); |
223 | ||
774f4d12 | 224 | // |
0b7dce54 | 225 | // These are convenience functions which - if not available natively will be assembled |
a4e73390 | 226 | // using the primitives from above |
774f4d12 | 227 | // |
a4e73390 SC |
228 | |
229 | // adds a quadratic Bezier curve from the current point, using a control point and an end point | |
230 | virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y ); | |
231 | ||
0b7dce54 | 232 | // appends a rectangle as a new closed subpath |
a4e73390 SC |
233 | virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ); |
234 | ||
235 | // appends an ellipsis as a new closed subpath fitting the passed rectangle | |
236 | virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r ); | |
237 | ||
238 | // appends 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) | |
0b7dce54 VZ |
239 | virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ); |
240 | ||
a4e73390 SC |
241 | // appends an ellipse |
242 | virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h); | |
774f4d12 | 243 | |
a4e73390 SC |
244 | // appends a rounded rectangle |
245 | virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius); | |
774f4d12 | 246 | |
a4e73390 SC |
247 | // returns the native path |
248 | virtual void * GetNativePath() const; | |
0b7dce54 | 249 | |
a4e73390 SC |
250 | // give the native path returned by GetNativePath() back (there might be some deallocations necessary) |
251 | virtual void UnGetNativePath(void *p)const; | |
0b7dce54 | 252 | |
a4e73390 SC |
253 | // transforms each point of this path by the matrix |
254 | virtual void Transform( const wxGraphicsMatrix& matrix ); | |
0b7dce54 | 255 | |
a4e73390 SC |
256 | // gets the bounding box enclosing all points (possibly including control points) |
257 | virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)const; | |
258 | wxRect2DDouble GetBox()const; | |
0b7dce54 | 259 | |
94a007ec FM |
260 | virtual bool Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle = wxODDEVEN_RULE)const; |
261 | bool Contains( const wxPoint2DDouble& c, wxPolygonFillMode fillStyle = wxODDEVEN_RULE)const; | |
0b7dce54 VZ |
262 | |
263 | const wxGraphicsPathData* GetPathData() const | |
a4e73390 | 264 | { return (const wxGraphicsPathData*) GetRefData(); } |
0b7dce54 | 265 | wxGraphicsPathData* GetPathData() |
a4e73390 SC |
266 | { return (wxGraphicsPathData*) GetRefData(); } |
267 | ||
0b7dce54 | 268 | private: |
a4e73390 | 269 | DECLARE_DYNAMIC_CLASS(wxGraphicsPath) |
0b7dce54 | 270 | }; |
774f4d12 | 271 | |
53a2db12 | 272 | extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPath) wxNullGraphicsPath; |
a4e73390 SC |
273 | |
274 | ||
9e605538 | 275 | class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject |
50581042 SC |
276 | { |
277 | public: | |
9e605538 | 278 | wxGraphicsContext(wxGraphicsRenderer* renderer); |
774f4d12 | 279 | |
9e605538 | 280 | virtual ~wxGraphicsContext(); |
0b7dce54 VZ |
281 | |
282 | static wxGraphicsContext* Create( const wxWindowDC& dc); | |
283 | static wxGraphicsContext * Create( const wxMemoryDC& dc); | |
220d37c8 | 284 | #if wxUSE_PRINTING_ARCHITECTURE |
0b7dce54 | 285 | static wxGraphicsContext * Create( const wxPrinterDC& dc); |
220d37c8 | 286 | #endif |
773ccc31 | 287 | |
0b7dce54 | 288 | static wxGraphicsContext* CreateFromNative( void * context ); |
774f4d12 | 289 | |
0b7dce54 | 290 | static wxGraphicsContext* CreateFromNativeWindow( void * window ); |
9a02779a | 291 | |
0b7dce54 | 292 | static wxGraphicsContext* Create( wxWindow* window ); |
50581042 | 293 | |
ad667945 SC |
294 | // create a context that can be used for measuring texts only, no drawing allowed |
295 | static wxGraphicsContext * Create(); | |
296 | ||
cc18b1c7 | 297 | // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown |
0b7dce54 VZ |
298 | virtual bool StartDoc( const wxString& message ); |
299 | ||
300 | // done with that document (relevant only for printing / pdf etc) | |
cc18b1c7 SC |
301 | virtual void EndDoc(); |
302 | ||
0b7dce54 | 303 | // opens a new page (relevant only for printing / pdf etc) with the given size in points |
cc18b1c7 SC |
304 | // (if both are null the default page size will be used) |
305 | virtual void StartPage( wxDouble width = 0, wxDouble height = 0 ); | |
0b7dce54 VZ |
306 | |
307 | // ends the current page (relevant only for printing / pdf etc) | |
cc18b1c7 | 308 | virtual void EndPage(); |
0b7dce54 | 309 | |
cc18b1c7 SC |
310 | // make sure that the current content of this context is immediately visible |
311 | virtual void Flush(); | |
312 | ||
a4e73390 | 313 | wxGraphicsPath CreatePath() const; |
0b7dce54 | 314 | |
a4e73390 | 315 | virtual wxGraphicsPen CreatePen(const wxPen& pen) const; |
0b7dce54 | 316 | |
a4e73390 | 317 | virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) const; |
0b7dce54 | 318 | |
9e605538 | 319 | // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2 |
0b7dce54 | 320 | virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, |
a4e73390 | 321 | const wxColour&c1, const wxColour&c2) const; |
9e605538 | 322 | |
0b7dce54 | 323 | // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc) |
9e605538 | 324 | // with radius r and color cColor |
2c820406 | 325 | virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, |
a4e73390 | 326 | const wxColour &oColor, const wxColour &cColor) const; |
9e605538 SC |
327 | |
328 | // sets the font | |
a4e73390 | 329 | virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) const; |
9e605538 | 330 | |
1796d384 SC |
331 | // create a native bitmap representation |
332 | virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) const; | |
0b7dce54 | 333 | |
1796d384 SC |
334 | // create a native bitmap representation |
335 | virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) const; | |
336 | ||
0d3675a6 | 337 | // create a 'native' matrix corresponding to these values |
0b7dce54 | 338 | virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, |
a4e73390 | 339 | wxDouble tx=0.0, wxDouble ty=0.0) const; |
0b7dce54 | 340 | |
50581042 SC |
341 | // push the current state of the context, ie the transformation matrix on a stack |
342 | virtual void PushState() = 0; | |
343 | ||
344 | // pops a stored state from the stack | |
345 | virtual void PopState() = 0; | |
346 | ||
cc18b1c7 | 347 | // clips drawings to the region intersected with the current clipping region |
50581042 SC |
348 | virtual void Clip( const wxRegion ®ion ) = 0; |
349 | ||
cc18b1c7 | 350 | // clips drawings to the rect intersected with the current clipping region |
774f4d12 | 351 | virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; |
0b7dce54 | 352 | |
0d3675a6 | 353 | // resets the clipping to original extent |
0b7dce54 | 354 | virtual void ResetClip() = 0; |
774f4d12 | 355 | |
0d3675a6 RD |
356 | // returns the native context |
357 | virtual void * GetNativeContext() = 0; | |
774f4d12 | 358 | |
e22cf4b3 | 359 | // returns the current logical function |
3adf5bcf | 360 | virtual wxRasterOperationMode GetLogicalFunction() const { return m_logicalFunction; } |
0b7dce54 | 361 | |
e22cf4b3 | 362 | // sets the current logical function, returns true if it supported |
89efaf2b | 363 | virtual bool SetLogicalFunction(wxRasterOperationMode function); |
e22cf4b3 | 364 | |
cc18b1c7 SC |
365 | // returns the size of the graphics context in device coordinates |
366 | virtual void GetSize( wxDouble* width, wxDouble* height); | |
367 | ||
368 | // returns the resolution of the graphics context in device points per inch | |
369 | virtual void GetDPI( wxDouble* dpiX, wxDouble* dpiY); | |
0b7dce54 | 370 | |
cc18b1c7 SC |
371 | #if 0 |
372 | // sets the current alpha on this context | |
373 | virtual void SetAlpha( wxDouble alpha ); | |
0b7dce54 | 374 | |
cc18b1c7 SC |
375 | // returns the alpha on this context |
376 | virtual wxDouble GetAlpha() const; | |
377 | #endif | |
50581042 | 378 | // |
774f4d12 | 379 | // transformation : changes the current transformation matrix CTM of the context |
50581042 | 380 | // |
0b7dce54 | 381 | |
50581042 SC |
382 | // translate |
383 | virtual void Translate( wxDouble dx , wxDouble dy ) = 0; | |
384 | ||
385 | // scale | |
386 | virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0; | |
387 | ||
388 | // rotate (radians) | |
389 | virtual void Rotate( wxDouble angle ) = 0; | |
0b7dce54 | 390 | |
0d3675a6 | 391 | // concatenates this transform with the current transform of this context |
a4e73390 | 392 | virtual void ConcatTransform( const wxGraphicsMatrix& matrix ) = 0; |
9e605538 | 393 | |
0d3675a6 | 394 | // sets the transform of this context |
a4e73390 | 395 | virtual void SetTransform( const wxGraphicsMatrix& matrix ) = 0; |
50581042 | 396 | |
0d3675a6 | 397 | // gets the matrix of this context |
a4e73390 | 398 | virtual wxGraphicsMatrix GetTransform() const = 0; |
50581042 SC |
399 | // |
400 | // setting the paint | |
401 | // | |
0b7dce54 | 402 | |
9e605538 | 403 | // sets the pen |
2c820406 | 404 | virtual void SetPen( const wxGraphicsPen& pen ); |
0b7dce54 | 405 | |
9e605538 | 406 | void SetPen( const wxPen& pen ); |
50581042 SC |
407 | |
408 | // sets the brush for filling | |
2c820406 | 409 | virtual void SetBrush( const wxGraphicsBrush& brush ); |
0b7dce54 | 410 | |
9e605538 | 411 | void SetBrush( const wxBrush& brush ); |
50581042 SC |
412 | |
413 | // sets the font | |
2c820406 | 414 | virtual void SetFont( const wxGraphicsFont& font ); |
0b7dce54 | 415 | |
9e605538 | 416 | void SetFont( const wxFont& font, const wxColour& colour ); |
0d3675a6 | 417 | |
0b7dce54 | 418 | |
50581042 | 419 | // strokes along a path with the current pen |
a4e73390 | 420 | virtual void StrokePath( const wxGraphicsPath& path ) = 0; |
50581042 SC |
421 | |
422 | // fills a path with the current brush | |
94a007ec | 423 | virtual void FillPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle = wxODDEVEN_RULE ) = 0; |
50581042 SC |
424 | |
425 | // draws a path by first filling and then stroking | |
94a007ec | 426 | virtual void DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle = wxODDEVEN_RULE ); |
0b7dce54 | 427 | |
50581042 SC |
428 | // |
429 | // text | |
430 | // | |
50581042 | 431 | |
0b7dce54 VZ |
432 | void DrawText( const wxString &str, wxDouble x, wxDouble y ) |
433 | { DoDrawText(str, x, y); } | |
434 | ||
435 | void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ) | |
436 | { DoDrawRotatedText(str, x, y, angle); } | |
437 | ||
438 | void DrawText( const wxString &str, wxDouble x, wxDouble y, | |
439 | const wxGraphicsBrush& backgroundBrush ) | |
440 | { DoDrawFilledText(str, x, y, backgroundBrush); } | |
50581042 | 441 | |
0b7dce54 VZ |
442 | void DrawText( const wxString &str, wxDouble x, wxDouble y, |
443 | wxDouble angle, const wxGraphicsBrush& backgroundBrush ) | |
444 | { DoDrawRotatedFilledText(str, x, y, angle, backgroundBrush); } | |
068eb463 | 445 | |
068eb463 | 446 | |
50581042 SC |
447 | virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height, |
448 | wxDouble *descent, wxDouble *externalLeading ) const = 0; | |
449 | ||
450 | virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const = 0; | |
451 | ||
452 | // | |
453 | // image support | |
454 | // | |
455 | ||
d974a494 | 456 | #ifndef __WXGTK20__ |
1796d384 | 457 | virtual void DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; |
d974a494 | 458 | #endif |
1796d384 | 459 | |
50581042 SC |
460 | virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; |
461 | ||
462 | virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; | |
463 | ||
464 | // | |
465 | // convenience methods | |
466 | // | |
0b7dce54 | 467 | |
50581042 SC |
468 | // strokes a single line |
469 | virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2); | |
470 | ||
471 | // stroke lines connecting each of the points | |
472 | virtual void StrokeLines( size_t n, const wxPoint2DDouble *points); | |
473 | ||
474 | // stroke disconnected lines from begin to end points | |
475 | virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints); | |
476 | ||
477 | // draws a polygon | |
94a007ec | 478 | virtual void DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle = wxODDEVEN_RULE ); |
50581042 SC |
479 | |
480 | // draws a polygon | |
481 | virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h); | |
482 | ||
483 | // draws an ellipse | |
484 | virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h); | |
485 | ||
486 | // draws a rounded rectangle | |
487 | virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius); | |
488 | ||
9e605538 | 489 | // wrappers using wxPoint2DDouble TODO |
50581042 | 490 | |
de3cb39f RD |
491 | // helper to determine if a 0.5 offset should be applied for the drawing operation |
492 | virtual bool ShouldOffset() const { return false; } | |
9e605538 | 493 | |
0b7dce54 | 494 | protected: |
9da34e21 | 495 | |
2c820406 SC |
496 | wxGraphicsPen m_pen; |
497 | wxGraphicsBrush m_brush; | |
498 | wxGraphicsFont m_font; | |
89efaf2b | 499 | wxRasterOperationMode m_logicalFunction; |
9e605538 | 500 | |
02fd8b9b | 501 | protected: |
0b7dce54 VZ |
502 | // implementations of overloaded public functions: we use different names |
503 | // for them to avoid the virtual function hiding problems in the derived | |
504 | // classes | |
505 | virtual void DoDrawText(const wxString& str, wxDouble x, wxDouble y) = 0; | |
506 | virtual void DoDrawRotatedText(const wxString& str, wxDouble x, wxDouble y, | |
507 | wxDouble angle); | |
508 | virtual void DoDrawFilledText(const wxString& str, wxDouble x, wxDouble y, | |
509 | const wxGraphicsBrush& backgroundBrush); | |
510 | virtual void DoDrawRotatedFilledText(const wxString& str, | |
511 | wxDouble x, wxDouble y, | |
512 | wxDouble angle, | |
513 | const wxGraphicsBrush& backgroundBrush); | |
514 | ||
c0c133e1 | 515 | wxDECLARE_NO_COPY_CLASS(wxGraphicsContext); |
8ddf8e82 | 516 | DECLARE_ABSTRACT_CLASS(wxGraphicsContext) |
50581042 SC |
517 | }; |
518 | ||
0b7dce54 | 519 | #if 0 |
9e605538 SC |
520 | |
521 | // | |
522 | // A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements | |
523 | // | |
524 | ||
525 | class WXDLLIMPEXP_CORE wxGraphicsFigure : public wxGraphicsObject | |
526 | { | |
0b7dce54 VZ |
527 | public: |
528 | wxGraphicsFigure(wxGraphicsRenderer* renderer); | |
529 | ||
530 | virtual ~wxGraphicsFigure(); | |
531 | ||
0d3675a6 | 532 | void SetPath( wxGraphicsMatrix* matrix ); |
0b7dce54 | 533 | |
0d3675a6 RD |
534 | void SetMatrix( wxGraphicsPath* path); |
535 | ||
536 | // draws this object on the context | |
537 | virtual void Draw( wxGraphicsContext* cg ); | |
0b7dce54 | 538 | |
0d3675a6 RD |
539 | // returns the path of this object |
540 | wxGraphicsPath* GetPath() { return m_path; } | |
0b7dce54 | 541 | |
0d3675a6 RD |
542 | // returns the transformation matrix of this object, may be null if there is no transformation necessary |
543 | wxGraphicsMatrix* GetMatrix() { return m_matrix; } | |
0b7dce54 VZ |
544 | |
545 | private: | |
0d3675a6 RD |
546 | wxGraphicsMatrix* m_matrix; |
547 | wxGraphicsPath* m_path; | |
0b7dce54 | 548 | |
9e605538 | 549 | DECLARE_DYNAMIC_CLASS(wxGraphicsFigure) |
0b7dce54 VZ |
550 | }; |
551 | ||
552 | #endif | |
9e605538 SC |
553 | |
554 | // | |
555 | // The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer | |
556 | // instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional | |
557 | // paths at any point from a given matrix etc. | |
558 | // | |
559 | ||
560 | class WXDLLIMPEXP_CORE wxGraphicsRenderer : public wxObject | |
561 | { | |
0b7dce54 | 562 | public: |
9e605538 SC |
563 | wxGraphicsRenderer() {} |
564 | ||
565 | virtual ~wxGraphicsRenderer() {} | |
566 | ||
0d3675a6 | 567 | static wxGraphicsRenderer* GetDefaultRenderer(); |
9e605538 | 568 | |
0d3675a6 | 569 | // Context |
9e605538 | 570 | |
0b7dce54 VZ |
571 | virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) = 0; |
572 | virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc) = 0; | |
220d37c8 | 573 | #if wxUSE_PRINTING_ARCHITECTURE |
0b7dce54 | 574 | virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc) = 0; |
220d37c8 SC |
575 | #endif |
576 | ||
0d3675a6 | 577 | virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0; |
9e605538 | 578 | |
0d3675a6 | 579 | virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0; |
9e605538 | 580 | |
0d3675a6 | 581 | virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0; |
9e605538 | 582 | |
ad667945 SC |
583 | // create a context that can be used for measuring texts only, no drawing allowed |
584 | virtual wxGraphicsContext * CreateMeasuringContext() = 0; | |
585 | ||
0d3675a6 | 586 | // Path |
0b7dce54 | 587 | |
a4e73390 | 588 | virtual wxGraphicsPath CreatePath() = 0; |
9e605538 | 589 | |
0d3675a6 | 590 | // Matrix |
0b7dce54 VZ |
591 | |
592 | virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, | |
0d3675a6 | 593 | wxDouble tx=0.0, wxDouble ty=0.0) = 0; |
0b7dce54 | 594 | |
9e605538 | 595 | // Paints |
0b7dce54 VZ |
596 | |
597 | virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0; | |
598 | ||
599 | virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) = 0; | |
600 | ||
9e605538 | 601 | // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2 |
0b7dce54 | 602 | virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, |
9e605538 SC |
603 | const wxColour&c1, const wxColour&c2) = 0; |
604 | ||
0b7dce54 | 605 | // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc) |
9e605538 | 606 | // with radius r and color cColor |
2c820406 | 607 | virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, |
9e605538 SC |
608 | const wxColour &oColor, const wxColour &cColor) = 0; |
609 | ||
610 | // sets the font | |
2c820406 | 611 | virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) = 0; |
d974a494 | 612 | |
0b7dce54 | 613 | #ifndef __WXGTK20__ |
1796d384 SC |
614 | // create a native bitmap representation |
615 | virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) = 0; | |
0b7dce54 | 616 | |
1796d384 SC |
617 | // create a subimage from a native image representation |
618 | virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0; | |
d974a494 RR |
619 | #endif |
620 | ||
621 | ||
0b7dce54 | 622 | private: |
c0c133e1 | 623 | wxDECLARE_NO_COPY_CLASS(wxGraphicsRenderer); |
9e605538 | 624 | DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer) |
0b7dce54 | 625 | }; |
9e605538 | 626 | |
774f4d12 | 627 | #endif |
50581042 | 628 | |
8acd14d1 | 629 | #endif // _WX_GRAPHICS_H_ |