20 private ShapeStyle _style =
new(Color.Black,
null, 1f);
30 : base(host, mode, sceneLayer, view,
35 _style =
new ShapeStyle(color,
null, 1f);
51 _style = _style with { Color = color };
59 if (!
float.IsFinite(width) || width < 0)
60 throw new ArgumentOutOfRangeException(nameof(width));
70 _style = _style with {
FillColor = color };
78 if (destRectScreen.Width <= 0 || destRectScreen.Height <= 0)
81 ShapeStyle style = _style;
87 float strokeWidth = Math.Min(style.StrokeWidth, Math.Min(destRectScreen.Width, destRectScreen.Height));
88 float inset = strokeWidth / 2f;
89 var geometryBounds =
new SKRect(
90 destRectScreen.Left + inset,
91 destRectScreen.Top + inset,
92 destRectScreen.Right - inset,
93 destRectScreen.Bottom - inset);
95 var canvas = backbuffer.
Canvas;
99 canvas.ClipRect(
new SKRect(destRectScreen.Left, destRectScreen.Top, destRectScreen.Right, destRectScreen.Bottom));
101 if (style.FillColor is Color fill)
103 using var paint =
new SKPaint { Color = fill.ToSKColor(), IsAntialias =
true, Style = SKPaintStyle.Fill };
109 using var paint =
new SKPaint
111 Color = style.Color.ToSKColor(),
113 Style = SKPaintStyle.Stroke,
115 StrokeJoin = SKStrokeJoin.Round,
116 StrokeCap = SKStrokeCap.Round
128 protected abstract void DrawGeometry(SKCanvas canvas, SKRect bounds, SKPaint paint);
131 protected static PointF[]
CopyPoints(IEnumerable<PointF> points,
int minimumCount)
133 ArgumentNullException.ThrowIfNull(points);
134 PointF[] copy = points.ToArray();
136 if (copy.Length < minimumCount || copy.Any(p =>
137 !
float.IsFinite(p.X) || !
float.IsFinite(p.Y) ||
138 p.X < 0 || p.X > 1 || p.Y < 0 || p.Y > 1))
139 throw new ArgumentException(
"Expected enough finite points in the normalized range [0, 1].", nameof(points));
145 protected static SKPoint
MapPoint(PointF point, SKRect bounds) =>
146 new(bounds.Left + point.X * bounds.Width, bounds.Top + point.Y * bounds.Height);
149 protected static void DrawPointSequence(SKCanvas canvas, SKRect bounds, SKPaint paint, PointF[] points,
bool closed)
151 if (points.Length == 0)
154 using var path =
new SKPath();
155 path.AddPoly(points.Select(p =>
MapPoint(p, bounds)).ToArray(), closed);
156 canvas.DrawPath(path, paint);
View? View
Gets the view to which this direct drawing is attached, or null if the drawing is in scene-layer mode...
SceneLayer? SceneLayer
Gets the scene layer to which this direct drawing is attached, or null if the drawing is in view mode...
DirectDrawingMovableBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? name=null)
Initializes a new instance of the DirectDrawingMovableBase class with integrated movement capabilitie...
float StrokeWidth
Gets the outline width in screen pixels.
static SKPoint MapPoint(PointF point, SKRect bounds)
Maps a normalized local point into the drawing bounds.
static PointF[] CopyPoints(IEnumerable< PointF > points, int minimumCount)
Copies and validates a sequence of normalized local points.
TShape SetShapeFill(Color? color)
Sets or clears the fill of a fillable shape.
static void DrawPointSequence(SKCanvas canvas, SKRect bounds, SKPaint paint, PointF[] points, bool closed)
Draws a point sequence as an open or closed path.
Color StrokeColor
Gets the outline color.
DirectShapeBase(Color color, RenderSurfaceHostBase host, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle bounds, string? nickname)
TShape SetColor(Color color)
Sets the outline color.
TShape SetStrokeWidth(float width)
Sets the outline width in screen pixels; zero disables the outline.
Color? FillColor
Gets the optional fill color.
void DrawGeometry(SKCanvas canvas, SKRect bounds, SKPaint paint)
Renders geometry within the supplied stroke-inset bounds.
override void OnDraw(BackbufferBase backbuffer, RectangleF destRectScreen)
Represents a base class for managing a graphical backbuffer, and is the in-memory surface where rende...
SKCanvas Canvas
Gets the SkiaSharp canvas used for drawing operations on this backbuffer.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.