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