How to use custom ID2D1SimplifiedGeometrySink implementation #476
-
Hi, Here's the class imlpementation: private class D2D1SimplifiedGeometrySink : ID2D1SimplifiedGeometrySink
{
private readonly ID2D1RenderTarget renderTarget;
public D2D1SimplifiedGeometrySink()
{ }
public D2D1SimplifiedGeometrySink(ID2D1RenderTarget renderTarget)
{
this.renderTarget = renderTarget;
}
public void BeginFigure(Vector2 startPoint, FigureBegin figureBegin) { }
public void EndFigure(FigureEnd figureEnd) { }
public void Close() { }
public void SetFillMode(FillMode fillMode)
{
}
public void SetSegmentFlags(PathSegment vertexFlags)
{
}
public void AddLines(Vector2[] points)
{
//// Define brushes and text format
//using ID2D1SolidColorBrush brush = renderTarget.CreateSolidColorBrush(new Color4(0, 1, 0, 0.5f)); // Semi-transparent green
//using ID2D1SolidColorBrush textBrush = renderTarget.CreateSolidColorBrush(new Color4(0, 0, 0, 1)); // Solid black for text
//IDWriteFactory dwriteFactory = DWrite.DWriteCreateFactory<IDWriteFactory>(Vortice.DirectWrite.FactoryType.Shared);
//IDWriteTextFormat textFormat = dwriteFactory.CreateTextFormat(
// "Arial", null, FontWeight.Normal, Vortice.DirectWrite.FontStyle.Normal, FontStretch.Normal, 20, "en-us");
//textFormat.TextAlignment = TextAlignment.Center;
//textFormat.ParagraphAlignment = ParagraphAlignment.Center;
//const float rX = 20;
//const float rY = 20;
//// iterate over the points
//foreach (var point in points)
//{
// renderTarget.FillEllipse(new Ellipse(point, rX, rY), brush);
// Rect textRect = new(point.X, point.Y, 0, 0);
// textRect.Inflate(rX, rY);
// int pointNumber = Array.IndexOf(points, point);
// renderTarget.DrawText(pointNumber.ToString(), textFormat, textRect, textBrush);
//}
}
public void AddBeziers(BezierSegment[] beziers)
{
}
public void Dispose()
{
}
} I'm using this class as follows: D2D1SimplifiedGeometrySink sink = new();
geometry.Simplify(GeometrySimplificationOption.Lines, sink); geometry.Simplify call is throwing this error: Can anyone tell me the correct way to do this? |
Beta Was this translation helpful? Give feedback.
Answered by
amerkoleci
Dec 27, 2024
Replies: 1 comment 1 reply
-
Hi, |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
amannan-123
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Can you try to subclass from CallbackBase as well?