12 private SKPath? _sourcePath;
13 private SKPath? _transformedPath;
14 private SKRect? _transformedBounds;
15 private bool _resourcesDisposed;
30 SceneLayer? sceneLayer,
View? view, Rectangle bounds, SKPath path,
string? nickname)
31 : base(color, host, mode, sceneLayer, view, bounds, nickname)
33 lock (RenderStateSynchronization.SyncRoot)
35 if (_resourcesDisposed)
38 throw new ObjectDisposedException(nameof(
DirectPath));
49 lock (RenderStateSynchronization.SyncRoot)
51 ObjectDisposedException.ThrowIf(_resourcesDisposed,
this);
53 SKPath replacement = ParsePath(pathData);
54 _sourcePath?.Dispose();
55 _sourcePath = replacement;
56 _transformedBounds =
null;
66 private static SKPath ParsePath(
string pathData)
68 ArgumentException.ThrowIfNullOrWhiteSpace(pathData);
69 SKPath? path = SKPath.ParseSvgPathData(pathData);
72 throw new ArgumentException(
"Expected nonempty SVG path data.", nameof(pathData));
77 throw new ArgumentException(
"Expected nonempty SVG path data.", nameof(pathData));
80 SKRect bounds = path.Bounds;
82 if (!
float.IsFinite(bounds.Left) || !
float.IsFinite(bounds.Top) ||
83 !
float.IsFinite(bounds.Right) || !
float.IsFinite(bounds.Bottom) ||
84 !
float.IsFinite(bounds.Width) || !
float.IsFinite(bounds.Height))
87 throw new ArgumentException(
"Path bounds must be finite.", nameof(pathData));
94 protected override void DrawGeometry(SKCanvas canvas, SKRect bounds, SKPaint paint)
96 lock (RenderStateSynchronization.SyncRoot)
98 SKPath? source = _sourcePath;
105 if (_transformedBounds != bounds || _transformedPath is
null)
107 SKRect sourceBounds = source.Bounds;
108 float sx = sourceBounds.Width > 0 ? bounds.Width / sourceBounds.Width : 1f;
109 float sy = sourceBounds.Height > 0 ? bounds.Height / sourceBounds.Height : 1f;
110 float tx = (sourceBounds.Width > 0 ? bounds.Left : bounds.MidX) - sourceBounds.Left * sx;
111 float ty = (sourceBounds.Height > 0 ? bounds.Top : bounds.MidY) - sourceBounds.Top * sy;
112 var matrix = SKMatrix.CreateScaleTranslation(sx, sy, tx, ty);
113 _transformedPath ??=
new SKPath();
114 source.Transform(in matrix, _transformedPath);
115 _transformedBounds = bounds;
118 canvas.DrawPath(_transformedPath, paint);
123 protected override void Dispose(
bool disposing)
126 if (disposing && !_resourcesDisposed)
128 _resourcesDisposed =
true;
129 _sourcePath?.Dispose();
131 _transformedPath?.Dispose();
132 _transformedPath =
null;
133 _transformedBounds =
null;
136 base.Dispose(disposing);
A retained vector path described using SVG path-data syntax, fitted to the drawing bounds.
override void Dispose(bool disposing)
Releases resources used by this DirectDrawingBase instance.When disposing is true,...
DirectPath SetFillColor(Color? color)
Sets the interior color, or null to disable filling.
DirectPath(Color color, RenderSurfaceHostBase host, View view, Rectangle screenBounds, string pathData, string? nickname=null)
Creates a view-space path within the supplied bounds.
override void DrawGeometry(SKCanvas canvas, SKRect bounds, SKPaint paint)
DirectPath SetPathData(string pathData)
Replaces the SVG path data. Invalid data leaves the existing path unchanged.
DirectPath(Color color, RenderSurfaceHostBase host, SceneLayer sceneLayer, Rectangle worldBounds, string pathData, string? nickname=null)
Creates a scene-layer path within the supplied bounds.
TShape SetShapeFill(Color? color)
Sets or clears the fill of a fillable shape.
DirectShapeBase(Color color, RenderSurfaceHostBase host, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle bounds, string? nickname)
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.
@ View
Performs direct drawing at the view level using screen-space coordinates.
@ SceneLayer
Performs direct drawing within a scene layer using world-space coordinates.