]>
git.saurik.com Git - wxWidgets.git/blob - interface/graphics.h
2e784b87241538e5c10cfb56c9be8651dcc33328
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxGraphicsPath class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 A wxGraphicsPath is a native representation of an geometric path. The contents
14 are specific an private to the respective renderer. Instances are ref counted and can
15 therefore be assigned as usual. The only way to get a valid instance is via a
16 CreatePath call on the graphics context or the renderer instance.
21 class wxGraphicsPath
: public wxGraphicsObject
28 void AddArc ( wxDouble x
, wxDouble y
, wxDouble r
,
30 wxDouble endAngle
, bool clockwise
);
31 void AddArc ( const wxPoint2DDouble
& c
, wxDouble r
,
38 Appends a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to
39 (x2,y2), also a straight line from (current) to (x1,y1).
41 void AddArcToPoint ( wxDouble x1
, wxDouble y1
, wxDouble x2
,
46 Appends a circle around (x,y) with radius r as a new closed subpath.
48 void AddCircle ( wxDouble x
, wxDouble y
, wxDouble r
);
54 void AddCurveToPoint ( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
,
58 void AddCurveToPoint ( const wxPoint2DDouble
& c1
,
59 const wxPoint2DDouble
& c2
,
60 const wxPoint2DDouble
& e
);
64 Appends an ellipse fitting into the passed in rectangle.
66 void AddEllipse ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
72 void AddLineToPoint ( wxDouble x
, wxDouble y
);
73 void AddLineToPoint ( const wxPoint2DDouble
& p
);
79 void AddPath ( const wxGraphicsPath
& path
);
82 Adds a quadratic Bezier curve from the current point, using a control point and
85 void AddQuadCurveToPoint ( wxDouble cx
, wxDouble cy
, wxDouble x
,
89 Appends a rectangle as a new closed subpath.
91 void AddRectangle ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
94 Appends a rounded rectangle as a new closed subpath.
96 void AddRoundedRectangle ( wxDouble x
, wxDouble y
, wxDouble w
,
101 Closes the current sub-path.
107 Returns @true if the point is within the path.
109 bool Contains ( const wxPoint2DDouble
& c
,
110 int fillStyle
= wxODDEVEN_RULE
);
111 bool Contains ( wxDouble x
, wxDouble y
,
112 int fillStyle
= wxODDEVEN_RULE
);
117 Gets the bounding box enclosing all points (possibly including control points).
119 wxRect2DDouble
GetBox ();
120 void GetBox ( wxDouble
* x
, wxDouble
* y
, wxDouble
* w
,
126 Gets the last point of the current path, (0,0) if not yet set.
128 void GetCurrentPoint ( wxDouble
* x
, wxDouble
* y
);
129 wxPoint2DDouble
GetCurrentPoint ();
133 Returns the native path (CGPathRef for Core Graphics, Path pointer for GDIPlus
134 and a cairo_path_t pointer for cairo).
136 void * GetNativePath ();
140 Begins a new subpath at (x,y)
142 void MoveToPoint ( wxDouble x
, wxDouble y
);
143 void MoveToPoint ( const wxPoint2DDouble
& p
);
147 Transforms each point of this path by the matrix.
149 void Transform ( const wxGraphicsMatrix
& matrix
);
152 Gives back the native path returned by GetNativePath() because there might be
153 some deallocations necessary (eg on cairo the native path returned by
154 GetNativePath is newly allocated each time).
156 void UnGetNativePath ( void * p
);
161 @class wxGraphicsObject
162 @wxheader{graphics.h}
164 This class is the superclass of native graphics objects like pens etc. It
165 allows reference counting. Not instantiated by user code.
171 wxGraphicsBrush, wxGraphicsPen, wxGraphicsMatrix, wxGraphicsPath
173 class wxGraphicsObject
: public wxObject
177 Returns the renderer that was used to create this instance, or @NULL if it has
178 not been initialized yet
180 wxGraphicsRenderer
* GetRenderer ();
183 Is this object valid (@false) or still empty (@true)?
190 @class wxGraphicsContext
191 @wxheader{graphics.h}
193 A wxGraphicsContext instance is the object that is drawn upon. It is created by
194 a renderer using the CreateContext calls.., this can be either directly using a renderer
195 instance, or indirectly using the static convenience CreateXXX functions of
196 wxGraphicsContext that always delegate the task to the default renderer.
202 wxGraphicsRenderer:: CreateContext
204 class wxGraphicsContext
: public wxGraphicsObject
209 Clips drawings to the rectangle.
211 void Clip ( const wxRegion
& region
);
212 void Clip ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
216 Concatenates the passed in transform with the current transform of this context
218 void ConcatTransform ( const wxGraphicsMatrix
& matrix
);
222 Creates a wxGraphicsContext from a wxWindow.
224 @see wxGraphicsRenderer:: CreateContext
226 wxGraphicsContext
* Create ( const wxWindowDC
& dc
);
227 wxGraphicsContext
* Create ( wxWindow
* window
);
231 Creates a native brush from a wxBrush.
233 wxGraphicsBrush
CreateBrush ( const wxBrush
& brush
);
236 Creates a native graphics font from a wxFont and a text colour.
238 wxGraphicsFont
CreateFont ( const wxFont
& font
,
239 const wxColour
& col
= wxBLACK
);
242 Creates a wxGraphicsContext from a native context. This native context must be
243 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a
244 cairo_t pointer for cairo.
246 Creates a wxGraphicsContext from a native window.
248 @see wxGraphicsRenderer:: CreateContextFromNativeContext
250 wxGraphicsContext
* CreateFromNative ( void * context
);
253 @see wxGraphicsRenderer:: CreateContextFromNativeWindow
255 wxGraphicsContext
* CreateFromNativeWindow ( void * window
);
258 Creates a native brush, having a linear gradient, starting at (x1,y1) with
259 color c1 to (x2,y2) with color c2
261 wxGraphicsBrush
CreateLinearGradientBrush ( wxDouble x1
,
265 const wxColouramp
; c1
,
266 const wxColouramp
; c2
);
269 Creates a native affine transformation matrix from the passed in values. The
270 defaults result in an identity matrix.
272 wxGraphicsMatrix
CreateMatrix ( wxDouble a
= 1.0 , wxDouble b
= 0.0 ,
279 Creates a native graphics path which is initially empty.
281 wxGraphicsPath
CreatePath ();
284 Creates a native pen from a wxPen.
286 wxGraphicsPen
CreatePen ( const wxPen
& pen
);
289 Creates a native brush, having a radial gradient originating at (xo,yc) with
290 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
292 wxGraphicsBrush
CreateRadialGradientBrush ( wxDouble xo
,
297 const wxColour
& oColor
,
298 const wxColour
& cColor
);
301 Draws the bitmap. In case of a mono bitmap, this is treated as a mask and the
302 current brushed is used for filling.
304 void DrawBitmap ( const wxBitmap
& bmp
, wxDouble x
, wxDouble y
,
305 wxDouble w
, wxDouble h
);
310 void DrawEllipse ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
315 void DrawIcon ( const wxIcon
& icon
, wxDouble x
, wxDouble y
,
316 wxDouble w
, wxDouble h
);
321 void DrawLines ( size_t n
, const wxPoint2DDouble
* points
,
322 int fillStyle
= wxODDEVEN_RULE
);
325 Draws the path by first filling and then stroking.
327 void DrawPath ( const wxGraphicsPath
& path
,
328 int fillStyle
= wxODDEVEN_RULE
);
333 void DrawRectangle ( wxDouble x
, wxDouble y
, wxDouble w
,
337 Draws a rounded rectangle.
339 void DrawRoundedRectangle ( wxDouble x
, wxDouble y
, wxDouble w
,
345 Draws a text at the defined position, at the given angle.
347 void DrawText ( const wxString
& str
, wxDouble x
, wxDouble y
,
349 void DrawText ( const wxString
& str
, wxDouble x
, wxDouble y
);
353 Fills the path with the current brush.
355 void FillPath ( const wxGraphicsPath
& path
,
356 int fillStyle
= wxODDEVEN_RULE
);
359 Returns the native context (CGContextRef for Core Graphics, Graphics pointer
360 for GDIPlus and cairo_t pointer for cairo).
362 void * GetNativeContext ();
365 Fills the @a widths array with the widths from the beginning of
366 @a text to the corresponding character of @e text.
368 void GetPartialTextExtents ( const wxString
& text
,
369 wxArrayDouble
& widths
);
372 Gets the dimensions of the string using the currently selected font.
373 @e string is the text string to measure, @e w and @e h are
374 the total width and height respectively, @a descent is the
375 dimension from the baseline of the font to the bottom of the
376 descender, and @a externalLeading is any extra vertical space added
377 to the font by the font designer (usually is zero).
379 void GetTextExtent ( const wxString
& text
, wxDouble
* width
,
382 wxDouble
* externalLeading
);
385 Gets the current transformation matrix of this context.
387 wxGraphicsMatrix
GetTransform ();
390 Resets the clipping to original shape.
395 Rotates the current transformation matrix (radians),
397 void Rotate ( wxDouble angle
);
400 Scales the current transformation matrix.
402 void Scale ( wxDouble xScale
, wxDouble yScale
);
406 Sets the brush for filling paths.
408 void SetBrush ( const wxBrush
& brush
);
409 void SetBrush ( const wxGraphicsBrush
& brush
);
414 Sets the font for drawing text.
416 void SetFont ( const wxFont
& font
, const wxColour
& colour
);
417 void SetFont ( const wxGraphicsFont
& font
);
422 Sets the pen used for stroking.
424 void SetPen ( const wxGraphicsPen
& pen
);
425 void SetPen ( const wxPen
& pen
);
429 Sets the current transformation matrix of this context
431 void SetTransform ( const wxGraphicsMatrix
& matrix
);
434 Strokes a single line.
436 void StrokeLine ( wxDouble x1
, wxDouble y1
, wxDouble x2
,
441 Stroke disconnected lines from begin to end points, fastest method available
444 void StrokeLines ( size_t n
, const wxPoint2DDouble
* beginPoints
,
445 const wxPoint2DDouble
* endPoints
);
446 void StrokeLines ( size_t n
, const wxPoint2DDouble
* points
);
450 Strokes along a path with the current pen.
452 void StrokePath ( const wxGraphicsPath
& path
);
455 Translates the current transformation matrix.
457 void Translate ( wxDouble dx
, wxDouble dy
);
462 @class wxGraphicsRenderer
463 @wxheader{graphics.h}
465 A wxGraphicsRenderer is the instance corresponding to the rendering engine
466 used. There may be multiple instances on a system, if there are different rendering engines present, but there is always one instance per engine, eg there is ONE core graphics renderer instance on OSX. This instance is pointed back to by all objects created by it (wxGraphicsContext, wxGraphicsPath etc). Therefore you can create ag additional instances of paths etc. by calling GetRenderer() and then using the appropriate CreateXXX function.
471 class wxGraphicsRenderer
: public wxObject
475 Creates a native brush from a wxBrush.
477 wxGraphicsBrush
CreateBrush ( const wxBrush
& brush
);
481 Creates a wxGraphicsContext from a wxWindow.
483 wxGraphicsContext
* CreateContext ( const wxWindowDC
& dc
);
484 wxGraphicsContext
* CreateContext ( wxWindow
* window
);
488 Creates a wxGraphicsContext from a native context. This native context must be
489 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a cairo_t pointer for cairo.
491 wxGraphicsContext
* CreateContextFromNativeContext ( void * context
);
494 Creates a wxGraphicsContext from a native window.
496 wxGraphicsContext
* CreateContextFromNativeWindow ( void * window
);
499 Creates a native graphics font from a wxFont and a text colour.
501 wxGraphicsFont
CreateFont ( const wxFont
& font
,
502 const wxColour
& col
= wxBLACK
);
505 Creates a native brush, having a linear gradient, starting at (x1,y1) with
506 color c1 to (x2,y2) with color c2
508 wxGraphicsBrush
CreateLinearGradientBrush ( wxDouble x1
,
512 const wxColouramp
; c1
,
513 const wxColouramp
; c2
);
516 Creates a native affine transformation matrix from the passed in values. The
517 defaults result in an identity matrix.
519 wxGraphicsMatrix
CreateMatrix ( wxDouble a
= 1.0 , wxDouble b
= 0.0 ,
526 Creates a native graphics path which is initially empty.
528 wxGraphicsPath
CreatePath ();
531 Creates a native pen from a wxPen.
533 wxGraphicsPen
CreatePen ( const wxPen
& pen
);
536 Creates a native brush, having a radial gradient originating at (xo,yc) with
537 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
539 wxGraphicsBrush
CreateRadialGradientBrush ( wxDouble xo
,
544 const wxColour
& oColour
,
545 const wxColour
& cColour
);
548 Returns the default renderer on this platform. On OS X this is the Core
549 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and on GTK we currently default to the cairo renderer.
551 wxGraphicsRenderer
* GetDefaultRenderer ();
556 @class wxGraphicsBrush
557 @wxheader{graphics.h}
563 class wxGraphicsBrush
: public wxGraphicsObject
571 @class wxGraphicsFont
572 @wxheader{graphics.h}
578 class wxGraphicsFont
: public wxGraphicsObject
587 @wxheader{graphics.h}
593 class wxGraphicsPen
: public wxGraphicsObject
601 @class wxGraphicsMatrix
602 @wxheader{graphics.h}
604 A wxGraphicsMatrix is a native representation of an affine matrix. The contents
605 are specific and private to the respective renderer. Instances are ref counted and can therefore be assigned as usual. The only way to get a valid instance is via a CreateMatrix call on the graphics context or the renderer instance.
610 class wxGraphicsMatrix
: public wxGraphicsObject
617 void Concat ( const wxGraphicsMatrix
* t
);
618 void Concat ( const wxGraphicsMatrix
& t
);
622 Returns the component values of the matrix via the argument pointers.
624 void Get ( wxDouble
* a
= NULL
, wxDouble
* b
= NULL
, wxDouble
* c
= NULL
,
625 wxDouble
* d
= NULL
, wxDouble
* tx
= NULL
,
626 wxDouble
* ty
= NULL
);
629 Returns the native representation of the matrix. For CoreGraphics this is a
630 CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for Cairo a cairo_matrix_t pointer.
632 void * GetNativeMatrix ();
640 Returns @true if the elements of the transformation matrix are equal.
642 bool IsEqual ( const wxGraphicsMatrix
& t
);
645 Return @true if this is the identity matrix.
650 Rotates this matrix (radians).
652 void Rotate ( wxDouble angle
);
657 void Scale ( wxDouble xScale
, wxDouble yScale
);
660 Sets the matrix to the respective values (default values are the identity
663 void Set ( wxDouble a
= 1.0 , wxDouble b
= 0.0 , wxDouble c
= 0.0 ,
664 wxDouble d
= 1.0 , wxDouble tx
= 0.0 ,
668 Applies this matrix to a distance (ie. performs all transforms except
671 void TransformDistance ( wxDouble
* dx
, wxDouble
* dy
);
674 Applies this matrix to a point.
676 void TransformPoint ( wxDouble
* x
, wxDouble
* y
);
679 Translates this matrix.
681 void Translate ( wxDouble dx
, wxDouble dy
);