Table of Contents

Class DrawingContext

Namespace
PluginUI
Assembly
PluginUI.dll

Immediate-mode drawing API handed to OnRender(DrawingContext). All coordinates are DIPs.

public sealed class DrawingContext
Inheritance
DrawingContext
Inherited Members

Remarks

Angles are degrees measured clockwise from 12 o'clock (knob convention) unless stated otherwise.

State changes (clip, opacity, transform) are stacked: pair each Push… with a Pop…, or use the using scopes (Clip(Rect), Opacity(float), Transform(Matrix3x2)).

Properties

ClipBounds

Current clip rectangle in DIPs (untransformed approximation, used to skip invisible elements).

public Rect ClipBounds { get; }

Property Value

Rect

GlobalAlpha

Current global alpha multiplier (product of the pushed opacities).

public float GlobalAlpha { get; }

Property Value

float

Hairline

Thickness of one device pixel in DIPs.

public float Hairline { get; }

Property Value

float

Scale

Pixels per DIP (for pixel snapping).

public float Scale { get; }

Property Value

float

SupportsSvg

true if DrawSvg(SvgImage, Rect, float, float) renders natively on this target.

public bool SupportsSvg { get; }

Property Value

bool

Text

Text measurement on the current device.

public ITextMeasurer Text { get; }

Property Value

ITextMeasurer

Methods

Clear(Color)

Fills the whole target (ignores clip and transform).

public void Clear(Color color)

Parameters

color Color

Clip(Rect)

Clip scope: using (dc.Clip(r)) { … }.

public DrawingContext.StateScope Clip(Rect rect)

Parameters

rect Rect

Returns

DrawingContext.StateScope

DrawArc(Point, float, float, float, Color, float, StrokeStyle?)

