wxGraphicsContext — wx v2.4.2

Search documentation of wx

# View Source wxGraphicsContext (wx v2.4.2)

Functions for wxGraphicsContext class

A `wxGraphicsContext` instance is the object that is drawn upon. It is created by a renderer using `wxGraphicsRenderer:createContext/2`. This can be either directly using a renderer instance, or indirectly using the static convenience `create/1` functions of `wxGraphicsContext` that always delegate the task to the default renderer.

Remark: 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 `wxGraphicsContext::Flush()` (not implemented in wx) or by destroying the context.

See: `wxGraphicsRenderer:createContext/2`, `wxGCDC`, `wxDC`

This class is derived (and can use functions) from: `wxGraphicsObject`

wxWidgets docs: wxGraphicsContext

# Summary

## Types

wxGraphicsContext()

## Functions

clip(This, Region)

Sets the clipping region to the intersection of the given region and the previously set clipping region.

clip(This, X, Y, W, H)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

concatTransform(This, Matrix)

Concatenates the passed in transform with the current transform of this context.

create()

Create a lightweight context that can be used only for measuring text.

create(WindowDC)

Creates a `wxGraphicsContext` from a `wxWindowDC`.

createBrush(This, Brush)

Creates a native brush from a `wxBrush`.

createFont(This, Font)
createFont/3

Creates a native graphics font from a `wxFont` and a text colour.

createFont/4

Creates a font object with the specified attributes.

createLinearGradientBrush(This, X1, Y1, X2, Y2, Stops)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

createLinearGradientBrush(This, X1, Y1, X2, Y2, C1, C2)

`Creates a native brush with a linear gradient. The brush starts at (@a x1, @a y1) and ends at (@a x2, @a y2). Either just the start and end gradient colours (@a c1 and @a c2) or full set of gradient @a stops can be specified. The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.`

createMatrix(This)
createMatrix/2

Creates a native affine transformation matrix from the passed in values.

createPath(This)

Creates a native graphics path which is initially empty.

createPen(This, Pen)

Creates a native pen from a `wxPen`.

createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, Stops)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, OColor, CColor)

`Creates a native brush with a radial gradient. The brush originates at (@a startX, @a startY) and ends on a circle around (@a endX, @a endY) with the given @a radius. The gradient may be specified either by its start and end colours @a oColor and @a cColor or by a full set of gradient @a stops. The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.`

destroy(This)

Creates a `wxGraphicsContext` from a `wxWindow`.

drawBitmap(This, Bmp, X, Y, W, H)

Draws the bitmap.

drawEllipse(This, X, Y, W, H)

Draws an ellipse.

drawIcon(This, Icon, X, Y, W, H)

Draws the icon.

drawLines(This, Points)
drawLines/3

Draws a polygon.

drawPath(This, Path)
drawPath/3

Draws the path by first filling and then stroking.

drawRectangle(This, X, Y, W, H)

Draws a rectangle.

drawRoundedRectangle(This, X, Y, W, H, Radius)

Draws a rounded rectangle.

drawText(This, Str, X, Y)

Draws text at the defined position.

drawText/5

Draws text at the defined position.

drawText(This, Str, X, Y, Angle, BackgroundBrush)

Draws text at the defined position.

fillPath(This, Path)
fillPath/3

Fills the path with the current brush.

getPartialTextExtents(This, Text)

Fills the `widths` array with the widths from the beginning of `text` to the corresponding character of `text`.

getTextExtent(This, Text)

Gets the dimensions of the string using the currently selected font.

getTransform(This)

Gets the current transformation matrix of this context.

resetClip(This)

Resets the clipping to original shape.

rotate(This, Angle)

Rotates the current transformation matrix (in radians).

scale(This, XScale, YScale)

Scales the current transformation matrix.

setBrush(This, Brush)

Sets the brush for filling paths.

setFont(This, Font)

Sets the font for drawing text.

setFont(This, Font, Colour)

Sets the font for drawing text.

setPen(This, Pen)

Sets the pen used for stroking.

setTransform(This, Matrix)

Sets the current transformation matrix of this context.

strokeLine(This, X1, Y1, X2, Y2)

Strokes a single line.

