Save is now working.
Run button now sets scale and debug symbol. Run button now displays preview image.
This commit is contained in:
@@ -2,20 +2,16 @@
|
||||
using Jint.Native;
|
||||
using Progrart.Core.JSExecution;
|
||||
using SkiaSharp;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class Line : BaseElement
|
||||
{
|
||||
float Size;
|
||||
float StartX;
|
||||
float StartY;
|
||||
float EndX;
|
||||
float EndY;
|
||||
float ColorR;
|
||||
float ColorG;
|
||||
float ColorB;
|
||||
float ColorA;
|
||||
SKPoint Start;
|
||||
SKPoint End;
|
||||
SKColorF Color;
|
||||
SKShader? shader = null;
|
||||
public override void SetupProperties(Engine engine)
|
||||
{
|
||||
@@ -48,15 +44,19 @@ namespace Progrart.Core.Graphics
|
||||
{
|
||||
if (__object.Get("Start") is JsObject Start)
|
||||
{
|
||||
StartX = (float)Start.Get("x").AsNumber();
|
||||
StartY = (float)Start.Get("y").AsNumber();
|
||||
this.Start = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("End") is JsObject End)
|
||||
{
|
||||
EndX = (float)End.Get("x").AsNumber();
|
||||
EndY = (float)End.Get("y").AsNumber();
|
||||
this.End = ProgrartConversion.ObtainSKPointFromJsObject(End);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Color") is JsObject Color)
|
||||
{
|
||||
this.Color = ProgrartConversion.ObtainSKColorFFromJsObject(Color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,17 +67,20 @@ namespace Progrart.Core.Graphics
|
||||
public override void Render(RenderContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
LoadProperties();
|
||||
SKPoint FinalStartPos = context.TranslatePoint(Start);
|
||||
SKPoint FinalEndPos = context.TranslatePoint(End);
|
||||
Trace.WriteLine($"Draw Line from {FinalStartPos} to {FinalEndPos} using {Color} with size of {Size}.");
|
||||
context.DrawingCore.canvas.DrawLine(
|
||||
context.TranslatePoint((float)StartX, (float)StartY),
|
||||
context.TranslatePoint((float)EndX, (float)EndY),
|
||||
FinalStartPos,
|
||||
FinalEndPos,
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = new SKColorF(ColorR, ColorG, ColorB, ColorA),
|
||||
ColorF = Color,
|
||||
StrokeWidth = Size,
|
||||
Shader = shader
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
Progrart.Core/Graphics/Rectangle.cs
Normal file
7
Progrart.Core/Graphics/Rectangle.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class Rectangle : BaseElement
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,14 @@ namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class ImageRoot : BaseElement
|
||||
{
|
||||
public override void Render(RenderContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
foreach (var item in Children)
|
||||
{
|
||||
item.Render(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
public class VisualRoot : BaseElement
|
||||
{
|
||||
@@ -18,11 +26,13 @@ namespace Progrart.Core.Graphics
|
||||
{
|
||||
context.canvas.Translate(tx, ty);
|
||||
context.canvas.RotateDegrees(rotate, context.DrawingCore.Width / 2, context.DrawingCore.Height / 2);
|
||||
context.canvas.Scale(scale, scale, context.DrawingCore.Width / 2, context.DrawingCore.Height / 2);
|
||||
if (scale != 1)
|
||||
context.canvas.Scale(scale, scale, context.DrawingCore.Width / 2, context.DrawingCore.Height / 2);
|
||||
}
|
||||
void Untransform(RenderContext context)
|
||||
{
|
||||
context.canvas.Scale(scale, scale, context.DrawingCore.Width / 2, context.DrawingCore.Height / 2);
|
||||
if (scale != 1)
|
||||
context.canvas.Scale(1 / scale, 1 / scale, context.DrawingCore.Width / 2, context.DrawingCore.Height / 2);
|
||||
context.canvas.RotateDegrees(rotate, context.DrawingCore.Width / 2, context.DrawingCore.Height / 2);
|
||||
context.canvas.Translate(-tx, -ty);
|
||||
}
|
||||
@@ -41,7 +51,7 @@ namespace Progrart.Core.Graphics
|
||||
scale = (float)__object.Get("scale").AsNumber();
|
||||
}
|
||||
{
|
||||
scale = (float)__object.Get("rotation").AsNumber();
|
||||
rotate = (float)__object.Get("rotation").AsNumber();
|
||||
}
|
||||
w = (float)__object.Get("width").AsNumber();
|
||||
h = (float)__object.Get("height").AsNumber();
|
||||
|
||||
@@ -10,6 +10,10 @@ namespace Progrart.Core.JSExecution
|
||||
{
|
||||
public static class ProgrartConversion
|
||||
{
|
||||
public static SKPoint ObtainSKPointFromJsObject(JsObject jsObject)
|
||||
{
|
||||
return new SKPoint((float)jsObject.Get("x").AsNumber(), (float)jsObject.Get("y").AsNumber());
|
||||
}
|
||||
public static SKColorF ObtainSKColorFFromJsObject(JsObject jsObject)
|
||||
{
|
||||
var r = (float)jsObject.Get("r").AsNumber();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Jint.Native.Function;
|
||||
using Jint.Native.Json;
|
||||
using Progrart.Core.Graphics;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
@@ -62,28 +63,26 @@ namespace Progrart.Core.JSExecution
|
||||
}
|
||||
public RenderContext RenderImage(int Scale, string script, ExecuteArguments arguments)
|
||||
{
|
||||
int width = 1;
|
||||
int height = 1;
|
||||
foreach (var item in arguments.data)
|
||||
{
|
||||
engine.Engine.SetValue(item.Key, item.Value);
|
||||
}
|
||||
float width = 1;
|
||||
float height = 1;
|
||||
engine.Symbols = arguments.data;
|
||||
engine.Execute(script);
|
||||
if (engine.Engine.GetValue("Width") is JsNumber js_width)
|
||||
{
|
||||
width = (int)(js_width.AsNumber());
|
||||
width = (float)(js_width.AsNumber());
|
||||
}
|
||||
if (engine.Engine.GetValue("Height") is JsNumber js_height)
|
||||
{
|
||||
height = (int)(js_height.AsNumber());
|
||||
height = (float)(js_height.AsNumber());
|
||||
}
|
||||
RenderContext renderContext = new RenderContext(width * Scale, width * Scale);
|
||||
RenderContext renderContext = new RenderContext((int)(width * Scale), (int)(width * Scale));
|
||||
ImageRoot imageRoot = new ImageRoot();
|
||||
|
||||
engine.Execute(script);
|
||||
var img = engine.Engine.Call("main");
|
||||
if (ObjectPool[$"{img.Get("id")}"] is BaseElement element)
|
||||
imageRoot.Add(element);
|
||||
imageRoot.Render(renderContext);
|
||||
renderContext.canvas.Flush();
|
||||
return renderContext;
|
||||
}
|
||||
public string RegisterObject(object obj)
|
||||
@@ -92,8 +91,8 @@ namespace Progrart.Core.JSExecution
|
||||
ObjectPool[v] = obj;
|
||||
return v;
|
||||
}
|
||||
public JsObject linear_gradient()=>ProgrartFunctions.linear_gradient(engine.Engine);
|
||||
public JsObject radial_gradient()=>ProgrartFunctions.radial_gradient(engine.Engine);
|
||||
public JsObject linear_gradient() => ProgrartFunctions.linear_gradient(engine.Engine);
|
||||
public JsObject radial_gradient() => ProgrartFunctions.radial_gradient(engine.Engine);
|
||||
public void Dispose()
|
||||
{
|
||||
engine.Dispose();
|
||||
|
||||
@@ -112,10 +112,10 @@ namespace Progrart.Core.JSExecution
|
||||
}
|
||||
public static JsObject CreateLine(ProgrartExecutor executor)
|
||||
{
|
||||
Line root = new();
|
||||
var obj = WrapObject(executor, executor.RegisterObject(root));
|
||||
root.__object = obj;
|
||||
root.SetupProperties(executor.engine.Engine);
|
||||
Line element = new();
|
||||
var obj = WrapObject(executor, executor.RegisterObject(element));
|
||||
element.__object = obj;
|
||||
element.SetupProperties(executor.engine.Engine);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using SkiaSharp;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Progrart.Core
|
||||
{
|
||||
@@ -15,6 +16,10 @@ namespace Progrart.Core
|
||||
{
|
||||
return new SKPoint(x * DrawingCore.Width, y * DrawingCore.Height);
|
||||
}
|
||||
public SKPoint TranslatePoint(SKPoint point)
|
||||
{
|
||||
return TranslatePoint(point.X, point.Y);
|
||||
}
|
||||
public RenderContext(int W, int H)
|
||||
{
|
||||
DrawingCore = new PrimitiveDrawingCore(W, H);
|
||||
@@ -32,10 +37,11 @@ namespace Progrart.Core
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user