Skip to main content

DrawingContext Class

Definition​

Namespace:Avalonia.Media
Assembly:Avalonia.Base
Package:Avalonia
public class DrawingContext

Inheritance: object -> DrawingContext

Implements: IDisposable

Methods​

NameDescription
CustomDraws a custom drawing operation
DisposeNo summary available.
DrawEllipse (2 overloads)Draws an ellipse with the specified Brush and Pen.
DrawGeometry (2 overloads)Draws a geometry.
DrawGlyphRunDraws a glyph run.
DrawImage (2 overloads)Draws an image.
DrawLineDraws a line.
DrawRectangle (3 overloads)Draws a rectangle with the specified Brush and Pen.
DrawTextDraws text.
FillRectangleDraws a filled rectangle.
PushClip (2 overloads)Pushes a clip rectangle.
PushEffectPushes an effect.
PushGeometryClipPushes a clip geometry.
PushOpacityPushes an opacity value.
PushOpacityMaskPushes an opacity mask.
PushRenderOptionsPushes render options.
PushTextOptionsPushes text options for the drawing context.
PushTransformPushes a matrix transformation.

Custom Method​

Draws a custom drawing operation

public void Custom(Avalonia.Rendering.SceneGraph.ICustomDrawOperation custom)

Parameters​

custom Avalonia.Rendering.SceneGraph.ICustomDrawOperation

custom operation

Dispose Method​

public void Dispose()

DrawEllipse overloads​

DrawEllipse Method​

Draws an ellipse with the specified Brush and Pen.

public void DrawEllipse(Avalonia.Media.IBrush brush, Avalonia.Media.IPen pen, Avalonia.Point center, double radiusX, double radiusY)
Parameters​

brush Avalonia.Media.IBrush

The brush used to fill the ellipse, or null for no fill.

pen Avalonia.Media.IPen

The pen used to stroke the ellipse, or null for no stroke.

center Avalonia.Point

The location of the center of the ellipse.

radiusX double

The horizontal radius of the ellipse.

radiusY double

The vertical radius of the ellipse.

Remarks​

The brush and the pen can both be null. If the brush is null, then no fill is performed. If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible.

DrawEllipse Method​

Draws an ellipse with the specified Brush and Pen.

public void DrawEllipse(Avalonia.Media.IBrush brush, Avalonia.Media.IPen pen, Avalonia.Rect rect)
Parameters​

brush Avalonia.Media.IBrush

The brush used to fill the ellipse, or null for no fill.

pen Avalonia.Media.IPen

The pen used to stroke the ellipse, or null for no stroke.

rect Avalonia.Rect

The bounding rect.

Remarks​

The brush and the pen can both be null. If the brush is null, then no fill is performed. If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible.

DrawGeometry overloads​

DrawGeometry Method​

Draws a geometry.

public void DrawGeometry(Avalonia.Media.IBrush brush, Avalonia.Media.IPen pen, Avalonia.Media.Geometry geometry)
Parameters​

brush Avalonia.Media.IBrush

The fill brush.

pen Avalonia.Media.IPen

The stroke pen.

geometry Avalonia.Media.Geometry

The geometry.

DrawGeometry Method​

Draws a geometry.

public void DrawGeometry(Avalonia.Media.IBrush brush, Avalonia.Media.IPen pen, Avalonia.Platform.IGeometryImpl geometry)
Parameters​

brush Avalonia.Media.IBrush

The fill brush.

pen Avalonia.Media.IPen

The stroke pen.

geometry Avalonia.Platform.IGeometryImpl

The geometry.

DrawGlyphRun Method​

Draws a glyph run.

public void DrawGlyphRun(Avalonia.Media.IBrush foreground, Avalonia.Media.GlyphRun glyphRun)

Parameters​

foreground Avalonia.Media.IBrush

The foreground brush.

glyphRun Avalonia.Media.GlyphRun

The glyph run.

DrawImage overloads​

DrawImage Method​

Draws an image.

public void DrawImage(Avalonia.Media.IImage source, Avalonia.Rect rect)
Parameters​

source Avalonia.Media.IImage

The image.

rect Avalonia.Rect

The rect in the output to draw to.

DrawImage Method​

Draws an image.

public void DrawImage(Avalonia.Media.IImage source, Avalonia.Rect sourceRect, Avalonia.Rect destRect)
Parameters​

source Avalonia.Media.IImage

The image.

sourceRect Avalonia.Rect

The rect in the image to draw.

destRect Avalonia.Rect

The rect in the output to draw to.

DrawLine Method​

Draws a line.

public void DrawLine(Avalonia.Media.IPen pen, Avalonia.Point p1, Avalonia.Point p2)

Parameters​

pen Avalonia.Media.IPen

The stroke pen.

p1 Avalonia.Point

The first point of the line.

p2 Avalonia.Point

The second point of the line.

DrawRectangle overloads​

DrawRectangle Method​

Draws a rectangle with the specified Brush and Pen.

public void DrawRectangle(Avalonia.Media.IBrush brush, Avalonia.Media.IPen pen, Avalonia.Rect rect, double radiusX, double radiusY, Avalonia.Media.BoxShadows boxShadows)
Parameters​

