wxRuby Documentation Home

# Wx::GraphicsContext

GraphicsContext is a drawing context that can be used to do high-quality
anti-aliased drawing, and sophisticated transforms upon text, lines and
images such as shears and rotations.

The GraphicsContext instance is the object that carries out the drawing
upon a Window or other graphics surface, such as a Bitmap or Printer. In
wxRuby, one is created by calling
GraphicsContext.create and passing either an
ordinary DeviceContext instance, or a Window
that should be drawn upon.

## Derived from

GraphicsObject

## Methods

- GraphicsContext#create
- GraphicsContext#create_pen
- GraphicsContext#create_brush
- GraphicsContext#create_radial_gradient_brush
- GraphicsContext#create_linear_gradient_brush
- GraphicsContext#create_font
- GraphicsContext#create_matrix
- GraphicsContext#create_path
- GraphicsContext#clip
- GraphicsContext#reset_clip
- GraphicsContext#draw_bitmap
- GraphicsContext#draw_ellipse
- GraphicsContext#draw_icon
- GraphicsContext#draw_lines
- GraphicsContext#draw_path
- GraphicsContext#draw_rectangle
- GraphicsContext#draw_rounded_rectangle
- GraphicsContext#draw_text
- GraphicsContext#fill_path
- GraphicsContext#stroke_path
- GraphicsContext#get_native_context
- GraphicsContext#get_partial_text_extents
- GraphicsContext#get_text_extent
- GraphicsContext#rotate
- GraphicsContext#scale
- GraphicsContext#translate
- GraphicsContext#get_transform
- GraphicsContext#set_transform
- GraphicsContext#concat_transform
- GraphicsContext#set_brush
- GraphicsContext#set_font
- GraphicsContext#set_pen
- GraphicsContext#stroke_line
- GraphicsContext#stroke_lines

### GraphicsContext#create

GraphicsContext create(%(arg-type)WindowDC% dc)

Creates a GraphicsContext from a WindowDC (eg a PaintDC).

GraphicsContext create(%(arg-type)Window% window)

Creates a GraphicsContext from a Window.

### GraphicsContext#create_pen

GraphicsPen create_pen(%(arg-type)Pen% pen)

Creates a native pen from a Pen.

### GraphicsContext#create_brush

GraphicsBrush create_brush(%(arg-type)Brush% brush)

Creates a native brush from a Brush.

### GraphicsContext#create_radial_gradient_brush

GraphicsBrush create_radial_gradient_brush(%(arg-type)Double% xo, Double yo, Double xc, Double yc, Double radius, Colour oColor, Colour cColor)

Creates a native brush, having a radial gradient originating at (xo,yc) with color oColour and ends on a circle around (xc,yc) with radius r and color cColour

### GraphicsContext#create_linear_gradient_brush

GraphicsBrush create_linear_gradient_brush(%(arg-type)Double% x1, Double y1, Double x2, Double y2, (arg-type) Colour&c1, (arg-type) Colour&c2)

Creates a native brush, having a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2

### GraphicsContext#create_font

GraphicsFont create_font(%(arg-type)Font% font, Colour col = BLACK)

Creates a native graphics font from a Font and a text colour.

### GraphicsContext#create_matrix

GraphicsMatrix create_matrix(%(arg-type)Double% a = 1.0, Double b = 0.0, Double c = 0.0, Double d = 1.0, Double tx = 0.0, Double ty = 0.0)

Creates a native affine transformation matrix from the passed in values. The defaults result in an identity matrix.

### GraphicsContext#create_path

GraphicsPath create_path()

Creates a native graphics path which is initially empty.

### GraphicsContext#clip

clip(%(arg-type)Region% region)

Clips drawings to the region, combined to current clipping region

clip(%(arg-type)Double% x, Double y, Double w, Double h)

Clips drawings to the rectangle.

### GraphicsContext#reset_clip

reset_clip()

Resets the clipping to original shape.

