]>
git.saurik.com Git - wxWidgets.git/blob - interface/graphics.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxGraphicsPath
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
) const ;
111 const bool Contains ( wxDouble x
, wxDouble y
,
112 int fillStyle
= wxODDEVEN_RULE
) const ;
117 Gets the bounding box enclosing all points (possibly including control points).
119 wxRect2DDouble
GetBox () const ;
120 const 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
) const ;
129 const wxPoint2DDouble
GetCurrentPoint () const ;
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 () const ;
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
) const ;
162 @class wxGraphicsObject
163 @wxheader{graphics.h}
165 This class is the superclass of native graphics objects like pens etc. It
166 allows reference counting. Not instantiated by user code.
171 @see 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 () const ;
183 Is this object valid (@false) or still empty (@true)?
191 @class wxGraphicsContext
192 @wxheader{graphics.h}
194 A wxGraphicsContext instance is the object that is drawn upon. It is created by
195 a renderer using wxGraphicsRenderer::CreateContext(). This can be either directly
196 using a renderer instance, or indirectly using the static convenience Create()
197 functions of wxGraphicsContext that always delegate the task to the default renderer.
200 void MyCanvas::OnPaint(wxPaintEvent &event)
205 // Create graphics context from it
206 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
210 // make a path that contains a circle and some lines
211 gc->SetPen( *wxRED_PEN );
212 wxGraphicsPath path = gc->CreatePath();
213 path.AddCircle( 50.0, 50.0, 50.0 );
214 path.MoveToPoint(0.0, 50.0);
215 path.AddLineToPoint(100.0, 50.0);
216 path.MoveToPoint(50.0, 0.0);
217 path.AddLineToPoint(50.0, 100.0 );
219 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
221 gc->StrokePath(path);
232 @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
234 class wxGraphicsContext
: public wxGraphicsObject
238 Creates a wxGraphicsContext from a wxWindow.
240 @see wxGraphicsRenderer::CreateContext()
242 static wxGraphicsContext
* Create ( wxWindow
* window
) ;
245 Creates a wxGraphicsContext from a wxWindowDC
247 @see wxGraphicsRenderer::CreateContext()
249 static wxGraphicsContext
* Create ( const wxWindowDC
& dc
) ;
252 Creates a wxGraphicsContext from a wxMemoryDC
254 @see wxGraphicsRenderer::CreateContext()
256 static wxGraphicsContext
* Create ( const wxMemoryDC
& dc
) ;
259 Creates a wxGraphicsContext from a wxPrinterDC. Under
260 GTK+, this will only work when using the GtkPrint
261 printing backend which is available since GTK+ 2.10.
263 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting "Printing under Unix"
265 static wxGraphicsContext
* Create ( const wxPrinterDC
& dc
) ;
268 Clips drawings to the region
270 void Clip ( const wxRegion
& region
);
273 Clips drawings to the rectangle.
275 void Clip ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
278 Concatenates the passed in transform with the current transform of this context
280 void ConcatTransform ( const wxGraphicsMatrix
& matrix
);
284 Creates a native brush from a wxBrush.
286 wxGraphicsBrush
CreateBrush ( const wxBrush
& brush
) const ;
289 Creates a native graphics font from a wxFont and a text colour.
291 wxGraphicsFont
CreateFont ( const wxFont
& font
,
292 const wxColour
& col
= wxBLACK
) const ;
295 Creates a wxGraphicsContext from a native context. This native context must be
296 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a
297 cairo_t pointer for cairo.
299 @see wxGraphicsRenderer:: CreateContextFromNativeContext
301 wxGraphicsContext
* CreateFromNative ( void * context
);
304 Creates a wxGraphicsContext from a native window.
306 @see wxGraphicsRenderer:: CreateContextFromNativeWindow
308 wxGraphicsContext
* CreateFromNativeWindow ( void * window
);
311 Creates a native brush, having a linear gradient, starting at (x1,y1) with
312 color c1 to (x2,y2) with color c2
314 wxGraphicsBrush
CreateLinearGradientBrush ( wxDouble x1
,
318 const wxColouramp
; c1
,
319 const wxColouramp
; c2
) const ;
322 Creates a native affine transformation matrix from the passed in values. The
323 defaults result in an identity matrix.
325 wxGraphicsMatrix
CreateMatrix ( wxDouble a
= 1.0 , wxDouble b
= 0.0 ,
329 wxDouble ty
= 0.0 ) const ;
332 Creates a native graphics path which is initially empty.
334 wxGraphicsPath
CreatePath () const ;
337 Creates a native pen from a wxPen.
339 wxGraphicsPen
CreatePen ( const wxPen
& pen
) const ;
342 Creates a native brush, having a radial gradient originating at (xo,yc) with
343 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
345 wxGraphicsBrush
CreateRadialGradientBrush ( wxDouble xo
,
350 const wxColour
& oColor
,
351 const wxColour
& cColor
) const ;
354 Draws the bitmap. In case of a mono bitmap, this is treated as a mask and the
355 current brushed is used for filling.
357 void DrawBitmap ( const wxBitmap
& bmp
, wxDouble x
, wxDouble y
,
358 wxDouble w
, wxDouble h
);
363 void DrawEllipse ( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
368 void DrawIcon ( const wxIcon
& icon
, wxDouble x
, wxDouble y
,
369 wxDouble w
, wxDouble h
);
374 void DrawLines ( size_t n
, const wxPoint2DDouble
* points
,
375 int fillStyle
= wxODDEVEN_RULE
);
378 Draws the path by first filling and then stroking.
380 void DrawPath ( const wxGraphicsPath
& path
,
381 int fillStyle
= wxODDEVEN_RULE
);
386 void DrawRectangle ( wxDouble x
, wxDouble y
, wxDouble w
,
390 Draws a rounded rectangle.
392 void DrawRoundedRectangle ( wxDouble x
, wxDouble y
, wxDouble w
,
398 Draws a text at the defined position, at the given angle.
400 void DrawText ( const wxString
& str
, wxDouble x
, wxDouble y
,
402 void DrawText ( const wxString
& str
, wxDouble x
, wxDouble y
);
406 Fills the path with the current brush.
408 void FillPath ( const wxGraphicsPath
& path
,
409 int fillStyle
= wxODDEVEN_RULE
);
412 Returns the native context (CGContextRef for Core Graphics, Graphics pointer
413 for GDIPlus and cairo_t pointer for cairo).
415 void * GetNativeContext ();
418 Fills the @a widths array with the widths from the beginning of
419 @a text to the corresponding character of @e text.
421 void GetPartialTextExtents ( const wxString
& text
,
422 wxArrayDouble
& widths
) const ;
425 Gets the dimensions of the string using the currently selected font.
426 @e string is the text string to measure, @e w and @e h are
427 the total width and height respectively, @a descent is the
428 dimension from the baseline of the font to the bottom of the
429 descender, and @a externalLeading is any extra vertical space added
430 to the font by the font designer (usually is zero).
432 void GetTextExtent ( const wxString
& text
, wxDouble
* width
,
435 wxDouble
* externalLeading
) const ;
438 Gets the current transformation matrix of this context.
440 wxGraphicsMatrix
GetTransform () const ;
443 Resets the clipping to original shape.
448 Rotates the current transformation matrix (radians),
450 void Rotate ( wxDouble angle
);
453 Scales the current transformation matrix.
455 void Scale ( wxDouble xScale
, wxDouble yScale
);
459 Sets the brush for filling paths.
461 void SetBrush ( const wxBrush
& brush
);
462 void SetBrush ( const wxGraphicsBrush
& brush
);
467 Sets the font for drawing text.
469 void SetFont ( const wxFont
& font
, const wxColour
& colour
);
470 void SetFont ( const wxGraphicsFont
& font
);
475 Sets the pen used for stroking.
477 void SetPen ( const wxGraphicsPen
& pen
);
478 void SetPen ( const wxPen
& pen
);
482 Sets the current transformation matrix of this context
484 void SetTransform ( const wxGraphicsMatrix
& matrix
);
487 Strokes a single line.
489 void StrokeLine ( wxDouble x1
, wxDouble y1
, wxDouble x2
,
494 Stroke disconnected lines from begin to end points, fastest method available
497 void StrokeLines ( size_t n
, const wxPoint2DDouble
* beginPoints
,
498 const wxPoint2DDouble
* endPoints
);
499 void StrokeLines ( size_t n
, const wxPoint2DDouble
* points
);
503 Strokes along a path with the current pen.
505 void StrokePath ( const wxGraphicsPath
& path
);
508 Translates the current transformation matrix.
510 void Translate ( wxDouble dx
, wxDouble dy
);
516 @class wxGraphicsRenderer
517 @wxheader{graphics.h}
519 A wxGraphicsRenderer is the instance corresponding to the rendering engine
520 used. There may be multiple instances on a system, if there are different
521 rendering engines present, but there is always only one instance per engine.
522 This instance is pointed back to by all objects created by it (wxGraphicsContext,
523 wxGraphicsPath etc) and can be retrieved through their wxGraphicsObject::GetRenderer()
524 method. Therefore you can create an additional instance of a path etc. by calling
525 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX function
529 wxGraphicsPath *path = // from somewhere
530 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
536 class wxGraphicsRenderer
: public wxObject
540 Creates a wxGraphicsContext from a wxWindow.
542 virtual wxGraphicsContext
* CreateContext ( wxWindow
* window
) = 0 ;
545 Creates a wxGraphicsContext from a wxWindowDC
547 virtual wxGraphicsContext
* CreateContext ( const wxWindowDC
& dc
) = 0 ;
550 Creates a wxGraphicsContext from a wxMemoryDC
552 virtual wxGraphicsContext
* CreateContext ( const wxMemoryDC
& dc
) = 0 ;
555 Creates a wxGraphicsContext from a wxPrinterDC
557 virtual wxGraphicsContext
* CreateContext ( const wxPrinterDC
& dc
) = 0 ;
560 Creates a native brush from a wxBrush.
562 wxGraphicsBrush
CreateBrush ( const wxBrush
& brush
);
566 Creates a wxGraphicsContext from a native context. This native context must be
567 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a cairo_t
570 wxGraphicsContext
* CreateContextFromNativeContext ( void * context
);
573 Creates a wxGraphicsContext from a native window.
575 wxGraphicsContext
* CreateContextFromNativeWindow ( void * window
);
578 Creates a native graphics font from a wxFont and a text colour.
580 wxGraphicsFont
CreateFont ( const wxFont
& font
,
581 const wxColour
& col
= wxBLACK
);
584 Creates a native brush, having a linear gradient, starting at (x1,y1) with
585 color c1 to (x2,y2) with color c2
587 wxGraphicsBrush
CreateLinearGradientBrush ( wxDouble x1
,
591 const wxColouramp
; c1
,
592 const wxColouramp
; c2
);
595 Creates a native affine transformation matrix from the passed in values. The
596 defaults result in an identity matrix.
598 wxGraphicsMatrix
CreateMatrix ( wxDouble a
= 1.0 , wxDouble b
= 0.0 ,
605 Creates a native graphics path which is initially empty.
607 wxGraphicsPath
CreatePath ();
610 Creates a native pen from a wxPen.
612 wxGraphicsPen
CreatePen ( const wxPen
& pen
);
615 Creates a native brush, having a radial gradient originating at (xo,yc) with
616 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
618 wxGraphicsBrush
CreateRadialGradientBrush ( wxDouble xo
,
623 const wxColour
& oColour
,
624 const wxColour
& cColour
);
627 Returns the default renderer on this platform. On OS X this is the Core
628 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and on GTK we currently default to the cairo renderer.
630 static wxGraphicsRenderer
* GetDefaultRenderer ();
636 @class wxGraphicsBrush
637 @wxheader{graphics.h}
643 class wxGraphicsBrush
: public wxGraphicsObject
652 @class wxGraphicsFont
653 @wxheader{graphics.h}
659 class wxGraphicsFont
: public wxGraphicsObject
669 @wxheader{graphics.h}
675 class wxGraphicsPen
: public wxGraphicsObject
684 @class wxGraphicsMatrix
685 @wxheader{graphics.h}
687 A wxGraphicsMatrix is a native representation of an affine matrix. The contents
688 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.
693 class wxGraphicsMatrix
: public wxGraphicsObject
700 void Concat ( const wxGraphicsMatrix
* t
);
701 void Concat ( const wxGraphicsMatrix
& t
);
705 Returns the component values of the matrix via the argument pointers.
707 void Get ( wxDouble
* a
= NULL
, wxDouble
* b
= NULL
, wxDouble
* c
= NULL
,
708 wxDouble
* d
= NULL
, wxDouble
* tx
= NULL
,
709 wxDouble
* ty
= NULL
) const ;
712 Returns the native representation of the matrix. For CoreGraphics this is a
713 CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for Cairo a cairo_matrix_t pointer.
715 void * GetNativeMatrix () const ;
723 Returns @true if the elements of the transformation matrix are equal.
725 bool IsEqual ( const wxGraphicsMatrix
& t
) const ;
728 Return @true if this is the identity matrix.
730 bool IsIdentity () const ;
733 Rotates this matrix (radians).
735 void Rotate ( wxDouble angle
);
740 void Scale ( wxDouble xScale
, wxDouble yScale
);
743 Sets the matrix to the respective values (default values are the identity
746 void Set ( wxDouble a
= 1.0 , wxDouble b
= 0.0 , wxDouble c
= 0.0 ,
747 wxDouble d
= 1.0 , wxDouble tx
= 0.0 ,
751 Applies this matrix to a distance (ie. performs all transforms except
754 void TransformDistance ( wxDouble
* dx
, wxDouble
* dy
) const ;
757 Applies this matrix to a point.
759 void TransformPoint ( wxDouble
* x
, wxDouble
* y
) const ;
762 Translates this matrix.
764 void Translate ( wxDouble dx
, wxDouble dy
);