brush Avalonia.Media.IBrush

The brush used to fill the rectangle, or null for no fill.

pen Avalonia.Media.IPen

The pen used to stroke the rectangle, or null for no stroke.

rect Avalonia.Rect

The rectangle bounds.

radiusX double

The radius in the X dimension of the rounded corners. This value will be clamped to the range of 0 to Width/2

radiusY double

The radius in the Y dimension of the rounded corners. This value will be clamped to the range of 0 to Height/2

boxShadows Avalonia.Media.BoxShadows

Box shadow effect parameters

Remarks​

The brush and the pen can both be null. If the brush is null, then no fill is performed. If the pen is null, then no stroke is performed. If both the pen and the brush are null, then the drawing is not visible.

DrawRectangle Method​

Draws a rectangle with the specified Brush and Pen.

public void DrawRectangle(Avalonia.Media.IBrush brush, Avalonia.Media.IPen pen, Avalonia.RoundedRect rrect, Avalonia.Media.BoxShadows boxShadows)
Parameters​

brush Avalonia.Media.IBrush

The brush used to fill the rectangle, or null for no fill.

pen Avalonia.Media.IPen

The pen used to stroke the rectangle, or null for no stroke.

rrect Avalonia.RoundedRect

The rectangle bounds.

boxShadows Avalonia.Media.BoxShadows

Box shadow effect parameters

Remarks​

The brush and the pen can both be null. If the brush is null, then no fill is performed. If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible.

DrawRectangle Method​

Draws the outline of a rectangle.

public void DrawRectangle(Avalonia.Media.IPen pen, Avalonia.Rect rect, float cornerRadius)
Parameters​

pen Avalonia.Media.IPen

The pen.

rect Avalonia.Rect

The rectangle bounds.

cornerRadius float

The corner radius.

DrawText Method​

Draws text.

public void DrawText(Avalonia.Media.FormattedText text, Avalonia.Point origin)

Parameters​

text Avalonia.Media.FormattedText

The text.

origin Avalonia.Point

The upper-left corner of the text.

FillRectangle Method​

Draws a filled rectangle.

public void FillRectangle(Avalonia.Media.IBrush brush, Avalonia.Rect rect, float cornerRadius)

Parameters​

brush Avalonia.Media.IBrush

The brush.

rect Avalonia.Rect

The rectangle bounds.

cornerRadius float

The corner radius.

PushClip overloads​

PushClip Method​

Pushes a clip rectangle.

public Avalonia.Media.DrawingContext.PushedState PushClip(Avalonia.Rect clip)
Parameters​

clip Avalonia.Rect

The clip rectangle.

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable used to undo the clip rectangle.

PushClip Method​

Pushes a clip rectangle.

public Avalonia.Media.DrawingContext.PushedState PushClip(Avalonia.RoundedRect clip)
Parameters​

clip Avalonia.RoundedRect

The clip rectangle.

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable used to undo the clip rectangle.

PushEffect Method​

Pushes an effect.

public Avalonia.Media.DrawingContext.PushedState PushEffect(Avalonia.Media.IEffect effect, Avalonia.Rect bounds)

Parameters​

effect Avalonia.Media.IEffect

The effect.

bounds Avalonia.Rect

The content bounds of the area the effect is applied to (pre-inflation). The drawing context will internally inflate these by the effect's output padding to ensure the full effect output (e.g. blur/shadow) is not clipped.

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable used to undo the effect.

PushGeometryClip Method​

Pushes a clip geometry.

public Avalonia.Media.DrawingContext.PushedState PushGeometryClip(Avalonia.Media.Geometry clip)

Parameters​

clip Avalonia.Media.Geometry

The clip geometry.

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable used to undo the clip geometry.

PushOpacity Method​

Pushes an opacity value.

public Avalonia.Media.DrawingContext.PushedState PushOpacity(double opacity)

Parameters​

opacity double

The opacity.

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable used to undo the opacity.

PushOpacityMask Method​

Pushes an opacity mask.

public Avalonia.Media.DrawingContext.PushedState PushOpacityMask(Avalonia.Media.IBrush mask, Avalonia.Rect bounds)

Parameters​

mask Avalonia.Media.IBrush

The opacity mask.

bounds Avalonia.Rect

The size of the brush's target area. TODO: Are we sure this is needed?

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable to undo the opacity mask.

PushRenderOptions Method​

Pushes render options.

public Avalonia.Media.DrawingContext.PushedState PushRenderOptions(Avalonia.Media.RenderOptions renderOptions)

Parameters​

renderOptions Avalonia.Media.RenderOptions

The render options.

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable to undo the render options.

PushTextOptions Method​

Pushes text options for the drawing context.

public Avalonia.Media.DrawingContext.PushedState PushTextOptions(Avalonia.Media.TextOptions textOptions)

Parameters​

textOptions Avalonia.Media.TextOptions

The text options.

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable to undo the text options.

PushTransform Method​

Pushes a matrix transformation.

public Avalonia.Media.DrawingContext.PushedState PushTransform(Avalonia.Matrix matrix)

Parameters​

matrix Avalonia.Matrix

The matrix

Returns​

Avalonia.Media.DrawingContext.PushedState

A disposable used to undo the transformation.