mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Support custom LED shape drawing in editor
This commit is contained in:
parent
090c726880
commit
6ea6f57ee8
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
d:DataContext="{d:DesignInstance rgbDevice:RgbDeviceViewModel}"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<Image Source="{Binding Device.DeviceInfo.Image}"></Image>
|
||||
<ItemsControl ItemsSource="{Binding Leds}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
@ -27,5 +28,6 @@
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
Loading…
x
Reference in New Issue
Block a user