strokeLines(This, Points)

Stroke lines connecting all the points.

strokePath(This, Path)

Strokes along a path with the current pen.

translate(This, Dx, Dy)

Translates the current transformation matrix.

# Types

Link to this type

# wxGraphicsContext()

View Source

    -type wxGraphicsContext() :: wx:wx_object().

# Functions

Link to this function

# clip(This, Region)

View Source

    -spec clip(This, Region) -> ok when This :: wxGraphicsContext(), Region :: wxRegion:wxRegion().

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.

Remark:

Link to this function

# clip(This, X, Y, W, H)

View Source

    -spec clip(This, X, Y, W, H) -> ok
                  when
                      This :: wxGraphicsContext(),
                      X :: number(),
                      Y :: number(),
                      W :: number(),
                      H :: number().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Link to this function

# concatTransform(This, Matrix)

View Source

    -spec concatTransform(This, Matrix) -> ok
                             when This :: wxGraphicsContext(), Matrix :: wxGraphicsMatrix:wxGraphicsMatrix().

Concatenates the passed in transform with the current transform of this context.

Link to this function

# create()

View Source

    -spec create() -> wxGraphicsContext().

Create a lightweight context that can be used only for measuring text.

Link to this function

# create(WindowDC)

View Source

    -spec create(WindowDC) -> wxGraphicsContext()
                    when
                        WindowDC ::
                            wxWindowDC:wxWindowDC() |
                            wxWindow:wxWindow() |
                            wxMemoryDC:wxMemoryDC() |
                            wxImage:wxImage().

Creates a `wxGraphicsContext` from a `wxWindowDC`.

See: `wxGraphicsRenderer:createContext/2`

Link to this function

# createBrush(This, Brush)

View Source

    -spec createBrush(This, Brush) -> wxGraphicsBrush:wxGraphicsBrush()
                         when This :: wxGraphicsContext(), Brush :: wxBrush:wxBrush().

Creates a native brush from a `wxBrush`.

Link to this function

# createFont(This, Font)

View Source

    -spec createFont(This, Font) -> wxGraphicsFont:wxGraphicsFont()
                        when This :: wxGraphicsContext(), Font :: wxFont:wxFont().

Link to this function

# createFont/3

View Source

    -spec createFont(This, SizeInPixels, Facename) -> wxGraphicsFont:wxGraphicsFont()
                        when
                            This :: wxGraphicsContext(),
                            SizeInPixels :: number(),
                            Facename :: unicode:chardata();
                    (This, Font, [Option]) -> wxGraphicsFont:wxGraphicsFont()
                        when
                            This :: wxGraphicsContext(),
                            Font :: wxFont:wxFont(),
                            Option :: {col, wx:wx_colour()}.

Creates a native graphics font from a `wxFont` and a text colour.

Remark: For Direct2D graphics fonts can be created from TrueType fonts only.

Link to this function

# createFont/4

View Source

    -spec createFont(This, SizeInPixels, Facename, [Option]) -> wxGraphicsFont:wxGraphicsFont()
                        when
                            This :: wxGraphicsContext(),
                            SizeInPixels :: number(),
                            Facename :: unicode:chardata(),
                            Option :: {flags, integer()} | {col, wx:wx_colour()}.

Creates a font object with the specified attributes.

The use of overload taking `wxFont` is preferred, see `wxGraphicsRenderer:createFont/4` for more details.

Remark: For Direct2D graphics fonts can be created from TrueType fonts only.

Since: 2.9.3

Link to this function

# createLinearGradientBrush(This, X1, Y1, X2, Y2, Stops)

View Source

    -spec createLinearGradientBrush(This, X1, Y1, X2, Y2, Stops) -> wxGraphicsBrush:wxGraphicsBrush()
                                       when
                                           This :: wxGraphicsContext(),
                                           X1 :: number(),
                                           Y1 :: number(),
                                           X2 :: number(),
                                           Y2 :: number(),
                                           Stops :: wxGraphicsGradientStops:wxGraphicsGradientStops().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Link to this function

# createLinearGradientBrush(This, X1, Y1, X2, Y2, C1, C2)

