diff --git a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs b/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs index 29f5745c4..0d1a6d16a 100644 --- a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs +++ b/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs @@ -1,11 +1,13 @@ using System; using System.Windows; using System.Windows.Media; +using System.Windows.Shapes; using RGB.NET.Core; using SharpVectors.Converters; using SharpVectors.Renderers.Wpf; using Stylet; using Color = System.Windows.Media.Color; +using Shape = RGB.NET.Core.Shape; namespace Artemis.UI.ViewModels.Controls.RgbDevice { @@ -37,35 +39,33 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice private void CreateLedGeometry() { - // Prepare the SVG for this LED - var converter = new FileSvgReader(new WpfDrawingSettings {OptimizePath = true}); - if (Led.Image != null) + var relativeRectangle = new Rect(0, 0, Led.LedRectangle.Width, Led.LedRectangle.Height); + Geometry geometry; + switch (Led.Shape) { - DisplayDrawing = new DrawingImage(converter.Read(Led.Image)); + case Shape.Custom: + geometry = Geometry.Parse(Led.ShapeData); + break; + case Shape.Rectangle: + geometry = new RectangleGeometry(relativeRectangle, 2, 2); + break; + case Shape.Circle: + geometry = new EllipseGeometry(relativeRectangle); + break; + default: + throw new ArgumentOutOfRangeException(); } - else - { - var relativeRectangle = new Rect(0, 0, Led.LedRectangle.Width, Led.LedRectangle.Height); - Geometry geometry; - switch (Led.Shape) - { - case Shape.Custom: - geometry = Geometry.Parse(Led.ShapeData); - break; - case Shape.Rectangle: - geometry = new RectangleGeometry(relativeRectangle, 2, 2); - break; - case Shape.Circle: - geometry = new EllipseGeometry(relativeRectangle); - break; - default: - throw new ArgumentOutOfRangeException(); - } + var drawing = new GeometryDrawing(null, new Pen(null, 2), geometry); - var drawing = new GeometryDrawing(null, new Pen(null, 2), geometry); - DisplayDrawing = new DrawingImage(drawing); + // The pen needs some adjustments when drawing custom shapes, a thickness of 2 just means you get a very thick pen that covers the + // entire shape.. I'm not sure why to be honest sssh don't tell + if (Led.Shape == Shape.Custom) + { + drawing.Pen.Thickness = 0.075; + drawing.Pen.LineJoin = PenLineJoin.Round; } + DisplayDrawing = new DrawingImage(drawing); NotifyOfPropertyChange(() => DisplayDrawing); } @@ -80,21 +80,25 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice FillColor = newFillColor; changed = true; } + if (Math.Abs(Led.LedRectangle.X - X) > 0.1) { X = Led.LedRectangle.X; changed = true; } + if (Math.Abs(Led.LedRectangle.Y - Y) > 0.1) { Y = Led.LedRectangle.Y; changed = true; } + if (Math.Abs(Led.LedRectangle.Width - Width) > 0.1) { Width = Led.LedRectangle.Width; changed = true; } + if (Math.Abs(Led.LedRectangle.Height - Height) > 0.1) { Height = Led.LedRectangle.Height; @@ -107,13 +111,12 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice { if (DisplayDrawing.Drawing is GeometryDrawing geometryDrawing) { - geometryDrawing.Brush = new SolidColorBrush(FillColor) {Opacity = 0.6}; + geometryDrawing.Brush = new SolidColorBrush(FillColor) {Opacity = 0.3}; geometryDrawing.Pen.Brush = new SolidColorBrush(FillColor); } - else if (DisplayDrawing.Drawing is DrawingGroup drawingGroup) - drawingGroup.OpacityMask = new SolidColorBrush(FillColor); + + NotifyOfPropertyChange(() => DisplayDrawing); }); - NotifyOfPropertyChange(() => DisplayDrawing); } } } diff --git a/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml b/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml index 699fe70b4..13da70e30 100644 --- a/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml +++ b/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml @@ -9,6 +9,7 @@ d:DataContext="{d:DesignInstance rgbDevice:RgbDeviceViewModel}" d:DesignHeight="450" d:DesignWidth="800"> + @@ -27,5 +28,6 @@ + \ No newline at end of file