]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/graphics.h
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 a
15 CreatePath call on the graphics context or the renderer instance.
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 void AddArcToPoint ( wxDouble x1
, wxDouble y1
, wxDouble x2
,
45 Appends a circle around (x,y) with radius r as a new closed subpath.
47 void AddCircle ( wxDouble x
, wxDouble y
, wxDouble r
);
53 void AddCurveToPoint ( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
,
57 void AddCurveToPoint ( const wxPoint2DDouble
& c1
,
58 const wxPoint2DDouble
& c2
,
59 const wxPoint2DDouble
& e
);
63 Appends an ellipse fitting into the passed in rectangle.
65 void AddEllipse ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
71 void AddLineToPoint ( wxDouble x
, wxDouble y
);
72 void AddLineToPoint ( const wxPoint2DDouble
& p
);
78 void AddPath ( const wxGraphicsPath
& path
);
81 Adds a quadratic Bezier curve from the current point, using a control point and
84 void AddQuadCurveToPoint ( wxDouble cx
, wxDouble cy
, wxDouble x
,
88 Appends a rectangle as a new closed subpath.
90 void AddRectangle ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
93 Appends a rounded rectangle as a new closed subpath.
95 void AddRoundedRectangle ( wxDouble x
, wxDouble y
, wxDouble w
,
100 Closes the current sub-path.
106 Returns @true if the point is within the path.
108 bool Contains ( const wxPoint2DDouble
& c
,
109 int fillStyle
= wxODDEVEN_RULE
) const ;
110 const bool Contains ( wxDouble x
, wxDouble y
,
111 int fillStyle
= wxODDEVEN_RULE
) const ;
116 Gets the bounding box enclosing all points (possibly including control points).
118 wxRect2DDouble
GetBox () const ;
119 const void GetBox ( wxDouble
* x
, wxDouble
* y
, wxDouble
* w
,
125 Gets the last point of the current path, (0,0) if not yet set.
127 void GetCurrentPoint ( wxDouble
* x
, wxDouble
* y
) const ;
128 const wxPoint2DDouble
GetCurrentPoint () const ;
132 Returns the native path (CGPathRef for Core Graphics, Path pointer for GDIPlus
133 and a cairo_path_t pointer for cairo).
135 void * GetNativePath () const ;
139 Begins a new subpath at (x,y)
141 void MoveToPoint ( wxDouble x
, wxDouble y
);
142 void MoveToPoint ( const wxPoint2DDouble
& p
);
146 Transforms each point of this path by the matrix.
148 void Transform ( const wxGraphicsMatrix
& matrix
);
151 Gives back the native path returned by GetNativePath() because there might be
152 some deallocations necessary (eg on cairo the native path returned by
153 GetNativePath is newly allocated each time).
155 void UnGetNativePath ( void * p
) const ;
161 @class wxGraphicsObject
163 This class is the superclass of native graphics objects like pens etc. It
164 allows reference counting. Not instantiated by user code.
169 @see wxGraphicsBrush, wxGraphicsPen, wxGraphicsMatrix, wxGraphicsPath
171 class wxGraphicsObject
: public wxObject
175 Returns the renderer that was used to create this instance, or @NULL if it has
176 not been initialized yet
178 wxGraphicsRenderer
* GetRenderer () const ;
181 Is this object valid (@false) or still empty (@true)?
189 @class wxGraphicsContext
191 A wxGraphicsContext instance is the object that is drawn upon. It is created by
192 a renderer using wxGraphicsRenderer::CreateContext(). This can be either directly
193 using a renderer instance, or indirectly using the static convenience Create()
194 functions of wxGraphicsContext that always delegate the task to the default renderer.
197 void MyCanvas::OnPaint(wxPaintEvent &event)
202 // Create graphics context from it
203 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
207 // make a path that contains a circle and some lines
208 gc->SetPen( *wxRED_PEN );
209 wxGraphicsPath path = gc->CreatePath();
210 path.AddCircle( 50.0, 50.0, 50.0 );
211 path.MoveToPoint(0.0, 50.0);
212 path.AddLineToPoint(100.0, 50.0);
213 path.MoveToPoint(50.0, 0.0);
214 path.AddLineToPoint(50.0, 100.0 );
216 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
218 gc->StrokePath(path);
229 @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
231 class wxGraphicsContext
: public wxGraphicsObject
235 Creates a wxGraphicsContext from a wxWindow.
237 @see wxGraphicsRenderer::CreateContext()
239 static wxGraphicsContext
* Create ( wxWindow
* window
) ;
242 Creates a wxGraphicsContext from a wxWindowDC
244 @see wxGraphicsRenderer::CreateContext()
246 static wxGraphicsContext
* Create ( const wxWindowDC
& dc
) ;
249 Creates a wxGraphicsContext from a wxMemoryDC
251 @see wxGraphicsRenderer::CreateContext()
253 static wxGraphicsContext
* Create ( const wxMemoryDC
& dc
) ;
256 Creates a wxGraphicsContext from a wxPrinterDC. Under
257 GTK+, this will only work when using the GtkPrint
258 printing backend which is available since GTK+ 2.10.
260 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting "Printing under Unix"
262 static wxGraphicsContext
* Create ( const wxPrinterDC
& dc
) ;
265 Clips drawings to the region
267 void Clip ( const wxRegion
& region
);
270 Clips drawings to the rectangle.
272 void Clip ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
275 Concatenates the passed in transform with the current transform of this context
277 void ConcatTransform ( const wxGraphicsMatrix
& matrix
);
281 Creates a native brush from a wxBrush.
283 wxGraphicsBrush
CreateBrush ( const wxBrush
& brush
) const ;
286 Creates a native graphics font from a wxFont and a text colour.
288 wxGraphicsFont
CreateFont ( const wxFont
& font
,
289 const wxColour
& col
= wxBLACK
) const ;
292 Creates a wxGraphicsContext from a native context. This native context must be
293 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a
294 cairo_t pointer for cairo.
296 @see wxGraphicsRenderer:: CreateContextFromNativeContext
298 wxGraphicsContext
* CreateFromNative ( void * context
);
301 Creates a wxGraphicsContext from a native window.
303 @see wxGraphicsRenderer:: CreateContextFromNativeWindow
305 wxGraphicsContext
* CreateFromNativeWindow ( void * window
);
308 Creates a native brush, having a linear gradient, starting at (x1,y1) with
309 color c1 to (x2,y2) with color c2
311 wxGraphicsBrush
CreateLinearGradientBrush ( wxDouble x1
,
315 const wxColouramp
; c1
,
316 const wxColouramp
; c2
) const ;
319 Creates a native affine transformation matrix from the passed in values. The
320 defaults result in an identity matrix.
322 wxGraphicsMatrix
CreateMatrix ( wxDouble a
= 1.0 , wxDouble b
= 0.0 ,
326 wxDouble ty
= 0.0 ) const ;
329 Creates a native graphics path which is initially empty.
331 wxGraphicsPath
CreatePath () const ;
334 Creates a native pen from a wxPen.
336 wxGraphicsPen
CreatePen ( const wxPen
& pen
) const ;
339 Creates a native brush, having a radial gradient originating at (xo,yc) with
340 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
342 wxGraphicsBrush
CreateRadialGradientBrush ( wxDouble xo
,
347 const wxColour
& oColor
,
348 const wxColour
& cColor
) const ;
351 Draws the bitmap. In case of a mono bitmap, this is treated as a mask and the
352 current brushed is used for filling.
354 void DrawBitmap ( const wxBitmap
& bmp
, wxDouble x
, wxDouble y
,
355 wxDouble w
, wxDouble h
);
360 void DrawEllipse ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
365 void DrawIcon ( const wxIcon
& icon
, wxDouble x
, wxDouble y
,
366 wxDouble w
, wxDouble h
);
371 void DrawLines ( size_t n
, const wxPoint2DDouble
* points
,
372 int fillStyle
= wxODDEVEN_RULE
);
375 Draws the path by first filling and then stroking.
377 void DrawPath ( const wxGraphicsPath
& path
,
378 int fillStyle
= wxODDEVEN_RULE
);
383 void DrawRectangle ( wxDouble x
, wxDouble y
, wxDouble w
,
387 Draws a rounded rectangle.
389 void DrawRoundedRectangle ( wxDouble x
, wxDouble y
, wxDouble w
,
395 Draws a text at the defined position, at the given angle.
397 void DrawText ( const wxString
& str
, wxDouble x
, wxDouble y
,
399 void DrawText ( const wxString
& str
, wxDouble x
, wxDouble y
);
403 Fills the path with the current brush.
405 void FillPath ( const wxGraphicsPath
& path
,
406 int fillStyle
= wxODDEVEN_RULE
);
409 Returns the native context (CGContextRef for Core Graphics, Graphics pointer
410 for GDIPlus and cairo_t pointer for cairo).
412 void * GetNativeContext ();
415 Fills the @a widths array with the widths from the beginning of
416 @a text to the corresponding character of @e text.
418 void GetPartialTextExtents ( const wxString
& text
,
419 wxArrayDouble
& widths
) const ;
422 Gets the dimensions of the string using the currently selected font.
423 @e string is the text string to measure, @e w and @e h are
424 the total width and height respectively, @a descent is the
425 dimension from the baseline of the font to the bottom of the
426 descender, and @a externalLeading is any extra vertical space added
427 to the font by the font designer (usually is zero).
429 void GetTextExtent ( const wxString
& text
, wxDouble
* width
,
432 wxDouble
* externalLeading
) const ;
435 Gets the current transformation matrix of this context.
437 wxGraphicsMatrix
GetTransform () const ;
440 Resets the clipping to original shape.
445 Rotates the current transformation matrix (radians),
447 void Rotate ( wxDouble angle
);
450 Scales the current transformation matrix.
452 void Scale ( wxDouble xScale
, wxDouble yScale
);
456 Sets the brush for filling paths.
458 void SetBrush ( const wxBrush
& brush
);
459 void SetBrush ( const wxGraphicsBrush
& brush
);
464 Sets the font for drawing text.
466 void SetFont ( const wxFont
& font
, const wxColour
& colour
);
467 void SetFont ( const wxGraphicsFont
& font
);
472 Sets the pen used for stroking.
474 void SetPen ( const wxGraphicsPen
& pen
);
475 void SetPen ( const wxPen
& pen
);
479 Sets the current transformation matrix of this context
481 void SetTransform ( const wxGraphicsMatrix
& matrix
);
484 Strokes a single line.
486 void StrokeLine ( wxDouble x1
, wxDouble y1
, wxDouble x2
,
491 Stroke disconnected lines from begin to end points, fastest method available
494 void StrokeLines ( size_t n
, const wxPoint2DDouble
* beginPoints
,
495 const wxPoint2DDouble
* endPoints
);
496 void StrokeLines ( size_t n
, const wxPoint2DDouble
* points
);
500 Strokes along a path with the current pen.
502 void StrokePath ( const wxGraphicsPath
& path
);
505 Translates the current transformation matrix.
507 void Translate ( wxDouble dx
, wxDouble dy
);
513 @class wxGraphicsRenderer
515 A wxGraphicsRenderer is the instance corresponding to the rendering engine
516 used. There may be multiple instances on a system, if there are different
517 rendering engines present, but there is always only one instance per engine.
518 This instance is pointed back to by all objects created by it (wxGraphicsContext,
519 wxGraphicsPath etc) and can be retrieved through their wxGraphicsObject::GetRenderer()
520 method. Therefore you can create an additional instance of a path etc. by calling
521 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX function
525 wxGraphicsPath *path = // from somewhere
526 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
532 class wxGraphicsRenderer
: public wxObject
536 Creates a wxGraphicsContext from a wxWindow.
538 virtual wxGraphicsContext
* CreateContext ( wxWindow
* window
) = 0 ;
541 Creates a wxGraphicsContext from a wxWindowDC
543 virtual wxGraphicsContext
* CreateContext ( const wxWindowDC
& dc
) = 0 ;
546 Creates a wxGraphicsContext from a wxMemoryDC
548 virtual wxGraphicsContext
* CreateContext ( const wxMemoryDC
& dc
) = 0 ;
551 Creates a wxGraphicsContext from a wxPrinterDC
553 virtual wxGraphicsContext
* CreateContext ( const wxPrinterDC
& dc
) = 0 ;
556 Creates a native brush from a wxBrush.
558 wxGraphicsBrush
CreateBrush ( const wxBrush
& brush
);
562 Creates a wxGraphicsContext from a native context. This native context must be
563 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a cairo_t
566 wxGraphicsContext
* CreateContextFromNativeContext ( void * context
);
569 Creates a wxGraphicsContext from a native window.
571 wxGraphicsContext
* CreateContextFromNativeWindow ( void * window
);
574 Creates a native graphics font from a wxFont and a text colour.
576 wxGraphicsFont
CreateFont ( const wxFont
& font
,
577 const wxColour
& col
= wxBLACK
);
580 Creates a native brush, having a linear gradient, starting at (x1,y1) with
581 color c1 to (x2,y2) with color c2
583 wxGraphicsBrush
CreateLinearGradientBrush ( wxDouble x1
,
587 const wxColouramp
; c1
,
588 const wxColouramp
; c2
);
591 Creates a native affine transformation matrix from the passed in values. The
592 defaults result in an identity matrix.
594 wxGraphicsMatrix
CreateMatrix ( wxDouble a
= 1.0 , wxDouble b
= 0.0 ,
601 Creates a native graphics path which is initially empty.
603 wxGraphicsPath
CreatePath ();
606 Creates a native pen from a wxPen.
608 wxGraphicsPen
CreatePen ( const wxPen
& pen
);
611 Creates a native brush, having a radial gradient originating at (xo,yc) with
612 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
614 wxGraphicsBrush
CreateRadialGradientBrush ( wxDouble xo
,
619 const wxColour
& oColour
,
620 const wxColour
& cColour
);
623 Returns the default renderer on this platform. On OS X this is the Core
624 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and on GTK we currently default to the cairo renderer.
626 static wxGraphicsRenderer
* GetDefaultRenderer ();
632 @class wxGraphicsBrush
638 class wxGraphicsBrush
: public wxGraphicsObject
647 @class wxGraphicsFont
653 class wxGraphicsFont
: public wxGraphicsObject
668 class wxGraphicsPen
: public wxGraphicsObject
677 @class wxGraphicsMatrix
679 A wxGraphicsMatrix is a native representation of an affine matrix. The contents
680 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.
685 class wxGraphicsMatrix
: public wxGraphicsObject
692 void Concat ( const wxGraphicsMatrix
* t
);
693 void Concat ( const wxGraphicsMatrix
& t
);
697 Returns the component values of the matrix via the argument pointers.
699 void Get ( wxDouble
* a
= NULL
, wxDouble
* b
= NULL
, wxDouble
* c
= NULL
,
700 wxDouble
* d
= NULL
, wxDouble
* tx
= NULL
,
701 wxDouble
* ty
= NULL
) const ;
704 Returns the native representation of the matrix. For CoreGraphics this is a
705 CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for Cairo a cairo_matrix_t pointer.
707 void * GetNativeMatrix () const ;
715 Returns @true if the elements of the transformation matrix are equal.
717 bool IsEqual ( const wxGraphicsMatrix
& t
) const ;
720 Return @true if this is the identity matrix.
722 bool IsIdentity () const ;
725 Rotates this matrix (radians).
727 void Rotate ( wxDouble angle
);
732 void Scale ( wxDouble xScale
, wxDouble yScale
);
735 Sets the matrix to the respective values (default values are the identity
738 void Set ( wxDouble a
= 1.0 , wxDouble b
= 0.0 , wxDouble c
= 0.0 ,
739 wxDouble d
= 1.0 , wxDouble tx
= 0.0 ,
743 Applies this matrix to a distance (ie. performs all transforms except
746 void TransformDistance ( wxDouble
* dx
, wxDouble
* dy
) const ;
749 Applies this matrix to a point.
751 void TransformPoint ( wxDouble
* x
, wxDouble
* y
) const ;
754 Translates this matrix.
756 void Translate ( wxDouble dx
, wxDouble dy
);