.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2020 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. _wx.GraphicsContext:
==========================================================================================================================================
|phoenix_title| **wx.GraphicsContext**
==========================================================================================================================================
A :ref:`wx.GraphicsContext` instance is the object that is drawn upon.
It is created by a renderer using :meth:`wx.GraphicsRenderer.CreateContext` . This can be either directly using a renderer instance, or indirectly using the static convenience :meth:`~wx.GraphicsContext.Create` functions of :ref:`wx.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)
.. note::
For some renderers (like Direct2D or Cairo) processing of drawing operations may be deferred (Direct2D render target normally builds up a batch of rendering commands but defers processing of these commands, Cairo operates on a separate surface) so to make drawing results visible you need to update the content of the context by calling :meth:`wx.GraphicsContext.Flush` or by destroying the context.
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContext` , :ref:`wx.GCDC`, :ref:`wx.DC`
|
|class_hierarchy| Class Hierarchy
=================================
.. raw:: html

Inheritance diagram for class
GraphicsContext:
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.GraphicsContext.BeginLayer` All rendering will be done into a fully transparent temporary context.
:meth:`~wx.GraphicsContext.Clip` Sets the clipping region to the intersection of the given region and the previously set clipping region.
:meth:`~wx.GraphicsContext.ConcatTransform` Concatenates the passed in transform with the current transform of this context.
:meth:`~wx.GraphicsContext.Create` Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.Window`.
:meth:`~wx.GraphicsContext.CreateBitmap` Creates :ref:`wx.GraphicsBitmap` from an existing :ref:`wx.Bitmap`.
:meth:`~wx.GraphicsContext.CreateBitmapFromImage` Creates :ref:`wx.GraphicsBitmap` from an existing :ref:`wx.Image`.
:meth:`~wx.GraphicsContext.CreateBrush` Creates a native brush from a :ref:`wx.Brush`.
:meth:`~wx.GraphicsContext.CreateFont` Creates a native graphics font from a :ref:`wx.Font` and a text colour.
:meth:`~wx.GraphicsContext.CreateFromNative` Creates a :ref:`wx.GraphicsContext` from a native context.
:meth:`~wx.GraphicsContext.CreateFromNativeWindow` Creates a :ref:`wx.GraphicsContext` from a native window.
:meth:`~wx.GraphicsContext.CreateFromUnknownDC` Creates a :ref:`wx.GraphicsContext` from a DC of unknown specific type.
:meth:`~wx.GraphicsContext.CreateLinearGradientBrush` Creates a native brush with a linear gradient.
:meth:`~wx.GraphicsContext.CreateMatrix` Creates a native affine transformation matrix from the passed in values.
:meth:`~wx.GraphicsContext.CreatePath` Creates a native graphics path which is initially empty.
:meth:`~wx.GraphicsContext.CreatePen` Creates a native pen from a :ref:`wx.Pen`.
:meth:`~wx.GraphicsContext.CreateRadialGradientBrush` Creates a native brush with a radial gradient.
:meth:`~wx.GraphicsContext.CreateSubBitmap` Extracts a sub-bitmap from an existing bitmap.
:meth:`~wx.GraphicsContext.DisableOffset` Helper to determine if a 0.5 offset should be applied for the drawing operation.
:meth:`~wx.GraphicsContext.DrawBitmap` Draws the bitmap.
:meth:`~wx.GraphicsContext.DrawEllipse` Draws an ellipse.
:meth:`~wx.GraphicsContext.DrawIcon` Draws the icon.
:meth:`~wx.GraphicsContext.DrawLines` Draws a polygon.
:meth:`~wx.GraphicsContext.DrawPath` Draws the path by first filling and then stroking.
:meth:`~wx.GraphicsContext.DrawRectangle` Draws a rectangle.
:meth:`~wx.GraphicsContext.DrawRoundedRectangle` Draws a rounded rectangle.
:meth:`~wx.GraphicsContext.DrawText` Draws text at the defined position.
:meth:`~wx.GraphicsContext.EnableOffset` Indicates whether the context should try to offset for pixel boundaries.
:meth:`~wx.GraphicsContext.EndDoc` Done with that document (relevant only for printing / pdf etc.)
:meth:`~wx.GraphicsContext.EndLayer` Composites back the drawings into the context with the opacity given at the :meth:`~GraphicsContext.BeginLayer` call.
:meth:`~wx.GraphicsContext.EndPage` Ends the current page (relevant only for printing / pdf etc.)
:meth:`~wx.GraphicsContext.FillPath` Fills the path with the current brush.
:meth:`~wx.GraphicsContext.Flush` Make sure that the current content of this context is immediately visible.
:meth:`~wx.GraphicsContext.FromDIP` Convert DPI-independent pixel values to the value in pixels appropriate for the graphics context.
:meth:`~wx.GraphicsContext.GetAntialiasMode` Returns the current shape antialiasing mode.
:meth:`~wx.GraphicsContext.GetClipBox` Returns bounding box of the current clipping region.
:meth:`~wx.GraphicsContext.GetCompositionMode` Returns the current compositing operator.
:meth:`~wx.GraphicsContext.GetDPI` Returns the resolution of the graphics context in device points per inch.
:meth:`~wx.GraphicsContext.GetInterpolationQuality` Returns the current interpolation quality.
:meth:`~wx.GraphicsContext.GetNativeContext` Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo).
:meth:`~wx.GraphicsContext.GetPartialTextExtents` Fills the `widths` array with the widths from the beginning of `text` to the corresponding character of `text`.
:meth:`~wx.GraphicsContext.GetSize` Returns the size of the graphics context in device coordinates.
:meth:`~wx.GraphicsContext.GetFullTextExtent` Gets the dimensions of the string using the currently selected font.
:meth:`~wx.GraphicsContext.GetTransform` Gets the current transformation matrix of this context.
:meth:`~wx.GraphicsContext.GetWindow` Returns the associated window if any.
:meth:`~wx.GraphicsContext.OffsetEnabled` Helper to determine if a 0.5 offset should be applied for the drawing operation.
:meth:`~wx.GraphicsContext.PopState` Sets current state of the context to the state saved by a preceding call to :meth:`~GraphicsContext.PushState` and removes that state from the stack of saved states.
:meth:`~wx.GraphicsContext.PushState` Push the current state (like transformations, clipping region and quality settings) of the context on a stack.
:meth:`~wx.GraphicsContext.ResetClip` Resets the clipping to original shape.
:meth:`~wx.GraphicsContext.Rotate` Rotates the current transformation matrix (in radians).
:meth:`~wx.GraphicsContext.Scale` Scales the current transformation matrix.
:meth:`~wx.GraphicsContext.SetAntialiasMode` Sets the antialiasing mode, returns ``True`` if it supported.
:meth:`~wx.GraphicsContext.SetBrush` Sets the brush for filling paths.
:meth:`~wx.GraphicsContext.SetCompositionMode` Sets the compositing operator, returns ``True`` if it supported.
:meth:`~wx.GraphicsContext.SetFont` Sets the font for drawing text.
:meth:`~wx.GraphicsContext.SetInterpolationQuality` Sets the interpolation quality, returns ``True`` if it is supported.
:meth:`~wx.GraphicsContext.SetPen` Sets the pen used for stroking.
:meth:`~wx.GraphicsContext.SetTransform` Sets the current transformation matrix of this context.
:meth:`~wx.GraphicsContext.ShouldOffset` Helper to determine if a 0.5 offset should be applied for the drawing operation.
:meth:`~wx.GraphicsContext.StartDoc` Begin a new document (relevant only for printing / pdf etc.) If there is a progress dialog, message will be shown.
:meth:`~wx.GraphicsContext.StartPage` Opens a new page (relevant only for printing / pdf etc.) with the given size in points.
:meth:`~wx.GraphicsContext.StrokeLine` Strokes a single line.
:meth:`~wx.GraphicsContext.StrokeLineSegments` Stroke disconnected lines from begin to end points.
:meth:`~wx.GraphicsContext.StrokeLines` Stroke lines connecting all the points.
:meth:`~wx.GraphicsContext.StrokePath` Strokes along a path with the current pen.
:meth:`~wx.GraphicsContext.ToDIP` Convert pixel values of the current graphics context to DPI-independent pixel values.
:meth:`~wx.GraphicsContext.Translate` Translates the current transformation matrix.
================================================================================ ================================================================================
|
|property_summary| Properties Summary
=====================================
================================================================================ ================================================================================
:attr:`~wx.GraphicsContext.AntialiasMode` See :meth:`~wx.GraphicsContext.GetAntialiasMode` and :meth:`~wx.GraphicsContext.SetAntialiasMode`
:attr:`~wx.GraphicsContext.CompositionMode` See :meth:`~wx.GraphicsContext.GetCompositionMode` and :meth:`~wx.GraphicsContext.SetCompositionMode`
:attr:`~wx.GraphicsContext.InterpolationQuality` See :meth:`~wx.GraphicsContext.GetInterpolationQuality` and :meth:`~wx.GraphicsContext.SetInterpolationQuality`
:attr:`~wx.GraphicsContext.NativeContext` See :meth:`~wx.GraphicsContext.GetNativeContext`
:attr:`~wx.GraphicsContext.TextExtent` See :meth:`~wx.GraphicsContext.GetTextExtent`
:attr:`~wx.GraphicsContext.Transform` See :meth:`~wx.GraphicsContext.GetTransform` and :meth:`~wx.GraphicsContext.SetTransform`
:attr:`~wx.GraphicsContext.Window` See :meth:`~wx.GraphicsContext.GetWindow`
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.GraphicsContext(GraphicsObject)
A GraphicsContext instance is the object that is drawn upon.
.. method:: BeginLayer(self, opacity : float)
All rendering will be done into a fully transparent temporary context.
Layers can be nested by making balanced calls to :meth:`BeginLayer` /EndLayer().
:param `opacity`:
:type `opacity`: wx.Double
:rtype: `None`
.. method:: Clip(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**Clip** `(self, region : Region)`
Sets the clipping region to the intersection of the given region and the previously set clipping region.
The clipping region is an area to which drawing is restricted.
:param `region`:
:type `region`: wx.Region
:rtype: `None`
.. note::
- Clipping region should be given in logical coordinates.
- Calling this function can only make the clipping region smaller, never larger.
- You need to call :meth:`ResetClip` first if you want to set the clipping region exactly to the region specified.
- If resulting clipping region is empty, then all drawing upon the context is clipped out (all changes made by drawing operations are masked out).
:html:`
`
**Clip** `(self, x : float, y : float, w : float, h : float)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:rtype: `None`
:html:`
`
.. method:: ConcatTransform(self, matrix : GraphicsMatrix)
Concatenates the passed in transform with the current transform of this context.
:param `matrix`:
:type `matrix`: wx.GraphicsMatrix
:rtype: `None`
.. staticmethod:: Create(*args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**Create** `(window : Window)`
Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.Window`.
:param `window`:
:type `window`: wx.Window
:rtype: :ref:`wx.GraphicsContext`
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContext`
:html:`
`
**Create** `(windowDC : WindowDC)`
Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.WindowDC`.
:param `windowDC`:
:type `windowDC`: wx.WindowDC
:rtype: :ref:`wx.GraphicsContext`
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContext`
:html:`
`
**Create** `(memoryDC : MemoryDC)`
Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.MemoryDC`.
:param `memoryDC`:
:type `memoryDC`: wx.MemoryDC
:rtype: :ref:`wx.GraphicsContext`
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContext`
:html:`
`
**Create** `(printerDC : PrinterDC)`
Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.PrinterDC`.
Under GTK+, this will only work when using the GtkPrint printing backend which is available since GTK+ 2.10.
:param `printerDC`:
:type `printerDC`: wx.PrinterDC
:rtype: :ref:`wx.GraphicsContext`
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContext` ,
:html:`
`
**Create** `(metaFileDC : MetafileDC)`
Creates a :ref:`wx.GraphicsContext` from a EnhMetaFileDC.
This function, as EnhMetaFileDC class itself, is only available only under MSW.
:param `metaFileDC`:
:type `metaFileDC`: :class:`MetafileDC`
:rtype: :ref:`wx.GraphicsContext`
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContext`
:html:`
`
**Create** `(image : Image)`
Creates a :ref:`wx.GraphicsContext` associated with a :ref:`wx.Image`.
The image specifies the size of the context as well as whether alpha is supported (if :meth:`wx.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.
:param `image`:
:type `image`: wx.Image
:rtype: :ref:`wx.GraphicsContext`
.. versionadded:: 2.9.3
:html:`
`
**Create** `()`
Create a lightweight context that can be used only for measuring text.
:rtype: :ref:`wx.GraphicsContext`
:html:`
`
**Create** `(autoPaintDC)`
:rtype: :ref:`wx.GraphicsContext`
:html:`
`
.. method:: CreateBitmap(self, bitmap : Bitmap)
Creates :ref:`wx.GraphicsBitmap` from an existing :ref:`wx.Bitmap`.
Returns an invalid NullGraphicsBitmap on failure.
:param `bitmap`:
:type `bitmap`: wx.Bitmap
:rtype: :ref:`wx.GraphicsBitmap`
.. method:: CreateBitmapFromImage(self, image : Image)
Creates :ref:`wx.GraphicsBitmap` from an existing :ref:`wx.Image`.
This method is more efficient than converting :ref:`wx.Image` to :ref:`wx.Bitmap` first and then calling :meth:`CreateBitmap` but otherwise has the same effect.
Returns an invalid NullGraphicsBitmap on failure.
:param `image`:
:type `image`: wx.Image
:rtype: :ref:`wx.GraphicsBitmap`
.. versionadded:: 2.9.3
.. method:: CreateBrush(self, brush : Brush)
Creates a native brush from a :ref:`wx.Brush`.
:param `brush`:
:type `brush`: wx.Brush
:rtype: :ref:`wx.GraphicsBrush`
.. method:: CreateFont(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**CreateFont** `(self, font : Font, col: Colour=BLACK)`
Creates a native graphics font from a :ref:`wx.Font` and a text colour.
:param `font`:
:type `font`: wx.Font
:param `col`:
:type `col`: wx.Colour
:rtype: :ref:`wx.GraphicsFont`
.. note::
For Direct2D graphics fonts can be created from TrueType fonts only.
:html:`
`
**CreateFont** `(self, sizeInPixels : float, facename : str, flags: int=FONTFLAG_DEFAULT, col: Colour=BLACK)`
Creates a font object with the specified attributes.
The use of overload taking :ref:`wx.Font` is preferred, see :meth:`wx.GraphicsRenderer.CreateFont` for more details.
:param `sizeInPixels`:
:type `sizeInPixels`: float
:param `facename`:
:type `facename`: string
:param `flags`:
:type `flags`: int
:param `col`:
:type `col`: wx.Colour
:rtype: :ref:`wx.GraphicsFont`
.. versionadded:: 2.9.3
.. note::
For Direct2D graphics fonts can be created from TrueType fonts only.
:html:`
`
.. staticmethod:: CreateFromNative(context : Any)
Creates a :ref:`wx.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.
:param `context`:
:rtype: :ref:`wx.GraphicsContext`
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContextFromNativeContext`
.. staticmethod:: CreateFromNativeWindow(window : Any)
Creates a :ref:`wx.GraphicsContext` from a native window.
:param `window`:
:rtype: :ref:`wx.GraphicsContext`
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContextFromNativeWindow`
.. staticmethod:: CreateFromUnknownDC(dc : DC)
Creates a :ref:`wx.GraphicsContext` from a DC of unknown specific type.
Creates a :ref:`wx.GraphicsContext` if `dc` is a supported type (i.e. has a corresponding :meth:`Create` method, e.g. :ref:`wx.WindowDC` or :ref:`wx.MemoryDC`). Returns ``None`` if the DC is unsupported.
This method is only useful as a helper in generic code that operates with :ref:`wx.DC` and doesn't known its exact type. Use :meth:`Create` instead if you know that the DC is e.g. :ref:`wx.WindowDC`.
:param `dc`:
:type `dc`: wx.DC
:rtype: :ref:`wx.GraphicsContext`
.. versionadded:: 4.1/wxWidgets-3.1.1
.. seealso:: :meth:`wx.GraphicsRenderer.CreateContextFromUnknownDC`
.. method:: CreateLinearGradientBrush(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**CreateLinearGradientBrush** `(self, x1 : float, y1 : float, x2 : float, y2 : float, c1 : Colour, c2 : Colour, matrix: GraphicsMatrix=NullGraphicsMatrix)`
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 :ref:`wx.GraphicsGradientStops` is new in wxWidgets 2.9.1.
The `matrix` parameter was added in wxWidgets 3.1.3
:param `x1`:
:type `x1`: wx.Double
:param `y1`:
:type `y1`: wx.Double
:param `x2`:
:type `x2`: wx.Double
:param `y2`:
:type `y2`: wx.Double
:param `c1`:
:type `c1`: wx.Colour
:param `c2`:
:type `c2`: wx.Colour
:param `matrix`:
:type `matrix`: wx.GraphicsMatrix
:rtype: :ref:`wx.GraphicsBrush`
:html:`
`
**CreateLinearGradientBrush** `(self, x1 : float, y1 : float, x2 : float, y2 : float, stops : GraphicsGradientStops, matrix: GraphicsMatrix=NullGraphicsMatrix)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `x1`:
:type `x1`: wx.Double
:param `y1`:
:type `y1`: wx.Double
:param `x2`:
:type `x2`: wx.Double
:param `y2`:
:type `y2`: wx.Double
:param `stops`:
:type `stops`: wx.GraphicsGradientStops
:param `matrix`:
:type `matrix`: wx.GraphicsMatrix
:rtype: :ref:`wx.GraphicsBrush`
:html:`
`
.. method:: CreateMatrix(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**CreateMatrix** `(self, a: float=1.0, b: float=0.0, c: float=0.0, d: float=1.0, tx: float=0.0, ty: float=0.0)`
Creates a native affine transformation matrix from the passed in values.
The default parameters result in an identity matrix.
:param `a`:
:type `a`: wx.Double
:param `b`:
:type `b`: wx.Double
:param `c`:
:type `c`: wx.Double
:param `d`:
:type `d`: wx.Double
:param `tx`:
:type `tx`: wx.Double
:param `ty`:
:type `ty`: wx.Double
:rtype: :ref:`wx.GraphicsMatrix`
:html:`
`
**CreateMatrix** `(self, mat : AffineMatrix2DBase)`
Creates a native affine transformation matrix from the passed generic one.
:param `mat`:
:type `mat`: wx.AffineMatrix2DBase
:rtype: :ref:`wx.GraphicsMatrix`
.. versionadded:: 2.9.4
:html:`
`
.. method:: CreatePath(self)
Creates a native graphics path which is initially empty.
:rtype: :ref:`wx.GraphicsPath`
.. method:: CreatePen(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**CreatePen** `(self, pen : Pen)`
Creates a native pen from a :ref:`wx.Pen`.
Prefer to use the overload taking :ref:`wx.GraphicsPenInfo` unless you already have a :ref:`wx.Pen` as constructing one only to pass it to this method is wasteful.
:param `pen`:
:type `pen`: wx.Pen
:rtype: :ref:`wx.GraphicsPen`
:html:`
`
**CreatePen** `(self, info : GraphicsPenInfo)`
Creates a native pen from a :ref:`wx.GraphicsPenInfo`.
:param `info`:
:type `info`: wx.GraphicsPenInfo
:rtype: :ref:`wx.GraphicsPen`
.. versionadded:: 4.1/wxWidgets-3.1.1
:html:`
`
.. method:: CreateRadialGradientBrush(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**CreateRadialGradientBrush** `(self, startX : float, startY : float, endX : float, endY : float, radius : float, oColor : Colour, cColor : Colour, matrix: GraphicsMatrix=NullGraphicsMatrix)`
Creates a native brush with a radial gradient.
The brush originates at (`startX`, `startY`) and ends on a circle around (`endX`, `endY`) 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 :ref:`wx.GraphicsGradientStops` is new in wxWidgets 2.9.1.
The ability to apply a transformation matrix to the gradient was added in 3.1.3
:param `startX`:
:type `startX`: wx.Double
:param `startY`:
:type `startY`: wx.Double
:param `endX`:
:type `endX`: wx.Double
:param `endY`:
:type `endY`: wx.Double
:param `radius`:
:type `radius`: wx.Double
:param `oColor`:
:type `oColor`: wx.Colour
:param `cColor`:
:type `cColor`: wx.Colour
:param `matrix`:
:type `matrix`: wx.GraphicsMatrix
:rtype: :ref:`wx.GraphicsBrush`
:html:`
`
**CreateRadialGradientBrush** `(self, startX : float, startY : float, endX : float, endY : float, radius : float, stops : GraphicsGradientStops, matrix: GraphicsMatrix=NullGraphicsMatrix)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `startX`:
:type `startX`: wx.Double
:param `startY`:
:type `startY`: wx.Double
:param `endX`:
:type `endX`: wx.Double
:param `endY`:
:type `endY`: wx.Double
:param `radius`:
:type `radius`: wx.Double
:param `stops`:
:type `stops`: wx.GraphicsGradientStops
:param `matrix`:
:type `matrix`: wx.GraphicsMatrix
:rtype: :ref:`wx.GraphicsBrush`
:html:`
`
.. method:: CreateSubBitmap(self, bitmap : GraphicsBitmap, x : float, y : float, w : float, h : float)
Extracts a sub-bitmap from an existing bitmap.
:param `bitmap`:
:type `bitmap`: wx.GraphicsBitmap
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:rtype: :ref:`wx.GraphicsBitmap`
.. method:: DisableOffset(self)
Helper to determine if a 0.5 offset should be applied for the drawing operation.
:rtype: `None`
.. method:: DrawBitmap(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**DrawBitmap** `(self, bmp : GraphicsBitmap, x : float, y : float, w : float, h : float)`
Draws the bitmap.
In case of a mono bitmap, this is treated as a mask and the current brushed is used for filling.
:param `bmp`:
:type `bmp`: wx.GraphicsBitmap
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:rtype: `None`
:html:`
`
**DrawBitmap** `(self, bmp : Bitmap, x : float, y : float, w : float, h : float)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `bmp`:
:type `bmp`: wx.Bitmap
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:rtype: `None`
:html:`
`
.. method:: DrawEllipse(self, x : float, y : float, w : float, h : float)
Draws an ellipse.
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:rtype: `None`
.. method:: DrawIcon(self, icon : Icon, x : float, y : float, w : float, h : float)
Draws the icon.
:param `icon`:
:type `icon`: wx.Icon
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:rtype: `None`
.. method:: DrawLines(self, point2Ds, fillStyle=ODDEVEN_RULE)
Draws a polygon.
.. method:: DrawPath(self, path : GraphicsPath, fillStyle: PolygonFillMode=ODDEVEN_RULE)
Draws the path by first filling and then stroking.
:param `path`:
:type `path`: wx.GraphicsPath
:param `fillStyle`:
:type `fillStyle`: wx.PolygonFillMode
:rtype: `None`
.. method:: DrawRectangle(self, x : float, y : float, w : float, h : float)
Draws a rectangle.
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:rtype: `None`
.. method:: DrawRoundedRectangle(self, x : float, y : float, w : float, h : float, radius : float)
Draws a rounded rectangle.
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:param `radius`:
:type `radius`: wx.Double
:rtype: `None`
.. method:: DrawText(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**DrawText** `(self, str : str, x : float, y : float)`
Draws text at the defined position.
:param `str`:
:type `str`: string
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:rtype: `None`
:html:`
`
**DrawText** `(self, str : str, x : float, y : float, angle : float)`
Draws text at the defined position.
:param `str`: The text to draw.
:type `str`: string
:param `x`: The x coordinate position to draw the text at.
:type `x`: wx.Double
:param `y`: The y coordinate position to draw the text at.
:type `y`: wx.Double
:param `angle`: The angle, in radians, relative to the (default) horizontal direction to draw the string.
:type `angle`: wx.Double
:rtype: `None`
:html:`
`
**DrawText** `(self, str : str, x : float, y : float, backgroundBrush : GraphicsBrush)`
Draws text at the defined position.
:param `str`: The text to draw.
:type `str`: string
:param `x`: The x coordinate position to draw the text at.
:type `x`: wx.Double
:param `y`: The y coordinate position to draw the text at.
:type `y`: wx.Double
:param `backgroundBrush`: Brush to fill the text with.
:type `backgroundBrush`: wx.GraphicsBrush
:rtype: `None`
:html:`
`
**DrawText** `(self, str : str, x : float, y : float, angle : float, backgroundBrush : GraphicsBrush)`
Draws text at the defined position.
:param `str`: The text to draw.
:type `str`: string
:param `x`: The x coordinate position to draw the text at.
:type `x`: wx.Double
:param `y`: The y coordinate position to draw the text at.
:type `y`: wx.Double
:param `angle`: The angle, in radians, relative to the (default) horizontal direction to draw the string.
:type `angle`: wx.Double
:param `backgroundBrush`: Brush to fill the text with.
:type `backgroundBrush`: wx.GraphicsBrush
:rtype: `None`
:html:`
`
.. method:: EnableOffset(self, enable: bool=True)
Indicates whether the context should try to offset for pixel boundaries.
This only makes sense on bitmap devices like screen. By default this is turned off.
:param `enable`:
:type `enable`: bool
:rtype: `None`
.. method:: EndDoc(self)
Done with that document (relevant only for printing / pdf etc.)
:rtype: `None`
.. method:: EndLayer(self)
Composites back the drawings into the context with the opacity given at the :meth:`BeginLayer` call.
:rtype: `None`
.. method:: EndPage(self)
Ends the current page (relevant only for printing / pdf etc.)
:rtype: `None`
.. method:: FillPath(self, path : GraphicsPath, fillStyle: PolygonFillMode=ODDEVEN_RULE)
Fills the path with the current brush.
:param `path`:
:type `path`: wx.GraphicsPath
:param `fillStyle`:
:type `fillStyle`: wx.PolygonFillMode
:rtype: `None`
.. method:: Flush(self)
Make sure that the current content of this context is immediately visible.
:rtype: `None`
.. method:: FromDIP(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**FromDIP** `(self, sz : Size)`
Convert DPI-independent pixel values to the value in pixels appropriate for the graphics context.
See `Window.FromDIP(const` Size& sz) and `DC.FromDIP(const` Size& sz) for more info about converting device independent pixel values.
:param `sz`:
:type `sz`: wx.Size
:rtype: :ref:`wx.Size`
.. versionadded:: 4.1/wxWidgets-3.1.7
:html:`
`
**FromDIP** `(self, pt : Point)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `pt`:
:type `pt`: wx.Point
:rtype: :ref:`wx.Point`
:html:`
`
**FromDIP** `(self, d : int)`
Convert DPI-independent value in pixels to the value in pixels appropriate for the graphics context.
This is the same as FromDIP(const Size& sz) overload, but assumes that the resolution is the same in horizontal and vertical directions.
:param `d`:
:type `d`: int
:rtype: `int`
.. versionadded:: 4.1/wxWidgets-3.1.7
:html:`
`
.. method:: GetAntialiasMode(self)
Returns the current shape antialiasing mode.
:rtype: :ref:`wx.AntialiasMode`
.. method:: GetClipBox(self, x : float, y : float, w : float, h : float)
Returns bounding box of the current clipping region.
:param `x`:
:type `x`: wx.Double
:param `y`:
:type `y`: wx.Double
:param `w`:
:type `w`: wx.Double
:param `h`:
:type `h`: wx.Double
:rtype: `None`
.. versionadded:: 4.1/wxWidgets-3.1.1
.. note::
- If clipping region is empty, then empty rectangle is returned (`x`, `y`, `w`, `h` are set to zero).
.. method:: GetCompositionMode(self)
Returns the current compositing operator.
:rtype: :ref:`wx.CompositionMode`
.. method:: GetDPI(self)
Returns the resolution of the graphics context in device points per inch.
:rtype: :ref:`Tuple[float, float]`
.. method:: GetInterpolationQuality(self)
Returns the current interpolation quality.
:rtype: :ref:`wx.InterpolationQuality`
.. method:: GetNativeContext(self)
Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo).
:rtype: `Any`
.. method:: GetPartialTextExtents(self, text : str)
Fills the `widths` array with the widths from the beginning of `text` to the corresponding character of `text`.
:param `text`:
:type `text`: string
:rtype: `List[float]`
.. method:: GetSize(self)
Returns the size of the graphics context in device coordinates.
:rtype: :ref:`Tuple[float, float]`
.. method:: GetFullTextExtent(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**GetFullTextExtent** `(self, text : str)`
Gets the dimensions of the string using the currently selected font.
:param `text`: The text string to measure.
:type `text`: string
:rtype: :ref:`Tuple[float, float, float, float]`
:html:`
`
**GetFullTextExtent** `(self, text)`
Gets the dimensions of the string using the currently selected font.
:rtype: `tuple`
:returns:
( `width`, `height` )
:html:`
`
.. method:: GetTransform(self)
Gets the current transformation matrix of this context.
:rtype: :ref:`wx.GraphicsMatrix`
.. method:: GetWindow(self)
Returns the associated window if any.
If this context was created using :meth:`Create` overload taking :ref:`wx.Window` or :ref:`wx.WindowDC`, this method returns the corresponding window. Otherwise returns ``None``.
:rtype: :ref:`wx.Window`
:returns:
A possibly ``None`` window pointer.
.. versionadded:: 4.1/wxWidgets-3.1.2
.. method:: OffsetEnabled(self)
Helper to determine if a 0.5 offset should be applied for the drawing operation.
:rtype: `bool`
.. method:: PopState(self)
Sets current state of the context to the state saved by a preceding call to :meth:`PushState` and removes that state from the stack of saved states.
:rtype: `None`
.. seealso:: :meth:`PushState`
.. method:: PushState(self)
Push the current state (like transformations, clipping region and quality settings) of the context on a stack.
Multiple balanced calls to :meth:`PushState` and :meth:`PopState` can be nested.
:rtype: `None`
.. seealso:: :meth:`PopState`
.. method:: ResetClip(self)
Resets the clipping to original shape.
:rtype: `None`
.. method:: Rotate(self, angle : float)
Rotates the current transformation matrix (in radians).
:param `angle`:
:type `angle`: wx.Double
:rtype: `None`
.. method:: Scale(self, xScale : float, yScale : float)
Scales the current transformation matrix.
:param `xScale`:
:type `xScale`: wx.Double
:param `yScale`:
:type `yScale`: wx.Double
:rtype: `None`
.. method:: SetAntialiasMode(self, antialias : AntialiasMode)
Sets the antialiasing mode, returns ``True`` if it supported.
:param `antialias`:
:type `antialias`: wx.AntialiasMode
:rtype: `bool`
.. method:: SetBrush(self, *args, **kw)
Sets the brush for filling paths.
|overload| **Overloaded Implementations:**
:html:`
`
**SetBrush** `(self, brush : Brush)`
:param `brush`:
:type `brush`: wx.Brush
:rtype: `None`
:html:`
`
**SetBrush** `(self, brush : GraphicsBrush)`
:param `brush`:
:type `brush`: wx.GraphicsBrush
:rtype: `None`
:html:`
`
.. method:: SetCompositionMode(self, op : CompositionMode)
Sets the compositing operator, returns ``True`` if it supported.
:param `op`:
:type `op`: wx.CompositionMode
:rtype: `bool`
.. method:: SetFont(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**SetFont** `(self, font : Font, colour : Colour)`
Sets the font for drawing text.
:param `font`:
:type `font`: wx.Font
:param `colour`:
:type `colour`: wx.Colour
:rtype: `None`
.. note::
For Direct2D only TrueType fonts can be used.
:html:`
`
**SetFont** `(self, font : GraphicsFont)`
Sets the font for drawing text.
:param `font`:
:type `font`: wx.GraphicsFont
:rtype: `None`
:html:`
`
.. method:: SetInterpolationQuality(self, interpolation : InterpolationQuality)
Sets the interpolation quality, returns ``True`` if it is supported.
:param `interpolation`:
:type `interpolation`: wx.InterpolationQuality
:rtype: `bool`
.. note::
Not implemented in Cairo backend currently.
.. method:: SetPen(self, *args, **kw)
Sets the pen used for stroking.
|overload| **Overloaded Implementations:**
:html:`
`
**SetPen** `(self, pen : Pen)`
:param `pen`:
:type `pen`: wx.Pen
:rtype: `None`
:html:`
`
**SetPen** `(self, pen : GraphicsPen)`
:param `pen`:
:type `pen`: wx.GraphicsPen
:rtype: `None`
:html:`
`
.. method:: SetTransform(self, matrix : GraphicsMatrix)
Sets the current transformation matrix of this context.
:param `matrix`:
:type `matrix`: wx.GraphicsMatrix
:rtype: `None`
.. method:: ShouldOffset(self)
Helper to determine if a 0.5 offset should be applied for the drawing operation.
:rtype: `bool`
.. method:: StartDoc(self, message : str)
Begin a new document (relevant only for printing / pdf etc.) If there is a progress dialog, message will be shown.
:param `message`:
:type `message`: string
:rtype: `bool`
.. method:: StartPage(self, width: float=0, height: float=0)
Opens a new page (relevant only for printing / pdf etc.) with the given size in points.
(If both are null the default page size will be used.)
:param `width`:
:type `width`: wx.Double
:param `height`:
:type `height`: wx.Double
:rtype: `None`
.. method:: StrokeLine(self, x1 : float, y1 : float, x2 : float, y2 : float)
Strokes a single line.
:param `x1`:
:type `x1`: wx.Double
:param `y1`:
:type `y1`: wx.Double
:param `x2`:
:type `x2`: wx.Double
:param `y2`:
:type `y2`: wx.Double
:rtype: `None`
.. method:: StrokeLineSegments(self, beginPoint2Ds, endPoint2Ds)
Stroke disconnected lines from begin to end points.
.. method:: StrokeLines(self, point2Ds)
Stroke lines connecting all the points.
.. method:: StrokePath(self, path : GraphicsPath)
Strokes along a path with the current pen.
:param `path`:
:type `path`: wx.GraphicsPath
:rtype: `None`
.. method:: ToDIP(self, *args, **kw)
|overload| **Overloaded Implementations:**
:html:`
`
**ToDIP** `(self, sz : Size)`
Convert pixel values of the current graphics context to DPI-independent pixel values.
See `Window.ToDIP(const` Size& sz) and `DC.ToDIP(const` Size& sz) for more info about converting device independent pixel values.
:param `sz`:
:type `sz`: wx.Size
:rtype: :ref:`wx.Size`
.. versionadded:: 4.1/wxWidgets-3.1.7
:html:`
`
**ToDIP** `(self, pt : Point)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `pt`:
:type `pt`: wx.Point
:rtype: :ref:`wx.Point`
:html:`
`
**ToDIP** `(self, d : int)`
Convert pixel values of the current graphics context to DPI-independent pixel values.
This is the same as ToDIP(const Size& sz) overload, but assumes that the resolution is the same in horizontal and vertical directions.
:param `d`:
:type `d`: int
:rtype: `int`
.. versionadded:: 4.1/wxWidgets-3.1.7
:html:`
`
.. method:: Translate(self, dx : float, dy : float)
Translates the current transformation matrix.
:param `dx`:
:type `dx`: wx.Double
:param `dy`:
:type `dy`: wx.Double
:rtype: `None`
.. attribute:: AntialiasMode
See :meth:`~wx.GraphicsContext.GetAntialiasMode` and :meth:`~wx.GraphicsContext.SetAntialiasMode`
.. attribute:: CompositionMode
See :meth:`~wx.GraphicsContext.GetCompositionMode` and :meth:`~wx.GraphicsContext.SetCompositionMode`
.. attribute:: InterpolationQuality
See :meth:`~wx.GraphicsContext.GetInterpolationQuality` and :meth:`~wx.GraphicsContext.SetInterpolationQuality`
.. attribute:: NativeContext
See :meth:`~wx.GraphicsContext.GetNativeContext`
.. attribute:: TextExtent
See :meth:`~wx.GraphicsContext.GetTextExtent`
.. attribute:: Transform
See :meth:`~wx.GraphicsContext.GetTransform` and :meth:`~wx.GraphicsContext.SetTransform`
.. attribute:: Window
See :meth:`~wx.GraphicsContext.GetWindow`