Strokes a circular arc (angles in degrees clockwise from 12 o'clock).

public void DrawArc(Point center, float radius, float startDegrees, float sweepDegrees, Color color, float thickness = 1, StrokeStyle? style = null)

Parameters

center Point
radius float
startDegrees float
sweepDegrees float
color Color
thickness float
style StrokeStyle

DrawCircle(Point, float, Color, float, StrokeStyle?)

Strokes a circle.

public void DrawCircle(Point center, float radius, Color color, float thickness = 1, StrokeStyle? style = null)

Parameters

center Point
radius float
color Color
thickness float
style StrokeStyle

DrawEllipse(Point, float, float, Color, float, StrokeStyle?)

Strokes an ellipse.

public void DrawEllipse(Point center, float radiusX, float radiusY, Color color, float thickness = 1, StrokeStyle? style = null)

Parameters

center Point
radiusX float
radiusY float
color Color
thickness float
style StrokeStyle

DrawFilmStripFrame(FilmStrip, int, Rect, float)

Draws one frame of a film-strip.

public void DrawFilmStripFrame(FilmStrip strip, int frame, Rect destination, float opacity = 1)

Parameters

strip FilmStrip
frame int
destination Rect
opacity float

DrawGeometry(PathGeometry, Color, float, StrokeStyle?)

Strokes a path.

public void DrawGeometry(PathGeometry path, Color color, float thickness = 1, StrokeStyle? style = null)

Parameters

path PathGeometry
color Color
thickness float
style StrokeStyle

DrawImage(ImageSource, Rect, float, Rect?, bool)

Draws an image (or a pixel region of it) into a destination rectangle.

public void DrawImage(ImageSource image, Rect destination, float opacity = 1, Rect? sourcePixels = null, bool smooth = true)

Parameters

image ImageSource
destination Rect
opacity float
sourcePixels Rect?
smooth bool

DrawLine(Point, Point, Color, float, StrokeStyle?)

Draws a line.

public void DrawLine(Point from, Point to, Color color, float thickness = 1, StrokeStyle? style = null)

Parameters

from Point
to Point
color Color
thickness float
style StrokeStyle

DrawNineSlice(NineSlice, Rect, float)

Draws a nine-slice image stretched to the destination.

public void DrawNineSlice(NineSlice nine, Rect destination, float opacity = 1)

Parameters

nine NineSlice
destination Rect
opacity float

DrawPolyline(ReadOnlySpan<Point>, Color, float, StrokeStyle?)

Draws an open polyline.

public void DrawPolyline(ReadOnlySpan<Point> points, Color color, float thickness = 1, StrokeStyle? style = null)

Parameters

points ReadOnlySpan<Point>
color Color
thickness float
style StrokeStyle

DrawRect(Rect, Color, float, StrokeStyle?)

Strokes a rectangle (the stroke is centered on the edges).

public void DrawRect(Rect rect, Color color, float thickness = 1, StrokeStyle? style = null)

Parameters

rect Rect
color Color
thickness float
style StrokeStyle

DrawRoundedRect(Rect, float, Color, float, StrokeStyle?)

Strokes a rounded rectangle.

public void DrawRoundedRect(Rect rect, float radius, Color color, float thickness = 1, StrokeStyle? style = null)

Parameters

rect Rect
radius float
color Color
thickness float
style StrokeStyle

DrawShadow(Rect, float, float, Point, Color)

Soft drop shadow under a rounded rectangle, approximated by stacked translucent layers (cheap, no effect pipeline, works on every render target).

public void DrawShadow(Rect rect, float radius, float blur, Point offset, Color color)

Parameters

rect Rect
radius float
blur float
offset Point
color Color

DrawSvg(SvgImage, Rect, float, float)

Draws an SVG document fitted (aspect preserved by the document's own rules) into the destination, optionally rotated around its center. Draws a placeholder when SVG is not supported.

public void DrawSvg(SvgImage svg, Rect destination, float rotationDegrees = 0, float opacity = 1)

Parameters

svg SvgImage
destination Rect
rotationDegrees float
opacity float

DrawText(string?, Rect, TextStyle, Color)

Draws text inside a layout rectangle, aligned and clipped according to style.

public void DrawText(string? text, Rect layout, TextStyle style, Color color)

Parameters

text string
layout Rect
style TextStyle
color Color

FillCircle(Point, float, Color)

Fills a circle.

public void FillCircle(Point center, float radius, Color color)

Parameters

center Point
radius float
color Color

FillCircle(Point, float, Paint)

Fills a circle with a paint.

public void FillCircle(Point center, float radius, Paint paint)

Parameters

center Point
radius float
paint Paint

FillEllipse(Point, float, float, Paint)

Fills an ellipse.

public void FillEllipse(Point center, float radiusX, float radiusY, Paint paint)

Parameters

center Point
radiusX float
radiusY float
paint Paint

FillGeometry(PathGeometry, Paint)

Fills a path.

public void FillGeometry(PathGeometry path, Paint paint)

Parameters

path PathGeometry
paint Paint

FillPie(Point, float, float, float, Paint)

Fills a pie slice.

public void FillPie(Point center, float radius, float startDegrees, float sweepDegrees, Paint paint)

Parameters

center Point
radius float
startDegrees float
sweepDegrees float
paint Paint

FillPolygon(ReadOnlySpan<Point>, Paint)

Fills a closed polygon.

public void FillPolygon(ReadOnlySpan<Point> points, Paint paint)

Parameters

points ReadOnlySpan<Point>
paint Paint

FillRect(Rect, Color)

Fills a rectangle.

public void FillRect(Rect rect, Color color)

Parameters

rect Rect
color Color

FillRect(Rect, Paint)

Fills a rectangle with a paint.

public void FillRect(Rect rect, Paint paint)

Parameters

rect Rect
paint Paint

FillRoundedRect(Rect, float, Color)

Fills a rounded rectangle.

public void FillRoundedRect(Rect rect, float radius, Color color)

Parameters

rect Rect
radius float
color Color

FillRoundedRect(Rect, float, Paint)

Fills a rounded rectangle with a paint.

public void FillRoundedRect(Rect rect, float radius, Paint paint)

Parameters

rect Rect
radius float
paint Paint

MeasureText(string, TextStyle, float)

Measures text.

public Size MeasureText(string text, TextStyle style, float maxWidth = Infinity)

Parameters

text string
style TextStyle
maxWidth float

Returns

Size

Opacity(float)

Opacity scope.

public DrawingContext.StateScope Opacity(float opacity)

Parameters

opacity float

Returns

DrawingContext.StateScope

PopClip()

Pops the last clip.

public void PopClip()

PopOpacity()

public void PopOpacity()

PopTransform()

Pops the last transform.

public void PopTransform()

PushClip(Rect)

Restricts drawing to a rectangle until PopClip().

public void PushClip(Rect rect)

Parameters

rect Rect

PushOpacity(float)

Multiplies the opacity of everything drawn until PopOpacity() (VSTGUI-style global alpha: each drawing operation is attenuated, so overlapping shapes of a translucent element show through each other). Cheap, and supported by every Direct2D implementation.

public void PushOpacity(float opacity)

Parameters

opacity float

PushOpacityLayer(float)

Composes everything drawn until PopOpacity() as one group with the given opacity (Direct2D layer): exact for overlapping content, more expensive than PushOpacity(float).

public void PushOpacityLayer(float opacity)

Parameters

opacity float

PushRoundedClip(Rect, float)

Restricts drawing to a rounded rectangle until PopClip().

public void PushRoundedClip(Rect rect, float radius)

Parameters

rect Rect
radius float

PushTransform(Matrix3x2)

Applies a local transform until PopTransform().

public void PushTransform(Matrix3x2 transform)

Parameters

transform Matrix3x2

Rotate(float, Point)

Rotation scope around a point (degrees, clockwise).

public DrawingContext.StateScope Rotate(float degrees, Point center)

Parameters

degrees float
center Point

Returns

DrawingContext.StateScope

Snap(Rect)

Snaps a rectangle to device pixels (crisp hairlines).

public Rect Snap(Rect rect)

Parameters

rect Rect

Returns

Rect

Transform(Matrix3x2)

Transform scope.

public DrawingContext.StateScope Transform(Matrix3x2 transform)

Parameters

transform Matrix3x2

Returns

DrawingContext.StateScope