1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: graphics context header
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GRAPHICS_H_
13 #define _WX_GRAPHICS_H_
17 #if wxUSE_GRAPHICS_CONTEXT
19 #include "wx/geometry.h"
20 #include "wx/dynarray.h"
23 #include "wx/vector.h"
27 wxANTIALIAS_NONE
, // should be 0
31 enum wxInterpolationQuality
33 // default interpolation
34 wxINTERPOLATION_DEFAULT
,
37 // fast interpolation, suited for interactivity
41 // best quality, not suited for interactivity
45 enum wxCompositionMode
47 // R = Result, S = Source, D = Destination, premultiplied with alpha
48 // Ra, Sa, Da their alpha components
50 // classic Porter-Duff compositions
51 // http://keithp.com/~keithp/porterduff/p253-porter.pdf
53 wxCOMPOSITION_INVALID
= -1, /* indicates invalid/unsupported mode */
54 wxCOMPOSITION_CLEAR
, /* R = 0 */
55 wxCOMPOSITION_SOURCE
, /* R = S */
56 wxCOMPOSITION_OVER
, /* R = S + D*(1 - Sa) */
57 wxCOMPOSITION_IN
, /* R = S*Da */
58 wxCOMPOSITION_OUT
, /* R = S*(1 - Da) */
59 wxCOMPOSITION_ATOP
, /* R = S*Da + D*(1 - Sa) */
61 wxCOMPOSITION_DEST
, /* R = D, essentially a noop */
62 wxCOMPOSITION_DEST_OVER
, /* R = S*(1 - Da) + D */
63 wxCOMPOSITION_DEST_IN
, /* R = D*Sa */
64 wxCOMPOSITION_DEST_OUT
, /* R = D*(1 - Sa) */
65 wxCOMPOSITION_DEST_ATOP
, /* R = S*(1 - Da) + D*Sa */
66 wxCOMPOSITION_XOR
, /* R = S*(1 - Da) + D*(1 - Sa) */
68 // mathematical compositions
69 wxCOMPOSITION_ADD
/* R = S + D */
72 class WXDLLIMPEXP_FWD_CORE wxWindowDC
;
73 class WXDLLIMPEXP_FWD_CORE wxMemoryDC
;
74 #if wxUSE_PRINTING_ARCHITECTURE
75 class WXDLLIMPEXP_FWD_CORE wxPrinterDC
;
78 #if wxUSE_ENH_METAFILE
79 class WXDLLIMPEXP_FWD_CORE wxEnhMetaFileDC
;
82 class WXDLLIMPEXP_FWD_CORE wxGraphicsContext
;
83 class WXDLLIMPEXP_FWD_CORE wxGraphicsPath
;
84 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix
;
85 class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure
;
86 class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer
;
87 class WXDLLIMPEXP_FWD_CORE wxGraphicsPen
;
88 class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush
;
89 class WXDLLIMPEXP_FWD_CORE wxGraphicsFont
;
90 class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap
;
93 * notes about the graphics context apis
95 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
96 * in direction of positive y axis.
99 // Base class of all objects used for drawing in the new graphics API, the always point back to their
100 // originating rendering engine, there is no dynamic unloading of a renderer currently allowed,
101 // these references are not counted
104 // The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive
105 // duplication. Any operation on a shared instance that results in a modified state, uncouples this
106 // instance from the other instances that were shared - using copy on write semantics
109 class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData
;
110 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData
;
111 class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData
;
113 class WXDLLIMPEXP_CORE wxGraphicsObject
: public wxObject
117 wxGraphicsObject( wxGraphicsRenderer
* renderer
);
118 virtual ~wxGraphicsObject();
122 // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
123 wxGraphicsRenderer
* GetRenderer() const;
124 wxGraphicsObjectRefData
* GetGraphicsData() const;
126 virtual wxObjectRefData
* CreateRefData() const;
127 virtual wxObjectRefData
* CloneRefData(const wxObjectRefData
* data
) const;
129 DECLARE_DYNAMIC_CLASS(wxGraphicsObject
)
132 class WXDLLIMPEXP_CORE wxGraphicsPen
: public wxGraphicsObject
136 virtual ~wxGraphicsPen() {}
138 DECLARE_DYNAMIC_CLASS(wxGraphicsPen
)
141 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen
) wxNullGraphicsPen
;
143 class WXDLLIMPEXP_CORE wxGraphicsBrush
: public wxGraphicsObject
147 virtual ~wxGraphicsBrush() {}
149 DECLARE_DYNAMIC_CLASS(wxGraphicsBrush
)
152 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush
) wxNullGraphicsBrush
;
154 class WXDLLIMPEXP_CORE wxGraphicsFont
: public wxGraphicsObject
158 virtual ~wxGraphicsFont() {}
160 DECLARE_DYNAMIC_CLASS(wxGraphicsFont
)
163 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont
) wxNullGraphicsFont
;
165 class WXDLLIMPEXP_CORE wxGraphicsBitmap
: public wxGraphicsObject
168 wxGraphicsBitmap() {}
169 virtual ~wxGraphicsBitmap() {}
171 // Convert bitmap to wxImage: this is more efficient than converting to
172 // wxBitmap first and then to wxImage and also works without X server
173 // connection under Unix that wxBitmap requires.
175 wxImage
ConvertToImage() const;
176 #endif // wxUSE_IMAGE
179 DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap
)
182 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap
) wxNullGraphicsBitmap
;
184 class WXDLLIMPEXP_CORE wxGraphicsMatrix
: public wxGraphicsObject
187 wxGraphicsMatrix() {}
189 virtual ~wxGraphicsMatrix() {}
191 // concatenates the matrix
192 virtual void Concat( const wxGraphicsMatrix
*t
);
193 void Concat( const wxGraphicsMatrix
&t
) { Concat( &t
); }
195 // sets the matrix to the respective values
196 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
197 wxDouble tx
=0.0, wxDouble ty
=0.0);
199 // gets the component valuess of the matrix
200 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
201 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
203 // makes this the inverse matrix
204 virtual void Invert();
206 // returns true if the elements of the transformation matrix are equal ?
207 virtual bool IsEqual( const wxGraphicsMatrix
* t
) const;
208 bool IsEqual( const wxGraphicsMatrix
& t
) const { return IsEqual( &t
); }
210 // return true if this is the identity matrix
211 virtual bool IsIdentity() const;
217 // add the translation to this matrix
218 virtual void Translate( wxDouble dx
, wxDouble dy
);
220 // add the scale to this matrix
221 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
223 // add the rotation to this matrix (radians)
224 virtual void Rotate( wxDouble angle
);
227 // apply the transforms
230 // applies that matrix to the point
231 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
233 // applies the matrix except for translations
234 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
236 // returns the native representation
237 virtual void * GetNativeMatrix() const;
239 const wxGraphicsMatrixData
* GetMatrixData() const
240 { return (const wxGraphicsMatrixData
*) GetRefData(); }
241 wxGraphicsMatrixData
* GetMatrixData()
242 { return (wxGraphicsMatrixData
*) GetRefData(); }
245 DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix
)
248 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix
) wxNullGraphicsMatrix
;
250 class WXDLLIMPEXP_CORE wxGraphicsPath
: public wxGraphicsObject
254 virtual ~wxGraphicsPath() {}
257 // These are the path primitives from which everything else can be constructed
260 // begins a new subpath at (x,y)
261 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
262 void MoveToPoint( const wxPoint2DDouble
& p
);
264 // adds a straight line from the current point to (x,y)
265 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
266 void AddLineToPoint( const wxPoint2DDouble
& p
);
268 // adds a cubic Bezier curve from the current point, using two control points and an end point
269 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
270 void AddCurveToPoint( const wxPoint2DDouble
& c1
, const wxPoint2DDouble
& c2
, const wxPoint2DDouble
& e
);
273 virtual void AddPath( const wxGraphicsPath
& path
);
275 // closes the current sub-path
276 virtual void CloseSubpath();
278 // gets the last point of the current path, (0,0) if not yet set
279 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
280 wxPoint2DDouble
GetCurrentPoint() const;
282 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
283 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
284 void AddArc( const wxPoint2DDouble
& c
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
287 // These are convenience functions which - if not available natively will be assembled
288 // using the primitives from above
291 // adds a quadratic Bezier curve from the current point, using a control point and an end point
292 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
294 // appends a rectangle as a new closed subpath
295 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
297 // appends an ellipsis as a new closed subpath fitting the passed rectangle
298 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
300 // 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)
301 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
303 // appends an ellipse
304 virtual void AddEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
306 // appends a rounded rectangle
307 virtual void AddRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
309 // returns the native path
310 virtual void * GetNativePath() const;
312 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
313 virtual void UnGetNativePath(void *p
)const;
315 // transforms each point of this path by the matrix
316 virtual void Transform( const wxGraphicsMatrix
& matrix
);
318 // gets the bounding box enclosing all points (possibly including control points)
319 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
)const;
320 wxRect2DDouble
GetBox()const;
322 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)const;
323 bool Contains( const wxPoint2DDouble
& c
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
)const;
325 const wxGraphicsPathData
* GetPathData() const
326 { return (const wxGraphicsPathData
*) GetRefData(); }
327 wxGraphicsPathData
* GetPathData()
328 { return (wxGraphicsPathData
*) GetRefData(); }
331 DECLARE_DYNAMIC_CLASS(wxGraphicsPath
)
334 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPath
) wxNullGraphicsPath
;
337 // Describes a single gradient stop.
338 class wxGraphicsGradientStop
341 wxGraphicsGradientStop(wxColour col
= wxTransparentColour
,
348 // default copy ctor, assignment operator and dtor are ok
350 const wxColour
& GetColour() const { return m_col
; }
351 void SetColour(const wxColour
& col
) { m_col
= col
; }
353 float GetPosition() const { return m_pos
; }
354 void SetPosition(float pos
)
356 wxASSERT_MSG( pos
>= 0 && pos
<= 1, "invalid gradient stop position" );
362 // The colour of this gradient band.
365 // Its starting position: 0 is the beginning and 1 is the end.
369 // A collection of gradient stops ordered by their positions (from lowest to
370 // highest). The first stop (index 0, position 0.0) is always the starting
371 // colour and the last one (index GetCount() - 1, position 1.0) is the end
373 class WXDLLIMPEXP_CORE wxGraphicsGradientStops
376 wxGraphicsGradientStops(wxColour startCol
= wxTransparentColour
,
377 wxColour endCol
= wxTransparentColour
)
379 // we can't use Add() here as it relies on having start/end stops as
380 // first/last array elements so do it manually
381 m_stops
.push_back(wxGraphicsGradientStop(startCol
, 0.f
));
382 m_stops
.push_back(wxGraphicsGradientStop(endCol
, 1.f
));
385 // default copy ctor, assignment operator and dtor are ok for this class
388 // Add a stop in correct order.
389 void Add(const wxGraphicsGradientStop
& stop
);
390 void Add(wxColour col
, float pos
) { Add(wxGraphicsGradientStop(col
, pos
)); }
392 // Get the number of stops.
393 unsigned GetCount() const { return m_stops
.size(); }
395 // Return the stop at the given index (which must be valid).
396 wxGraphicsGradientStop
Item(unsigned n
) const { return m_stops
.at(n
); }
398 // Get/set start and end colours.
399 void SetStartColour(wxColour col
)
400 { m_stops
[0].SetColour(col
); }
401 wxColour
GetStartColour() const
402 { return m_stops
[0].GetColour(); }
403 void SetEndColour(wxColour col
)
404 { m_stops
[m_stops
.size() - 1].SetColour(col
); }
405 wxColour
GetEndColour() const
406 { return m_stops
[m_stops
.size() - 1].GetColour(); }
409 // All the stops stored in ascending order of positions.
410 wxVector
<wxGraphicsGradientStop
> m_stops
;
413 class WXDLLIMPEXP_CORE wxGraphicsContext
: public wxGraphicsObject
416 wxGraphicsContext(wxGraphicsRenderer
* renderer
);
418 virtual ~wxGraphicsContext();
420 static wxGraphicsContext
* Create( const wxWindowDC
& dc
);
421 static wxGraphicsContext
* Create( const wxMemoryDC
& dc
);
422 #if wxUSE_PRINTING_ARCHITECTURE
423 static wxGraphicsContext
* Create( const wxPrinterDC
& dc
);
426 #if wxUSE_ENH_METAFILE
427 static wxGraphicsContext
* Create( const wxEnhMetaFileDC
& dc
);
431 static wxGraphicsContext
* CreateFromNative( void * context
);
433 static wxGraphicsContext
* CreateFromNativeWindow( void * window
);
435 static wxGraphicsContext
* Create( wxWindow
* window
);
438 // Create a context for drawing onto a wxImage. The image life time must be
439 // greater than that of the context itself as when the context is destroyed
440 // it will copy its contents to the specified image.
441 static wxGraphicsContext
* Create(wxImage
& image
);
442 #endif // wxUSE_IMAGE
444 // create a context that can be used for measuring texts only, no drawing allowed
445 static wxGraphicsContext
* Create();
447 // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown
448 virtual bool StartDoc( const wxString
& message
);
450 // done with that document (relevant only for printing / pdf etc)
451 virtual void EndDoc();
453 // opens a new page (relevant only for printing / pdf etc) with the given size in points
454 // (if both are null the default page size will be used)
455 virtual void StartPage( wxDouble width
= 0, wxDouble height
= 0 );
457 // ends the current page (relevant only for printing / pdf etc)
458 virtual void EndPage();
460 // make sure that the current content of this context is immediately visible
461 virtual void Flush();
463 wxGraphicsPath
CreatePath() const;
465 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) const;
467 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) const;
469 // sets the brush to a linear gradient, starting at (x1,y1) and ending at
470 // (x2,y2) with the given boundary colours or the specified stops
472 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
473 wxDouble x2
, wxDouble y2
,
474 const wxColour
& c1
, const wxColour
& c2
) const;
476 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
477 wxDouble x2
, wxDouble y2
,
478 const wxGraphicsGradientStops
& stops
) const;
480 // sets the brush to a radial gradient originating at (xo,yc) and ending
481 // on a circle around (xc,yc) with the given radius; the colours may be
482 // specified by just the two extremes or the full array of gradient stops
484 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
485 wxDouble xc
, wxDouble yc
, wxDouble radius
,
486 const wxColour
& oColor
, const wxColour
& cColor
) const;
489 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
490 wxDouble xc
, wxDouble yc
, wxDouble radius
,
491 const wxGraphicsGradientStops
& stops
) const;
494 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) const;
495 virtual wxGraphicsFont
CreateFont(double sizeInPixels
,
496 const wxString
& facename
,
497 int flags
= wxFONTFLAG_DEFAULT
,
498 const wxColour
& col
= *wxBLACK
) const;
500 // create a native bitmap representation
501 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) const;
503 wxGraphicsBitmap
CreateBitmapFromImage(const wxImage
& image
) const;
504 #endif // wxUSE_IMAGE
506 // create a native bitmap representation
507 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) const;
509 // create a 'native' matrix corresponding to these values
510 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
511 wxDouble tx
=0.0, wxDouble ty
=0.0) const;
513 // push the current state of the context, ie the transformation matrix on a stack
514 virtual void PushState() = 0;
516 // pops a stored state from the stack
517 virtual void PopState() = 0;
519 // clips drawings to the region intersected with the current clipping region
520 virtual void Clip( const wxRegion
®ion
) = 0;
522 // clips drawings to the rect intersected with the current clipping region
523 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
525 // resets the clipping to original extent
526 virtual void ResetClip() = 0;
528 // returns the native context
529 virtual void * GetNativeContext() = 0;
531 // returns the current shape antialiasing mode
532 virtual wxAntialiasMode
GetAntialiasMode() const { return m_antialias
; }
534 // sets the antialiasing mode, returns true if it supported
535 virtual bool SetAntialiasMode(wxAntialiasMode antialias
) = 0;
537 // returns the current interpolation quality
538 virtual wxInterpolationQuality
GetInterpolationQuality() const { return m_interpolation
; }
540 // sets the interpolation quality, returns true if it supported
541 virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation
) = 0;
543 // returns the current compositing operator
544 virtual wxCompositionMode
GetCompositionMode() const { return m_composition
; }
546 // sets the compositing operator, returns true if it supported
547 virtual bool SetCompositionMode(wxCompositionMode op
) = 0;
549 // returns the size of the graphics context in device coordinates
550 void GetSize(wxDouble
* width
, wxDouble
* height
)
558 // returns the resolution of the graphics context in device points per inch
559 virtual void GetDPI( wxDouble
* dpiX
, wxDouble
* dpiY
);
562 // sets the current alpha on this context
563 virtual void SetAlpha( wxDouble alpha
);
565 // returns the alpha on this context
566 virtual wxDouble
GetAlpha() const;
569 // all rendering is done into a fully transparent temporary context
570 virtual void BeginLayer(wxDouble opacity
) = 0;
572 // composites back the drawings into the context with the opacity given at
573 // the BeginLayer call
574 virtual void EndLayer() = 0;
577 // transformation : changes the current transformation matrix CTM of the context
581 virtual void Translate( wxDouble dx
, wxDouble dy
) = 0;
584 virtual void Scale( wxDouble xScale
, wxDouble yScale
) = 0;
587 virtual void Rotate( wxDouble angle
) = 0;
589 // concatenates this transform with the current transform of this context
590 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
) = 0;
592 // sets the transform of this context
593 virtual void SetTransform( const wxGraphicsMatrix
& matrix
) = 0;
595 // gets the matrix of this context
596 virtual wxGraphicsMatrix
GetTransform() const = 0;
602 virtual void SetPen( const wxGraphicsPen
& pen
);
604 void SetPen( const wxPen
& pen
);
606 // sets the brush for filling
607 virtual void SetBrush( const wxGraphicsBrush
& brush
);
609 void SetBrush( const wxBrush
& brush
);
612 virtual void SetFont( const wxGraphicsFont
& font
);
614 void SetFont( const wxFont
& font
, const wxColour
& colour
);
617 // strokes along a path with the current pen
618 virtual void StrokePath( const wxGraphicsPath
& path
) = 0;
620 // fills a path with the current brush
621 virtual void FillPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) = 0;
623 // draws a path by first filling and then stroking
624 virtual void DrawPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
630 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
631 { DoDrawText(str
, x
, y
); }
633 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
634 { DoDrawRotatedText(str
, x
, y
, angle
); }
636 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
,
637 const wxGraphicsBrush
& backgroundBrush
)
638 { DoDrawFilledText(str
, x
, y
, backgroundBrush
); }
640 void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
,
641 wxDouble angle
, const wxGraphicsBrush
& backgroundBrush
)
642 { DoDrawRotatedFilledText(str
, x
, y
, angle
, backgroundBrush
); }
645 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
646 wxDouble
*descent
= NULL
, wxDouble
*externalLeading
= NULL
) const = 0;
648 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const = 0;
654 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
656 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
658 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
661 // convenience methods
664 // strokes a single line
665 virtual void StrokeLine( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
667 // stroke lines connecting each of the points
668 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
670 // stroke disconnected lines from begin to end points
671 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*beginPoints
, const wxPoint2DDouble
*endPoints
);
674 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
677 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
680 virtual void DrawEllipse( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
682 // draws a rounded rectangle
683 virtual void DrawRoundedRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
, wxDouble radius
);
685 // wrappers using wxPoint2DDouble TODO
687 // helper to determine if a 0.5 offset should be applied for the drawing operation
688 virtual bool ShouldOffset() const { return false; }
690 // indicates whether the context should try to offset for pixel boundaries, this only makes sense on
691 // bitmap devices like screen, by default this is turned off
692 virtual void EnableOffset(bool enable
= true);
694 void DisableOffset() { EnableOffset(false); }
695 bool OffsetEnabled() { return m_enableOffset
; }
698 // These fields must be initialized in the derived class ctors.
703 wxGraphicsBrush m_brush
;
704 wxGraphicsFont m_font
;
705 wxAntialiasMode m_antialias
;
706 wxCompositionMode m_composition
;
707 wxInterpolationQuality m_interpolation
;
711 // implementations of overloaded public functions: we use different names
712 // for them to avoid the virtual function hiding problems in the derived
714 virtual void DoDrawText(const wxString
& str
, wxDouble x
, wxDouble y
) = 0;
715 virtual void DoDrawRotatedText(const wxString
& str
, wxDouble x
, wxDouble y
,
717 virtual void DoDrawFilledText(const wxString
& str
, wxDouble x
, wxDouble y
,
718 const wxGraphicsBrush
& backgroundBrush
);
719 virtual void DoDrawRotatedFilledText(const wxString
& str
,
720 wxDouble x
, wxDouble y
,
722 const wxGraphicsBrush
& backgroundBrush
);
724 wxDECLARE_NO_COPY_CLASS(wxGraphicsContext
);
725 DECLARE_ABSTRACT_CLASS(wxGraphicsContext
)
731 // A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements
734 class WXDLLIMPEXP_CORE wxGraphicsFigure
: public wxGraphicsObject
737 wxGraphicsFigure(wxGraphicsRenderer
* renderer
);
739 virtual ~wxGraphicsFigure();
741 void SetPath( wxGraphicsMatrix
* matrix
);
743 void SetMatrix( wxGraphicsPath
* path
);
745 // draws this object on the context
746 virtual void Draw( wxGraphicsContext
* cg
);
748 // returns the path of this object
749 wxGraphicsPath
* GetPath() { return m_path
; }
751 // returns the transformation matrix of this object, may be null if there is no transformation necessary
752 wxGraphicsMatrix
* GetMatrix() { return m_matrix
; }
755 wxGraphicsMatrix
* m_matrix
;
756 wxGraphicsPath
* m_path
;
758 DECLARE_DYNAMIC_CLASS(wxGraphicsFigure
)
764 // The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer
765 // instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional
766 // paths at any point from a given matrix etc.
769 class WXDLLIMPEXP_CORE wxGraphicsRenderer
: public wxObject
772 wxGraphicsRenderer() {}
774 virtual ~wxGraphicsRenderer() {}
776 static wxGraphicsRenderer
* GetDefaultRenderer();
778 static wxGraphicsRenderer
* GetCairoRenderer();
781 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
) = 0;
782 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
) = 0;
783 #if wxUSE_PRINTING_ARCHITECTURE
784 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
) = 0;
787 #if wxUSE_ENH_METAFILE
788 virtual wxGraphicsContext
* CreateContext( const wxEnhMetaFileDC
& dc
) = 0;
792 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
) = 0;
794 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
) = 0;
796 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
) = 0;
799 virtual wxGraphicsContext
* CreateContextFromImage(wxImage
& image
) = 0;
800 #endif // wxUSE_IMAGE
802 // create a context that can be used for measuring texts only, no drawing allowed
803 virtual wxGraphicsContext
* CreateMeasuringContext() = 0;
807 virtual wxGraphicsPath
CreatePath() = 0;
811 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
812 wxDouble tx
=0.0, wxDouble ty
=0.0) = 0;
816 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) = 0;
818 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) = 0;
820 // Gradient brush creation functions may not honour all the stops specified
821 // stops and use just its boundary colours (this is currently the case
823 virtual wxGraphicsBrush
824 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
825 wxDouble x2
, wxDouble y2
,
826 const wxGraphicsGradientStops
& stops
) = 0;
828 virtual wxGraphicsBrush
829 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
830 wxDouble xc
, wxDouble yc
,
832 const wxGraphicsGradientStops
& stops
) = 0;
835 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) = 0;
836 virtual wxGraphicsFont
CreateFont(double sizeInPixels
,
837 const wxString
& facename
,
838 int flags
= wxFONTFLAG_DEFAULT
,
839 const wxColour
& col
= *wxBLACK
) = 0;
841 // create a native bitmap representation
842 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) = 0;
844 virtual wxGraphicsBitmap
CreateBitmapFromImage(const wxImage
& image
) = 0;
845 virtual wxImage
CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
) = 0;
846 #endif // wxUSE_IMAGE
848 // create a graphics bitmap from a native bitmap
849 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
) = 0;
851 // create a subimage from a native image representation
852 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
855 wxDECLARE_NO_COPY_CLASS(wxGraphicsRenderer
);
856 DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer
)
862 wxImage
wxGraphicsBitmap::ConvertToImage() const
864 wxGraphicsRenderer
* renderer
= GetRenderer();
865 return renderer
? renderer
->CreateImageFromBitmap(*this) : wxNullImage
;
867 #endif // wxUSE_IMAGE
869 #endif // wxUSE_GRAPHICS_CONTEXT
871 #endif // _WX_GRAPHICS_H_