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