View Source

    -spec createLinearGradientBrush(This, X1, Y1, X2, Y2, C1, C2) -> wxGraphicsBrush:wxGraphicsBrush()
                                       when
                                           This :: wxGraphicsContext(),
                                           X1 :: number(),
                                           Y1 :: number(),
                                           X2 :: number(),
                                           Y2 :: number(),
                                           C1 :: wx:wx_colour(),
                                           C2 :: wx:wx_colour().

`Creates a native brush with a linear gradient. The brush starts at (@a x1, @a y1) and ends at (@a x2, @a y2). Either just the start and end gradient colours (@a c1 and @a c2) or full set of gradient @a stops can be specified. The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.`

The `matrix` parameter was added in wxWidgets 3.1.3

Link to this function

# createMatrix(This)

View Source

    -spec createMatrix(This) -> wxGraphicsMatrix:wxGraphicsMatrix() when This :: wxGraphicsContext().

Link to this function

# createMatrix/2

View Source

    -spec createMatrix(This, [Option]) -> wxGraphicsMatrix:wxGraphicsMatrix()
                          when
                              This :: wxGraphicsContext(),
                              Option ::
                                  {a, number()} |
                                  {b, number()} |
                                  {c, number()} |
                                  {d, number()} |
                                  {tx, number()} |
                                  {ty, number()}.

Creates a native affine transformation matrix from the passed in values.

The default parameters result in an identity matrix.

Link to this function

# createPath(This)

View Source

    -spec createPath(This) -> wxGraphicsPath:wxGraphicsPath() when This :: wxGraphicsContext().

Creates a native graphics path which is initially empty.

Link to this function

# createPen(This, Pen)

View Source

    -spec createPen(This, Pen) -> wxGraphicsPen:wxGraphicsPen()
                       when This :: wxGraphicsContext(), Pen :: wxPen:wxPen().

Creates a native pen from a `wxPen`.

Prefer to use the overload taking `wxGraphicsPenInfo` (not implemented in wx) unless you already have a `wxPen` as constructing one only to pass it to this method is wasteful.

Link to this function

# createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, Stops)

View Source

    -spec createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, Stops) ->
                                       wxGraphicsBrush:wxGraphicsBrush()
                                       when
                                           This :: wxGraphicsContext(),
                                           StartX :: number(),
                                           StartY :: number(),
                                           EndX :: number(),
                                           EndY :: number(),
                                           Radius :: number(),
                                           Stops :: wxGraphicsGradientStops:wxGraphicsGradientStops().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Link to this function

# createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, OColor, CColor)

View Source

    -spec createRadialGradientBrush(This, StartX, StartY, EndX, EndY, Radius, OColor, CColor) ->
                                       wxGraphicsBrush:wxGraphicsBrush()
                                       when
                                           This :: wxGraphicsContext(),
                                           StartX :: number(),
                                           StartY :: number(),
                                           EndX :: number(),
                                           EndY :: number(),
                                           Radius :: number(),
                                           OColor :: wx:wx_colour(),
                                           CColor :: wx:wx_colour().

`Creates a native brush with a radial gradient. The brush originates at (@a startX, @a startY) and ends on a circle around (@a endX, @a endY) with the given @a radius. The gradient may be specified either by its start and end colours @a oColor and @a cColor or by a full set of gradient @a stops. The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.`

The ability to apply a transformation matrix to the gradient was added in 3.1.3

Link to this function

# destroy(This)

View Source

    -spec destroy(This :: wxGraphicsContext()) -> ok.

Creates a `wxGraphicsContext` from a `wxWindow`.

See: `wxGraphicsRenderer:createContext/2`

Link to this function

# drawBitmap(This, Bmp, X, Y, W, H)

View Source

    -spec drawBitmap(This, Bmp, X, Y, W, H) -> ok
                        when
                            This :: wxGraphicsContext(),
                            Bmp :: wxBitmap:wxBitmap(),
                            X :: number(),
                            Y :: number(),
                            W :: number(),
                            H :: number().

Draws the bitmap.

In case of a mono bitmap, this is treated as a mask and the current brushed is used for filling.

Link to this function

# drawEllipse(This, X, Y, W, H)

