Added round rectangle, cicle and triangle.
Applied Antialias on most of elements.
This commit is contained in:
80
Progrart.Core/Graphics/Circle.cs
Normal file
80
Progrart.Core/Graphics/Circle.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Progrart.Core.JSExecution;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class Circle : BaseElement
|
||||
{
|
||||
|
||||
float StrokeWidth;
|
||||
SKPoint Position;
|
||||
float 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("Size", 1);
|
||||
__object.Set("IsStroke", true);
|
||||
__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();
|
||||
Size = (float)__object.Get("Size").AsNumber();
|
||||
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
||||
{
|
||||
if (__object.Get("Position") is JsObject Start)
|
||||
{
|
||||
this.Position = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
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 pos = context.TranslatePoint(Position);
|
||||
float Size = context.TranslateSize(this.Size);
|
||||
context.DrawingCore.canvas.DrawCircle(
|
||||
pos.X, pos.Y,
|
||||
Size,
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader,
|
||||
IsStroke = IsStroke,
|
||||
IsAntialias = true
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,8 @@ namespace Progrart.Core.Graphics
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(Size),
|
||||
Shader = shader
|
||||
Shader = shader,
|
||||
IsAntialias = true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,6 @@ namespace Progrart.Core.Graphics
|
||||
LoadProperties();
|
||||
SKPoint FinalStartPos = context.TranslatePoint(Start);
|
||||
SKPoint FinalEndPos = context.TranslatePoint(Size);
|
||||
Trace.WriteLine($"Draw Rectangle from {FinalStartPos} to {FinalEndPos} using {Color} with size of {StrokeWidth}.");
|
||||
context.DrawingCore.canvas.DrawRect(
|
||||
FinalStartPos.X, FinalStartPos.Y,
|
||||
FinalEndPos.X, FinalEndPos.Y,
|
||||
@@ -83,7 +82,8 @@ namespace Progrart.Core.Graphics
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader,
|
||||
IsStroke = true
|
||||
IsStroke = IsStroke,
|
||||
IsAntialias = true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
100
Progrart.Core/Graphics/RoundRectangle.cs
Normal file
100
Progrart.Core/Graphics/RoundRectangle.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Progrart.Core.JSExecution;
|
||||
using SkiaSharp;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class RoundRectangle : BaseElement
|
||||
{
|
||||
|
||||
float StrokeWidth;
|
||||
float rx;
|
||||
float ry;
|
||||
SKPoint Start;
|
||||
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("rx", 0);
|
||||
__object.Set("ry", 0);
|
||||
__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();
|
||||
rx = (float)__object.Get("rx").AsNumber();
|
||||
ry = (float)__object.Get("ry").AsNumber();
|
||||
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
||||
{
|
||||
if (__object.Get("Position") is JsObject Start)
|
||||
{
|
||||
this.Start = 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 Position = context.TranslatePoint(Start);
|
||||
SKPoint Size = context.TranslatePoint(this.Size);
|
||||
float rx = context.TranslateSize(this.rx);
|
||||
float ry = context.TranslateSize(this.ry);
|
||||
Trace.WriteLine($"Draw Rectangle from {Position} to {Size} using {Color} with size of {StrokeWidth}.");
|
||||
context.DrawingCore.canvas.DrawRoundRect(
|
||||
Position.X, Position.Y,
|
||||
Size.X, Size.Y, rx, ry,
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader,
|
||||
IsStroke = IsStroke,
|
||||
IsAntialias = true
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
110
Progrart.Core/Graphics/Triangle.cs
Normal file
110
Progrart.Core/Graphics/Triangle.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using Jint;
|
||||
using Jint.Native;
|
||||
using Progrart.Core.JSExecution;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Progrart.Core.Graphics
|
||||
{
|
||||
public class Triangle : BaseElement
|
||||
{
|
||||
float StrokeWidth;
|
||||
SKPoint Vertex0;
|
||||
SKPoint Vertex1;
|
||||
SKPoint Vertex2;
|
||||
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("Vertex0", point);
|
||||
}
|
||||
{
|
||||
JsObject point = new JsObject(engine);
|
||||
point.Set("x", 0);
|
||||
point.Set("y", 0);
|
||||
__object.Set("Vertex1", point);
|
||||
}
|
||||
{
|
||||
JsObject point = new JsObject(engine);
|
||||
point.Set("x", 0);
|
||||
point.Set("y", 0);
|
||||
__object.Set("Vertex2", point);
|
||||
}
|
||||
__object.Set("StrokeWidth", 1);
|
||||
__object.Set("IsStroke", true);
|
||||
__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();
|
||||
IsStroke = (bool)__object.Get("IsStroke").AsBoolean();
|
||||
{
|
||||
if (__object.Get("Vertex0") is JsObject Start)
|
||||
{
|
||||
this.Vertex0 = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Vertex1") is JsObject Start)
|
||||
{
|
||||
this.Vertex1 = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (__object.Get("Vertex2") is JsObject Start)
|
||||
{
|
||||
this.Vertex2 = ProgrartConversion.ObtainSKPointFromJsObject(Start);
|
||||
}
|
||||
}
|
||||
{
|
||||
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();
|
||||
var v0 = context.TranslatePoint(Vertex0);
|
||||
var v1 = context.TranslatePoint(Vertex1);
|
||||
var v2 = context.TranslatePoint(Vertex2);
|
||||
using var p = new SKPath();
|
||||
p.MoveTo(v0);
|
||||
p.MoveTo(v0);
|
||||
//p.LineTo(v0);
|
||||
p.LineTo(v1);
|
||||
p.LineTo(v2);
|
||||
p.LineTo(v0);
|
||||
p.Close();
|
||||
|
||||
context.DrawingCore.canvas.DrawPath(p,
|
||||
new SKPaint()
|
||||
{
|
||||
ColorF = Color,
|
||||
StrokeWidth = context.TranslateSize(StrokeWidth),
|
||||
Shader = shader,
|
||||
IsStroke = IsStroke,
|
||||
IsAntialias = true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user