Implemented ellipse shape application

This commit is contained in:
SpoinkyNL committed 2019-12-17 22:42:17 +01:00
1 parent 94df1544c5
commit 8dc15f6894
11 files changed
+104 -54

No files matched your search

@@ -10,23 +10,23 @@
<!-- The part of the layer's shape that falls outside the layer -->
<Path Data="{Binding ShapeGeometry, Mode=OneWay}" >
<Path.Fill>
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.25" />
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.05" />
</Path.Fill>
<Path.Stroke>
<SolidColorBrush Color="{StaticResource Accent700}" />
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.15" />
</Path.Stroke>
</Path>
<!-- The part of the layer's shape that is inside the layer -->
<Path Data="{Binding ShapeGeometry, Mode=OneWay}" >
<Path.Fill>
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.25" />
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.35" />
</Path.Fill>
<Path.Stroke>
<SolidColorBrush Color="{StaticResource Accent700}" />
</Path.Stroke>
<Path.OpacityMask>
<VisualBrush >
<VisualBrush Viewport="{Binding ViewportRectangle}" ViewportUnits="Absolute">
<VisualBrush.Visual>
<Path Data="{Binding LayerGeometry, Mode=OneWay}" ClipToBounds="False" Fill="Black" />
</VisualBrush.Visual>
@@ -7,6 +7,7 @@ using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.Core.Models.Surface;
using Artemis.UI.Extensions;
using RGB.NET.Core;
using SkiaSharp.Views.WPF;
using Rectangle = Artemis.Core.Models.Profile.LayerShapes.Rectangle;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
@@ -85,17 +86,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
return;
}
var x = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.X);
var y = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.Y);
var width = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.X + l.RgbLed.AbsoluteLedRectangle.Size.Width) - x;
var height = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y;
var rect = new Rect(
x + width * Layer.LayerShape.Position.X,
y + height * Layer.LayerShape.Position.Y,
width * Layer.LayerShape.Size.Width,
height * Layer.LayerShape.Size.Height
);
var skRect = Layer.LayerShape.GetUnscaledRectangle();
var rect = new Rect(skRect.Left, skRect.Top, skRect.Width, skRect.Height);
var shapeGeometry = Geometry.Empty;
switch (Layer.LayerShape)
{
@@ -121,17 +113,20 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
private void CreateViewportRectangle()
{
if (!Layer.Leds.Any())
if (!Layer.Leds.Any() || Layer.LayerShape == null)
{
ViewportRectangle = Rect.Empty;
return;
}
var x = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.X);
var y = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.Y);
var width = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.X + l.RgbLed.AbsoluteLedRectangle.Size.Width) - x;
var height = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y;
ViewportRectangle = new Rect(x - x * Layer.LayerShape.Position.X, y - y * Layer.LayerShape.Position.Y, width, height);
var rect = new Rect(x, y, width, height);
ViewportRectangle = rect;
}
private Geometry CreateRectangleGeometry(ArtemisLed led)
@@ -183,7 +183,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
lock (CanvasViewModels)
{
foreach (var device in Devices.OrderBy(d => d.ZIndex).ToList())
CanvasViewModels.Move(CanvasViewModels.IndexOf(device), device.ZIndex - 1);
{
var newIndex = Math.Max(device.ZIndex - 1, CanvasViewModels.Count - 1);
CanvasViewModels.Move(CanvasViewModels.IndexOf(device), newIndex);
}
}
});
}
@@ -7,6 +7,7 @@ using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.UI.Properties;
using Artemis.UI.Services.Interfaces;
using SkiaSharp;
using SkiaSharp.Views.WPF;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
@@ -44,8 +45,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
if (ProfileEditorService.SelectedProfileElement is Layer layer)
{
GetShapePosition(out var point, out var size);
layer.LayerShape = new Ellipse(layer) {Size = size, Position = point};
if (!(layer.LayerShape is Ellipse))
layer.LayerShape = new Ellipse(layer);
layer.LayerShape.SetFromUnscaledRectangle(DragRectangle.ToSKRect());
ProfileEditorService.UpdateSelectedProfileElement();
}
}
@@ -65,25 +67,5 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
_shiftDown = true;
}
private void GetShapePosition(out SKPoint point, out SKSize size)
{
var layer = (Layer) ProfileEditorService.SelectedProfileElement;
var x = layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.X);
var y = layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.Y);
var width = layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.X + l.RgbLed.AbsoluteLedRectangle.Size.Width) - x;
var height = layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y;
var widthScale = width / 100f;
var heightScale = height / 100f;
var rect = new Rect(
x - width / DragRectangle.X,
y - height / DragRectangle.Y,
width / DragRectangle.Width,
height / DragRectangle.Height
);
point = new SKPoint(0.5f,0.5f);
size = new SKSize((float) (DragRectangle.Width * widthScale), (float) (DragRectangle.Height * heightScale));
}
}
}
@@ -7,6 +7,7 @@ using Artemis.Core.Models.Surface;
using Artemis.UI.Extensions;
using Artemis.UI.Properties;
using Artemis.UI.Services.Interfaces;
using SkiaSharp;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
@@ -46,8 +47,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
// Apply the selection to the selected layer layer
if (ProfileEditorService.SelectedProfileElement is Layer layer)
{
// If the layer has a shape, save it's size
var shapeSize = SKRect.Empty;
if (layer.LayerShape != null)
shapeSize = layer.LayerShape.GetUnscaledRectangle();
layer.ClearLeds();
layer.AddLeds(selectedLeds);
// Restore the saved size
if (layer.LayerShape != null)
layer.LayerShape.SetFromUnscaledRectangle(shapeSize);
ProfileEditorService.UpdateSelectedProfileElement();
}
// If no layer selected, apply it to a new layer in the selected folder