1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of various wxGraphics* classes
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
12 A wxGraphicsPath is a native representation of a geometric path. The
13 contents are specific an private to the respective renderer. Instances are
14 reference counted and can therefore be assigned as usual. The only way to
15 get a valid instance is by using wxGraphicsContext::CreatePath() or
16 wxGraphicsRenderer::CreatePath().
21 class wxGraphicsPath
: public wxGraphicsObject
25 Adds an arc of a circle.
27 The circle is defined by the coordinates of its centre (@a x, @a y) or
28 @a c and its radius @a r. The arc goes from the starting angle @a
29 startAngle to @a endAngle either clockwise or counter-clockwise
30 depending on the value of @a clockwise argument.
32 The angles are measured in radians but, contrary to the usual
33 mathematical convention, are always @e clockwise from the horizontal
37 virtual void AddArc(wxDouble x
, wxDouble y
, wxDouble r
,
38 wxDouble startAngle
, wxDouble endAngle
,
40 void AddArc(const wxPoint2DDouble
& c
, wxDouble r
,
41 wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
45 Appends a an arc to two tangents connecting (current) to (@a x1,@a y1)
46 and (@a x1,@a y1) to (@a x2,@a y2), also a straight line from (current)
49 virtual void AddArcToPoint(wxDouble x1
, wxDouble y1
, wxDouble x2
,
50 wxDouble y2
, wxDouble r
);
53 Appends a circle around (@a x,@a y) with radius @a r as a new closed
56 virtual void AddCircle(wxDouble x
, wxDouble y
, wxDouble r
);
59 Adds a cubic bezier curve from the current point, using two control
60 points and an end point.
62 virtual void AddCurveToPoint(wxDouble cx1
, wxDouble cy1
,
63 wxDouble cx2
, wxDouble cy2
,
64 wxDouble x
, wxDouble y
);
66 Adds a cubic bezier curve from the current point, using two control
67 points and an end point.
69 void AddCurveToPoint(const wxPoint2DDouble
& c1
,
70 const wxPoint2DDouble
& c2
,
71 const wxPoint2DDouble
& e
);
74 Appends an ellipse fitting into the passed in rectangle.
76 virtual void AddEllipse(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
79 Adds a straight line from the current point to (@a x,@a y).
81 virtual void AddLineToPoint(wxDouble x
, wxDouble y
);
83 Adds a straight line from the current point to @a p.
85 void AddLineToPoint(const wxPoint2DDouble
& p
);
90 virtual void AddPath(const wxGraphicsPath
& path
);
93 Adds a quadratic bezier curve from the current point, using a control
94 point and an end point.
96 virtual void AddQuadCurveToPoint(wxDouble cx
, wxDouble cy
,
97 wxDouble x
, wxDouble y
);
100 Appends a rectangle as a new closed subpath.
102 virtual void AddRectangle(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
105 Appends a rounded rectangle as a new closed subpath.
107 virtual void AddRoundedRectangle(wxDouble x
, wxDouble y
, wxDouble w
,
108 wxDouble h
, wxDouble radius
);
111 Closes the current sub-path.
113 virtual void CloseSubpath();
116 @return @true if the point is within the path.
118 bool Contains(const wxPoint2DDouble
& c
,
119 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) const;
121 @return @true if the point is within the path.
123 virtual bool Contains(wxDouble x
, wxDouble y
,
124 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) const;
127 Gets the bounding box enclosing all points (possibly including control
130 wxRect2DDouble
GetBox() const;
132 Gets the bounding box enclosing all points (possibly including control
135 virtual void GetBox(wxDouble
* x
, wxDouble
* y
,
136 wxDouble
* w
, wxDouble
* h
) const;
139 Gets the last point of the current path, (0,0) if not yet set.
141 virtual void GetCurrentPoint(wxDouble
* x
, wxDouble
* y
) const;
143 Gets the last point of the current path, (0,0) if not yet set.
145 wxPoint2DDouble
GetCurrentPoint() const;
148 Returns the native path (CGPathRef for Core Graphics, Path pointer for
149 GDIPlus and a cairo_path_t pointer for cairo).
151 virtual void* GetNativePath() const;
154 Begins a new subpath at (@a x,@a y).
156 virtual void MoveToPoint(wxDouble x
, wxDouble y
);
158 Begins a new subpath at @a p.
160 void MoveToPoint(const wxPoint2DDouble
& p
);
163 Transforms each point of this path by the matrix.
165 virtual void Transform(const wxGraphicsMatrix
& matrix
);
168 Gives back the native path returned by GetNativePath() because there
169 might be some deallocations necessary (e.g. on cairo the native path
170 returned by GetNativePath() is newly allocated each time).
172 virtual void UnGetNativePath(void* p
) const;
178 @class wxGraphicsObject
180 This class is the superclass of native graphics objects like pens etc. It
181 allows reference counting. Not instantiated by user code.
186 @see wxGraphicsBrush, wxGraphicsPen, wxGraphicsMatrix, wxGraphicsPath
188 class wxGraphicsObject
: public wxObject
192 Returns the renderer that was used to create this instance, or @NULL
193 if it has not been initialized yet.
195 wxGraphicsRenderer
* GetRenderer() const;
198 @return @false if this object is valid, otherwise returns @true.
204 Anti-aliasing modes used by wxGraphicsContext::SetAntialiasMode().
208 /** No anti-aliasing */
211 /** The default anti-aliasing */
216 Interpolation quality used by wxGraphicsContext::SetInterpolationQuality().
218 enum wxInterpolationQuality
220 /** default interpolation, based on type of context, in general medium quality */
221 wxINTERPOLATION_DEFAULT
,
222 /** no interpolation */
223 wxINTERPOLATION_NONE
,
224 /** fast interpolation, suited for interactivity */
225 wxINTERPOLATION_FAST
,
226 /** better quality */
227 wxINTERPOLATION_GOOD
,
228 /** best quality, not suited for interactivity */
233 Compositing is done using Porter-Duff compositions
234 (see http://keithp.com/~keithp/porterduff/p253-porter.pdf) with
235 wxGraphicsContext::SetCompositionMode().
237 The description give a short equation on how the values of a resulting
238 pixel are calculated.
239 @e R = Result, @e S = Source, @e D = Destination, colors premultiplied with alpha
240 @e Ra, @e Sa, @e Da their alpha components
242 enum wxCompositionMode
245 Indicates invalid or unsupported composition mode.
247 This value can't be passed to wxGraphicsContext::SetCompositionMode().
251 wxCOMPOSITION_INVALID
= -1,
252 wxCOMPOSITION_CLEAR
, /**< @e R = 0 */
253 wxCOMPOSITION_SOURCE
, /**< @e R = S */
254 wxCOMPOSITION_OVER
, /**< @e R = @e S + @e D*(1 - @e Sa) */
255 wxCOMPOSITION_IN
, /**< @e R = @e S*@e Da */
256 wxCOMPOSITION_OUT
, /**< @e R = @e S*(1 - @e Da) */
257 wxCOMPOSITION_ATOP
, /**< @e R = @e S*@e Da + @e D*(1 - @e Sa) */
259 wxCOMPOSITION_DEST
, /**< @e R = @e D, essentially a noop */
260 wxCOMPOSITION_DEST_OVER
, /**< @e R = @e S*(1 - @e Da) + @e D */
261 wxCOMPOSITION_DEST_IN
, /**< @e R = @e D*@e Sa */
262 wxCOMPOSITION_DEST_OUT
, /**< @e R = @e D*(1 - @e Sa) */
263 wxCOMPOSITION_DEST_ATOP
, /**< @e R = @e S*(1 - @e Da) + @e D*@e Sa */
264 wxCOMPOSITION_XOR
, /**< @e R = @e S*(1 - @e Da) + @e D*(1 - @e Sa) */
265 wxCOMPOSITION_ADD
/**< @e R = @e S + @e D */
271 The objects of this class are not created directly but only via
272 wxGraphicsContext or wxGraphicsRenderer CreateBitmap(),
273 CreateBitmapFromImage() or CreateSubBitmap() methods. They can subsequently
274 be used with wxGraphicsContext::DrawBitmap(). The only other operation is
275 testing for the bitmap validity which can be performed using IsNull()
276 method inherited from the base class.
278 class wxGraphicsBitmap
: public wxGraphicsObject
282 Default constructor creates an invalid bitmap.
284 wxGraphicsBitmap() {}
287 Return the contents of this bitmap as wxImage.
289 Using this method is more efficient than converting wxGraphicsBitmap to
290 wxBitmap first and then to wxImage and can be useful if, for example,
291 you want to save wxGraphicsBitmap as a disk file in a format not
292 directly supported by wxBitmap.
294 Invalid image is returned if the bitmap is invalid.
298 wxImage
ConvertToImage() const;
301 Return the pointer to the native bitmap data. (CGImageRef for Core Graphics,
302 cairo_surface_t for Cairo, Bitmap* for GDI+.)
306 void* GetNativeBitmap() const;
310 @class wxGraphicsContext
312 A wxGraphicsContext instance is the object that is drawn upon. It is
313 created by a renderer using wxGraphicsRenderer::CreateContext(). This can
314 be either directly using a renderer instance, or indirectly using the
315 static convenience Create() functions of wxGraphicsContext that always
316 delegate the task to the default renderer.
319 void MyCanvas::OnPaint(wxPaintEvent &event)
324 // Create graphics context from it
325 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
329 // make a path that contains a circle and some lines
330 gc->SetPen( *wxRED_PEN );
331 wxGraphicsPath path = gc->CreatePath();
332 path.AddCircle( 50.0, 50.0, 50.0 );
333 path.MoveToPoint(0.0, 50.0);
334 path.AddLineToPoint(100.0, 50.0);
335 path.MoveToPoint(50.0, 0.0);
336 path.AddLineToPoint(50.0, 100.0 );
338 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
340 gc->StrokePath(path);
350 @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
352 class wxGraphicsContext
: public wxGraphicsObject
356 Creates a wxGraphicsContext from a wxWindow.
358 @see wxGraphicsRenderer::CreateContext()
360 static wxGraphicsContext
* Create(wxWindow
* window
);
363 Creates a wxGraphicsContext from a wxWindowDC
365 @see wxGraphicsRenderer::CreateContext()
367 static wxGraphicsContext
* Create(const wxWindowDC
& windowDC
);
370 Creates a wxGraphicsContext from a wxMemoryDC
372 @see wxGraphicsRenderer::CreateContext()
374 static wxGraphicsContext
* Create(const wxMemoryDC
& memoryDC
);
377 Creates a wxGraphicsContext from a wxPrinterDC. Under GTK+, this will
378 only work when using the GtkPrint printing backend which is available
381 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting
383 static wxGraphicsContext
* Create(const wxPrinterDC
& printerDC
);
386 Creates a wxGraphicsContext from a wxEnhMetaFileDC.
388 This function, as wxEnhMetaFileDC class itself, is only available only
391 @see wxGraphicsRenderer::CreateContext()
393 static wxGraphicsContext
* Create(const wxEnhMetaFileDC
& metaFileDC
);
396 Creates a wxGraphicsContext associated with a wxImage.
398 The image specifies the size of the context as well as whether alpha is
399 supported (if wxImage::HasAlpha()) or not and the initial contents of
400 the context. The @a image object must have a life time greater than
401 that of the new context as the context copies its contents back to the
402 image when it is destroyed.
406 static wxGraphicsContext
* Create(wxImage
& image
);
409 Create a lightweight context that can be used only for measuring text.
411 static wxGraphicsContext
* Create();
414 Clips drawings to the specified region.
416 virtual void Clip(const wxRegion
& region
) = 0;
419 Clips drawings to the specified rectangle.
421 virtual void Clip(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
424 Concatenates the passed in transform with the current transform of this
427 virtual void ConcatTransform(const wxGraphicsMatrix
& matrix
) = 0;
430 Creates wxGraphicsBitmap from an existing wxBitmap.
432 Returns an invalid wxNullGraphicsBitmap on failure.
434 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) = 0;
437 Creates wxGraphicsBitmap from an existing wxImage.
439 This method is more efficient than converting wxImage to wxBitmap first
440 and then calling CreateBitmap() but otherwise has the same effect.
442 Returns an invalid wxNullGraphicsBitmap on failure.
446 virtual wxGraphicsBitmap
CreateBitmapFromImage(const wxImage
& image
);
449 Extracts a sub-bitmap from an existing bitmap.
451 Currently this function is implemented in the native MSW and OS X
452 versions but not when using Cairo.
454 virtual wxGraphicsBitmap
CreateSubBitmap(const wxGraphicsBitmap
& bitmap
,
455 wxDouble x
, wxDouble y
,
456 wxDouble w
, wxDouble h
) = 0;
459 Creates a native brush from a wxBrush.
461 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) const;
464 Creates a native graphics font from a wxFont and a text colour.
466 virtual wxGraphicsFont
CreateFont(const wxFont
& font
,
467 const wxColour
& col
= *wxBLACK
) const;
470 Creates a font object with the specified attributes.
472 The use of overload taking wxFont is preferred, see
473 wxGraphicsRenderer::CreateFont() for more details.
477 virtual wxGraphicsFont
CreateFont(double sizeInPixels
,
478 const wxString
& facename
,
479 int flags
= wxFONTFLAG_DEFAULT
,
480 const wxColour
& col
= *wxBLACK
) const;
483 Creates a wxGraphicsContext from a native context. This native context
484 must be a CGContextRef for Core Graphics, a Graphics pointer for
485 GDIPlus, or a cairo_t pointer for cairo.
487 @see wxGraphicsRenderer::CreateContextFromNativeContext()
489 static wxGraphicsContext
* CreateFromNative(void* context
);
492 Creates a wxGraphicsContext from a native window.
494 @see wxGraphicsRenderer::CreateContextFromNativeWindow()
496 static wxGraphicsContext
* CreateFromNativeWindow(void* window
);
499 Creates a native brush with a linear gradient.
501 The brush starts at (@a x1, @a y1) and ends at (@a x2, @a y2). Either
502 just the start and end gradient colours (@a c1 and @a c2) or full set
503 of gradient @a stops can be specified.
505 The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.
509 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
510 wxDouble x2
, wxDouble y2
,
511 const wxColour
& c1
, const wxColour
& c2
) const;
514 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
515 wxDouble x2
, wxDouble y2
,
516 const wxGraphicsGradientStops
& stops
) const;
520 Creates a native affine transformation matrix from the passed in
521 values. The default parameters result in an identity matrix.
523 virtual wxGraphicsMatrix
CreateMatrix(wxDouble a
= 1.0, wxDouble b
= 0.0,
524 wxDouble c
= 0.0, wxDouble d
= 1.0,
526 wxDouble ty
= 0.0) const;
529 Creates a native affine transformation matrix from the passed
534 wxGraphicsMatrix
CreateMatrix(const wxAffineMatrix2DBase
& mat
) const;
537 Creates a native graphics path which is initially empty.
539 wxGraphicsPath
CreatePath() const;
542 Creates a native pen from a wxPen.
544 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) const;
547 Creates a native brush with a radial gradient.
549 The brush originates at (@a xo, @a yc) and ends on a circle around
550 (@a xc, @a yc) with the given @a radius.
552 The gradient may be specified either by its start and end colours @a
553 oColor and @a cColor or by a full set of gradient @a stops.
555 The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.
558 virtual wxGraphicsBrush
559 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
560 wxDouble xc
, wxDouble yc
,
562 const wxColour
& oColor
,
563 const wxColour
& cColor
) const;
565 virtual wxGraphicsBrush
566 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
567 wxDouble xc
, wxDouble yc
,
569 const wxGraphicsGradientStops
& stops
) = 0;
573 Draws the bitmap. In case of a mono bitmap, this is treated as a mask
574 and the current brushed is used for filling.
577 virtual void DrawBitmap(const wxGraphicsBitmap
& bmp
,
578 wxDouble x
, wxDouble y
,
579 wxDouble w
, wxDouble h
) = 0;
580 virtual void DrawBitmap(const wxBitmap
& bmp
,
581 wxDouble x
, wxDouble y
,
582 wxDouble w
, wxDouble h
) = 0;
588 virtual void DrawEllipse(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
593 virtual void DrawIcon(const wxIcon
& icon
, wxDouble x
, wxDouble y
,
594 wxDouble w
, wxDouble h
) = 0;
599 virtual void DrawLines(size_t n
, const wxPoint2DDouble
* points
,
600 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
603 Draws the path by first filling and then stroking.
605 virtual void DrawPath(const wxGraphicsPath
& path
,
606 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
611 virtual void DrawRectangle(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
614 Draws a rounded rectangle.
616 virtual void DrawRoundedRectangle(wxDouble x
, wxDouble y
, wxDouble w
,
617 wxDouble h
, wxDouble radius
);
620 Draws text at the defined position.
622 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
);
624 Draws text at the defined position.
629 The x coordinate position to draw the text at.
631 The y coordinate position to draw the text at.
633 The angle relative to the (default) horizontal direction to draw
636 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
, wxDouble angle
);
638 Draws text at the defined position.
643 The x coordinate position to draw the text at.
645 The y coordinate position to draw the text at.
646 @param backgroundBrush
647 Brush to fill the text with.
649 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
,
650 const wxGraphicsBrush
& backgroundBrush
);
652 Draws text at the defined position.
657 The x coordinate position to draw the text at.
659 The y coordinate position to draw the text at.
661 The angle relative to the (default) horizontal direction to draw
663 @param backgroundBrush
664 Brush to fill the text with.
666 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
,
667 wxDouble angle
, const wxGraphicsBrush
& backgroundBrush
);
670 Fills the path with the current brush.
672 virtual void FillPath(const wxGraphicsPath
& path
,
673 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) = 0;
676 Returns the native context (CGContextRef for Core Graphics, Graphics
677 pointer for GDIPlus and cairo_t pointer for cairo).
679 virtual void* GetNativeContext() = 0;
682 Fills the @a widths array with the widths from the beginning of
683 @a text to the corresponding character of @a text.
685 virtual void GetPartialTextExtents(const wxString
& text
,
686 wxArrayDouble
& widths
) const = 0;
689 Gets the dimensions of the string using the currently selected font.
692 The text string to measure.
694 Variable to store the total calculated width of the text.
696 Variable to store the total calculated height of the text.
698 Variable to store the dimension from the baseline of the font to
699 the bottom of the descender.
700 @param externalLeading
701 Any extra vertical space added to the font by the font designer
704 virtual void GetTextExtent(const wxString
& text
, wxDouble
* width
,
705 wxDouble
* height
, wxDouble
* descent
,
706 wxDouble
* externalLeading
) const = 0;
709 Gets the current transformation matrix of this context.
711 virtual wxGraphicsMatrix
GetTransform() const = 0;
714 Resets the clipping to original shape.
716 virtual void ResetClip() = 0;
719 Rotates the current transformation matrix (in radians).
721 virtual void Rotate(wxDouble angle
) = 0;
724 Scales the current transformation matrix.
726 virtual void Scale(wxDouble xScale
, wxDouble yScale
) = 0;
729 Sets the brush for filling paths.
731 void SetBrush(const wxBrush
& brush
);
733 Sets the brush for filling paths.
735 virtual void SetBrush(const wxGraphicsBrush
& brush
);
738 Sets the font for drawing text.
740 void SetFont(const wxFont
& font
, const wxColour
& colour
);
742 Sets the font for drawing text.
744 virtual void SetFont(const wxGraphicsFont
& font
);
747 Sets the pen used for stroking.
749 void SetPen(const wxPen
& pen
);
751 Sets the pen used for stroking.
753 virtual void SetPen(const wxGraphicsPen
& pen
);
756 Sets the current transformation matrix of this context
758 virtual void SetTransform(const wxGraphicsMatrix
& matrix
) = 0;
761 Strokes a single line.
763 virtual void StrokeLine(wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
766 Stroke disconnected lines from begin to end points, fastest method
767 available for this purpose.
769 virtual void StrokeLines(size_t n
, const wxPoint2DDouble
* beginPoints
,
770 const wxPoint2DDouble
* endPoints
);
772 Stroke lines connecting all the points.
774 Unlike the other overload of this function, this method draws a single
775 polyline and not a number of disconnected lines.
777 virtual void StrokeLines(size_t n
, const wxPoint2DDouble
* points
);
780 Strokes along a path with the current pen.
782 virtual void StrokePath(const wxGraphicsPath
& path
) = 0;
785 Translates the current transformation matrix.
787 virtual void Translate(wxDouble dx
, wxDouble dy
) = 0;
790 Redirects all rendering is done into a fully transparent temporary context
792 virtual void BeginLayer(wxDouble opacity
) = 0;
795 Composites back the drawings into the context with the opacity given at
798 virtual void EndLayer() = 0;
801 Sets the antialiasing mode, returns true if it supported
803 virtual bool SetAntialiasMode(wxAntialiasMode antialias
) = 0;
806 Returns the current shape antialiasing mode
808 virtual wxAntialiasMode
GetAntialiasMode() const ;
811 Sets the interpolation quality, returns true if it is supported.
813 Not implemented in Cairo backend currently.
815 virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation
) = 0;
818 Returns the current interpolation quality.
820 virtual wxInterpolationQuality
GetInterpolationQuality() const;
823 Sets the compositing operator, returns true if it supported
825 virtual bool SetCompositionMode(wxCompositionMode op
) = 0;
828 Returns the current compositing operator
830 virtual wxCompositionMode
GetCompositionMode() const;
834 Push the current state of the context's transformation matrix on a
837 @see wxGraphicsContext::PopState
839 virtual void PushState() = 0;
842 Pops a stored state from the stack and sets the current transformation
843 matrix to that state.
845 @see wxGraphicsContext::PopState
847 virtual void PopState() = 0;
850 virtual void EnableOffset(bool enable
= true);
851 void DisableOffset();
852 bool OffsetEnabled();
857 Represents a single gradient stop in a collection of gradient stops as
858 represented by wxGraphicsGradientStops.
865 class wxGraphicsGradientStop
869 Creates a stop with the given colour and position.
871 @param col The colour of this stop. Note that the alpha component of
872 the colour is honoured thus allowing the background colours to
873 partially show through the gradient.
874 @param pos The stop position, must be in [0, 1] range with 0 being the
875 beginning and 1 the end of the gradient.
877 wxGraphicsGradientStop(wxColour col
= wxTransparentColour
, float pos
= 0.);
879 /// Return the stop colour.
880 const wxColour
& GetColour() const;
883 Change the stop colour.
885 @param col The new colour.
887 void SetColour(const wxColour
& col
);
889 /// Return the stop position.
890 float GetPosition() const;
893 Change the stop position.
895 @param pos The new position, must always be in [0, 1] range.
897 void SetPosition(float pos
);
901 Represents a collection of wxGraphicGradientStop values for use with
902 CreateLinearGradientBrush and CreateRadialGradientBrush.
904 The stops are maintained in order of position. If two or more stops are
905 added with the same position then the one(s) added later come later.
906 This can be useful for producing discontinuities in the colour gradient.
908 Notice that this class is write-once, you can't modify the stops once they
916 class wxGraphicsGradientStops
920 Initializes the gradient stops with the given boundary colours.
922 Creates a wxGraphicsGradientStops instance with start colour given
923 by @a startCol and end colour given by @a endCol.
925 wxGraphicsGradientStops(wxColour startCol
= wxTransparentColour
,
926 wxColour endCol
= wxTransparentColour
);
932 void Add(const wxGraphicsGradientStop
& stop
);
933 void Add(wxColour col
, float pos
);
937 Returns the stop at the given index.
939 @param n The index, must be in [0, GetCount()) range.
941 wxGraphicsGradientStop
Item(unsigned n
) const;
944 Returns the number of stops.
946 unsigned GetCount() const;
949 Set the start colour to @a col
951 void SetStartColour(wxColour col
);
954 Returns the start colour.
956 wxColour
GetStartColour() const;
959 Set the end colour to @a col
961 void SetEndColour(wxColour col
);
964 Returns the end colour.
966 wxColour
GetEndColour() const;
970 @class wxGraphicsRenderer
972 A wxGraphicsRenderer is the instance corresponding to the rendering engine
973 used. There may be multiple instances on a system, if there are different
974 rendering engines present, but there is always only one instance per
975 engine. This instance is pointed back to by all objects created by it
976 (wxGraphicsContext, wxGraphicsPath etc) and can be retrieved through their
977 wxGraphicsObject::GetRenderer() method. Therefore you can create an
978 additional instance of a path etc. by calling
979 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX()
980 function of that renderer.
983 wxGraphicsPath *path = // from somewhere
984 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
990 class wxGraphicsRenderer
: public wxObject
994 Creates wxGraphicsBitmap from an existing wxBitmap.
996 Returns an invalid wxNullGraphicsBitmap on failure.
998 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
) = 0;
1001 Creates wxGraphicsBitmap from an existing wxImage.
1003 This method is more efficient than converting wxImage to wxBitmap first
1004 and then calling CreateBitmap() but otherwise has the same effect.
1006 Returns an invalid wxNullGraphicsBitmap on failure.
1010 virtual wxGraphicsBitmap
CreateBitmapFromImage(const wxImage
& image
) = 0;
1013 Creates a wxImage from a wxGraphicsBitmap.
1015 This method is used by the more convenient wxGraphicsBitmap::ConvertToImage.
1017 virtual wxImage
CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
) = 0;
1020 Creates wxGraphicsBitmap from a native bitmap handle.
1022 @a bitmap meaning is platform-dependent. Currently it's a GDI+ @c
1023 Bitmap pointer under MSW, @c CGImage pointer under OS X or a @c
1024 cairo_surface_t pointer when using Cairo under any platform.
1026 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
) = 0;
1029 Creates a wxGraphicsContext from a wxWindow.
1031 virtual wxGraphicsContext
* CreateContext(wxWindow
* window
) = 0;
1034 Creates a wxGraphicsContext from a wxWindowDC
1036 virtual wxGraphicsContext
* CreateContext(const wxWindowDC
& windowDC
) = 0 ;
1039 Creates a wxGraphicsContext from a wxMemoryDC
1041 virtual wxGraphicsContext
* CreateContext(const wxMemoryDC
& memoryDC
) = 0 ;
1044 Creates a wxGraphicsContext from a wxPrinterDC
1046 virtual wxGraphicsContext
* CreateContext(const wxPrinterDC
& printerDC
) = 0 ;
1049 Creates a wxGraphicsContext from a wxEnhMetaFileDC.
1051 This function, as wxEnhMetaFileDC class itself, is only available only
1054 virtual wxGraphicsContext
* CreateContext(const wxEnhMetaFileDC
& metaFileDC
) = 0;
1057 Creates a wxGraphicsContext associated with a wxImage.
1059 This function is used by wxContext::CreateFromImage() and is not
1060 normally called directly.
1064 wxGraphicsContext
* CreateContextFromImage(wxImage
& image
);
1067 Creates a native brush from a wxBrush.
1069 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) = 0;
1072 Creates a wxGraphicsContext from a native context. This native context
1073 must be a CGContextRef for Core Graphics, a Graphics pointer for
1074 GDIPlus, or a cairo_t pointer for cairo.
1076 virtual wxGraphicsContext
* CreateContextFromNativeContext(void* context
) = 0;
1079 Creates a wxGraphicsContext from a native window.
1081 virtual wxGraphicsContext
* CreateContextFromNativeWindow(void* window
) = 0;
1084 Creates a wxGraphicsContext that can be used for measuring texts only.
1085 No drawing commands are allowed.
1087 virtual wxGraphicsContext
* CreateMeasuringContext() = 0;
1090 Creates a native graphics font from a wxFont and a text colour.
1092 virtual wxGraphicsFont
CreateFont(const wxFont
& font
,
1093 const wxColour
& col
= *wxBLACK
) = 0;
1096 Creates a graphics font with the given characteristics.
1098 If possible, the CreateFont() overload taking wxFont should be used
1099 instead. The main advantage of this overload is that it can be used
1100 without X server connection under Unix when using Cairo.
1103 Height of the font in user space units, i.e. normally pixels.
1104 Notice that this is different from the overload taking wxFont as
1105 wxFont size is specified in points.
1107 The name of the font. The same font name might not be available
1108 under all platforms so the font name can also be empty to use the
1109 default platform font.
1111 Combination of wxFontFlag enum elements. Currently only
1112 @c wxFONTFLAG_ITALIC and @c wxFONTFLAG_BOLD are supported. By
1113 default the normal font version is used.
1115 The font colour, black by default.
1119 virtual wxGraphicsFont
CreateFont(double sizeInPixels
,
1120 const wxString
& facename
,
1121 int flags
= wxFONTFLAG_DEFAULT
,
1122 const wxColour
& col
= *wxBLACK
) = 0;
1126 Creates a native brush with a linear gradient.
1128 Stops support is new since wxWidgets 2.9.1, previously only the start
1129 and end colours could be specified.
1131 virtual wxGraphicsBrush
CreateLinearGradientBrush(wxDouble x1
,
1135 const wxGraphicsGradientStops
& stops
) = 0;
1138 Creates a native affine transformation matrix from the passed in
1139 values. The defaults result in an identity matrix.
1141 virtual wxGraphicsMatrix
CreateMatrix(wxDouble a
= 1.0, wxDouble b
= 0.0,
1142 wxDouble c
= 0.0, wxDouble d
= 1.0,
1144 wxDouble ty
= 0.0) = 0;
1147 Creates a native graphics path which is initially empty.
1149 virtual wxGraphicsPath
CreatePath() = 0;
1152 Creates a native pen from a wxPen.
1154 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) = 0;
1157 Creates a native brush with a radial gradient.
1159 Stops support is new since wxWidgets 2.9.1, previously only the start
1160 and end colours could be specified.
1162 virtual wxGraphicsBrush
CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
1163 wxDouble xc
, wxDouble yc
,
1165 const wxGraphicsGradientStops
& stops
) = 0;
1168 Extracts a sub-bitmap from an existing bitmap.
1170 Currently this function is implemented in the native MSW and OS X
1171 versions but not when using Cairo.
1173 virtual wxGraphicsBitmap
CreateSubBitmap(const wxGraphicsBitmap
& bitmap
,
1174 wxDouble x
, wxDouble y
,
1175 wxDouble w
, wxDouble h
) = 0;
1178 Returns the default renderer on this platform. On OS X this is the Core
1179 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and
1180 on GTK we currently default to the cairo renderer.
1182 static wxGraphicsRenderer
* GetDefaultRenderer();
1183 static wxGraphicsRenderer
* GetCairoRenderer();
1190 @class wxGraphicsBrush
1192 A wxGraphicsBrush is a native representation of a brush. The contents are
1193 specific and private to the respective renderer. Instances are ref counted
1194 and can therefore be assigned as usual. The only way to get a valid
1195 instance is via wxGraphicsContext::CreateBrush() or
1196 wxGraphicsRenderer::CreateBrush().
1201 class wxGraphicsBrush
: public wxGraphicsObject
1210 @class wxGraphicsFont
1212 A wxGraphicsFont is a native representation of a font. The contents are
1213 specific and private to the respective renderer. Instances are ref counted
1214 and can therefore be assigned as usual. The only way to get a valid
1215 instance is via wxGraphicsContext::CreateFont() or
1216 wxGraphicsRenderer::CreateFont().
1221 class wxGraphicsFont
: public wxGraphicsObject
1230 @class wxGraphicsPen
1232 A wxGraphicsPen is a native representation of a pen. The contents are
1233 specific and private to the respective renderer. Instances are ref counted
1234 and can therefore be assigned as usual. The only way to get a valid
1235 instance is via wxGraphicsContext::CreatePen() or
1236 wxGraphicsRenderer::CreatePen().
1241 class wxGraphicsPen
: public wxGraphicsObject
1250 @class wxGraphicsMatrix
1252 A wxGraphicsMatrix is a native representation of an affine matrix. The
1253 contents are specific and private to the respective renderer. Instances are
1254 ref counted and can therefore be assigned as usual. The only way to get a
1255 valid instance is via wxGraphicsContext::CreateMatrix() or
1256 wxGraphicsRenderer::CreateMatrix().
1261 class wxGraphicsMatrix
: public wxGraphicsObject
1265 Concatenates the matrix passed with the current matrix.
1267 virtual void Concat(const wxGraphicsMatrix
* t
);
1269 Concatenates the matrix passed with the current matrix.
1271 void Concat(const wxGraphicsMatrix
& t
);
1274 Returns the component values of the matrix via the argument pointers.
1276 virtual void Get(wxDouble
* a
= NULL
, wxDouble
* b
= NULL
,
1277 wxDouble
* c
= NULL
, wxDouble
* d
= NULL
,
1278 wxDouble
* tx
= NULL
, wxDouble
* ty
= NULL
) const;
1281 Returns the native representation of the matrix. For CoreGraphics this
1282 is a CFAffineMatrix pointer, for GDIPlus a Matrix Pointer, and for
1283 Cairo a cairo_matrix_t pointer.
1285 virtual void* GetNativeMatrix() const;
1290 virtual void Invert();
1293 Returns @true if the elements of the transformation matrix are equal.
1295 virtual bool IsEqual(const wxGraphicsMatrix
* t
) const;
1297 Returns @true if the elements of the transformation matrix are equal.
1299 bool IsEqual(const wxGraphicsMatrix
& t
) const;
1302 Return @true if this is the identity matrix.
1304 virtual bool IsIdentity() const;
1307 Rotates this matrix clockwise (in radians).
1310 Rotation angle in radians, clockwise.
1312 virtual void Rotate(wxDouble angle
);
1317 virtual void Scale(wxDouble xScale
, wxDouble yScale
);
1320 Sets the matrix to the respective values (default values are the
1323 virtual void Set(wxDouble a
= 1.0, wxDouble b
= 0.0, wxDouble c
= 0.0,
1324 wxDouble d
= 1.0, wxDouble tx
= 0.0, wxDouble ty
= 0.0);
1327 Applies this matrix to a distance (ie. performs all transforms except
1330 virtual void TransformDistance(wxDouble
* dx
, wxDouble
* dy
) const;
1333 Applies this matrix to a point.
1335 virtual void TransformPoint(wxDouble
* x
, wxDouble
* y
) const;
1338 Translates this matrix.
1340 virtual void Translate(wxDouble dx
, wxDouble dy
);
1344 const wxGraphicsPen wxNullGraphicsPen
;
1345 const wxGraphicsBrush wxNullGraphicsBrush
;
1346 const wxGraphicsFont wxNullGraphicsFont
;
1347 const wxGraphicsBitmap wxNullGraphicsBitmap
;
1348 const wxGraphicsMatrix wxNullGraphicsMatrix
;
1349 const wxGraphicsPath wxNullGraphicsPath
;