1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of various wxGraphics* classes
4 // Author: wxWidgets team
6 // Licence: wxWindows license
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 centering at (@a x,@a y) with radius (@a r)
26 from @a startAngle to @a endAngle.
28 virtual void AddArc(wxDouble x
, wxDouble y
, wxDouble r
,
29 wxDouble startAngle
, wxDouble endAngle
,
32 Adds an arc of a circle centering at @a c with radius (@a r)
33 from @a startAngle to @a endAngle.
35 void AddArc(const wxPoint2DDouble
& c
, wxDouble r
,
36 wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
39 Appends a an arc to two tangents connecting (current) to (@a x1,@a y1)
40 and (@a x1,@a y1) to (@a x2,@a y2), also a straight line from (current)
43 virtual void AddArcToPoint(wxDouble x1
, wxDouble y1
, wxDouble x2
,
44 wxDouble y2
, wxDouble r
);
47 Appends a circle around (@a x,@a y) with radius @a r as a new closed
50 virtual void AddCircle(wxDouble x
, wxDouble y
, wxDouble r
);
53 Adds a cubic bezier curve from the current point, using two control
54 points and an end point.
56 virtual void AddCurveToPoint(wxDouble cx1
, wxDouble cy1
,
57 wxDouble cx2
, wxDouble cy2
,
58 wxDouble x
, wxDouble y
);
60 Adds a cubic bezier curve from the current point, using two control
61 points and an end point.
63 void AddCurveToPoint(const wxPoint2DDouble
& c1
,
64 const wxPoint2DDouble
& c2
,
65 const wxPoint2DDouble
& e
);
68 Appends an ellipse fitting into the passed in rectangle.
70 virtual void AddEllipse(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
73 Adds a straight line from the current point to (@a x,@a y).
75 virtual void AddLineToPoint(wxDouble x
, wxDouble y
);
77 Adds a straight line from the current point to @a p.
79 void AddLineToPoint(const wxPoint2DDouble
& p
);
84 virtual void AddPath(const wxGraphicsPath
& path
);
87 Adds a quadratic bezier curve from the current point, using a control
88 point and an end point.
90 virtual void AddQuadCurveToPoint(wxDouble cx
, wxDouble cy
,
91 wxDouble x
, wxDouble y
);
94 Appends a rectangle as a new closed subpath.
96 virtual void AddRectangle(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
99 Appends a rounded rectangle as a new closed subpath.
101 virtual void AddRoundedRectangle(wxDouble x
, wxDouble y
, wxDouble w
,
102 wxDouble h
, wxDouble radius
);
105 Closes the current sub-path.
107 virtual void CloseSubpath();
110 @return @true if the point is within the path.
112 bool Contains(const wxPoint2DDouble
& c
,
113 int fillStyle
= wxODDEVEN_RULE
) const;
115 @return @true if the point is within the path.
117 virtual bool Contains(wxDouble x
, wxDouble y
,
118 int fillStyle
= wxODDEVEN_RULE
) const;
121 Gets the bounding box enclosing all points (possibly including control
124 wxRect2DDouble
GetBox() const;
126 Gets the bounding box enclosing all points (possibly including control
129 virtual void GetBox(wxDouble
* x
, wxDouble
* y
,
130 wxDouble
* w
, wxDouble
* h
) const;
133 Gets the last point of the current path, (0,0) if not yet set.
135 virtual void GetCurrentPoint(wxDouble
* x
, wxDouble
* y
) const;
137 Gets the last point of the current path, (0,0) if not yet set.
139 wxPoint2DDouble
GetCurrentPoint() const;
142 Returns the native path (CGPathRef for Core Graphics, Path pointer for
143 GDIPlus and a cairo_path_t pointer for cairo).
145 virtual void* GetNativePath() const;
148 Begins a new subpath at (@a x,@a y).
150 virtual void MoveToPoint(wxDouble x
, wxDouble y
);
152 Begins a new subpath at @a p.
154 void MoveToPoint(const wxPoint2DDouble
& p
);
157 Transforms each point of this path by the matrix.
159 virtual void Transform(const wxGraphicsMatrix
& matrix
);
162 Gives back the native path returned by GetNativePath() because there
163 might be some deallocations necessary (e.g. on cairo the native path
164 returned by GetNativePath() is newly allocated each time).
166 virtual void UnGetNativePath(void* p
) const;
172 @class wxGraphicsObject
174 This class is the superclass of native graphics objects like pens etc. It
175 allows reference counting. Not instantiated by user code.
180 @see wxGraphicsBrush, wxGraphicsPen, wxGraphicsMatrix, wxGraphicsPath
182 class wxGraphicsObject
: public wxObject
186 Returns the renderer that was used to create this instance, or @NULL
187 if it has not been initialized yet.
189 wxGraphicsRenderer
* GetRenderer() const;
192 @return @false if this object is valid, otherwise returns @true.
200 @class wxGraphicsContext
202 A wxGraphicsContext instance is the object that is drawn upon. It is
203 created by a renderer using wxGraphicsRenderer::CreateContext(). This can
204 be either directly using a renderer instance, or indirectly using the
205 static convenience Create() functions of wxGraphicsContext that always
206 delegate the task to the default renderer.
209 void MyCanvas::OnPaint(wxPaintEvent &event)
214 // Create graphics context from it
215 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
219 // make a path that contains a circle and some lines
220 gc->SetPen( *wxRED_PEN );
221 wxGraphicsPath path = gc->CreatePath();
222 path.AddCircle( 50.0, 50.0, 50.0 );
223 path.MoveToPoint(0.0, 50.0);
224 path.AddLineToPoint(100.0, 50.0);
225 path.MoveToPoint(50.0, 0.0);
226 path.AddLineToPoint(50.0, 100.0 );
228 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
230 gc->StrokePath(path);
240 @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
242 class wxGraphicsContext
: public wxGraphicsObject
246 Creates a wxGraphicsContext from a wxWindow.
248 @see wxGraphicsRenderer::CreateContext()
250 static wxGraphicsContext
* Create(wxWindow
* window
);
253 Creates a wxGraphicsContext from a wxWindowDC
255 @see wxGraphicsRenderer::CreateContext()
257 static wxGraphicsContext
* Create(const wxWindowDC
& dc
);
260 Creates a wxGraphicsContext from a wxMemoryDC
262 @see wxGraphicsRenderer::CreateContext()
264 static wxGraphicsContext
* Create(const wxMemoryDC
& dc
);
267 Creates a wxGraphicsContext from a wxPrinterDC. Under GTK+, this will
268 only work when using the GtkPrint printing backend which is available
271 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting
273 static wxGraphicsContext
* Create(const wxPrinterDC
& dc
);
276 Clips drawings to the specified region.
278 virtual void Clip(const wxRegion
& region
) = 0;
281 Clips drawings to the specified rectangle.
283 virtual void Clip(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
286 Concatenates the passed in transform with the current transform of this
289 virtual void ConcatTransform(const wxGraphicsMatrix
& matrix
) = 0;
292 Creates a native brush from a wxBrush.
294 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) const;
297 Creates a native graphics font from a wxFont and a text colour.
299 virtual wxGraphicsFont
CreateFont(const wxFont
& font
,
300 const wxColour
& col
= *wxBLACK
) const;
303 Creates a wxGraphicsContext from a native context. This native context
304 must be a CGContextRef for Core Graphics, a Graphics pointer for
305 GDIPlus, or a cairo_t pointer for cairo.
307 @see wxGraphicsRenderer::CreateContextFromNativeContext()
309 static wxGraphicsContext
* CreateFromNative(void* context
);
312 Creates a wxGraphicsContext from a native window.
314 @see wxGraphicsRenderer::CreateContextFromNativeWindow()
316 static wxGraphicsContext
* CreateFromNativeWindow(void* window
);
319 Creates a native brush, having a linear gradient, starting at
320 (@a x1, @a y1) with color @a c1 to (@a x2, @a y2) with color @a c2.
322 virtual wxGraphicsBrush
CreateLinearGradientBrush(wxDouble x1
,
327 const wxColour
& c2
) const;
330 Creates a native affine transformation matrix from the passed in
331 values. The default parameters result in an identity matrix.
333 virtual wxGraphicsMatrix
CreateMatrix(wxDouble a
= 1.0, wxDouble b
= 0.0,
334 wxDouble c
= 0.0, wxDouble d
= 1.0,
336 wxDouble ty
= 0.0) const;
339 Creates a native graphics path which is initially empty.
341 wxGraphicsPath
CreatePath() const;
344 Creates a native pen from a wxPen.
346 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) const;
349 Creates a native brush, having a radial gradient originating at
350 (@a xo, @a yc) with color @a oColour and ends on a circle around
351 (@a xc, @a yc) with the given @a radius and color @a cColour.
353 virtual wxGraphicsBrush
CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
354 wxDouble xc
, wxDouble yc
,
356 const wxColour
& oColor
,
357 const wxColour
& cColor
) const;
360 Draws the bitmap. In case of a mono bitmap, this is treated as a mask
361 and the current brushed is used for filling.
363 virtual void DrawBitmap(const wxBitmap
& bmp
, wxDouble x
, wxDouble y
,
364 wxDouble w
, wxDouble h
) = 0;
369 virtual void DrawEllipse(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
374 virtual void DrawIcon(const wxIcon
& icon
, wxDouble x
, wxDouble y
,
375 wxDouble w
, wxDouble h
) = 0;
380 virtual void DrawLines(size_t n
, const wxPoint2DDouble
* points
,
381 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
384 Draws the path by first filling and then stroking.
386 virtual void DrawPath(const wxGraphicsPath
& path
,
387 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
392 virtual void DrawRectangle(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
395 Draws a rounded rectangle.
397 virtual void DrawRoundedRectangle(wxDouble x
, wxDouble y
, wxDouble w
,
398 wxDouble h
, wxDouble radius
);
401 Draws text at the defined position.
403 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
);
405 Draws text at the defined position.
410 The x coordinate position to draw the text at.
412 The y coordinate position to draw the text at.
414 The angle relative to the (default) horizontal direction to draw
417 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
, wxDouble angle
);
419 Draws text at the defined position.
424 The x coordinate position to draw the text at.
426 The y coordinate position to draw the text at.
427 @param backgroundBrush
428 Brush to fill the text with.
430 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
,
431 const wxGraphicsBrush
& backgroundBrush
);
433 Draws text at the defined position.
438 The x coordinate position to draw the text at.
440 The y coordinate position to draw the text at.
442 The angle relative to the (default) horizontal direction to draw
444 @param backgroundBrush
445 Brush to fill the text with.
447 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
,
448 wxDouble angle
, const wxGraphicsBrush
& backgroundBrush
);
451 Fills the path with the current brush.
453 virtual void FillPath(const wxGraphicsPath
& path
,
454 wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) = 0;
457 Returns the native context (CGContextRef for Core Graphics, Graphics
458 pointer for GDIPlus and cairo_t pointer for cairo).
460 virtual void* GetNativeContext() = 0;
463 Fills the @a widths array with the widths from the beginning of
464 @a text to the corresponding character of @a text.
466 virtual void GetPartialTextExtents(const wxString
& text
,
467 wxArrayDouble
& widths
) const = 0;
470 Gets the dimensions of the string using the currently selected font.
473 The text string to measure.
475 Variable to store the total calculated width of the text.
477 Variable to store the total calculated height of the text.
479 Variable to store the dimension from the baseline of the font to
480 the bottom of the descender.
481 @param externalLeading
482 Any extra vertical space added to the font by the font designer
485 virtual void GetTextExtent(const wxString
& text
, wxDouble
* width
,
486 wxDouble
* height
, wxDouble
* descent
,
487 wxDouble
* externalLeading
) const = 0;
490 Gets the current transformation matrix of this context.
492 virtual wxGraphicsMatrix
GetTransform() const = 0;
495 Resets the clipping to original shape.
497 virtual void ResetClip() = 0;
500 Rotates the current transformation matrix (in radians).
502 virtual void Rotate(wxDouble angle
) = 0;
505 Scales the current transformation matrix.
507 virtual void Scale(wxDouble xScale
, wxDouble yScale
) = 0;
510 Sets the brush for filling paths.
512 void SetBrush(const wxBrush
& brush
);
514 Sets the brush for filling paths.
516 virtual void SetBrush(const wxGraphicsBrush
& brush
);
519 Sets the font for drawing text.
521 void SetFont(const wxFont
& font
, const wxColour
& colour
);
523 Sets the font for drawing text.
525 virtual void SetFont(const wxGraphicsFont
& font
);
528 Sets the pen used for stroking.
530 void SetPen(const wxPen
& pen
);
532 Sets the pen used for stroking.
534 virtual void SetPen(const wxGraphicsPen
& pen
);
537 Sets the current transformation matrix of this context
539 virtual void SetTransform(const wxGraphicsMatrix
& matrix
) = 0;
542 Strokes a single line.
544 virtual void StrokeLine(wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
547 Stroke disconnected lines from begin to end points, fastest method
548 available for this purpose.
550 virtual void StrokeLines(size_t n
, const wxPoint2DDouble
* beginPoints
,
551 const wxPoint2DDouble
* endPoints
);
553 Stroke disconnected lines from begin to end points, fastest method
554 available for this purpose.
556 virtual void StrokeLines(size_t n
, const wxPoint2DDouble
* points
);
559 Strokes along a path with the current pen.
561 virtual void StrokePath(const wxGraphicsPath
& path
) = 0;
564 Translates the current transformation matrix.
566 virtual void Translate(wxDouble dx
, wxDouble dy
) = 0;
572 @class wxGraphicsRenderer
574 A wxGraphicsRenderer is the instance corresponding to the rendering engine
575 used. There may be multiple instances on a system, if there are different
576 rendering engines present, but there is always only one instance per
577 engine. This instance is pointed back to by all objects created by it
578 (wxGraphicsContext, wxGraphicsPath etc) and can be retrieved through their
579 wxGraphicsObject::GetRenderer() method. Therefore you can create an
580 additional instance of a path etc. by calling
581 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX()
582 function of that renderer.
585 wxGraphicsPath *path = // from somewhere
586 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
592 class wxGraphicsRenderer
: public wxObject
596 Creates a wxGraphicsContext from a wxWindow.
598 virtual wxGraphicsContext
* CreateContext(wxWindow
* window
) = 0;
601 Creates a wxGraphicsContext from a wxWindowDC
603 virtual wxGraphicsContext
* CreateContext(const wxWindowDC
& dc
) = 0 ;
606 Creates a wxGraphicsContext from a wxMemoryDC
608 virtual wxGraphicsContext
* CreateContext(const wxMemoryDC
& dc
) = 0 ;
611 Creates a wxGraphicsContext from a wxPrinterDC
613 virtual wxGraphicsContext
* CreateContext(const wxPrinterDC
& dc
) = 0 ;
616 Creates a native brush from a wxBrush.
618 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) = 0;
621 Creates a wxGraphicsContext from a native context. This native context
622 must be a CGContextRef for Core Graphics, a Graphics pointer for
623 GDIPlus, or a cairo_t pointer for cairo.
625 virtual wxGraphicsContext
* CreateContextFromNativeContext(void* context
) = 0;
628 Creates a wxGraphicsContext from a native window.
630 virtual wxGraphicsContext
* CreateContextFromNativeWindow(void* window
) = 0;
633 Creates a native graphics font from a wxFont and a text colour.
635 virtual wxGraphicsFont
CreateFont(const wxFont
& font
,
636 const wxColour
& col
= *wxBLACK
) = 0;
639 Creates a native brush, having a linear gradient, starting at
640 (@a x1, @a y1) with color @a c1 to (@a x2, @a y2) with color @a c2.
642 virtual wxGraphicsBrush
CreateLinearGradientBrush(wxDouble x1
,
647 const wxColour
& c2
) = 0;
650 Creates a native affine transformation matrix from the passed in
651 values. The defaults result in an identity matrix.
653 virtual wxGraphicsMatrix
CreateMatrix(wxDouble a
= 1.0, wxDouble b
= 0.0,
654 wxDouble c
= 0.0, wxDouble d
= 1.0,
656 wxDouble ty
= 0.0) = 0;
659 Creates a native graphics path which is initially empty.
661 virtual wxGraphicsPath
CreatePath() = 0;
664 Creates a native pen from a wxPen.
666 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) = 0;
669 Creates a native brush, having a radial gradient originating at
670 (@a xo, @a yc) with color @a oColour and ends on a circle around
671 (@a xc, @a yc) with the given @a radius and color @a cColour.
673 virtual wxGraphicsBrush
CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
674 wxDouble xc
, wxDouble yc
,
676 const wxColour
& oColour
,
677 const wxColour
& cColour
) = 0;
680 Returns the default renderer on this platform. On OS X this is the Core
681 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and
682 on GTK we currently default to the cairo renderer.
684 static wxGraphicsRenderer
* GetDefaultRenderer();
690 @class wxGraphicsBrush
692 A wxGraphicsBrush is a native representation of a brush. The contents are
693 specific and private to the respective renderer. Instances are ref counted
694 and can therefore be assigned as usual. The only way to get a valid
695 instance is via wxGraphicsContext::CreateBrush() or
696 wxGraphicsRenderer::CreateBrush().
701 class wxGraphicsBrush
: public wxGraphicsObject
710 @class wxGraphicsFont
712 A wxGraphicsFont is a native representation of a font. The contents are
713 specific and private to the respective renderer. Instances are ref counted
714 and can therefore be assigned as usual. The only way to get a valid
715 instance is via wxGraphicsContext::CreateFont() or
716 wxGraphicsRenderer::CreateFont().
721 class wxGraphicsFont
: public wxGraphicsObject
732 A wxGraphicsPen is a native representation of a pen. The contents are
733 specific and private to the respective renderer. Instances are ref counted
734 and can therefore be assigned as usual. The only way to get a valid
735 instance is via wxGraphicsContext::CreatePen() or
736 wxGraphicsRenderer::CreatePen().
741 class wxGraphicsPen
: public wxGraphicsObject
750 @class wxGraphicsMatrix
752 A wxGraphicsMatrix is a native representation of an affine matrix. The
753 contents are specific and private to the respective renderer. Instances are
754 ref counted and can therefore be assigned as usual. The only way to get a
755 valid instance is via wxGraphicsContext::CreateMatrix() or
756 wxGraphicsRenderer::CreateMatrix().
761 class wxGraphicsMatrix
: public wxGraphicsObject
765 Concatenates the matrix passed with the current matrix.
767 virtual void Concat(const wxGraphicsMatrix
* t
);
769 Concatenates the matrix passed with the current matrix.
771 void Concat(const wxGraphicsMatrix
& t
);
774 Returns the component values of the matrix via the argument pointers.
776 virtual void Get(wxDouble
* a
= NULL
, wxDouble
* b
= NULL
,
777 wxDouble
* c
= NULL
, wxDouble
* d
= NULL
,
778 wxDouble
* tx
= NULL
, wxDouble
* ty
= NULL
) const;
781 Returns the native representation of the matrix. For CoreGraphics this
782 is a CFAffineMatrix pointer, for GDIPlus a Matrix Pointer, and for
783 Cairo a cairo_matrix_t pointer.
785 virtual void* GetNativeMatrix() const;
790 virtual void Invert();
793 Returns @true if the elements of the transformation matrix are equal.
795 virtual bool IsEqual(const wxGraphicsMatrix
* t
) const;
797 Returns @true if the elements of the transformation matrix are equal.
799 bool IsEqual(const wxGraphicsMatrix
& t
) const;
802 Return @true if this is the identity matrix.
804 virtual bool IsIdentity() const;
807 Rotates this matrix (in radians).
809 virtual void Rotate(wxDouble angle
);
814 virtual void Scale(wxDouble xScale
, wxDouble yScale
);
817 Sets the matrix to the respective values (default values are the
820 virtual void Set(wxDouble a
= 1.0, wxDouble b
= 0.0, wxDouble c
= 0.0,
821 wxDouble d
= 1.0, wxDouble tx
= 0.0, wxDouble ty
= 0.0);
824 Applies this matrix to a distance (ie. performs all transforms except
827 virtual void TransformDistance(wxDouble
* dx
, wxDouble
* dy
) const;
830 Applies this matrix to a point.
832 virtual void TransformPoint(wxDouble
* x
, wxDouble
* y
) const;
835 Translates this matrix.
837 virtual void Translate(wxDouble dx
, wxDouble dy
);