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