.. include:: headings.inc .. currentmodule:: lib.graphics .. highlight:: python .. _lib.graphics.GraphicsContext: ========================================================================================================================================== |phoenix_title| **GraphicsContext** ========================================================================================================================================== The GraphicsContext is the object which facilitates drawing to a surface. | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **GraphicsContext** .. raw:: html

Inheritance diagram of GraphicsContext

| |super_classes| Known Superclasses ================================== :class:`lib.graphics.GraphicsObject` | |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~lib.graphics.GraphicsContext.__init__` :meth:`~lib.graphics.GraphicsContext.BeginLayer` Redirects future rendering to a temorary context. See `EndLayer`. :meth:`~lib.graphics.GraphicsContext.Clear` Clear the context using the given color or the currently set brush. :meth:`~lib.graphics.GraphicsContext.Clip` Adds the rectangle to the current clipping region. The :meth:`~lib.graphics.GraphicsContext.ClipPath` Set the clip region to the path. :meth:`~lib.graphics.GraphicsContext.ClipRegion` Adds the wx.Region to the current clipping region. :meth:`~lib.graphics.GraphicsContext.ConcatTransform` Modifies the current transformation matrix by applying matrix :meth:`~lib.graphics.GraphicsContext.Create` :meth:`~lib.graphics.GraphicsContext.CreateBrush` Create a brush from a wx.Brush. :meth:`~lib.graphics.GraphicsContext.CreateFont` Create a font from a wx.Font :meth:`~lib.graphics.GraphicsContext.CreateFromNative` :meth:`~lib.graphics.GraphicsContext.CreateFromSurface` Wrap a context around the given cairo Surface. Note that a :meth:`~lib.graphics.GraphicsContext.CreateLinearGradientBrush` Creates a native brush having a linear gradient, starting at (x1,y1) :meth:`~lib.graphics.GraphicsContext.CreateMatrix` Create a new matrix object. :meth:`~lib.graphics.GraphicsContext.CreateMeasuringContext` If you need a temporary context just to quickly measure some :meth:`~lib.graphics.GraphicsContext.CreatePath` Create a new path obejct. :meth:`~lib.graphics.GraphicsContext.CreatePen` Create a new pen from a wx.Pen. :meth:`~lib.graphics.GraphicsContext.CreateRadialGradientBrush` Creates a native brush, having a radial gradient originating at point :meth:`~lib.graphics.GraphicsContext.DrawBitmap` Draw the bitmap at (x,y). If the width and height parameters :meth:`~lib.graphics.GraphicsContext.DrawCircle` Stroke and fill a circle centered at (x,y) with the given :meth:`~lib.graphics.GraphicsContext.DrawEllipse` Stroke and fill an elipse that fits in the given rectangle, :meth:`~lib.graphics.GraphicsContext.DrawIcon` :meth:`~lib.graphics.GraphicsContext.DrawLines` Stroke and fill a series of connected lines using the current :meth:`~lib.graphics.GraphicsContext.DrawPath` Draws the path by first filling it and then stroking it. :meth:`~lib.graphics.GraphicsContext.DrawRectangle` Stroke and fill a rectangle using the current pen and current :meth:`~lib.graphics.GraphicsContext.DrawRotatedText` Draw the text at (x,y) using the current font and rotated :meth:`~lib.graphics.GraphicsContext.DrawRoundedRectangle` Stroke and fill a rounded rectangle using the current pen and :meth:`~lib.graphics.GraphicsContext.DrawText` Draw the text at (x,y) using the current font. If :meth:`~lib.graphics.GraphicsContext.EndLayer` Composites the drawing done on the temporary context created :meth:`~lib.graphics.GraphicsContext.FillPath` Fills the path using the current brush. :meth:`~lib.graphics.GraphicsContext.GetAntialiasMode` Returns the current antialias mode. :meth:`~lib.graphics.GraphicsContext.GetBrush` :meth:`~lib.graphics.GraphicsContext.GetCompositingOperator` Returns the current compositing operator for the context. :meth:`~lib.graphics.GraphicsContext.GetFont` :meth:`~lib.graphics.GraphicsContext.GetFullTextExtent` Returns the (width, height, descent, externalLeading) of the :meth:`~lib.graphics.GraphicsContext.GetLogicalFunction` :meth:`~lib.graphics.GraphicsContext.GetNativeContext` :meth:`~lib.graphics.GraphicsContext.GetPartialTextExtents` :meth:`~lib.graphics.GraphicsContext.GetPen` :meth:`~lib.graphics.GraphicsContext.GetSize` :meth:`~lib.graphics.GraphicsContext.GetTextExtent` Returns the (width, height) of the text using the current :meth:`~lib.graphics.GraphicsContext.GetTransform` Returns the context's current transformation matrix. :meth:`~lib.graphics.GraphicsContext.IsNull` :meth:`~lib.graphics.GraphicsContext.PopState` Restore the most recently saved state which was saved with :meth:`~lib.graphics.GraphicsContext.PushState` Makes a copy of the current state of the context (ie the :meth:`~lib.graphics.GraphicsContext.ResetClip` Resets the clipping region to the original shape of the context. :meth:`~lib.graphics.GraphicsContext.Rotate` Modifies the current transformation matrix by rotating the :meth:`~lib.graphics.GraphicsContext.Scale` Modifies the current transformation matrix by translating the :meth:`~lib.graphics.GraphicsContext.SetAntialiasMode` Set the antialiasing mode of the rasterizer used for drawing :meth:`~lib.graphics.GraphicsContext.SetBrush` Set the brush to be used for filling shapes in future drawing :meth:`~lib.graphics.GraphicsContext.SetCompositingOperator` Sets the compositin operator to be used for all drawing :meth:`~lib.graphics.GraphicsContext.SetFont` Sets the font to be used for drawing text. Either a wx.Font :meth:`~lib.graphics.GraphicsContext.SetLogicalFunction` :meth:`~lib.graphics.GraphicsContext.SetPen` Set the pen to be used for stroking lines in future drawing :meth:`~lib.graphics.GraphicsContext.SetTransform` Set the context's current transformation matrix to matrix. :meth:`~lib.graphics.GraphicsContext.StrokeLine` Strokes a single line using the current pen. :meth:`~lib.graphics.GraphicsContext.StrokeLines` Stroke a series of conencted lines using the current pen. :meth:`~lib.graphics.GraphicsContext.StrokeLineSegments` Stroke a series of lines using the current pen. For each line :meth:`~lib.graphics.GraphicsContext.StrokePath` Strokes the path (draws the lines) using the current pen. :meth:`~lib.graphics.GraphicsContext.Translate` Modifies the current transformation matrix by translating the ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~lib.graphics.GraphicsContext.Brush` :attr:`~lib.graphics.GraphicsContext.Context` :attr:`~lib.graphics.GraphicsContext.Font` :attr:`~lib.graphics.GraphicsContext.Pen` :attr:`~lib.graphics.GraphicsContext.Size` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: GraphicsContext(GraphicsObject) The GraphicsContext is the object which facilitates drawing to a surface. .. method:: __init__(self, context=None, size=None) .. method:: BeginLayer(self, opacity) Redirects future rendering to a temorary context. See `EndLayer`. .. method:: Clear(self, colour=None) Clear the context using the given color or the currently set brush. .. method:: 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. .. method:: ClipPath(self, path) Set the clip region to the path. .. method:: ClipRegion(self, region) Adds the wx.Region to the current clipping region. .. method:: ConcatTransform(self, matrix) Modifies the current transformation matrix by applying matrix as an additional transformation. .. staticmethod:: Create(dc) .. method:: CreateBrush(self, brush) Create a brush from a wx.Brush. .. method:: CreateFont(self, font, colour=None) Create a font from a wx.Font .. staticmethod:: CreateFromNative(cairoContext) .. staticmethod:: 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. .. method:: 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. .. method:: CreateMatrix(self, a=1.0, b=0, c=0, d=1.0, tx=0, ty=0) Create a new matrix object. .. staticmethod:: 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. .. method:: CreatePath(self) Create a new path obejct. .. method:: CreatePen(self, pen) Create a new pen from a wx.Pen. .. method:: 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. .. method:: 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. .. method:: DrawCircle(self, x, y, radius) Stroke and fill a circle centered at (x,y) with the given radius, using the current pen and brush. .. method:: DrawEllipse(self, x, y, w, h) Stroke and fill an elipse that fits in the given rectangle, using the current pen and current brush. .. method:: DrawIcon(self, icon, x, y, w=-1, h=-1) .. method:: DrawLines(self, points, fillStyle=ODDEVEN_RULE) Stroke and fill a series of connected lines using the current pen and current brush. .. method:: DrawPath(self, path, fillStyle=ODDEVEN_RULE) Draws the path by first filling it and then stroking it. .. method:: DrawRectangle(self, x, y, w, h) Stroke and fill a rectangle using the current pen and current brush. .. method:: 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. .. method:: DrawRoundedRectangle(self, x, y, w, h, radius) Stroke and fill a rounded rectangle using the current pen and current brush. .. method:: 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. .. method:: 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. .. method:: FillPath(self, path, fillStyle=ODDEVEN_RULE) Fills the path using the current brush. .. method:: GetAntialiasMode(self) Returns the current antialias mode. .. method:: GetBrush(self): return self._brush .. method:: GetCompositingOperator(self) Returns the current compositing operator for the context. .. method:: GetFont(self): return (self._font, self._fontColour) .. method:: GetFullTextExtent(self, text) Returns the (width, height, descent, externalLeading) of the text using the current font. .. method:: GetLogicalFunction(self) .. method:: GetNativeContext(self) .. method:: GetPartialTextExtents(self, text) .. method:: GetPen(self): return self._pen .. method:: GetSize(self) .. method:: GetTextExtent(self, text) Returns the (width, height) of the text using the current font. .. method:: GetTransform(self) Returns the context's current transformation matrix. .. method:: IsNull(self) .. method:: PopState(self) Restore the most recently saved state which was saved with PushState. .. method:: 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. .. method:: ResetClip(self) Resets the clipping region to the original shape of the context. .. method:: Rotate(self, angle) Modifies the current transformation matrix by rotating the user-space axes by angle radians. .. method:: Scale(self, xScale, yScale) Modifies the current transformation matrix by translating the user-space axes by xScale and yScale. .. method:: 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. .. method:: 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. .. method:: SetCompositingOperator(self, op) Sets the compositin operator to be used for all drawing operations. The default operator is OPERATOR_OVER. .. method:: SetFont(self, font, colour=None) Sets the font to be used for drawing text. Either a wx.Font or a GrpahicsFont may be used. .. method:: SetLogicalFunction(self, function) .. method:: 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. .. method:: SetTransform(self, matrix) Set the context's current transformation matrix to matrix. .. method:: StrokeLine(self, x1, y1, x2, y2) Strokes a single line using the current pen. .. method:: 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. .. method:: 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. .. method:: StrokePath(self, path) Strokes the path (draws the lines) using the current pen. .. method:: Translate(self, dx, dy) Modifies the current transformation matrix by translating the user-space origin by (dx, dy). .. attribute:: Brush See :meth:`~GraphicsContext.SetBrush` , :meth:`~GraphicsContext.GetBrush` .. attribute:: Context See :meth:`~GraphicsContext.fget` .. attribute:: Font See :meth:`~GraphicsContext.GetFont` .. attribute:: Pen See :meth:`~GraphicsContext.SetPen` , :meth:`~GraphicsContext.GetPen` .. attribute:: Size See :meth:`~GraphicsContext.GetSize`