Working on the progrart functions.
This commit is contained in:
24
Progrart.Core/Graphics/BaseElement.cs
Normal file
24
Progrart.Core/Graphics/BaseElement.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Jint;
|
||||||
|
using Jint.Native;
|
||||||
|
|
||||||
|
namespace Progrart.Core.Graphics
|
||||||
|
{
|
||||||
|
public class BaseElement
|
||||||
|
{
|
||||||
|
public List<BaseElement> Children = new List<BaseElement>();
|
||||||
|
public JsObject? __object = null;
|
||||||
|
public virtual void Add(BaseElement element)
|
||||||
|
{
|
||||||
|
Children.Add(element);
|
||||||
|
}
|
||||||
|
public virtual void Remove(BaseElement element)
|
||||||
|
{
|
||||||
|
Children.Remove(element);
|
||||||
|
}
|
||||||
|
public virtual void Render(RenderContext context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public virtual void LoadProperties() { }
|
||||||
|
public virtual void SetupProperties(Engine engine) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
65
Progrart.Core/Graphics/Line.cs
Normal file
65
Progrart.Core/Graphics/Line.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
using Jint;
|
||||||
|
using Jint.Native;
|
||||||
|
using Progrart.Core.JSExecution;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
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;
|
||||||
|
public override void SetupProperties(Engine engine)
|
||||||
|
{
|
||||||
|
base.SetupProperties(engine);
|
||||||
|
if (__object != null)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
JsObject point = new JsObject(engine);
|
||||||
|
point.Set("x", 0);
|
||||||
|
point.Set("y", 0);
|
||||||
|
__object.Set("Start", point);
|
||||||
|
}
|
||||||
|
__object.Set("Size", 1);
|
||||||
|
__object.Set("Color", ProgrartFunctions.color(engine, 1, 1, 1, 1));
|
||||||
|
{
|
||||||
|
JsObject point = new JsObject(engine);
|
||||||
|
point.Set("x", 0);
|
||||||
|
point.Set("y", 0);
|
||||||
|
__object.Set("End", point);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public override void LoadProperties()
|
||||||
|
{
|
||||||
|
if (__object is not null)
|
||||||
|
{
|
||||||
|
Size = (float)__object.Get("Size").AsNumber();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void Render(RenderContext context)
|
||||||
|
{
|
||||||
|
base.Render(context);
|
||||||
|
context.DrawingCore.canvas.DrawLine(
|
||||||
|
context.TranslatePoint((float)StartX, (float)StartY),
|
||||||
|
context.TranslatePoint((float)StartX, (float)StartY),
|
||||||
|
new SkiaSharp.SKPaint()
|
||||||
|
{
|
||||||
|
ColorF = new SkiaSharp.SKColorF(ColorR, ColorG, ColorB, ColorA),
|
||||||
|
StrokeWidth = Size,
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Progrart.Core/Graphics/ShaderType.cs
Normal file
13
Progrart.Core/Graphics/ShaderType.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Progrart.Core.Graphics
|
||||||
|
{
|
||||||
|
public enum ShaderType
|
||||||
|
{
|
||||||
|
LinearGradient,
|
||||||
|
RadialGradient,
|
||||||
|
Picture,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +1,44 @@
|
|||||||
using Jint.Native;
|
using Jint;
|
||||||
using System;
|
using Jint.Native;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Progrart.Core.Graphics
|
namespace Progrart.Core.Graphics
|
||||||
{
|
{
|
||||||
public class BaseElement
|
|
||||||
{
|
|
||||||
public JsObject? __object = null;
|
|
||||||
public virtual void Add(BaseElement element) { }
|
|
||||||
public virtual void Remove(BaseElement element) { }
|
|
||||||
public virtual void Render(RenderContext context)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public virtual void SetProperty(string key, string value)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class ImageRoot : BaseElement
|
public class ImageRoot : BaseElement
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public class VisualRoot : BaseElement
|
public class VisualRoot : BaseElement
|
||||||
{
|
{
|
||||||
|
public override void Render(RenderContext context)
|
||||||
|
{
|
||||||
|
base.Render(context);
|
||||||
|
foreach (var item in Children)
|
||||||
|
{
|
||||||
|
item.Render(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void SetupProperties(Engine engine)
|
||||||
|
{
|
||||||
|
base.SetupProperties(engine);
|
||||||
|
if (__object != null)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
JsObject point = new JsObject(engine);
|
||||||
|
point.Set("x", 0);
|
||||||
|
point.Set("y", 0);
|
||||||
|
__object.Set("translate", point);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JsObject point = new JsObject(engine);
|
||||||
|
point.Set("x", 0);
|
||||||
|
point.Set("y", 0);
|
||||||
|
__object.Set("scale", point);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__object.Set("rotation", 0);
|
||||||
|
}
|
||||||
|
__object.Set("Width", 1);
|
||||||
|
__object.Set("Height", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ namespace Progrart.Core.JSExecution
|
|||||||
{
|
{
|
||||||
Engine.Evaluate(formSymbol(Symbols));
|
Engine.Evaluate(formSymbol(Symbols));
|
||||||
Engine.Evaluate(content);
|
Engine.Evaluate(content);
|
||||||
if (Engine.GetValue("config").AsObject().TryGetValue("width", out var w))
|
|
||||||
{
|
|
||||||
Trace.WriteLine(w);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
16
Progrart.Core/JSExecution/ProgrartConversion.cs
Normal file
16
Progrart.Core/JSExecution/ProgrartConversion.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Jint.Native;
|
||||||
|
using SkiaSharp;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Progrart.Core.JSExecution
|
||||||
|
{
|
||||||
|
public static class ProgrartConversion
|
||||||
|
{
|
||||||
|
public static SKShader? ObtainFromJsObject(JsObject jsObject)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,46 +2,69 @@
|
|||||||
using Jint.Native;
|
using Jint.Native;
|
||||||
using Jint.Native.Function;
|
using Jint.Native.Function;
|
||||||
using Progrart.Core.Graphics;
|
using Progrart.Core.Graphics;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Progrart.Core.JSExecution
|
namespace Progrart.Core.JSExecution
|
||||||
{
|
{
|
||||||
public class ProgrartExecutor
|
public class ProgrartExecutor : IDisposable
|
||||||
{
|
{
|
||||||
public ExecutionEngine engine;
|
public ExecutionEngine engine;
|
||||||
public Dictionary<string, BaseElement> ObjectPool = new();
|
public Dictionary<string, object> ObjectPool = new();
|
||||||
public ProgrartExecutor()
|
public ProgrartExecutor()
|
||||||
{
|
{
|
||||||
engine = new ExecutionEngine();
|
engine = new ExecutionEngine();
|
||||||
engine.Engine.SetValue("visual_root", new Func<JsObject>(() =>
|
SetupCalls();
|
||||||
{
|
|
||||||
return ProgrartFunctions.CreateVisualRoot(this);
|
|
||||||
}
|
|
||||||
));
|
|
||||||
engine.Engine.SetValue("color4", new Func<JsNumber, JsNumber, JsNumber, JsNumber, JsObject>((r, g, b, a) =>
|
|
||||||
{
|
|
||||||
return ProgrartFunctions.color(this
|
|
||||||
, r.AsNumber()
|
|
||||||
, g.AsNumber()
|
|
||||||
, b.AsNumber()
|
|
||||||
, a.AsNumber()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
));
|
|
||||||
engine.Engine.SetValue("color3", new Func<JsNumber, JsNumber, JsNumber, JsObject>((r, g, b) =>
|
|
||||||
{
|
|
||||||
return ProgrartFunctions.color(this
|
|
||||||
, r.AsNumber()
|
|
||||||
, g.AsNumber()
|
|
||||||
, b.AsNumber()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
public RenderContext RenderImage(int Scale, string script, Dictionary<string, string> arguments)
|
public void SetupCalls()
|
||||||
|
{
|
||||||
|
engine.Engine.SetValue("visual_root", visual_root);
|
||||||
|
Jint.Native.Json.JsonSerializer serializer = new Jint.Native.Json.JsonSerializer(engine.Engine);
|
||||||
|
engine.Engine.SetValue("log", new Action<JsValue>((v) =>
|
||||||
|
{
|
||||||
|
if (v is JsObject obj)
|
||||||
|
{
|
||||||
|
Trace.WriteLine(serializer.Serialize(obj));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Trace.WriteLine(v);
|
||||||
|
}));
|
||||||
|
engine.Engine.SetValue("line", line);
|
||||||
|
engine.Engine.SetValue("color4", color4);
|
||||||
|
engine.Engine.SetValue("color3", color3);
|
||||||
|
engine.Engine.SetValue("linear_gradient", linear_gradient);
|
||||||
|
engine.Engine.SetValue("radial_gradient", radial_gradient);
|
||||||
|
}
|
||||||
|
public JsObject color4(JsNumber r, JsNumber g, JsNumber b, JsNumber a)
|
||||||
|
{
|
||||||
|
return ProgrartFunctions.color(engine.Engine
|
||||||
|
, r.AsNumber()
|
||||||
|
, g.AsNumber()
|
||||||
|
, b.AsNumber()
|
||||||
|
, a.AsNumber()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public JsObject color3(JsNumber r, JsNumber g, JsNumber b)
|
||||||
|
{
|
||||||
|
return ProgrartFunctions.color(engine.Engine
|
||||||
|
, r.AsNumber()
|
||||||
|
, g.AsNumber()
|
||||||
|
, b.AsNumber()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public JsObject visual_root()
|
||||||
|
{
|
||||||
|
return ProgrartFunctions.CreateVisualRoot(this);
|
||||||
|
}
|
||||||
|
public JsObject line()
|
||||||
|
{
|
||||||
|
return ProgrartFunctions.CreateLine(this);
|
||||||
|
}
|
||||||
|
public RenderContext RenderImage(int Scale, string script, ExecuteArguments arguments)
|
||||||
{
|
{
|
||||||
int width = 1;
|
int width = 1;
|
||||||
int height = 1;
|
int height = 1;
|
||||||
foreach (var item in arguments)
|
foreach (var item in arguments.data)
|
||||||
{
|
{
|
||||||
engine.Engine.SetValue(item.Key, item.Value);
|
engine.Engine.SetValue(item.Key, item.Value);
|
||||||
}
|
}
|
||||||
@@ -55,15 +78,25 @@ namespace Progrart.Core.JSExecution
|
|||||||
}
|
}
|
||||||
RenderContext renderContext = new RenderContext(width * Scale, width * Scale);
|
RenderContext renderContext = new RenderContext(width * Scale, width * Scale);
|
||||||
ImageRoot imageRoot = new ImageRoot();
|
ImageRoot imageRoot = new ImageRoot();
|
||||||
|
|
||||||
engine.Execute(script);
|
engine.Execute(script);
|
||||||
var img = engine.Engine.Call("main");
|
var img = engine.Engine.Call("main");
|
||||||
imageRoot.Add(ObjectPool[$"{img.Get("id")}"]);
|
if (ObjectPool[$"{img.Get("id")}"] is BaseElement element)
|
||||||
|
imageRoot.Add(element);
|
||||||
imageRoot.Render(renderContext);
|
imageRoot.Render(renderContext);
|
||||||
return renderContext;
|
return renderContext;
|
||||||
}
|
}
|
||||||
public int RegisterObject(object obj)
|
public string RegisterObject(object obj)
|
||||||
{
|
{
|
||||||
return obj.GetHashCode();
|
string v = $"{obj.GetHashCode()}";
|
||||||
|
ObjectPool[v] = obj;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
public JsObject linear_gradient()=>ProgrartFunctions.linear_gradient(engine.Engine);
|
||||||
|
public JsObject radial_gradient()=>ProgrartFunctions.radial_gradient(engine.Engine);
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
engine.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,115 @@
|
|||||||
using Jint.Native;
|
using Jint;
|
||||||
|
using Jint.Native;
|
||||||
using Progrart.Core.Graphics;
|
using Progrart.Core.Graphics;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace Progrart.Core.JSExecution
|
namespace Progrart.Core.JSExecution
|
||||||
{
|
{
|
||||||
public static class ProgrartFunctions
|
public static class ProgrartFunctions
|
||||||
{
|
{
|
||||||
public static JsObject WrapObject(ProgrartExecutor executor, int Handle)
|
public static JsObject WrapObject(ProgrartExecutor executor, string Handle)
|
||||||
{
|
{
|
||||||
var obj = new JsObject(executor.engine.Engine);
|
var obj = new JsObject(executor.engine.Engine);
|
||||||
string handle_str = $"{Handle}";
|
string handle_str = $"{Handle}";
|
||||||
obj.Set("id", handle_str);
|
obj.Set("id", handle_str);
|
||||||
obj.Set("add", JsValue.FromObject(executor.engine.Engine, new Action<JsObject>((obj) =>
|
obj.Set("add", JsValue.FromObject(executor.engine.Engine, new Action<JsObject>((obj) =>
|
||||||
{
|
{
|
||||||
executor.ObjectPool[handle_str].Add(executor.ObjectPool[$"{obj.Get("id")}"]);
|
if (executor.ObjectPool[handle_str] is BaseElement self)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (executor.ObjectPool[$"{obj.Get("id")}"] is BaseElement element)
|
||||||
|
{
|
||||||
|
self.Add(element);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception($"Object {obj} is not a Progrart Element!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception($"Object with id \"{handle_str}\" is not a Progrart Element!");
|
||||||
})));
|
})));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
public static JsObject color(ProgrartExecutor executor, double r, double g, double b, double a)
|
public static JsObject linear_gradient(Engine engine)
|
||||||
{
|
{
|
||||||
var obj = new JsObject(executor.engine.Engine);
|
var obj = new JsObject(engine);
|
||||||
|
|
||||||
|
{
|
||||||
|
JsObject point = new JsObject(engine);
|
||||||
|
point.Set("x", 0);
|
||||||
|
point.Set("y", 0);
|
||||||
|
obj.Set("Start", point);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
JsObject point = new JsObject(engine);
|
||||||
|
point.Set("x", 0);
|
||||||
|
point.Set("y", 0);
|
||||||
|
obj.Set("End", point);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
obj.Set("Colors", new JsArray(engine, [
|
||||||
|
color(engine, 1, 1, 1, 1) ,
|
||||||
|
color(engine, 1, 1, 1, 1)
|
||||||
|
]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
obj.Set("Colors", new JsArray(engine, [
|
||||||
|
color(engine, 1, 1, 1, 1) ,
|
||||||
|
color(engine, 1, 1, 1, 1)
|
||||||
|
]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
obj.Set("Positions", new JsArray(engine, new[] { new JsNumber(0), new JsNumber(1) }));
|
||||||
|
}
|
||||||
|
obj.Set("TileMode", $"{SKShaderTileMode.Repeat}");
|
||||||
|
obj.Set("Type", $"{ShaderType.LinearGradient}");
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
public static JsObject radial_gradient(Engine engine)
|
||||||
|
{
|
||||||
|
var obj = new JsObject(engine);
|
||||||
|
|
||||||
|
{
|
||||||
|
JsObject point = new JsObject(engine);
|
||||||
|
point.Set("x", 0);
|
||||||
|
point.Set("y", 0);
|
||||||
|
obj.Set("Center", point);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
obj.Set("Colors", new JsArray(engine, [
|
||||||
|
color(engine, 1, 1, 1, 1) ,
|
||||||
|
color(engine, 1, 1, 1, 1)
|
||||||
|
]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
obj.Set("Colors", new JsArray(engine, [
|
||||||
|
color(engine, 1, 1, 1, 1) ,
|
||||||
|
color(engine, 1, 1, 1, 1)
|
||||||
|
]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
obj.Set("Positions", new JsArray(engine, new[] { new JsNumber(0), new JsNumber(1) }));
|
||||||
|
}
|
||||||
|
obj.Set("TileMode", $"{SKShaderTileMode.Repeat}");
|
||||||
|
obj.Set("Type", $"{ShaderType.RadialGradient}");
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
public static JsObject color(Engine engine, double r, double g, double b, double a)
|
||||||
|
{
|
||||||
|
var obj = new JsObject(engine);
|
||||||
obj.Set("r", r);
|
obj.Set("r", r);
|
||||||
obj.Set("g", g);
|
obj.Set("g", g);
|
||||||
obj.Set("b", b);
|
obj.Set("b", b);
|
||||||
obj.Set("a", a);
|
obj.Set("a", a);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
public static JsObject color(ProgrartExecutor executor, double r, double g, double b)
|
public static JsObject color(Engine engine, double r, double g, double b)
|
||||||
{
|
{
|
||||||
var obj = new JsObject(executor.engine.Engine);
|
var obj = new JsObject(engine);
|
||||||
obj.Set("r", r);
|
obj.Set("r", r);
|
||||||
obj.Set("g", g);
|
obj.Set("g", g);
|
||||||
obj.Set("b", b);
|
obj.Set("b", b);
|
||||||
@@ -39,6 +121,15 @@ namespace Progrart.Core.JSExecution
|
|||||||
VisualRoot root = new();
|
VisualRoot root = new();
|
||||||
var obj = WrapObject(executor, executor.RegisterObject(root));
|
var obj = WrapObject(executor, executor.RegisterObject(root));
|
||||||
root.__object = obj;
|
root.__object = obj;
|
||||||
|
root.SetupProperties(executor.engine.Engine);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
public static JsObject CreateLine(ProgrartExecutor executor)
|
||||||
|
{
|
||||||
|
Line root = new();
|
||||||
|
var obj = WrapObject(executor, executor.RegisterObject(root));
|
||||||
|
root.__object = obj;
|
||||||
|
root.SetupProperties(executor.engine.Engine);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ namespace Progrart.Core
|
|||||||
{
|
{
|
||||||
this.DrawingCore = core;
|
this.DrawingCore = core;
|
||||||
}
|
}
|
||||||
|
public SKPoint TranslatePoint(float x, float y)
|
||||||
|
{
|
||||||
|
return new SKPoint(x * DrawingCore.Width, y * DrawingCore.Height);
|
||||||
|
}
|
||||||
public RenderContext(int W, int H)
|
public RenderContext(int W, int H)
|
||||||
{
|
{
|
||||||
DrawingCore = new PrimitiveDrawingCore(W, H);
|
DrawingCore = new PrimitiveDrawingCore(W, H);
|
||||||
@@ -22,9 +25,13 @@ namespace Progrart.Core
|
|||||||
internal bool isDisposed = false;
|
internal bool isDisposed = false;
|
||||||
SKSurface surface;
|
SKSurface surface;
|
||||||
SKImageInfo info;
|
SKImageInfo info;
|
||||||
|
public readonly int Width;
|
||||||
|
public readonly int Height;
|
||||||
public SKCanvas canvas { get; }
|
public SKCanvas canvas { get; }
|
||||||
public PrimitiveDrawingCore(int W, int H)
|
public PrimitiveDrawingCore(int W, int H)
|
||||||
{
|
{
|
||||||
|
Width = W;
|
||||||
|
Height = H;
|
||||||
info = new SKImageInfo(W, H);
|
info = new SKImageInfo(W, H);
|
||||||
surface = SKSurface.Create(info);
|
surface = SKSurface.Create(info);
|
||||||
canvas = surface.Canvas;
|
canvas = surface.Canvas;
|
||||||
@@ -38,6 +45,10 @@ namespace Progrart.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ExecuteArguments
|
||||||
|
{
|
||||||
|
public Dictionary<string, string> data = new Dictionary<string, string>();
|
||||||
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class RenderConfig
|
public class RenderConfig
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,17 @@ public partial class TabHost : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
public ITabPage? GetCurrentPage()
|
||||||
|
{
|
||||||
|
foreach (var item in PageContainer.Children)
|
||||||
|
{
|
||||||
|
if (item.IsVisible)
|
||||||
|
{
|
||||||
|
if (item is ITabPage page) return page;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public void AddPage(ITabPage page)
|
public void AddPage(ITabPage page)
|
||||||
{
|
{
|
||||||
TabButton button = new TabButton(page, this);
|
TabButton button = new TabButton(page, this);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Avalonia.Threading;
|
|||||||
using AvaloniaEdit;
|
using AvaloniaEdit;
|
||||||
using AvaloniaEdit.TextMate;
|
using AvaloniaEdit.TextMate;
|
||||||
using Progrart.Controls.TabSystem;
|
using Progrart.Controls.TabSystem;
|
||||||
|
using Progrart.Core;
|
||||||
using Progrart.Icons;
|
using Progrart.Icons;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Progrart.Controls.TabSystem;
|
using Progrart.Controls.TabSystem;
|
||||||
|
using Progrart.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|||||||
@@ -2,8 +2,4 @@
|
|||||||
|
|
||||||
namespace Progrart.Pages
|
namespace Progrart.Pages
|
||||||
{
|
{
|
||||||
public class ExecuteArguments
|
|
||||||
{
|
|
||||||
public Dictionary<string, string> data = new Dictionary<string, string>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ using Avalonia.Media.Imaging;
|
|||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using Progrart.Controls.TabSystem;
|
using Progrart.Controls.TabSystem;
|
||||||
|
using Progrart.Core;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Progrart.Pages;
|
namespace Progrart.Pages;
|
||||||
|
|||||||
@@ -4,20 +4,23 @@ using Avalonia.Markup.Xaml;
|
|||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using Progrart.Controls.TabSystem;
|
using Progrart.Controls.TabSystem;
|
||||||
|
using Progrart.Core;
|
||||||
|
using Progrart.Core.JSExecution;
|
||||||
using Progrart.Pages;
|
using Progrart.Pages;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Progrart;
|
namespace Progrart;
|
||||||
|
|
||||||
public partial class ProgrartEditorPage : UserControl, ITabPage,IEditorPage
|
public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||||
{
|
{
|
||||||
IStorageFile? file = null;
|
IStorageFile? file = null;
|
||||||
TabButton? btn = null;
|
TabButton? btn = null;
|
||||||
public ProgrartEditorPage()
|
public ProgrartEditorPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BindButton(TabButton button)
|
public void BindButton(TabButton button)
|
||||||
{
|
{
|
||||||
@@ -32,13 +35,23 @@ public partial class ProgrartEditorPage : UserControl, ITabPage,IEditorPage
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Execute(ExecuteArguments? args = null)
|
public void Execute(ExecuteArguments? args = null)
|
||||||
{
|
{
|
||||||
}
|
using ProgrartExecutor executor = new ProgrartExecutor();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
executor.RenderImage(100, CodeEditor.Text, new ExecuteArguments());
|
||||||
|
|
||||||
public bool IsModified()
|
}
|
||||||
{
|
catch (System.Exception e)
|
||||||
return false;
|
{
|
||||||
}
|
Trace.WriteLine(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsModified()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void LoadDocument(IStorageFile file)
|
public void LoadDocument(IStorageFile file)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -168,10 +168,24 @@
|
|||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<Border CornerRadius="12" Margin="8" BorderBrush="#8888" BorderThickness="1,1,1,0" Background="#4888">
|
<Border CornerRadius="12" Margin="8" BorderBrush="#8888" BorderThickness="1,1,1,0" Background="#4888">
|
||||||
<TextBlock Margin="8,4">Output</TextBlock>
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Margin="8,4">Output</TextBlock>
|
||||||
|
<StackPanel Grid.Column="1" Margin="8,0" VerticalAlignment="Center" Orientation="Horizontal">
|
||||||
|
|
||||||
|
<Button CornerRadius="8" Name="OutputClear" Click="OutputClear_Click">
|
||||||
|
<Viewbox Height="12">
|
||||||
|
<PathIcon Data="F1 M 8.52 5.799999 L 11.52 5.799999 C 11.52 5.373333 11.373333 5.013332 11.08 4.719999 C 10.786666 4.426666 10.426666 4.286667 10 4.299999 C 9.573333 4.313334 9.219999 4.459999 8.94 4.74 C 8.66 5.02 8.52 5.373333 8.52 5.799999 Z M 7.52 5.799999 C 7.52 5.106667 7.759999 4.52 8.24 4.039999 C 8.719999 3.560001 9.306666 3.313334 10 3.299999 C 10.693333 3.286667 11.28 3.526667 11.759999 4.02 C 12.239999 4.513334 12.479999 5.106667 12.48 5.799999 L 17.52 5.799999 C 17.653332 5.799999 17.766666 5.846666 17.859999 5.94 C 17.953331 6.033334 18 6.153334 18 6.299999 C 18 6.446667 17.953331 6.566668 17.859999 6.66 C 17.766666 6.753334 17.653332 6.8 17.52 6.799999 L 16.440001 6.799999 L 15.24 17.16 C 15.159999 17.906666 14.833332 18.533333 14.259999 19.039999 C 13.686666 19.546665 13.026666 19.799999 12.28 19.799999 L 7.72 19.799999 C 6.973333 19.799999 6.313333 19.546665 5.74 19.039999 C 5.166667 18.533333 4.84 17.906666 4.76 17.16 L 3.56 6.799999 L 2.52 6.799999 C 2.36 6.8 2.233333 6.753334 2.14 6.66 C 2.046667 6.566668 2 6.446667 2 6.299999 C 2 6.153334 2.046667 6.033334 2.14 5.94 C 2.233333 5.846666 2.36 5.799999 2.52 5.799999 Z M 5.76 17.039999 C 5.813333 17.546665 6.026666 17.966665 6.4 18.299999 C 6.773333 18.633333 7.213333 18.799999 7.72 18.799999 L 12.28 18.799999 C 12.786666 18.799999 13.226665 18.633333 13.599999 18.299999 C 13.973333 17.966665 14.186666 17.546665 14.24 17.039999 L 15.44 6.799999 L 4.56 6.799999 Z M 8.52 9.28 C 8.653333 9.306667 8.766666 9.366667 8.86 9.459999 C 8.953333 9.553333 9 9.666667 9 9.799999 L 9 15.799999 C 9 15.933332 8.953333 16.053333 8.86 16.16 C 8.766666 16.266666 8.646667 16.313332 8.5 16.299999 C 8.353333 16.286667 8.233333 16.233334 8.139999 16.139999 C 8.046666 16.046665 8 15.933332 8 15.799999 L 8 9.799999 C 8 9.666667 8.046666 9.546667 8.139999 9.44 C 8.233333 9.333334 8.346666 9.280001 8.48 9.28 Z M 12 9.799999 C 12 9.666667 11.953333 9.546667 11.86 9.44 C 11.766666 9.333334 11.646666 9.280001 11.5 9.28 C 11.353333 9.280001 11.233333 9.333334 11.139999 9.44 C 11.046666 9.546667 11 9.666667 11 9.799999 L 11 15.799999 C 11 15.933332 11.046666 16.046665 11.139999 16.139999 C 11.233333 16.233334 11.353333 16.286667 11.5 16.299999 C 11.646666 16.313332 11.766666 16.266666 11.86 16.16 C 11.953333 16.053333 12 15.933332 12 15.799999 Z " VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||||
|
</Viewbox>
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
<ScrollViewer Grid.Row="1">
|
<ScrollViewer Grid.Row="1">
|
||||||
<TextBlock Name="Output"/>
|
<TextBlock Name="Output" TextWrapping="Wrap"/>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
|
|||||||
@@ -11,26 +11,12 @@ namespace Progrart.Views;
|
|||||||
|
|
||||||
public partial class MainView : UserControl
|
public partial class MainView : UserControl
|
||||||
{
|
{
|
||||||
ExecutionEngine engine;
|
|
||||||
static MainView? Instance;
|
static MainView? Instance;
|
||||||
public MainView()
|
public MainView()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
engine = new ExecutionEngine();
|
Trace.Listeners.Add(new ConsoleLogger());
|
||||||
//engine.Engine.SetValue("log", new Action<string>((s) => { Output.Text += $"{s}\n"; }));
|
|
||||||
RunButton.Click += (_, _) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//engine.Execute(CodePane.Text);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
WriteLine(e.Message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//Trace.Listeners.Add(new ConsoleLogger());
|
|
||||||
EditorProvider.setHost(MainTabHost);
|
EditorProvider.setHost(MainTabHost);
|
||||||
BottomPanelToggle.IsCheckedChanged += (a, b) =>
|
BottomPanelToggle.IsCheckedChanged += (a, b) =>
|
||||||
{
|
{
|
||||||
@@ -89,11 +75,24 @@ public partial class MainView : UserControl
|
|||||||
LeftPanelToggle.IsChecked = false;
|
LeftPanelToggle.IsChecked = false;
|
||||||
};
|
};
|
||||||
LeftPanelToggle.IsChecked = true;
|
LeftPanelToggle.IsChecked = true;
|
||||||
|
RunButton.Click += (_, _) =>
|
||||||
|
{
|
||||||
|
if (MainTabHost.GetCurrentPage() is IEditorPage editor)
|
||||||
|
{
|
||||||
|
editor.Execute(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OutputClear_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Output.Text = "";
|
||||||
|
}
|
||||||
|
|
||||||
public void Write(string message)
|
public void Write(string message)
|
||||||
{
|
{
|
||||||
//Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
//Output.Text += message);
|
Output.Text += message);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Output.Text += message;
|
Output.Text += message;
|
||||||
@@ -104,10 +103,12 @@ public partial class MainView : UserControl
|
|||||||
}
|
}
|
||||||
public void WriteLine(string message)
|
public void WriteLine(string message)
|
||||||
{
|
{
|
||||||
//Dispatcher.UIThread.Invoke(() =>);
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Output.Text += $"{message}\n";
|
Output.Text += $"{message}\n";
|
||||||
|
});
|
||||||
|
try
|
||||||
|
{
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user