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