Added Oval and Path. Currently Path only have move_to and line_to commands.
This commit is contained in:
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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user