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