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