View Source

    -spec drawEllipse(This, X, Y, W, H) -> ok
                         when
                             This :: wxGraphicsContext(),
                             X :: number(),
                             Y :: number(),
                             W :: number(),
                             H :: number().

Draws an ellipse.

Link to this function

# drawIcon(This, Icon, X, Y, W, H)

View Source

    -spec drawIcon(This, Icon, X, Y, W, H) -> ok
                      when
                          This :: wxGraphicsContext(),
                          Icon :: wxIcon:wxIcon(),
                          X :: number(),
                          Y :: number(),
                          W :: number(),
                          H :: number().

Draws the icon.

Link to this function

# drawLines(This, Points)

View Source

    -spec drawLines(This, Points) -> ok
                       when This :: wxGraphicsContext(), Points :: [{X :: float(), Y :: float()}].

Link to this function

# drawLines/3

View Source

    -spec drawLines(This, Points, [Option]) -> ok
                       when
                           This :: wxGraphicsContext(),
                           Points :: [{X :: float(), Y :: float()}],
                           Option :: {fillStyle, wx:wx_enum()}.

Draws a polygon.

Link to this function

# drawPath(This, Path)

View Source

    -spec drawPath(This, Path) -> ok
                      when This :: wxGraphicsContext(), Path :: wxGraphicsPath:wxGraphicsPath().

Link to this function

# drawPath/3

View Source

    -spec drawPath(This, Path, [Option]) -> ok
                      when
                          This :: wxGraphicsContext(),
                          Path :: wxGraphicsPath:wxGraphicsPath(),
                          Option :: {fillStyle, wx:wx_enum()}.

Draws the path by first filling and then stroking.

Link to this function

# drawRectangle(This, X, Y, W, H)

View Source

    -spec drawRectangle(This, X, Y, W, H) -> ok
                           when
                               This :: wxGraphicsContext(),
                               X :: number(),
                               Y :: number(),
                               W :: number(),
                               H :: number().

Draws a rectangle.

Link to this function

# drawRoundedRectangle(This, X, Y, W, H, Radius)

View Source

    -spec drawRoundedRectangle(This, X, Y, W, H, Radius) -> ok
                                  when
                                      This :: wxGraphicsContext(),
                                      X :: number(),
                                      Y :: number(),
                                      W :: number(),
                                      H :: number(),
                                      Radius :: number().

Draws a rounded rectangle.

Link to this function

# drawText(This, Str, X, Y)

View Source

    -spec drawText(This, Str, X, Y) -> ok
                      when
                          This :: wxGraphicsContext(),
                          Str :: unicode:chardata(),
                          X :: number(),
                          Y :: number().

Draws text at the defined position.

Link to this function

# drawText/5

View Source

    -spec drawText(This, Str, X, Y, Angle) -> ok
                      when
                          This :: wxGraphicsContext(),
                          Str :: unicode:chardata(),
                          X :: number(),
                          Y :: number(),
                          Angle :: number();
                  (This, Str, X, Y, BackgroundBrush) -> ok
                      when
                          This :: wxGraphicsContext(),
                          Str :: unicode:chardata(),
                          X :: number(),
                          Y :: number(),
                          BackgroundBrush :: wxGraphicsBrush:wxGraphicsBrush().

Draws text at the defined position.

Link to this function

# drawText(This, Str, X, Y, Angle, BackgroundBrush)

View Source

    -spec drawText(This, Str, X, Y, Angle, BackgroundBrush) -> ok
                      when
                          This :: wxGraphicsContext(),
                          Str :: unicode:chardata(),
                          X :: number(),
                          Y :: number(),
                          Angle :: number(),
                          BackgroundBrush :: wxGraphicsBrush:wxGraphicsBrush().

Draws text at the defined position.

Link to this function

# fillPath(This, Path)

View Source

    -spec fillPath(This, Path) -> ok
                      when This :: wxGraphicsContext(), Path :: wxGraphicsPath:wxGraphicsPath().

Link to this function

# fillPath/3

View Source

    -spec fillPath(This, Path, [Option]) -> ok
                      when
                          This :: wxGraphicsContext(),
                          Path :: wxGraphicsPath:wxGraphicsPath(),
                          Option :: {fillStyle, wx:wx_enum()}.

