diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj
index d9240f12b..549f6a304 100644
--- a/src/Artemis.Core/Artemis.Core.csproj
+++ b/src/Artemis.Core/Artemis.Core.csproj
@@ -158,8 +158,6 @@
-
-
diff --git a/src/Artemis.Core/Models/Profile/Folder.cs b/src/Artemis.Core/Models/Profile/Folder.cs
index 7ca6f82ee..340a415cb 100644
--- a/src/Artemis.Core/Models/Profile/Folder.cs
+++ b/src/Artemis.Core/Models/Profile/Folder.cs
@@ -72,7 +72,7 @@ namespace Artemis.Core.Models.Profile
public Layer AddLayer(string name)
{
var layer = new Layer(Profile, this, name) {Order = Children.LastOrDefault()?.Order ?? 1};
- layer.LayerShape = new Fill(layer);
+ layer.LayerShape = new Rectangle(layer);
AddChild(layer);
return layer;
}
diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs
index 71afae138..2384236f6 100644
--- a/src/Artemis.Core/Models/Profile/Layer.cs
+++ b/src/Artemis.Core/Models/Profile/Layer.cs
@@ -51,22 +51,13 @@ namespace Artemis.Core.Models.Profile
CreateDefaultProperties();
- switch (layerEntity.ShapeEntity?.Type)
+ switch (layerEntity.ShapeType)
{
case ShapeEntityType.Ellipse:
- LayerShape = new Ellipse(this, layerEntity.ShapeEntity);
- break;
- case ShapeEntityType.Fill:
- LayerShape = new Fill(this, layerEntity.ShapeEntity);
- break;
- case ShapeEntityType.Polygon:
- LayerShape = new Polygon(this, layerEntity.ShapeEntity);
+ LayerShape = new Ellipse(this);
break;
case ShapeEntityType.Rectangle:
- LayerShape = new Rectangle(this, layerEntity.ShapeEntity);
- break;
- case null:
- LayerShape = null;
+ LayerShape = new Rectangle(this);
break;
default:
throw new ArgumentOutOfRangeException();
@@ -175,18 +166,18 @@ namespace Artemis.Core.Models.Profile
var sizeProperty = SizeProperty.CurrentValue;
var rotationProperty = RotationProperty.CurrentValue;
- var anchorPosition = GetLayerAnchorPosition() + Bounds.Location;
+ var anchorPosition = GetLayerAnchorPosition();
var anchorProperty = AnchorPointProperty.CurrentValue;
- // Translation originates from the unscaled center of the shape and is tied to the anchor
- var x = anchorPosition.X - LayerShape.Bounds.MidX - anchorProperty.X * Bounds.Width;
- var y = anchorPosition.Y - LayerShape.Bounds.MidY - anchorProperty.Y * Bounds.Height;
+ // Translation originates from the unscaled center of the layer and is tied to the anchor
+ var x = anchorPosition.X - Bounds.MidX - anchorProperty.X * Bounds.Width;
+ var y = anchorPosition.Y - Bounds.MidY - anchorProperty.Y * Bounds.Height;
- // Apply these before translation because anchorPosition takes translation into account
+ // Rotation is always applied on the canvas
canvas.RotateDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y);
- canvas.Scale(sizeProperty.Width, sizeProperty.Height, anchorPosition.X, anchorPosition.Y);
+ // canvas.Scale(sizeProperty.Width, sizeProperty.Height, anchorPosition.X, anchorPosition.Y);
// Once the other transformations are done it is save to translate
- canvas.Translate(x, y);
+ // canvas.Translate(x, y);
// Placeholder
if (LayerShape?.Path != null)
@@ -200,8 +191,12 @@ namespace Artemis.Core.Models.Profile
testColors.Add(SKColor.FromHsv(0, 100, 100));
}
- var shader = SKShader.CreateSweepGradient(new SKPoint(LayerShape.Bounds.MidX, LayerShape.Bounds.MidY), testColors.ToArray());
- canvas.DrawPath(LayerShape.Path, new SKPaint {Shader = shader, Color = new SKColor(0, 0, 0, (byte) (OpacityProperty.CurrentValue * 2.55f))});
+ var path = new SKPath(LayerShape.Path);
+ path.Transform(SKMatrix.MakeTranslation(x, y));
+ path.Transform(SKMatrix.MakeScale(sizeProperty.Width, sizeProperty.Height, anchorPosition.X, anchorPosition.Y));
+
+ var shader = SKShader.CreateSweepGradient(new SKPoint(path.Bounds.MidX, path.Bounds.MidY), testColors.ToArray());
+ canvas.DrawPath(path, new SKPaint {Shader = shader, Color = new SKColor(0, 0, 0, (byte) (OpacityProperty.CurrentValue * 2.55f))});
}
LayerBrush?.Render(canvas);
@@ -213,7 +208,7 @@ namespace Artemis.Core.Models.Profile
var positionProperty = PositionProperty.CurrentValue;
// Start at the center of the shape
- var position = new SKPoint(LayerShape.Bounds.MidX, LayerShape.Bounds.MidY);
+ var position = new SKPoint(Bounds.MidX, Bounds.MidY);
// Apply translation
position.X += positionProperty.X * Bounds.Width;
diff --git a/src/Artemis.Core/Models/Profile/LayerShapes/Ellipse.cs b/src/Artemis.Core/Models/Profile/LayerShapes/Ellipse.cs
index a046fa45c..58c6a6d9e 100644
--- a/src/Artemis.Core/Models/Profile/LayerShapes/Ellipse.cs
+++ b/src/Artemis.Core/Models/Profile/LayerShapes/Ellipse.cs
@@ -9,21 +9,16 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
}
- internal Ellipse(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
- {
- }
-
public override void CalculateRenderProperties()
{
var path = new SKPath();
- path.AddOval(GetUnscaledRectangle());
+ path.AddOval(Layer.Bounds);
Path = path;
}
- internal override void ApplyToEntity()
+ public override void ApplyToEntity()
{
- base.ApplyToEntity();
- Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Ellipse;
+ Layer.LayerEntity.ShapeType = ShapeEntityType.Ellipse;
}
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/LayerShapes/Fill.cs b/src/Artemis.Core/Models/Profile/LayerShapes/Fill.cs
deleted file mode 100644
index e194c32eb..000000000
--- a/src/Artemis.Core/Models/Profile/LayerShapes/Fill.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Artemis.Storage.Entities.Profile;
-using SkiaSharp;
-
-namespace Artemis.Core.Models.Profile.LayerShapes
-{
- public class Fill : LayerShape
- {
- public Fill(Layer layer) : base(layer)
- {
- }
-
- internal Fill(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
- {
- }
-
- public override void CalculateRenderProperties()
- {
- // Shape originates from the center so compensate the path for that
- Path = new SKPath(Layer.Path);
- }
-
- internal override void ApplyToEntity()
- {
- base.ApplyToEntity();
- Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Fill;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/LayerShapes/LayerShape.cs b/src/Artemis.Core/Models/Profile/LayerShapes/LayerShape.cs
index 538a1b726..7b462a3d7 100644
--- a/src/Artemis.Core/Models/Profile/LayerShapes/LayerShape.cs
+++ b/src/Artemis.Core/Models/Profile/LayerShapes/LayerShape.cs
@@ -1,97 +1,26 @@
-using System.Linq;
-using Artemis.Storage.Entities.Profile;
-using SkiaSharp;
+using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public abstract class LayerShape
{
- private SKPath _path;
-
protected LayerShape(Layer layer)
{
Layer = layer;
}
- protected LayerShape(Layer layer, ShapeEntity shapeEntity)
- {
- Layer = layer;
- ScaledRectangle = SKRect.Create(shapeEntity.X, shapeEntity.Y, shapeEntity.Width, shapeEntity.Height);
- }
-
///
/// The layer this shape is attached to
///
public Layer Layer { get; set; }
- ///
- /// A relative and scaled rectangle that defines where the shape is located in relation to the layer's size
- /// Note: scaled means a range of 0.0 to 1.0. 1.0 being full width/height, 0.5 being half
- ///
- public SKRect ScaledRectangle { get; set; }
-
///
/// A path outlining the shape
///
- public SKPath Path
- {
- get => _path;
- protected set
- {
- _path = value;
- Bounds = value?.Bounds ?? SKRect.Empty;
- }
- }
-
- ///
- /// The bounds of this shape
- ///
- public SKRect Bounds { get; private set; }
+ public SKPath Path { get; protected set; }
public abstract void CalculateRenderProperties();
- ///
- /// Updates Position and Size using the provided unscaled rectangle
- ///
- /// An unscaled rectangle where 1px = 1mm
- public void SetFromUnscaledRectangle(SKRect rect)
- {
- if (!Layer.Leds.Any())
- {
- ScaledRectangle = SKRect.Empty;
- return;
- }
-
- ScaledRectangle = SKRect.Create(
- 100f / Layer.Bounds.Width * rect.Left / 100f,
- 100f / Layer.Bounds.Height * rect.Top / 100f,
- 100f / Layer.Bounds.Width * rect.Width / 100f,
- 100f / Layer.Bounds.Height * rect.Height / 100f
- );
- }
-
- public SKRect GetUnscaledRectangle()
- {
- if (!Layer.Leds.Any())
- return SKRect.Empty;
-
- return SKRect.Create(
- Layer.Bounds.Width * ScaledRectangle.Left,
- Layer.Bounds.Height * ScaledRectangle.Top,
- Layer.Bounds.Width * ScaledRectangle.Width,
- Layer.Bounds.Height * ScaledRectangle.Height
- );
- }
-
- internal virtual void ApplyToEntity()
- {
- Layer.LayerEntity.ShapeEntity = new ShapeEntity
- {
- X = ScaledRectangle.Left,
- Y = ScaledRectangle.Top,
- Width = ScaledRectangle.Width,
- Height = ScaledRectangle.Height
- };
- }
+ public abstract void ApplyToEntity();
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/LayerShapes/Polygon.cs b/src/Artemis.Core/Models/Profile/LayerShapes/Polygon.cs
deleted file mode 100644
index e593b20be..000000000
--- a/src/Artemis.Core/Models/Profile/LayerShapes/Polygon.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using Artemis.Storage.Entities.Profile;
-using SkiaSharp;
-
-namespace Artemis.Core.Models.Profile.LayerShapes
-{
- public class Polygon : LayerShape
- {
- public Polygon(Layer layer) : base(layer)
- {
- }
-
- internal Polygon(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
- {
- }
-
- ///
- /// The points of this polygon
- ///
- public List Points { get; set; }
-
- ///
- /// The points of this polygon where they need to be rendered inside the layer
- ///
- public List RenderPoints
- {
- get { return Points.Select(p => new SKPoint(p.X * Layer.Bounds.Width, p.Y * Layer.Bounds.Height)).ToList(); }
- }
-
- public override void CalculateRenderProperties()
- {
- var path = new SKPath();
- path.AddPoly(RenderPoints.ToArray());
- Path = path;
- }
-
- internal override void ApplyToEntity()
- {
- base.ApplyToEntity();
- Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Polygon;
- Layer.LayerEntity.ShapeEntity.Points = Points.Select(p => new ShapePointEntity {X = p.X, Y = p.Y}).ToList();
- }
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/LayerShapes/Rectangle.cs b/src/Artemis.Core/Models/Profile/LayerShapes/Rectangle.cs
index bc568a7fb..740b6f5b9 100644
--- a/src/Artemis.Core/Models/Profile/LayerShapes/Rectangle.cs
+++ b/src/Artemis.Core/Models/Profile/LayerShapes/Rectangle.cs
@@ -9,21 +9,16 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{
}
- internal Rectangle(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
- {
- }
-
public override void CalculateRenderProperties()
{
var path = new SKPath();
- path.AddRect(GetUnscaledRectangle());
+ path.AddRect(Layer.Bounds);
Path = path;
}
- internal override void ApplyToEntity()
+ public override void ApplyToEntity()
{
- base.ApplyToEntity();
- Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Rectangle;
+ Layer.LayerEntity.ShapeType = ShapeEntityType.Rectangle;
}
}
}
\ No newline at end of file
diff --git a/src/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs b/src/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs
index fb8d3283e..c6245906d 100644
--- a/src/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs
+++ b/src/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs
@@ -35,7 +35,7 @@ namespace Artemis.Plugins.LayerBrushes.Color
private void CreateShader()
{
- var center = new SKPoint(Layer.LayerShape.Bounds.MidX, Layer.LayerShape.Bounds.MidY);
+ var center = new SKPoint(Layer.Bounds.MidX, Layer.Bounds.MidY);
SKShader shader;
switch (Settings.GradientType)
{
@@ -43,10 +43,10 @@ namespace Artemis.Plugins.LayerBrushes.Color
shader = SKShader.CreateColor(_testColors.First());
break;
case GradientType.LinearGradient:
- shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(Layer.LayerShape.Bounds.Width, 0), _testColors.ToArray(), SKShaderTileMode.Repeat);
+ shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(Layer.Bounds.Width, 0), _testColors.ToArray(), SKShaderTileMode.Repeat);
break;
case GradientType.RadialGradient:
- shader = SKShader.CreateRadialGradient(center, Math.Min(Layer.LayerShape.Bounds.Width, Layer.LayerShape.Bounds.Height), _testColors.ToArray(), SKShaderTileMode.Repeat);
+ shader = SKShader.CreateRadialGradient(center, Math.Min(Layer.Bounds.Width, Layer.Bounds.Height), _testColors.ToArray(), SKShaderTileMode.Repeat);
break;
case GradientType.SweepGradient:
shader = SKShader.CreateSweepGradient(center, _testColors.ToArray(), null, SKShaderTileMode.Clamp, 0, 360);
diff --git a/src/Artemis.Storage/Entities/Profile/LayerEntity.cs b/src/Artemis.Storage/Entities/Profile/LayerEntity.cs
index a67b54b44..bf11bd782 100644
--- a/src/Artemis.Storage/Entities/Profile/LayerEntity.cs
+++ b/src/Artemis.Storage/Entities/Profile/LayerEntity.cs
@@ -23,7 +23,7 @@ namespace Artemis.Storage.Entities.Profile
public List PropertyEntities { get; set; }
public List Condition { get; set; }
- public ShapeEntity ShapeEntity { get; set; }
+ public ShapeEntityType ShapeType { get; set; }
public BrushEntity BrushEntity { get; set; }
[BsonRef("ProfileEntity")]
@@ -31,4 +31,10 @@ namespace Artemis.Storage.Entities.Profile
public Guid ProfileId { get; set; }
}
+
+ public enum ShapeEntityType
+ {
+ Ellipse,
+ Rectangle
+ }
}
\ No newline at end of file
diff --git a/src/Artemis.Storage/Entities/Profile/ShapeEntity.cs b/src/Artemis.Storage/Entities/Profile/ShapeEntity.cs
deleted file mode 100644
index e8d07ca68..000000000
--- a/src/Artemis.Storage/Entities/Profile/ShapeEntity.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System.Collections.Generic;
-
-namespace Artemis.Storage.Entities.Profile
-{
- public class ShapeEntity
- {
- public float X { get; set; }
- public float Y { get; set; }
- public float Width { get; set; }
- public float Height { get; set; }
- public ShapeEntityType Type { get; set; }
- public List Points { get; set; }
- }
-
- public class ShapePointEntity
- {
- public float X { get; set; }
- public float Y { get; set; }
- }
-
- public enum ShapeEntityType
- {
- Ellipse,
- Fill,
- Polygon,
- Rectangle
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj
index bb8c3118c..426741974 100644
--- a/src/Artemis.UI/Artemis.UI.csproj
+++ b/src/Artemis.UI/Artemis.UI.csproj
@@ -189,22 +189,6 @@
-
- EllipseToolView.xaml
-
-
-
- FillToolView.xaml
-
-
-
- PolygonToolView.xaml
-
-
-
- RectangleToolView.xaml
-
-
SelectionRemoveToolView.xaml
@@ -374,22 +358,6 @@
Designer
MSBuild:Compile
-
- Designer
- MSBuild:Compile
-
-
- Designer
- MSBuild:Compile
-
-
- Designer
- MSBuild:Compile
-
-
- Designer
- MSBuild:Compile
-
Designer
MSBuild:Compile
diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLayerView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLayerView.xaml
index 804079a70..589442a93 100644
--- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLayerView.xaml
+++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLayerView.xaml
@@ -32,35 +32,33 @@