mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Fix shape positioning on layer LED selection change
This commit is contained in:
1 parent
5a44e5fbe8
commit
0794966e38
14 files changed
+89
-50
No files matched your search
@@ -179,8 +179,7 @@ namespace Artemis.Core.Models.Profile
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = position.X * AbsoluteRectangle.Width - LayerShape.RenderRectangle.Width / 2 - relativeAnchor.X;
|
||||
var y = position.Y * AbsoluteRectangle.Height - LayerShape.RenderRectangle.Height / 2 - relativeAnchor.Y;
|
||||
|
||||
|
||||
|
||||
canvas.RotateDegrees(rotation, anchor.X, anchor.Y);
|
||||
canvas.Scale(size.Width, size.Height, anchor.X, anchor.Y);
|
||||
canvas.Translate(x, y);
|
||||
|
||||
@@ -15,14 +15,15 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
|
||||
public override void CalculateRenderProperties()
|
||||
{
|
||||
RenderRectangle = GetUnscaledRectangle();
|
||||
|
||||
var unscaled = GetUnscaledRectangle();
|
||||
RenderRectangle = SKRect.Create(0,0 , unscaled.Width, unscaled.Height);
|
||||
|
||||
var path = new SKPath();
|
||||
path.AddOval(RenderRectangle);
|
||||
RenderPath = path;
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
base.ApplyToEntity();
|
||||
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Ellipse;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
RenderPath = renderPath;
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
base.ApplyToEntity();
|
||||
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Fill;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
@@ -41,18 +41,27 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
|
||||
public abstract void CalculateRenderProperties();
|
||||
|
||||
public virtual void ApplyToEntity()
|
||||
/// <summary>
|
||||
/// Updates Position and Size using the provided unscaled rectangle
|
||||
/// </summary>
|
||||
/// <param name="rect">An unscaled rectangle where 1px = 1mm</param>
|
||||
public void SetFromUnscaledRectangle(SKRect rect)
|
||||
{
|
||||
Layer.LayerEntity.ShapeEntity = new ShapeEntity
|
||||
if (!Layer.Leds.Any())
|
||||
{
|
||||
X = ScaledRectangle.Left,
|
||||
Y = ScaledRectangle.Top,
|
||||
Width = ScaledRectangle.Width,
|
||||
Height = ScaledRectangle.Height
|
||||
};
|
||||
ScaledRectangle = SKRect.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
ScaledRectangle = SKRect.Create(
|
||||
100f / Layer.AbsoluteRectangle.Width * (rect.Left - Layer.AbsoluteRectangle.Left) / 100f,
|
||||
100f / Layer.AbsoluteRectangle.Height * (rect.Top - Layer.AbsoluteRectangle.Top) / 100f,
|
||||
100f / Layer.AbsoluteRectangle.Width * rect.Width / 100f,
|
||||
100f / Layer.AbsoluteRectangle.Height * rect.Height / 100f
|
||||
);
|
||||
}
|
||||
|
||||
protected SKRect GetUnscaledRectangle()
|
||||
public SKRect GetUnscaledRectangle()
|
||||
{
|
||||
if (!Layer.Leds.Any())
|
||||
return SKRect.Empty;
|
||||
@@ -64,5 +73,16 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
Layer.AbsoluteRectangle.Height * ScaledRectangle.Height
|
||||
);
|
||||
}
|
||||
|
||||
internal virtual void ApplyToEntity()
|
||||
{
|
||||
Layer.LayerEntity.ShapeEntity = new ShapeEntity
|
||||
{
|
||||
X = ScaledRectangle.Left,
|
||||
Y = ScaledRectangle.Top,
|
||||
Width = ScaledRectangle.Width,
|
||||
Height = ScaledRectangle.Height
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
RenderRectangle = path.GetRect();
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
base.ApplyToEntity();
|
||||
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Polygon;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
RenderPath = path;
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
base.ApplyToEntity();
|
||||
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Rectangle;
|
||||
|
||||
Reference in new issue
Block a user