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
GlobalAlpha
Current global alpha multiplier (product of the pushed opacities).
public float GlobalAlpha { get; }
Property Value
Hairline
Thickness of one device pixel in DIPs.
public float Hairline { get; }
Property Value
Scale
Pixels per DIP (for pixel snapping).
public float Scale { get; }
Property Value
SupportsSvg
true if DrawSvg(SvgImage, Rect, float, float) renders natively on this target.
public bool SupportsSvg { get; }
Property Value
Text
Text measurement on the current device.
public ITextMeasurer Text { get; }
Property Value
Methods
Clear(Color)
Fills the whole target (ignores clip and transform).
public void Clear(Color color)
Parameters
colorColor
Clip(Rect)
Clip scope: using (dc.Clip(r)) { … }.
public DrawingContext.StateScope Clip(Rect rect)
Parameters
rectRect
Returns
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
centerPointradiusfloatstartDegreesfloatsweepDegreesfloatcolorColorthicknessfloatstyleStrokeStyle
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
centerPointradiusfloatcolorColorthicknessfloatstyleStrokeStyle
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
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
DrawGeometry(PathGeometry, Color, float, StrokeStyle?)
Strokes a path.
public void DrawGeometry(PathGeometry path, Color color, float thickness = 1, StrokeStyle? style = null)
Parameters
pathPathGeometrycolorColorthicknessfloatstyleStrokeStyle
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
imageImageSourcedestinationRectopacityfloatsourcePixelsRect?smoothbool
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
fromPointtoPointcolorColorthicknessfloatstyleStrokeStyle
DrawNineSlice(NineSlice, Rect, float)
Draws a nine-slice image stretched to the destination.
public void DrawNineSlice(NineSlice nine, Rect destination, float opacity = 1)
Parameters
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
pointsReadOnlySpan<Point>colorColorthicknessfloatstyleStrokeStyle
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
rectRectcolorColorthicknessfloatstyleStrokeStyle
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
rectRectradiusfloatcolorColorthicknessfloatstyleStrokeStyle
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
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
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
FillCircle(Point, float, Color)
Fills a circle.
public void FillCircle(Point center, float radius, Color color)
Parameters
FillCircle(Point, float, Paint)
Fills a circle with a paint.
public void FillCircle(Point center, float radius, Paint paint)
Parameters
FillEllipse(Point, float, float, Paint)
Fills an ellipse.
public void FillEllipse(Point center, float radiusX, float radiusY, Paint paint)
Parameters
FillGeometry(PathGeometry, Paint)
Fills a path.
public void FillGeometry(PathGeometry path, Paint paint)
Parameters
pathPathGeometrypaintPaint
FillPie(Point, float, float, float, Paint)
Fills a pie slice.
public void FillPie(Point center, float radius, float startDegrees, float sweepDegrees, Paint paint)
Parameters
FillPolygon(ReadOnlySpan<Point>, Paint)
Fills a closed polygon.
public void FillPolygon(ReadOnlySpan<Point> points, Paint paint)
Parameters
pointsReadOnlySpan<Point>paintPaint
FillRect(Rect, Color)
Fills a rectangle.
public void FillRect(Rect rect, Color color)
Parameters
FillRect(Rect, Paint)
Fills a rectangle with a paint.
public void FillRect(Rect rect, Paint paint)
Parameters
FillRoundedRect(Rect, float, Color)
Fills a rounded rectangle.
public void FillRoundedRect(Rect rect, float radius, Color color)
Parameters
FillRoundedRect(Rect, float, Paint)
Fills a rounded rectangle with a paint.
public void FillRoundedRect(Rect rect, float radius, Paint paint)
Parameters
MeasureText(string, TextStyle, float)
Measures text.
public Size MeasureText(string text, TextStyle style, float maxWidth = Infinity)
Parameters
Returns
Opacity(float)
Opacity scope.
public DrawingContext.StateScope Opacity(float opacity)
Parameters
opacityfloat
Returns
PopClip()
Pops the last clip.
public void PopClip()
PopOpacity()
Pops the last PushOpacity(float) or PushOpacityLayer(float).
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
rectRect
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
opacityfloat
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
opacityfloat
PushRoundedClip(Rect, float)
Restricts drawing to a rounded rectangle until PopClip().
public void PushRoundedClip(Rect rect, float radius)
Parameters
PushTransform(Matrix3x2)
Applies a local transform until PopTransform().
public void PushTransform(Matrix3x2 transform)
Parameters
transformMatrix3x2
Rotate(float, Point)
Rotation scope around a point (degrees, clockwise).
public DrawingContext.StateScope Rotate(float degrees, Point center)
Parameters
Returns
Snap(Rect)
Snaps a rectangle to device pixels (crisp hairlines).
public Rect Snap(Rect rect)
Parameters
rectRect
Returns
Transform(Matrix3x2)
Transform scope.
public DrawingContext.StateScope Transform(Matrix3x2 transform)
Parameters
transformMatrix3x2