From bdeeda44c3a8d094a1fa708097e5484751fbf443 Mon Sep 17 00:00:00 2001 From: Creeper Lv Date: Fri, 26 Dec 2025 03:06:15 +1100 Subject: [PATCH] Working on the rendering of visual root. --- Progrart.Core/Graphics/Line.cs | 16 ++++++++- Progrart.Core/Graphics/VisualRoot.cs | 50 ++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/Progrart.Core/Graphics/Line.cs b/Progrart.Core/Graphics/Line.cs index 81d8a9f..db58be1 100644 --- a/Progrart.Core/Graphics/Line.cs +++ b/Progrart.Core/Graphics/Line.cs @@ -44,6 +44,20 @@ namespace Progrart.Core.Graphics if (__object is not null) { Size = (float)__object.Get("Size").AsNumber(); + { + if (__object.Get("Start") is JsObject Start) + { + StartX = (float)Start.Get("x").AsNumber(); + StartY = (float)Start.Get("y").AsNumber(); + } + } + { + if (__object.Get("End") is JsObject End) + { + EndX = (float)End.Get("x").AsNumber(); + EndY = (float)End.Get("y").AsNumber(); + } + } } } public override void Render(RenderContext context) @@ -56,7 +70,7 @@ namespace Progrart.Core.Graphics { ColorF = new SkiaSharp.SKColorF(ColorR, ColorG, ColorB, ColorA), StrokeWidth = Size, - + } ); diff --git a/Progrart.Core/Graphics/VisualRoot.cs b/Progrart.Core/Graphics/VisualRoot.cs index a8fc46a..c8531f3 100644 --- a/Progrart.Core/Graphics/VisualRoot.cs +++ b/Progrart.Core/Graphics/VisualRoot.cs @@ -8,13 +8,54 @@ namespace Progrart.Core.Graphics } public class VisualRoot : BaseElement { + float w; + float h; + float tx; + float ty; + float scale; + float rotate; + void Transform(RenderContext context) + { + 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); + } + void Untransform(RenderContext context) + { + context.canvas.Scale(scale, 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); + } + public override void LoadProperties() + { + base.LoadProperties(); + if (__object is null) return; + { + if (__object.Get("translate") is JsObject translate) + { + tx = (float)translate.Get("x").AsNumber(); + ty = (float)translate.Get("y").AsNumber(); + } + } + { + scale = (float)__object.Get("scale").AsNumber(); + } + { + scale = (float)__object.Get("rotation").AsNumber(); + } + w = (float)__object.Get("width").AsNumber(); + h = (float)__object.Get("height").AsNumber(); + } public override void Render(RenderContext context) { base.Render(context); + this.LoadProperties(); + Transform(context); foreach (var item in Children) { item.Render(context); } + Untransform(context); } public override void SetupProperties(Engine engine) { @@ -28,16 +69,13 @@ namespace Progrart.Core.Graphics __object.Set("translate", point); } { - JsObject point = new JsObject(engine); - point.Set("x", 0); - point.Set("y", 0); - __object.Set("scale", point); + __object.Set("scale", 1); } { __object.Set("rotation", 0); } - __object.Set("Width", 1); - __object.Set("Height", 1); + __object.Set("width", 1); + __object.Set("height", 1); } } }