Added Oval and Path. Currently Path only have move_to and line_to commands.
This commit is contained in:
@@ -70,8 +70,7 @@ namespace Progrart.Core.Graphics
|
|||||||
LoadProperties();
|
LoadProperties();
|
||||||
SKPoint FinalStartPos = context.TranslatePoint(Start);
|
SKPoint FinalStartPos = context.TranslatePoint(Start);
|
||||||
SKPoint FinalEndPos = context.TranslatePoint(End);
|
SKPoint FinalEndPos = context.TranslatePoint(End);
|
||||||
Trace.WriteLine($"Draw Line from {FinalStartPos} to {FinalEndPos} using {Color} with size of {Size}.");
|
context.canvas.DrawLine(
|
||||||
context.DrawingCore.canvas.DrawLine(
|
|
||||||
FinalStartPos,
|
FinalStartPos,
|
||||||
FinalEndPos,
|
FinalEndPos,
|
||||||
new SKPaint()
|
new SKPaint()
|
||||||
|
|||||||
90
Progrart.Core/Graphics/Oval.cs
Normal file
90
Progrart.Core/Graphics/Oval.cs
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
using Jint;
|
||||||
|
using Jint.Native;
|
||||||
|
using Progrart.Core.JSExecution;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace Progrart.Core.Graphics
|
||||||
|
{
|
||||||
|
public class Oval : BaseElement
|
||||||
|
{
|
||||||
|
|
||||||
|
float StrokeWidth;
|
||||||
|
SKPoint Position;
|
||||||
|
SKPoint Size;
|
||||||
|
SKColorF Color;
|
||||||
|
bool IsStroke;
|
||||||
|
SKShader? shader = null;
|
||||||
|
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("Position", point);
|
||||||
|
}
|
||||||
|
__object.Set("StrokeWidth", 1);
|
||||||
|
__object.Set("IsStroke", true);
|
||||||
|
__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("Size", point);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public override void LoadProperties()
|
||||||
|
{
|
||||||
|
if (__object is not null)
|
||||||
|
{
|
||||||
|
StrokeWidth = (float)__object.Get("StrokeWidth").AsNumber();
|
||||||
|
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
||||||
|
{
|
||||||
|
if (__object.Get("Position") is JsObject Start)
|
||||||
|
{
|
||||||
|
this.Position = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if (__object.Get("Size") is JsObject End)
|
||||||
|
{
|
||||||
|
this.Size = ProgrartConversion.ObtainSKPointFromJsObject(End);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if (__object.Get("Color") is JsObject Color)
|
||||||
|
{
|
||||||
|
this.Color = ProgrartConversion.ObtainSKColorFFromJsObject(Color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (__object.Get("Shader") is JsObject shaderObj)
|
||||||
|
shader = ProgrartConversion.ObtainFromJsObject(shaderObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void Render(RenderContext context)
|
||||||
|
{
|
||||||
|
base.Render(context);
|
||||||
|
LoadProperties();
|
||||||
|
SKPoint FinalStartPos = context.TranslatePoint(Position);
|
||||||
|
SKPoint FinalEndPos = context.TranslatePoint(Size);
|
||||||
|
context.canvas.DrawOval(
|
||||||
|
FinalStartPos.X, FinalStartPos.Y,
|
||||||
|
FinalEndPos.X, FinalEndPos.Y,
|
||||||
|
new SKPaint()
|
||||||
|
{
|
||||||
|
ColorF = Color,
|
||||||
|
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||||
|
Shader = shader,
|
||||||
|
IsStroke = IsStroke,
|
||||||
|
IsAntialias = true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
Progrart.Core/Graphics/Path.cs
Normal file
33
Progrart.Core/Graphics/Path.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using Jint;
|
||||||
|
using Jint.Native;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace Progrart.Core.Graphics
|
||||||
|
{
|
||||||
|
public class Path : BaseElement
|
||||||
|
{
|
||||||
|
SKPath path = new SKPath();
|
||||||
|
public SKPath RealPath => path;
|
||||||
|
internal List<PathCmd> Commands = new List<PathCmd>();
|
||||||
|
public override void SetupProperties(Engine engine)
|
||||||
|
{
|
||||||
|
base.SetupProperties(engine);
|
||||||
|
if (__object != null)
|
||||||
|
{
|
||||||
|
__object.Set("line_to", JsValue.FromObject(engine, (object)line_to));
|
||||||
|
__object.Set("move_to", JsValue.FromObject(engine, (object)move_to));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void line_to(float x, float y) => Commands.Add(new LineToCmd(x, y));
|
||||||
|
void move_to(float x, float y) => Commands.Add(new MoveToCmd(x, y));
|
||||||
|
|
||||||
|
public override void Render(RenderContext context)
|
||||||
|
{
|
||||||
|
base.Render(context);
|
||||||
|
foreach (var item in Commands)
|
||||||
|
{
|
||||||
|
item.ApplyCommand(context, this.path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
Progrart.Core/Graphics/PathCmd.cs
Normal file
31
Progrart.Core/Graphics/PathCmd.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace Progrart.Core.Graphics
|
||||||
|
{
|
||||||
|
public class PathCmd
|
||||||
|
{
|
||||||
|
public virtual void ApplyCommand(RenderContext context, SKPath path) { }
|
||||||
|
}
|
||||||
|
public class LineToCmd(float x, float y) : PathCmd
|
||||||
|
{
|
||||||
|
public readonly float x = x;
|
||||||
|
public readonly float y = y;
|
||||||
|
public override void ApplyCommand(RenderContext context, SKPath path)
|
||||||
|
{
|
||||||
|
base.ApplyCommand(context, path);
|
||||||
|
var pos = context.TranslatePoint(x, y);
|
||||||
|
path.LineTo(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class MoveToCmd(float x, float y) : PathCmd
|
||||||
|
{
|
||||||
|
public readonly float x = x;
|
||||||
|
public readonly float y = y;
|
||||||
|
public override void ApplyCommand(RenderContext context, SKPath path)
|
||||||
|
{
|
||||||
|
base.ApplyCommand(context, path);
|
||||||
|
var pos = context.TranslatePoint(x, y);
|
||||||
|
path.MoveTo(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
62
Progrart.Core/Graphics/PathElement.cs
Normal file
62
Progrart.Core/Graphics/PathElement.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Jint;
|
||||||
|
using Jint.Native;
|
||||||
|
using Progrart.Core.JSExecution;
|
||||||
|
using SkiaSharp;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Progrart.Core.Graphics
|
||||||
|
{
|
||||||
|
public class PathElement : BaseElement
|
||||||
|
{
|
||||||
|
float StrokeWidth;
|
||||||
|
SKPoint Start;
|
||||||
|
SKPoint End;
|
||||||
|
SKColorF Color;
|
||||||
|
SKShader? shader = null;
|
||||||
|
public override void SetupProperties(Engine engine)
|
||||||
|
{
|
||||||
|
base.SetupProperties(engine);
|
||||||
|
if (__object != null)
|
||||||
|
{
|
||||||
|
__object.Set("StrokeWidth", 1);
|
||||||
|
__object.Set("Color", ProgrartFunctions.color(engine, 1, 1, 1, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void LoadProperties()
|
||||||
|
{
|
||||||
|
if (__object is not null)
|
||||||
|
{
|
||||||
|
StrokeWidth = (float)__object.Get("StrokeWidth").AsNumber();
|
||||||
|
{
|
||||||
|
if (__object.Get("Color") is JsObject Color)
|
||||||
|
{
|
||||||
|
this.Color = ProgrartConversion.ObtainSKColorFFromJsObject(Color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (__object.Get("Shader") is JsObject shaderObj)
|
||||||
|
shader = ProgrartConversion.ObtainFromJsObject(shaderObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void Render(RenderContext context)
|
||||||
|
{
|
||||||
|
base.Render(context);
|
||||||
|
LoadProperties();
|
||||||
|
foreach (var item in this.Children)
|
||||||
|
{
|
||||||
|
if (item is Path p)
|
||||||
|
{
|
||||||
|
p.Render(context);
|
||||||
|
context.canvas.DrawPath(p.RealPath,
|
||||||
|
new SKPaint()
|
||||||
|
{
|
||||||
|
ColorF = Color,
|
||||||
|
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||||
|
Shader = shader,
|
||||||
|
IsAntialias = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -74,7 +74,7 @@ namespace Progrart.Core.Graphics
|
|||||||
LoadProperties();
|
LoadProperties();
|
||||||
SKPoint FinalStartPos = context.TranslatePoint(Start);
|
SKPoint FinalStartPos = context.TranslatePoint(Start);
|
||||||
SKPoint FinalEndPos = context.TranslatePoint(Size);
|
SKPoint FinalEndPos = context.TranslatePoint(Size);
|
||||||
context.DrawingCore.canvas.DrawRect(
|
context.canvas.DrawRect(
|
||||||
FinalStartPos.X, FinalStartPos.Y,
|
FinalStartPos.X, FinalStartPos.Y,
|
||||||
FinalEndPos.X, FinalEndPos.Y,
|
FinalEndPos.X, FinalEndPos.Y,
|
||||||
new SKPaint()
|
new SKPaint()
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ namespace Progrart.Core.Graphics
|
|||||||
using var p = new SKPath();
|
using var p = new SKPath();
|
||||||
p.MoveTo(v0);
|
p.MoveTo(v0);
|
||||||
p.MoveTo(v0);
|
p.MoveTo(v0);
|
||||||
//p.LineTo(v0);
|
|
||||||
p.LineTo(v1);
|
p.LineTo(v1);
|
||||||
p.LineTo(v2);
|
p.LineTo(v2);
|
||||||
p.LineTo(v0);
|
p.LineTo(v0);
|
||||||
|
|||||||
@@ -32,8 +32,11 @@ namespace Progrart.Core.JSExecution
|
|||||||
engine.Engine.SetValue("visual_root", visual_root);
|
engine.Engine.SetValue("visual_root", visual_root);
|
||||||
engine.Engine.SetValue("line", line);
|
engine.Engine.SetValue("line", line);
|
||||||
engine.Engine.SetValue("rectangle", rectangle);
|
engine.Engine.SetValue("rectangle", rectangle);
|
||||||
engine.Engine.SetValue("roundrect", roundrect);
|
engine.Engine.SetValue("rectangle", rectangle);
|
||||||
|
engine.Engine.SetValue("oval", oval);
|
||||||
engine.Engine.SetValue("triangle", triangle);
|
engine.Engine.SetValue("triangle", triangle);
|
||||||
|
engine.Engine.SetValue("path", path);
|
||||||
|
engine.Engine.SetValue("path_element", path_element);
|
||||||
engine.Engine.SetValue("circle", circle);
|
engine.Engine.SetValue("circle", circle);
|
||||||
engine.Engine.SetValue("color4", color4);
|
engine.Engine.SetValue("color4", color4);
|
||||||
engine.Engine.SetValue("color3", color3);
|
engine.Engine.SetValue("color3", color3);
|
||||||
@@ -85,7 +88,10 @@ namespace Progrart.Core.JSExecution
|
|||||||
public JsObject line() => ProgrartFunctions.CreateElement<Line>(this);
|
public JsObject line() => ProgrartFunctions.CreateElement<Line>(this);
|
||||||
public JsObject rectangle() => ProgrartFunctions.CreateElement<Rectangle>(this);
|
public JsObject rectangle() => ProgrartFunctions.CreateElement<Rectangle>(this);
|
||||||
public JsObject roundrect() => ProgrartFunctions.CreateElement<RoundRectangle>(this);
|
public JsObject roundrect() => ProgrartFunctions.CreateElement<RoundRectangle>(this);
|
||||||
|
public JsObject path_element() => ProgrartFunctions.CreateElement<PathElement>(this);
|
||||||
|
public JsObject path() => ProgrartFunctions.CreateElement<Graphics.Path>(this);
|
||||||
public JsObject circle() => ProgrartFunctions.CreateElement<Circle>(this);
|
public JsObject circle() => ProgrartFunctions.CreateElement<Circle>(this);
|
||||||
|
public JsObject oval() => ProgrartFunctions.CreateElement<Oval>(this);
|
||||||
public JsObject triangle() => ProgrartFunctions.CreateElement<Triangle>(this);
|
public JsObject triangle() => ProgrartFunctions.CreateElement<Triangle>(this);
|
||||||
|
|
||||||
public RenderContext RenderImage(int Scale, string script, ExecuteArguments arguments)
|
public RenderContext RenderImage(int Scale, string script, ExecuteArguments arguments)
|
||||||
|
|||||||
Reference in New Issue
Block a user