92 lines
2.1 KiB
C#
92 lines
2.1 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();
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class ExecuteArguments
|
|
{
|
|
public Dictionary<string, string> data = new Dictionary<string, string>();
|
|
public ExecuteArguments Clone()
|
|
{
|
|
ExecuteArguments args = new ExecuteArguments();
|
|
foreach (var item in data)
|
|
{
|
|
args.data.Add(item.Key, item.Value);
|
|
}
|
|
return args;
|
|
}
|
|
public void MergeFrom(ExecuteArguments args)
|
|
{
|
|
|
|
foreach (var item in args.data)
|
|
{
|
|
args.data.Add(item.Key, item.Value);
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class RenderConfig
|
|
{
|
|
public int Scale;
|
|
}
|
|
}
|