Files
Progrart/Progrart.Core/RenderContext.cs
Creeper Lv c1e4c71985 Save All is now working.
Size is now a relative value in Line.
2026-01-01 23:02:12 +11:00

75 lines
1.7 KiB
C#

using SkiaSharp;
using System.Diagnostics;
namespace Progrart.Core
{
public class RenderContext
{
public PrimitiveDrawingCore DrawingCore { get; }
public SKCanvas canvas { get => DrawingCore.canvas; }
public float LogicalW;
public float LogicalH;
public RenderContext(PrimitiveDrawingCore core)
{
this.DrawingCore = core;
}
public SKPoint TranslatePoint(float x, float y)
{
return new SKPoint(x * DrawingCore.Width, y * DrawingCore.Height);
}
public SKPoint TranslatePoint(SKPoint point)
{
return TranslatePoint(point.X, point.Y);
}
public float TranslateSize(float s)
{
return (float)(s * Math.Sqrt(DrawingCore.Width * DrawingCore.Width + DrawingCore.Height * DrawingCore.Height)/ Math.Sqrt(LogicalH * LogicalH + LogicalW * LogicalW));
}
public RenderContext(int W, int H)
{
DrawingCore = new PrimitiveDrawingCore(W, H);
}
}
public class PrimitiveDrawingCore : IDisposable
{
internal bool isDisposed = false;
SKSurface surface;
SKImageInfo info;
public readonly int Width;
public readonly int Height;
public SKCanvas canvas { get; }
public PrimitiveDrawingCore(int W, int H)
{
Width = W;
Height = H;
Trace.WriteLine($"Createing Surface as: {W} x {H}");
info = new SKImageInfo(W, H);
surface = SKSurface.Create(info);
canvas = surface.Canvas;
canvas.Clear();
}
public SKData ToData()
{
return surface.Snapshot().Encode(SKEncodedImageFormat.Png, 100);
}
public void Dispose()
{
if (isDisposed) return;
//GC.SuppressFinalize(this);
isDisposed = true;
surface.Dispose();
}
}
public class ExecuteArguments
{
public Dictionary<string, string> data = new Dictionary<string, string>();
}
[Serializable]
public class RenderConfig
{
public int Scale;
}
}