1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxGraphicsPath
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 A wxGraphicsPath is a native representation of an geometric path. The contents
13 are specific an private to the respective renderer. Instances are ref counted and can
14 therefore be assigned as usual. The only way to get a valid instance is via
15 wxGraphicsContext::CreatePath or wxGraphicsRenderer::CreatePath.
20 class wxGraphicsPath
: public wxGraphicsObject
27 void AddArc(wxDouble x
, wxDouble y
, wxDouble r
,
29 wxDouble endAngle
, bool clockwise
);
30 void AddArc(const wxPoint2DDouble
& c
, wxDouble r
,
37 Appends a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to
38 (x2,y2), also a straight line from (current) to (x1,y1).
40 virtual void AddArcToPoint(wxDouble x1
, wxDouble y1
, wxDouble x2
,
41 wxDouble y2
, wxDouble r
);
44 Appends a circle around (x,y) with radius r as a new closed subpath.
46 virtual void AddCircle(wxDouble x
, wxDouble y
, wxDouble r
);
52 void AddCurveToPoint(wxDouble cx1
, wxDouble cy1
, wxDouble cx2
,
56 void AddCurveToPoint(const wxPoint2DDouble
& c1
,
57 const wxPoint2DDouble
& c2
,
58 const wxPoint2DDouble
& e
);
62 Appends an ellipse fitting into the passed in rectangle.
64 virtual void AddEllipse(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
70 void AddLineToPoint(wxDouble x
, wxDouble y
);
71 void AddLineToPoint(const wxPoint2DDouble
& p
);
77 virtual void AddPath(const wxGraphicsPath
& path
);
80 Adds a quadratic Bezier curve from the current point, using a control point and
83 virtual void AddQuadCurveToPoint(wxDouble cx
, wxDouble cy
, wxDouble x
,
87 Appends a rectangle as a new closed subpath.
89 virtual void AddRectangle(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
92 Appends a rounded rectangle as a new closed subpath.
94 virtual void AddRoundedRectangle(wxDouble x
, wxDouble y
, wxDouble w
,
95 wxDouble h
, wxDouble radius
);
98 Closes the current sub-path.
100 virtual void CloseSubpath();
104 Returns @true if the point is within the path.
106 bool Contains(const wxPoint2DDouble
& c
,
107 int fillStyle
= wxODDEVEN_RULE
) const;
108 const bool Contains(wxDouble x
, wxDouble y
,
109 int fillStyle
= wxODDEVEN_RULE
) const;
114 Gets the bounding box enclosing all points (possibly including control points).
116 wxRect2DDouble
GetBox() const;
117 const void GetBox(wxDouble
* x
, wxDouble
* y
, wxDouble
* w
,
123 Gets the last point of the current path, (0,0) if not yet set.
125 void GetCurrentPoint(wxDouble
* x
, wxDouble
* y
) const;
126 const wxPoint2DDouble
GetCurrentPoint() const;
130 Returns the native path (CGPathRef for Core Graphics, Path pointer for GDIPlus
131 and a cairo_path_t pointer for cairo).
133 virtual void* GetNativePath() const;
137 Begins a new subpath at (x,y)
139 void MoveToPoint(wxDouble x
, wxDouble y
);
140 void MoveToPoint(const wxPoint2DDouble
& p
);
144 Transforms each point of this path by the matrix.
146 virtual void Transform(const wxGraphicsMatrix
& matrix
);
149 Gives back the native path returned by GetNativePath() because there might be
150 some deallocations necessary (eg on cairo the native path returned by
151 GetNativePath is newly allocated each time).
153 virtual void UnGetNativePath(void* p
) const;
159 @class wxGraphicsObject
161 This class is the superclass of native graphics objects like pens etc. It
162 allows reference counting. Not instantiated by user code.
167 @see wxGraphicsBrush, wxGraphicsPen, wxGraphicsMatrix, wxGraphicsPath
169 class wxGraphicsObject
: public wxObject
173 Returns the renderer that was used to create this instance, or @NULL if it has
174 not been initialized yet
176 wxGraphicsRenderer
* GetRenderer() const;
179 Is this object valid (@false) or still empty (@true)?
187 @class wxGraphicsContext
189 A wxGraphicsContext instance is the object that is drawn upon. It is created by
190 a renderer using wxGraphicsRenderer::CreateContext(). This can be either directly
191 using a renderer instance, or indirectly using the static convenience Create()
192 functions of wxGraphicsContext that always delegate the task to the default renderer.
195 void MyCanvas::OnPaint(wxPaintEvent &event)
200 // Create graphics context from it
201 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
205 // make a path that contains a circle and some lines
206 gc->SetPen( *wxRED_PEN );
207 wxGraphicsPath path = gc->CreatePath();
208 path.AddCircle( 50.0, 50.0, 50.0 );
209 path.MoveToPoint(0.0, 50.0);
210 path.AddLineToPoint(100.0, 50.0);
211 path.MoveToPoint(50.0, 0.0);
212 path.AddLineToPoint(50.0, 100.0 );
214 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
216 gc->StrokePath(path);
227 @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
229 class wxGraphicsContext
: public wxGraphicsObject
233 Creates a wxGraphicsContext from a wxWindow.
235 @see wxGraphicsRenderer::CreateContext()
237 static wxGraphicsContext
* Create( wxWindow
* window
) ;
240 Creates a wxGraphicsContext from a wxWindowDC
242 @see wxGraphicsRenderer::CreateContext()
244 static wxGraphicsContext
* Create( const wxWindowDC
& dc
) ;
247 Creates a wxGraphicsContext from a wxMemoryDC
249 @see wxGraphicsRenderer::CreateContext()
251 static wxGraphicsContext
* Create( const wxMemoryDC
& dc
) ;
254 Creates a wxGraphicsContext from a wxPrinterDC. Under
255 GTK+, this will only work when using the GtkPrint
256 printing backend which is available since GTK+ 2.10.
258 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting "Printing under Unix"
260 static wxGraphicsContext
* Create( const wxPrinterDC
& dc
) ;
263 Clips drawings to the region
265 virtual void Clip(const wxRegion
& region
) = 0;
268 Clips drawings to the rectangle.
270 virtual void Clip(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) = 0;
273 Concatenates the passed in transform with the current transform of this context
275 virtual void ConcatTransform(const wxGraphicsMatrix
& matrix
) = 0;
279 Creates a native brush from a wxBrush.
281 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) const;
284 Creates a native graphics font from a wxFont and a text colour.
286 wxGraphicsFont
CreateFont(const wxFont
& font
,
287 const wxColour
& col
= wxBLACK
) const;
290 Creates a wxGraphicsContext from a native context. This native context must be
291 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a
292 cairo_t pointer for cairo.
294 @see wxGraphicsRenderer:: CreateContextFromNativeContext
296 static wxGraphicsContext
* CreateFromNative(void* context
);
299 Creates a wxGraphicsContext from a native window.
301 @see wxGraphicsRenderer:: CreateContextFromNativeWindow
303 static wxGraphicsContext
* CreateFromNativeWindow(void* window
);
306 Creates a native brush, having a linear gradient, starting at (x1,y1) with
307 color c1 to (x2,y2) with color c2
309 wxGraphicsBrush
CreateLinearGradientBrush(wxDouble x1
,
313 const wxColouramp
;c1
,
314 const wxColouramp
;c2
) const;
317 Creates a native affine transformation matrix from the passed in values. The
318 defaults result in an identity matrix.
320 wxGraphicsMatrix
CreateMatrix(wxDouble a
= 1.0, wxDouble b
= 0.0,
324 wxDouble ty
= 0.0) const;
327 Creates a native graphics path which is initially empty.
329 wxGraphicsPath
CreatePath() const;
332 Creates a native pen from a wxPen.
334 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) const;
337 Creates a native brush, having a radial gradient originating at (xo,yc) with
338 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
340 virtual wxGraphicsBrush
CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
341 wxDouble xc
, wxDouble yc
,
343 const wxColour
& oColor
,
344 const wxColour
& cColor
) const;
347 Draws the bitmap. In case of a mono bitmap, this is treated as a mask and the
348 current brushed is used for filling.
350 virtual void DrawBitmap(const wxBitmap
& bmp
, wxDouble x
, wxDouble y
,
351 wxDouble w
, wxDouble h
) = 0;
356 virtual void DrawEllipse(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
361 virtual void DrawIcon(const wxIcon
& icon
, wxDouble x
, wxDouble y
,
362 wxDouble w
, wxDouble h
) = 0;
367 virtual void DrawLines(size_t n
, const wxPoint2DDouble
* points
,
368 int fillStyle
= wxODDEVEN_RULE
);
371 Draws the path by first filling and then stroking.
373 virtual void DrawPath(const wxGraphicsPath
& path
,
374 int fillStyle
= wxODDEVEN_RULE
);
379 virtual void DrawRectangle(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
382 Draws a rounded rectangle.
384 virtual void DrawRoundedRectangle(wxDouble x
, wxDouble y
, wxDouble w
,
385 wxDouble h
, wxDouble radius
);
389 Draws a text at the defined position, at the given angle.
391 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
,
393 void DrawText(const wxString
& str
, wxDouble x
, wxDouble y
);
397 Fills the path with the current brush.
399 virtual void FillPath(const wxGraphicsPath
& path
,
400 int fillStyle
= wxODDEVEN_RULE
) = 0;
403 Returns the native context (CGContextRef for Core Graphics, Graphics pointer
404 for GDIPlus and cairo_t pointer for cairo).
406 virtual void* GetNativeContext() = 0;
409 Fills the @a widths array with the widths from the beginning of
410 @a text to the corresponding character of @e text.
412 virtual void GetPartialTextExtents(const wxString
& text
,
413 wxArrayDouble
& widths
) const = 0;
416 Gets the dimensions of the string using the currently selected font.
417 @e string is the text string to measure, @e w and @e h are
418 the total width and height respectively, @a descent is the
419 dimension from the baseline of the font to the bottom of the
420 descender, and @a externalLeading is any extra vertical space added
421 to the font by the font designer (usually is zero).
423 virtual void GetTextExtent(const wxString
& text
, wxDouble
* width
,
424 wxDouble
* height
, wxDouble
* descent
,
425 wxDouble
* externalLeading
) const = 0;
428 Gets the current transformation matrix of this context.
430 virtual wxGraphicsMatrix
GetTransform() const = 0;
433 Resets the clipping to original shape.
435 virtual void ResetClip() = 0;
438 Rotates the current transformation matrix (radians),
440 virtual void Rotate(wxDouble angle
) = 0;
443 Scales the current transformation matrix.
445 virtual void Scale(wxDouble xScale
, wxDouble yScale
) = 0;
449 Sets the brush for filling paths.
451 void SetBrush(const wxBrush
& brush
);
452 void SetBrush(const wxGraphicsBrush
& brush
);
457 Sets the font for drawing text.
459 void SetFont(const wxFont
& font
, const wxColour
& colour
);
460 void SetFont(const wxGraphicsFont
& font
);
465 Sets the pen used for stroking.
467 void SetPen(const wxGraphicsPen
& pen
);
468 void SetPen(const wxPen
& pen
);
472 Sets the current transformation matrix of this context
474 virtual void SetTransform(const wxGraphicsMatrix
& matrix
) = 0;
477 Strokes a single line.
479 virtual void StrokeLine(wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
);
483 Stroke disconnected lines from begin to end points, fastest method available
486 void StrokeLines(size_t n
, const wxPoint2DDouble
* beginPoints
,
487 const wxPoint2DDouble
* endPoints
);
488 void StrokeLines(size_t n
, const wxPoint2DDouble
* points
);
492 Strokes along a path with the current pen.
494 virtual void StrokePath(const wxGraphicsPath
& path
) = 0;
497 Translates the current transformation matrix.
499 virtual void Translate(wxDouble dx
, wxDouble dy
) = 0;
505 @class wxGraphicsRenderer
507 A wxGraphicsRenderer is the instance corresponding to the rendering engine
508 used. There may be multiple instances on a system, if there are different
509 rendering engines present, but there is always only one instance per engine.
510 This instance is pointed back to by all objects created by it (wxGraphicsContext,
511 wxGraphicsPath etc) and can be retrieved through their wxGraphicsObject::GetRenderer()
512 method. Therefore you can create an additional instance of a path etc. by calling
513 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX function
517 wxGraphicsPath *path = // from somewhere
518 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
524 class wxGraphicsRenderer
: public wxObject
528 Creates a wxGraphicsContext from a wxWindow.
530 virtual wxGraphicsContext
* CreateContext(wxWindow
* window
) = 0;
533 Creates a wxGraphicsContext from a wxWindowDC
535 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
) = 0 ;
538 Creates a wxGraphicsContext from a wxMemoryDC
540 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
) = 0 ;
543 Creates a wxGraphicsContext from a wxPrinterDC
545 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
) = 0 ;
548 Creates a native brush from a wxBrush.
550 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) = 0;
554 Creates a wxGraphicsContext from a native context. This native context must be
555 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a cairo_t
558 virtual wxGraphicsContext
* CreateContextFromNativeContext(void* context
) = 0;
561 Creates a wxGraphicsContext from a native window.
563 virtual wxGraphicsContext
* CreateContextFromNativeWindow(void* window
) = 0;
566 Creates a native graphics font from a wxFont and a text colour.
568 wxGraphicsFont
CreateFont(const wxFont
& font
,
569 const wxColour
& col
= wxBLACK
);
572 Creates a native brush, having a linear gradient, starting at (x1,y1) with
573 color c1 to (x2,y2) with color c2
575 wxGraphicsBrush
CreateLinearGradientBrush(wxDouble x1
,
579 const wxColouramp
;c1
,
580 const wxColouramp
;c2
);
583 Creates a native affine transformation matrix from the passed in values. The
584 defaults result in an identity matrix.
586 wxGraphicsMatrix
CreateMatrix(wxDouble a
= 1.0, wxDouble b
= 0.0,
593 Creates a native graphics path which is initially empty.
595 virtual wxGraphicsPath
CreatePath() = 0;
598 Creates a native pen from a wxPen.
600 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) = 0;
603 Creates a native brush, having a radial gradient originating at (xo,yc) with
604 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
606 virtual wxGraphicsBrush
CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
607 wxDouble xc
, wxDouble yc
,
609 const wxColour
& oColour
,
610 const wxColour
& cColour
) = 0;
613 Returns the default renderer on this platform. On OS X this is the Core
614 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and on GTK we currently default to the cairo renderer.
616 static wxGraphicsRenderer
* GetDefaultRenderer();
622 @class wxGraphicsBrush
624 A wxGraphicsBrush is a native representation of a brush. The contents
625 are specific and private to the respective renderer. Instances are ref counted and can
626 therefore be assigned as usual. The only way to get a valid instance is via
627 wxGraphicsContext::CreateBrush or wxGraphicsRenderer::CreateBrush.
632 class wxGraphicsBrush
: public wxGraphicsObject
641 @class wxGraphicsFont
643 A wxGraphicsFont is a native representation of a font. The contents
644 are specific and private to the respective renderer. Instances are ref counted and can
645 therefore be assigned as usual. The only way to get a valid instance is via
646 wxGraphicsContext::CreateFont or wxGraphicsRenderer::CreateFont.
651 class wxGraphicsFont
: public wxGraphicsObject
662 A wxGraphicsPen is a native representation of a pen. The contents
663 are specific and private to the respective renderer. Instances are ref counted and can
664 therefore be assigned as usual. The only way to get a valid instance is via
665 wxGraphicsContext::CreatePen or wxGraphicsRenderer::CreatePen.
670 class wxGraphicsPen
: public wxGraphicsObject
679 @class wxGraphicsMatrix
681 A wxGraphicsMatrix is a native representation of an affine matrix. The contents
682 are specific and private to the respective renderer. Instances are ref counted and can
683 therefore be assigned as usual. The only way to get a valid instance is via
684 wxGraphicsContext::CreateMatrix or wxGraphicsRenderer::CreateMatrix.
689 class wxGraphicsMatrix
: public wxGraphicsObject
696 void Concat(const wxGraphicsMatrix
* t
);
697 void Concat(const wxGraphicsMatrix
& t
);
701 Returns the component values of the matrix via the argument pointers.
703 virtual void Get(wxDouble
* a
= NULL
, wxDouble
* b
= NULL
, wxDouble
* c
= NULL
,
704 wxDouble
* d
= NULL
, wxDouble
* tx
= NULL
,
705 wxDouble
* ty
= NULL
) const;
708 Returns the native representation of the matrix. For CoreGraphics this is a
709 CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for Cairo a cairo_matrix_t pointer.
711 virtual void* GetNativeMatrix() const;
716 virtual void Invert();
719 Returns @true if the elements of the transformation matrix are equal.
721 bool IsEqual(const wxGraphicsMatrix
& t
) const;
724 Return @true if this is the identity matrix.
726 virtual bool IsIdentity() const;
729 Rotates this matrix (radians).
731 virtual void Rotate(wxDouble angle
);
736 virtual void Scale(wxDouble xScale
, wxDouble yScale
);
739 Sets the matrix to the respective values (default values are the identity
742 void Set(wxDouble a
= 1.0, wxDouble b
= 0.0, wxDouble c
= 0.0,
743 wxDouble d
= 1.0, wxDouble tx
= 0.0,
747 Applies this matrix to a distance (ie. performs all transforms except
750 virtual void TransformDistance(wxDouble
* dx
, wxDouble
* dy
) const;
753 Applies this matrix to a point.
755 virtual void TransformPoint(wxDouble
* x
, wxDouble
* y
) const;
758 Translates this matrix.
760 virtual void Translate(wxDouble dx
, wxDouble dy
);