1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxGraphicsPath
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 created by
203 a renderer using wxGraphicsRenderer::CreateContext(). This can be either directly
204 using a renderer instance, or indirectly using the static convenience Create()
205 functions of wxGraphicsContext that always delegate the task to the default renderer.
208 void MyCanvas::OnPaint(wxPaintEvent &event)
213 // Create graphics context from it
214 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
218 // make a path that contains a circle and some lines
219 gc->SetPen( *wxRED_PEN );
220 wxGraphicsPath path = gc->CreatePath();
221 path.AddCircle( 50.0, 50.0, 50.0 );
222 path.MoveToPoint(0.0, 50.0);
223 path.AddLineToPoint(100.0, 50.0);
224 path.MoveToPoint(50.0, 0.0);
225 path.AddLineToPoint(50.0, 100.0 );
227 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
229 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
268 GTK+, this will only work when using the GtkPrint
269 printing backend which is available since GTK+ 2.10.
271 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting "Printing under Unix"
273 static wxGraphicsContext
* Create( const wxPrinterDC
& dc
) ;
276 Clips drawings to the region
278 virtual void Clip(const wxRegion
& region
) = 0;
281 Clips drawings to the 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 context
288 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 must be
304 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a
305 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 (x1,y1) with
320 color c1 to (x2,y2) with color c2
322 virtual wxGraphicsBrush
CreateLinearGradientBrush(wxDouble x1
,
327 const wxColour
& c2
) const;
330 Creates a native affine transformation matrix from the passed in values. The
331 defaults 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 (xo,yc) with
350 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
352 virtual wxGraphicsBrush
CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
353 wxDouble xc
, wxDouble yc
,
355 const wxColour
& oColor
,
356 const wxColour
& cColor
) const;
359 Draws the bitmap. In case of a mono bitmap, this is treated as a mask and the
360 current brushed is used for filling.
362 virtual void DrawBitmap(const wxBitmap
& bmp
, wxDouble x
, wxDouble y
,
363 wxDouble w
, wxDouble h
) = 0;
368 virtual void DrawEllipse(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
373 virtual void DrawIcon(const wxIcon
& icon
, wxDouble x
, wxDouble y
,
374 wxDouble w
, wxDouble h
) = 0;
379 virtual void DrawLines(size_t n
, const wxPoint2DDouble
* points
,
380 int fillStyle
= wxODDEVEN_RULE
);
383 Draws the path by first filling and then stroking.
385 virtual void DrawPath(const wxGraphicsPath
& path
,
386 int fillStyle
= wxODDEVEN_RULE
);
391 virtual void DrawRectangle(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
394 Draws a rounded rectangle.
396 virtual void DrawRoundedRectangle(wxDouble x
, wxDouble y
, wxDouble w
,
397 wxDouble h
, wxDouble radius
);
401 Draws a text at the defined position.
403 If @a angle is specified, the string is drawn at the given angle to the
404 (default) horizontal direction. If @a backgroundBrush is specified, the
405 text is filled using it.
407 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
,
409 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
);
410 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
,
411 const wxGraphicsBrush
& backgroundBrush
)
412 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
,
414 const wxGraphicsBrush
& backgroundBrush
)
418 Fills the path with the current brush.
420 virtual void FillPath(const wxGraphicsPath
& path
,
421 int fillStyle
= wxODDEVEN_RULE
) = 0;
424 Returns the native context (CGContextRef for Core Graphics, Graphics pointer
425 for GDIPlus and cairo_t pointer for cairo).
427 virtual void* GetNativeContext() = 0;
430 Fills the @a widths array with the widths from the beginning of
431 @a text to the corresponding character of @e text.
433 virtual void GetPartialTextExtents(const wxString
& text
,
434 wxArrayDouble
& widths
) const = 0;
437 Gets the dimensions of the string using the currently selected font.
438 @e string is the text string to measure, @e w and @e h are
439 the total width and height respectively, @a descent is the
440 dimension from the baseline of the font to the bottom of the
441 descender, and @a externalLeading is any extra vertical space added
442 to the font by the font designer (usually is zero).
444 virtual void GetTextExtent(const wxString
& text
, wxDouble
* width
,
445 wxDouble
* height
, wxDouble
* descent
,
446 wxDouble
* externalLeading
) const = 0;
449 Gets the current transformation matrix of this context.
451 virtual wxGraphicsMatrix
GetTransform() const = 0;
454 Resets the clipping to original shape.
456 virtual void ResetClip() = 0;
459 Rotates the current transformation matrix (radians),
461 virtual void Rotate(wxDouble angle
) = 0;
464 Scales the current transformation matrix.
466 virtual void Scale(wxDouble xScale
, wxDouble yScale
) = 0;
470 Sets the brush for filling paths.
472 void SetBrush(const wxBrush
& brush
);
473 void SetBrush(const wxGraphicsBrush
& brush
);
478 Sets the font for drawing text.
480 void SetFont(const wxFont
& font
, const wxColour
& colour
);
481 void SetFont(const wxGraphicsFont
& font
);
486 Sets the pen used for stroking.
488 void SetPen(const wxGraphicsPen
& pen
);
489 void SetPen(const wxPen
& pen
);
493 Sets the current transformation matrix of this context
495 virtual void SetTransform(const wxGraphicsMatrix
& matrix
) = 0;
498 Strokes a single line.
500 virtual void StrokeLine(wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
504 Stroke disconnected lines from begin to end points, fastest method available
507 void StrokeLines(size_t n
, const wxPoint2DDouble
* beginPoints
,
508 const wxPoint2DDouble
* endPoints
);
509 void StrokeLines(size_t n
, const wxPoint2DDouble
* points
);
513 Strokes along a path with the current pen.
515 virtual void StrokePath(const wxGraphicsPath
& path
) = 0;
518 Translates the current transformation matrix.
520 virtual void Translate(wxDouble dx
, wxDouble dy
) = 0;
526 @class wxGraphicsRenderer
528 A wxGraphicsRenderer is the instance corresponding to the rendering engine
529 used. There may be multiple instances on a system, if there are different
530 rendering engines present, but there is always only one instance per engine.
531 This instance is pointed back to by all objects created by it (wxGraphicsContext,
532 wxGraphicsPath etc) and can be retrieved through their wxGraphicsObject::GetRenderer()
533 method. Therefore you can create an additional instance of a path etc. by calling
534 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX function
538 wxGraphicsPath *path = // from somewhere
539 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
545 class wxGraphicsRenderer
: public wxObject
549 Creates a wxGraphicsContext from a wxWindow.
551 virtual wxGraphicsContext
* CreateContext(wxWindow
* window
) = 0;
554 Creates a wxGraphicsContext from a wxWindowDC
556 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
) = 0 ;
559 Creates a wxGraphicsContext from a wxMemoryDC
561 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
) = 0 ;
564 Creates a wxGraphicsContext from a wxPrinterDC
566 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
) = 0 ;
569 Creates a native brush from a wxBrush.
571 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) = 0;
575 Creates a wxGraphicsContext from a native context. This native context must be
576 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a cairo_t
579 virtual wxGraphicsContext
* CreateContextFromNativeContext(void* context
) = 0;
582 Creates a wxGraphicsContext from a native window.
584 virtual wxGraphicsContext
* CreateContextFromNativeWindow(void* window
) = 0;
587 Creates a native graphics font from a wxFont and a text colour.
589 virtual wxGraphicsFont
CreateFont(const wxFont
& font
,
590 const wxColour
& col
= *wxBLACK
) = 0;
593 Creates a native brush, having a linear gradient, starting at (x1,y1) with
594 color c1 to (x2,y2) with color c2
596 wxGraphicsBrush
CreateLinearGradientBrush(wxDouble x1
,
601 const wxColour
& c2
) = 0;
604 Creates a native affine transformation matrix from the passed in values. The
605 defaults result in an identity matrix.
607 virtual wxGraphicsMatrix
CreateMatrix(wxDouble a
= 1.0, wxDouble b
= 0.0,
608 wxDouble c
= 0.0, wxDouble d
= 1.0,
610 wxDouble ty
= 0.0) = 0;
613 Creates a native graphics path which is initially empty.
615 virtual wxGraphicsPath
CreatePath() = 0;
618 Creates a native pen from a wxPen.
620 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) = 0;
623 Creates a native brush, having a radial gradient originating at (xo,yc) with
624 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
626 virtual wxGraphicsBrush
CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
627 wxDouble xc
, wxDouble yc
,
629 const wxColour
& oColour
,
630 const wxColour
& cColour
) = 0;
633 Returns the default renderer on this platform. On OS X this is the Core
634 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and on GTK we currently default to the cairo renderer.
636 static wxGraphicsRenderer
* GetDefaultRenderer();
642 @class wxGraphicsBrush
644 A wxGraphicsBrush is a native representation of a brush. The contents
645 are specific and private to the respective renderer. Instances are ref counted and can
646 therefore be assigned as usual. The only way to get a valid instance is via
647 wxGraphicsContext::CreateBrush or wxGraphicsRenderer::CreateBrush.
652 class wxGraphicsBrush
: public wxGraphicsObject
661 @class wxGraphicsFont
663 A wxGraphicsFont is a native representation of a font. The contents
664 are specific and private to the respective renderer. Instances are ref counted and can
665 therefore be assigned as usual. The only way to get a valid instance is via
666 wxGraphicsContext::CreateFont or wxGraphicsRenderer::CreateFont.
671 class wxGraphicsFont
: public wxGraphicsObject
682 A wxGraphicsPen is a native representation of a pen. The contents
683 are specific and private to the respective renderer. Instances are ref counted and can
684 therefore be assigned as usual. The only way to get a valid instance is via
685 wxGraphicsContext::CreatePen or wxGraphicsRenderer::CreatePen.
690 class wxGraphicsPen
: public wxGraphicsObject
699 @class wxGraphicsMatrix
701 A wxGraphicsMatrix is a native representation of an affine matrix. The contents
702 are specific and private to the respective renderer. Instances are ref counted and can
703 therefore be assigned as usual. The only way to get a valid instance is via
704 wxGraphicsContext::CreateMatrix or wxGraphicsRenderer::CreateMatrix.
709 class wxGraphicsMatrix
: public wxGraphicsObject
716 void Concat(const wxGraphicsMatrix
* t
);
717 void Concat(const wxGraphicsMatrix
& t
);
721 Returns the component values of the matrix via the argument pointers.
723 virtual void Get(wxDouble
* a
= NULL
, wxDouble
* b
= NULL
, wxDouble
* c
= NULL
,
724 wxDouble
* d
= NULL
, wxDouble
* tx
= NULL
,
725 wxDouble
* ty
= NULL
) const;
728 Returns the native representation of the matrix. For CoreGraphics this is a
729 CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for Cairo a cairo_matrix_t pointer.
731 virtual void* GetNativeMatrix() const;
736 virtual void Invert();
739 Returns @true if the elements of the transformation matrix are equal.
741 bool IsEqual(const wxGraphicsMatrix
& t
) const;
744 Return @true if this is the identity matrix.
746 virtual bool IsIdentity() const;
749 Rotates this matrix (radians).
751 virtual void Rotate(wxDouble angle
);
756 virtual void Scale(wxDouble xScale
, wxDouble yScale
);
759 Sets the matrix to the respective values (default values are the identity
762 virtual void Set(wxDouble a
= 1.0, wxDouble b
= 0.0, wxDouble c
= 0.0,
763 wxDouble d
= 1.0, wxDouble tx
= 0.0, wxDouble ty
= 0.0);
766 Applies this matrix to a distance (ie. performs all transforms except
769 virtual void TransformDistance(wxDouble
* dx
, wxDouble
* dy
) const;
772 Applies this matrix to a point.
774 virtual void TransformPoint(wxDouble
* x
, wxDouble
* y
) const;
777 Translates this matrix.
779 virtual void Translate(wxDouble dx
, wxDouble dy
);