Table Of Contents

Previous topic

GraphicsBrush

Next topic

GraphicsFont

This Page

phoenix_title GraphicsContext

The GraphicsContext is the object which facilitates drawing to a surface.


class_hierarchy Inheritance Diagram

Inheritance diagram for class GraphicsContext

Inheritance diagram of GraphicsContext


super_classes Known Superclasses

lib.graphics.GraphicsObject


method_summary Methods Summary

__init__  
BeginLayer Redirects future rendering to a temorary context. See EndLayer.
Clear Clear the context using the given color or the currently set brush.
Clip Adds the rectangle to the current clipping region. The
ClipPath Set the clip region to the path.
ClipRegion Adds the wx.Region to the current clipping region.
ConcatTransform Modifies the current transformation matrix by applying matrix
Create  
CreateBrush Create a brush from a wx.Brush.
CreateFont Create a font from a wx.Font
CreateFromNative  
CreateFromSurface Wrap a context around the given cairo Surface. Note that a
CreateLinearGradientBrush Creates a native brush having a linear gradient, starting at (x1,y1)
CreateMatrix Create a new matrix object.
CreateMeasuringContext If you need a temporary context just to quickly measure some
CreatePath Create a new path obejct.
CreatePen Create a new pen from a wx.Pen.
CreateRadialGradientBrush Creates a native brush, having a radial gradient originating at point
DrawBitmap Draw the bitmap at (x,y). If the width and height parameters
DrawCircle Stroke and fill a circle centered at (x,y) with the given
DrawEllipse Stroke and fill an elipse that fits in the given rectangle,
DrawIcon  
DrawLines Stroke and fill a series of connected lines using the current
DrawPath Draws the path by first filling it and then stroking it.
DrawRectangle Stroke and fill a rectangle using the current pen and current
DrawRotatedText Draw the text at (x,y) using the current font and rotated
DrawRoundedRectangle Stroke and fill a rounded rectangle using the current pen and
DrawText Draw the text at (x,y) using the current font. If
EndLayer Composites the drawing done on the temporary context created
FillPath Fills the path using the current brush.
GetAntialiasMode Returns the current antialias mode.
GetBrush  
GetCompositingOperator Returns the current compositing operator for the context.
GetFont  
GetFullTextExtent Returns the (width, height, descent, externalLeading) of the
GetLogicalFunction  
GetNativeContext  
GetPartialTextExtents  
GetPen  
GetSize  
GetTextExtent Returns the (width, height) of the text using the current
GetTransform Returns the context’s current transformation matrix.
IsNull  
PopState Restore the most recently saved state which was saved with
PushState Makes a copy of the current state of the context (ie the
ResetClip Resets the clipping region to the original shape of the context.
Rotate Modifies the current transformation matrix by rotating the
Scale Modifies the current transformation matrix by translating the
SetAntialiasMode Set the antialiasing mode of the rasterizer used for drawing
SetBrush Set the brush to be used for filling shapes in future drawing
SetCompositingOperator Sets the compositin operator to be used for all drawing
SetFont Sets the font to be used for drawing text. Either a wx.Font
SetLogicalFunction  
SetPen Set the pen to be used for stroking lines in future drawing
SetTransform Set the context’s current transformation matrix to matrix.
StrokeLine Strokes a single line using the current pen.
StrokeLines Stroke a series of conencted lines using the current pen.
StrokeLineSegments Stroke a series of lines using the current pen. For each line
StrokePath Strokes the path (draws the lines) using the current pen.
Translate Modifies the current transformation matrix by translating the

property_summary Properties Summary

Brush  
Context  
Font  
Pen  
Size  

api Class API



class GraphicsContext(GraphicsObject)

The GraphicsContext is the object which facilitates drawing to a surface.


Methods



__init__(self, context=None, size=None)


BeginLayer(self, opacity)

Redirects future rendering to a temorary context. See EndLayer.



Clear(self, colour=None)

Clear the context using the given color or the currently set brush.



Clip(self, x, y, w, h)

Adds the rectangle to the current clipping region. The clipping region causes drawing operations to be limited to the clipped areas of the context.



ClipPath(self, path)

Set the clip region to the path.



ClipRegion(self, region)

Adds the wx.Region to the current clipping region.



ConcatTransform(self, matrix)

Modifies the current transformation matrix by applying matrix as an additional transformation.



static Create(dc)


CreateBrush(self, brush)

Create a brush from a wx.Brush.



CreateFont(self, font, colour=None)

Create a font from a wx.Font



static CreateFromNative(cairoContext)


static CreateFromSurface(surface)

Wrap a context around the given cairo Surface. Note that a GraphicsBitmap contains a cairo ImageSurface which is accessible via the Surface property.



CreateLinearGradientBrush(self, x1, y1, x2, y2, *args)

Creates a native brush having a linear gradient, starting at (x1,y1) to (x2,y2) with the given boundary colors or the specified stops.

The *args can be either a GraphicsGradientStops or just two colours to be used as the starting and ending gradient colours.



CreateMatrix(self, a=1.0, b=0, c=0, d=1.0, tx=0, ty=0)

Create a new matrix object.



static CreateMeasuringContext()

If you need a temporary context just to quickly measure some text extents, or etc. then using this function will be a little less expensive than creating a real DC for it.



CreatePath(self)

Create a new path obejct.



CreatePen(self, pen)

Create a new pen from a wx.Pen.



CreateRadialGradientBrush(self, xo, yo, xc, yc, radius, *args)

Creates a native brush, having a radial gradient originating at point (xo,yo) and ending on a circle around (xc,yc) with the given radius; the colours may be specified by just the two extremes or the full array of gradient stops.

The *args can be either a GraphicsGradientStops or just two colours to be used as the starting and ending gradient colours.



DrawBitmap(self, bmp, x, y, w=-1, h=-1)

Draw the bitmap at (x,y). If the width and height parameters are passed then the bitmap is scaled to fit that size. Either a wx.Bitmap or a GraphicsBitmap may be used.



DrawCircle(self, x, y, radius)

Stroke and fill a circle centered at (x,y) with the given radius, using the current pen and brush.



DrawEllipse(self, x, y, w, h)

Stroke and fill an elipse that fits in the given rectangle, using the current pen and current brush.



DrawIcon(self, icon, x, y, w=-1, h=-1)


DrawLines(self, points, fillStyle=ODDEVEN_RULE)

Stroke and fill a series of connected lines using the current pen and current brush.



DrawPath(self, path, fillStyle=ODDEVEN_RULE)

Draws the path by first filling it and then stroking it.



DrawRectangle(self, x, y, w, h)

Stroke and fill a rectangle using the current pen and current brush.



DrawRotatedText(self, text, x, y, angle, backgroundBrush=None)

Draw the text at (x,y) using the current font and rotated angle radians. If backgroundBrush is set then it is used to fill the rectangle behind the text.



DrawRoundedRectangle(self, x, y, w, h, radius)

Stroke and fill a rounded rectangle using the current pen and current brush.



DrawText(self, text, x, y, backgroundBrush=None)

Draw the text at (x,y) using the current font. If backgroundBrush is set then it is used to fill the rectangle behind the text.



EndLayer(self)

Composites the drawing done on the temporary context created in BeginLayer back into the main context, using the opacity specified for the layer.



FillPath(self, path, fillStyle=ODDEVEN_RULE)

Fills the path using the current brush.



GetAntialiasMode(self)

Returns the current antialias mode.



GetBrush(self): return self._brush


GetCompositingOperator(self)

Returns the current compositing operator for the context.



GetFont(self): return (self._font, self._fontColour)


GetFullTextExtent(self, text)

Returns the (width, height, descent, externalLeading) of the text using the current font.



GetLogicalFunction(self)


GetNativeContext(self)


GetPartialTextExtents(self, text)


GetPen(self): return self._pen


GetSize(self)


GetTextExtent(self, text)

Returns the (width, height) of the text using the current font.



GetTransform(self)

Returns the context’s current transformation matrix.



IsNull(self)


PopState(self)

Restore the most recently saved state which was saved with PushState.



PushState(self)

Makes a copy of the current state of the context (ie the transformation matrix) and saves it on an internal stack of saved states. The saved state will be restored when PopState is called.



ResetClip(self)

Resets the clipping region to the original shape of the context.



Rotate(self, angle)

Modifies the current transformation matrix by rotating the user-space axes by angle radians.



Scale(self, xScale, yScale)

Modifies the current transformation matrix by translating the user-space axes by xScale and yScale.



SetAntialiasMode(self, mode=ANTIALIAS_DEFAULT)

Set the antialiasing mode of the rasterizer used for drawing shapes. This value is a hint, and a particular backend may or may not support a particular value.



SetBrush(self, brush)

Set the brush to be used for filling shapes in future drawing operations. Either a wx.Brush or a GraphicsBrush object may be used.



SetCompositingOperator(self, op)

Sets the compositin operator to be used for all drawing operations. The default operator is OPERATOR_OVER.



SetFont(self, font, colour=None)

Sets the font to be used for drawing text. Either a wx.Font or a GrpahicsFont may be used.



SetLogicalFunction(self, function)


SetPen(self, pen)

Set the pen to be used for stroking lines in future drawing operations. Either a wx.Pen or a GraphicsPen object may be used.



SetTransform(self, matrix)

Set the context’s current transformation matrix to matrix.



StrokeLine(self, x1, y1, x2, y2)

Strokes a single line using the current pen.



StrokeLines(self, points)

Stroke a series of conencted lines using the current pen. Points is a sequence of points or 2-tuples, and lines are drawn from point to point through the end of the sequence.



StrokeLineSegments(self, beginPoints, endPoints)

Stroke a series of lines using the current pen. For each line the begin point is taken from the beginPoints sequence and the ending point is taken from the endPoints sequence.



StrokePath(self, path)

Strokes the path (draws the lines) using the current pen.



Translate(self, dx, dy)

Modifies the current transformation matrix by translating the user-space origin by (dx, dy).


Properties



Brush

See SetBrush , GetBrush



Context

See fget



Font

See GetFont



Pen

See SetPen , GetPen



Size

See GetSize