Fills the path with the current brush.

Link to this function

# getPartialTextExtents(This, Text)

View Source

    -spec getPartialTextExtents(This, Text) -> [number()]
                                   when This :: wxGraphicsContext(), Text :: unicode:chardata().

Fills the `widths` array with the widths from the beginning of `text` to the corresponding character of `text`.

Link to this function

# getTextExtent(This, Text)

View Source

    -spec getTextExtent(This, Text) -> Result
                           when
                               Result ::
                                   {Width :: number(),
                                    Height :: number(),
                                    Descent :: number(),
                                    ExternalLeading :: number()},
                               This :: wxGraphicsContext(),
                               Text :: unicode:chardata().

Gets the dimensions of the string using the currently selected font.

Link to this function

# getTransform(This)

View Source

    -spec getTransform(This) -> wxGraphicsMatrix:wxGraphicsMatrix() when This :: wxGraphicsContext().

Gets the current transformation matrix of this context.

Link to this function

# resetClip(This)

View Source

    -spec resetClip(This) -> ok when This :: wxGraphicsContext().

Resets the clipping to original shape.

Link to this function

# rotate(This, Angle)

View Source

    -spec rotate(This, Angle) -> ok when This :: wxGraphicsContext(), Angle :: number().

Rotates the current transformation matrix (in radians).

Link to this function

# scale(This, XScale, YScale)

View Source

    -spec scale(This, XScale, YScale) -> ok
                   when This :: wxGraphicsContext(), XScale :: number(), YScale :: number().

Scales the current transformation matrix.

Link to this function

# setBrush(This, Brush)

View Source

    -spec setBrush(This, Brush) -> ok
                      when
                          This :: wxGraphicsContext(),
                          Brush :: wxGraphicsBrush:wxGraphicsBrush() | wxBrush:wxBrush().

Sets the brush for filling paths.

Link to this function

# setFont(This, Font)

View Source

    -spec setFont(This, Font) -> ok
                     when This :: wxGraphicsContext(), Font :: wxGraphicsFont:wxGraphicsFont().

Sets the font for drawing text.

Link to this function

# setFont(This, Font, Colour)

View Source

    -spec setFont(This, Font, Colour) -> ok
                     when This :: wxGraphicsContext(), Font :: wxFont:wxFont(), Colour :: wx:wx_colour().

Sets the font for drawing text.

Remark: For Direct2D only TrueType fonts can be used.

Link to this function

# setPen(This, Pen)

View Source

    -spec setPen(This, Pen) -> ok
                    when This :: wxGraphicsContext(), Pen :: wxPen:wxPen() | wxGraphicsPen:wxGraphicsPen().

Sets the pen used for stroking.

Link to this function

# setTransform(This, Matrix)

View Source

    -spec setTransform(This, Matrix) -> ok
                          when This :: wxGraphicsContext(), Matrix :: wxGraphicsMatrix:wxGraphicsMatrix().

Sets the current transformation matrix of this context.

Link to this function

# strokeLine(This, X1, Y1, X2, Y2)

View Source

    -spec strokeLine(This, X1, Y1, X2, Y2) -> ok
                        when
                            This :: wxGraphicsContext(),
                            X1 :: number(),
                            Y1 :: number(),
                            X2 :: number(),
                            Y2 :: number().

Strokes a single line.

Link to this function

# strokeLines(This, Points)

View Source

    -spec strokeLines(This, Points) -> ok
                         when This :: wxGraphicsContext(), Points :: [{X :: float(), Y :: float()}].

Stroke lines connecting all the points.

Unlike the other overload of this function, this method draws a single polyline and not a number of disconnected lines.

Link to this function

# strokePath(This, Path)

View Source

    -spec strokePath(This, Path) -> ok
                        when This :: wxGraphicsContext(), Path :: wxGraphicsPath:wxGraphicsPath().

Strokes along a path with the current pen.

Link to this function

# translate(This, Dx, Dy)

View Source

    -spec translate(This, Dx, Dy) -> ok when This :: wxGraphicsContext(), Dx :: number(), Dy :: number().

Translates the current transformation matrix.