A GraphicsContext instance is the object that is drawn upon.
It is created by a renderer using GraphicsRenderer.CreateContext . This can be either directly using a renderer instance, or indirectly using the static convenience Create functions of GraphicsContext that always delegate the task to the default renderer.
def OnPaint(self, event):
# Create paint DC
dc = wx.PaintDC(self)
# Create graphics context from it
gc = wx.GraphicsContext.Create(dc)
if gc:
# make a path that contains a circle and some lines
gc.SetPen(wx.RED_PEN)
path = gc.CreatePath()
path.AddCircle(50.0, 50.0, 50.0)
path.MoveToPoint(0.0, 50.0)
path.AddLineToPoint(100.0, 50.0)
path.MoveToPoint(50.0, 0.0)
path.AddLineToPoint(50.0, 100.0)
path.CloseSubpath()
path.AddRectangle(25.0, 25.0, 50.0, 50.0)
gc.StrokePath(path)
See also
BeginLayer | Redirects all rendering is done into a fully transparent temporary context. |
Clip | Clips drawings to the specified region. |
ConcatTransform | Concatenates the passed in transform with the current transform of this context. |
Create | Creates a GraphicsContext from a Window. |
CreateBitmap | Creates GraphicsBitmap from an existing Bitmap. |
CreateBitmapFromImage | Creates GraphicsBitmap from an existing Image. |
CreateBrush | Creates a native brush from a Brush. |
CreateFont | Creates a native graphics font from a Font and a text colour. |
CreateFromNative | Creates a GraphicsContext from a native context. |
CreateFromNativeWindow | Creates a GraphicsContext from a native window. |
CreateLinearGradientBrush | Creates a native brush with a linear gradient. |
CreateMatrix | Creates a native affine transformation matrix from the passed in values. |
CreatePath | Creates a native graphics path which is initially empty. |
CreatePen | Creates a native pen from a Pen. |
CreateRadialGradientBrush | Creates a native brush with a radial gradient. |
CreateSubBitmap | Extracts a sub-bitmap from an existing bitmap. |
DisableOffset | |
DrawBitmap | Draws the bitmap. |
DrawEllipse | Draws an ellipse. |
DrawIcon | Draws the icon. |
DrawPath | Draws the path by first filling and then stroking. |
DrawRectangle | Draws a rectangle. |
DrawRoundedRectangle | Draws a rounded rectangle. |
DrawText | Draws text at the defined position. |
EnableOffset | |
EndLayer | Composites back the drawings into the context with the opacity given at the BeginLayer call. |
FillPath | Fills the path with the current brush. |
GetAntialiasMode | Returns the current shape antialiasing mode. |
GetCompositionMode | Returns the current compositing operator. |
GetInterpolationQuality | Returns the current interpolation quality. |
GetNativeContext | Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo). |
GetPartialTextExtents | Fills the widths array with the widths from the beginning of text to the corresponding character of text. |
GetFullTextExtent | Gets the dimensions of the string using the currently selected font. |
GetTransform | Gets the current transformation matrix of this context. |
OffsetEnabled | |
PopState | Pops a stored state from the stack and sets the current transformation matrix to that state. |
PushState | Push the current state of the context’s transformation matrix on a stack. |
ResetClip | Resets the clipping to original shape. |
Rotate | Rotates the current transformation matrix (in radians). |
Scale | Scales the current transformation matrix. |
SetAntialiasMode | Sets the antialiasing mode, returns True if it supported. |
SetBrush | Sets the brush for filling paths. |
SetCompositionMode | Sets the compositing operator, returns True if it supported. |
SetFont | Sets the font for drawing text. |
SetInterpolationQuality | Sets the interpolation quality, returns True if it is supported. |
SetPen | Sets the pen used for stroking. |
SetTransform | Sets the current transformation matrix of this context. |
StrokeLine | Strokes a single line. |
StrokeLineSegments | Stroke disconnected lines from begin to end points. |
StrokePath | Strokes along a path with the current pen. |
Translate | Translates the current transformation matrix. |
AntialiasMode | See GetAntialiasMode and SetAntialiasMode |
CompositionMode | See GetCompositionMode and SetCompositionMode |
InterpolationQuality | See GetInterpolationQuality and SetInterpolationQuality |
NativeContext | See GetNativeContext |
TextExtent | See GetTextExtent |
Transform | See GetTransform and SetTransform |
A GraphicsContext instance is the object that is drawn upon.
Redirects all rendering is done into a fully transparent temporary context.
Parameters: | opacity (float) – |
---|
Overloaded Implementations:
Clip (self, region)
Clips drawings to the specified region.
Parameters: | region (Region) – |
---|
Clip (self, x, y, w, h)
Clips drawings to the specified rectangle.
Parameters: |
|
---|
Concatenates the passed in transform with the current transform of this context.
Parameters: | matrix (GraphicsMatrix) – |
---|
Overloaded Implementations:
Create (window)
Creates a GraphicsContext from a Window.
Parameters: | window (Window) – |
---|---|
Return type: | GraphicsContext |
See also
Create (windowDC)
Creates a GraphicsContext from a WindowDC.
Parameters: | windowDC (WindowDC) – |
---|---|
Return type: | GraphicsContext |
See also
Create (memoryDC)
Creates a GraphicsContext from a MemoryDC.
Parameters: | memoryDC (MemoryDC) – |
---|---|
Return type: | GraphicsContext |
See also
Create (printerDC)
Creates a GraphicsContext from a PrinterDC.
Under GTK+, this will only work when using the GtkPrint printing backend which is available since GTK+ 2.10.
Parameters: | printerDC (PrinterDC) – |
---|---|
Return type: | GraphicsContext |
See also
Create (image)
Creates a GraphicsContext associated with a Image.
The image specifies the size of the context as well as whether alpha is supported (if Image.HasAlpha ) or not and the initial contents of the context. The image object must have a life time greater than that of the new context as the context copies its contents back to the image when it is destroyed.
Parameters: | image (Image) – |
---|---|
Return type: | GraphicsContext |
New in version 2.9.3.
Creates GraphicsBitmap from an existing Bitmap.
Returns an invalid NullGraphicsBitmap on failure.
Parameters: | bitmap (Bitmap) – |
---|---|
Return type: | GraphicsBitmap |
Creates GraphicsBitmap from an existing Image.
This method is more efficient than converting Image to Bitmap first and then calling CreateBitmap but otherwise has the same effect.
Returns an invalid NullGraphicsBitmap on failure.
Parameters: | image (Image) – |
---|---|
Return type: | GraphicsBitmap |
New in version 2.9.3.
Creates a native brush from a Brush.
Parameters: | brush (Brush) – |
---|---|
Return type: | GraphicsBrush |
Overloaded Implementations:
CreateFont (self, font, col=BLACK)
Creates a native graphics font from a Font and a text colour.
Parameters: | |
---|---|
Return type: |
CreateFont (self, sizeInPixels, facename, flags=FONTFLAG_DEFAULT, col=BLACK)
Creates a font object with the specified attributes.
The use of overload taking Font is preferred, see GraphicsRenderer.CreateFont for more details.
Parameters: |
|
---|---|
Return type: |
New in version 2.9.3.
Creates a GraphicsContext from a native context.
This native context must be a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus, or a cairo_t pointer for cairo.
Parameters: | context – |
---|---|
Return type: | GraphicsContext |
Creates a GraphicsContext from a native window.
Parameters: | window – |
---|---|
Return type: | GraphicsContext |
Creates a native brush with a linear gradient.
The brush starts at (x1, y1) and ends at (x2, y2). Either just the start and end gradient colours (c1 and c2) or full set of gradient stops can be specified.
The version taking GraphicsGradientStops is new in wxWidgets 2.9.1.
Overloaded Implementations:
CreateLinearGradientBrush (self, x1, y1, x2, y2, c1, c2)
Parameters: | |
---|---|
Return type: |
CreateLinearGradientBrush (self, x1, y1, x2, y2, stops)
Parameters: |
|
---|---|
Return type: |
Overloaded Implementations:
CreateMatrix (self, a=1.0, b=0.0, c=0.0, d=1.0, tx=0.0, ty=0.0)
Creates a native affine transformation matrix from the passed in values.
The default parameters result in an identity matrix.
Parameters: |
|
---|---|
Return type: |
CreateMatrix (self, mat)
Creates a native affine transformation matrix from the passed generic one.
Parameters: | mat (AffineMatrix2DBase) – |
---|---|
Return type: | GraphicsMatrix |
New in version 2.9.4.
Creates a native graphics path which is initially empty.
Return type: | GraphicsPath |
---|
Creates a native pen from a Pen.
Parameters: | pen (Pen) – |
---|---|
Return type: | GraphicsPen |
Creates a native brush with a radial gradient.
The brush originates at (xo, yc) and ends on a circle around (xc, yc) with the given radius.
The gradient may be specified either by its start and end colours oColor and cColor or by a full set of gradient stops.
The version taking GraphicsGradientStops is new in wxWidgets 2.9.1.
Overloaded Implementations:
CreateRadialGradientBrush (self, xo, yo, xc, yc, radius, oColor, cColor)
Parameters: | |
---|---|
Return type: |
CreateRadialGradientBrush (self, xo, yo, xc, yc, radius, stops)
Parameters: |
|
---|---|
Return type: |
Extracts a sub-bitmap from an existing bitmap.
Currently this function is implemented in the native MSW and OS X versions but not when using Cairo.
Parameters: |
|
---|---|
Return type: |
Draws the bitmap.
In case of a mono bitmap, this is treated as a mask and the current brushed is used for filling.
Overloaded Implementations:
DrawBitmap (self, bmp, x, y, w, h)
Parameters: |
|
---|
DrawBitmap (self, bmp, x, y, w, h)
Parameters: |
|
---|
Draws an ellipse.
Parameters: |
|
---|
Draws the icon.
Parameters: |
|
---|
Draws the path by first filling and then stroking.
Parameters: |
|
---|
Draws a rectangle.
Parameters: |
|
---|
Draws a rounded rectangle.
Parameters: |
|
---|
Overloaded Implementations:
DrawText (self, str, x, y)
Draws text at the defined position.
Parameters: |
|
---|
DrawText (self, str, x, y, angle)
Draws text at the defined position.
Parameters: |
|
---|
DrawText (self, str, x, y, backgroundBrush)
Draws text at the defined position.
Parameters: |
|
---|
DrawText (self, str, x, y, angle, backgroundBrush)
Draws text at the defined position.
Parameters: |
|
---|
Parameters: | enable (bool) – |
---|
Composites back the drawings into the context with the opacity given at the BeginLayer call.
Fills the path with the current brush.
Parameters: |
|
---|
Returns the current shape antialiasing mode.
Return type: | AntialiasMode |
---|
Returns the current compositing operator.
Return type: | CompositionMode |
---|
Returns the current interpolation quality.
Return type: | InterpolationQuality |
---|
Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo).
Fills the widths array with the widths from the beginning of text to the corresponding character of text.
Parameters: | text (string) – |
---|---|
Return type: | list of floats |
Overloaded Implementations:
GetFullTextExtent (self, text)
Gets the dimensions of the string using the currently selected font.
Parameters: | text (string) – The text string to measure. |
---|
Variable to store the total calculated width of the text.
Variable to store the total calculated height of the text.
Variable to store the dimension from the baseline of the font to the bottom of the descender.
Any extra vertical space added to the font by the font designer (usually is zero).
Return type: | tuple |
---|---|
Returns: | ( width, height, descent, externalLeading ) |
GetFullTextExtent (self, text)
Gets the dimensions of the string using the currently selected font.
Return type: | tuple |
---|---|
Returns: | ( width, height ) |
Gets the current transformation matrix of this context.
Return type: | GraphicsMatrix |
---|
Return type: | bool |
---|
Pops a stored state from the stack and sets the current transformation matrix to that state.
See also
Push the current state of the context’s transformation matrix on a stack.
See also
Resets the clipping to original shape.
Rotates the current transformation matrix (in radians).
Parameters: | angle (float) – |
---|
Scales the current transformation matrix.
Parameters: |
|
---|
Sets the antialiasing mode, returns True if it supported.
Parameters: | antialias (AntialiasMode) – |
---|---|
Return type: | bool |
Sets the brush for filling paths.
Overloaded Implementations:
SetBrush (self, brush)
Parameters: | brush (Brush) – |
---|
SetBrush (self, brush)
Parameters: | brush (GraphicsBrush) – |
---|
Sets the compositing operator, returns True if it supported.
Parameters: | op (CompositionMode) – |
---|---|
Return type: | bool |
Sets the font for drawing text.
Overloaded Implementations:
SetFont (self, font, colour)
Parameters: |
---|
SetFont (self, font)
Parameters: | font (GraphicsFont) – |
---|
Sets the interpolation quality, returns True if it is supported.
Not implemented in Cairo backend currently.
Parameters: | interpolation (InterpolationQuality) – |
---|---|
Return type: | bool |
Sets the pen used for stroking.
Overloaded Implementations:
SetPen (self, pen)
Parameters: | pen (Pen) – |
---|
SetPen (self, pen)
Parameters: | pen (GraphicsPen) – |
---|
Sets the current transformation matrix of this context.
Parameters: | matrix (GraphicsMatrix) – |
---|
Strokes a single line.
Parameters: |
|
---|
Stroke disconnected lines from begin to end points.
Strokes along a path with the current pen.
Parameters: | path (GraphicsPath) – |
---|
Translates the current transformation matrix.
Parameters: |
|
---|
See GetAntialiasMode and SetAntialiasMode
See GetCompositionMode and SetCompositionMode
See GetNativeContext
See GetTextExtent
See GetTransform and SetTransform