### GraphicsContext#draw_bitmap

draw_bitmap(%(arg-type)Bitmap% bmp, Double x, Double y, Double w, Double h)

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

### GraphicsContext#draw_ellipse

draw_ellipse(%(arg-type)Double% x, Double y, Double w, Double h)

Draws an ellipse.

### GraphicsContext#draw_icon

draw_icon(%(arg-type)Icon% icon, Double x, Double y, Double w, Double h)

Draws the icon.

### GraphicsContext#draw_lines

draw_lines(%(arg-type)Integer% n, Point2DDouble points, Integer fillStyle = ODDEVEN_RULE)

Draws a polygon.

### GraphicsContext#draw_path

draw_path(%(arg-type)GraphicsPath% path, Integer fillStyle = ODDEVEN_RULE)

Draws the path by first filling and then stroking.

### GraphicsContext#draw_rectangle

draw_rectangle(%(arg-type)Double% x, Double y, Double w, Double h)

Draws a rectangle.

### GraphicsContext#draw_rounded_rectangle

draw_rounded_rectangle(%(arg-type)Double% x, Double y, Double w, Double h, Double radius)

Draws a rounded rectangle.

### GraphicsContext#draw_text

draw_text(%(arg-type)String% str, Double x, Double y, Double angle) draw_text(%(arg-type)String% str, Double x, Double y)

Draws a text at the defined position, at the given angle.

### GraphicsContext#fill_path

fill_path(%(arg-type)GraphicsPath% path, Integer fillStyle = ODDEVEN_RULE)

Fills the path with the current brush.

### GraphicsContext#stroke_path

stroke_path(%(arg-type)GraphicsPath% path)

Strokes along a path with the current pen.

### GraphicsContext#get_native_context

get_native_context()

Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo).

### GraphicsContext#get_partial_text_extents

get_partial_text_extents(%(arg-type)String% text, ArrayDouble widths)

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

### GraphicsContext#get_text_extent

get_text_extent(%(arg-type)String% text, Double width, Double height, Double descent, Double externalLeading)

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

### GraphicsContext#rotate

rotate(%(arg-type)Double% angle)

Rotates the current transformation matrix (radians)

### GraphicsContext#scale

scale(%(arg-type)Double% x_scale, Double y_scale)

Scales the current transformation matrix.

### GraphicsContext#translate

translate(%(arg-type)Double% dx, Double dy)

Translates the current transformation matrix.

### GraphicsContext#get_transform

GraphicsMatrix get_transform()

Gets the current transformation matrix of this context.

### GraphicsContext#set_transform

set_transform(%(arg-type)GraphicsMatrix% matrix)

Sets the current transformation matrix of this context.

### GraphicsContext#concat_transform

concat_transform(%(arg-type)GraphicsMatrix% matrix)

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

### GraphicsContext#set_brush

set_brush(%(arg-type)Brush% brush)
set_brush(%(arg-type)GraphicsBrush% brush)

Sets the brush for filling paths.

### GraphicsContext#set_font

set_font(%(arg-type)Font% font, Colour colour)
set_font(%(arg-type)GraphicsFont% font)

Sets the font for drawing text.

### GraphicsContext#set_pen

set_pen(%(arg-type)Pen% pen)
set_pen(%(arg-type)GraphicsPen% pen)

Sets the pen used for stroking.

### GraphicsContext#strokeline

strokeline(%(arg-type)Double% x1,%(arg-type)Double% y1,%(arg-type)Double% x2,%(arg-type)Double% y2)

Strokes a single line.

### GraphicsContext#strokelines

strokelines(%(arg-type)Integer% n,%(arg-type)Point2DDouble% begin_points,%(arg-type)Point2DDouble% end_points)
strokelines(%(arg-type)Integer% n,%(arg-type)Point2DDouble% points)

Stroke disconnected lines from begin to end points, fastest method available for this purpose.

[This page automatically generated from the Textile source at 2023-06-09 00:45:33 +0000]