UI - Added reusable device visualizer

Settings - Show device LED images in settings
Editor - Improved performance on big surfaces
This commit is contained in:
SpoinkyNL committed 2020-04-15 19:50:46 +02:00
1 parent 8a45039863
commit efa0f28231
31 files changed
+407 -402

No files matched your search

@@ -7,6 +7,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:converters="clr-namespace:Artemis.UI.Converters"
xmlns:surfaceEditor="clr-namespace:Artemis.UI.Screens.SurfaceEditor.Visualization"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance {x:Type surfaceEditor:SurfaceDeviceViewModel}}"
d:DesignHeight="450" d:DesignWidth="800"
@@ -25,10 +26,7 @@
<RotateTransform Angle="{Binding Device.Rotation}" />
</Grid.LayoutTransform>
<!-- Device image with fallback -->
<Image VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" />
<controls:DeviceVisualizer Device="{Binding Device}"></controls:DeviceVisualizer>
<Rectangle Fill="{DynamicResource MaterialDesignCardBackground}"
Stroke="{DynamicResource MaterialDesignTextBoxBorder}"
@@ -40,26 +38,6 @@
VerticalAlignment="Center"
TextWrapping="Wrap"
TextAlignment="Center" />
<!-- LEDs -->
<ItemsControl ItemsSource="{Binding Leds}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Canvas.Left" Value="{Binding X}" />
<Setter Property="Canvas.Top" Value="{Binding Y}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl s:View.Model="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<!-- Selection rectangle -->
@@ -9,28 +9,18 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
{
public class SurfaceDeviceViewModel : PropertyChangedBase
{
private readonly List<SurfaceLedViewModel> _leds;
private double _dragOffsetX;
private double _dragOffsetY;
public SurfaceDeviceViewModel(ArtemisDevice device)
{
Device = device;
_leds = new List<SurfaceLedViewModel>();
if (Device.RgbDevice != null)
{
foreach (var led in Device.RgbDevice)
_leds.Add(new SurfaceLedViewModel(led));
}
}
public ArtemisDevice Device { get; set; }
public SelectionStatus SelectionStatus { get; set; }
public Cursor Cursor { get; set; }
public IReadOnlyCollection<SurfaceLedViewModel> Leds => _leds.AsReadOnly();
public Rect DeviceRectangle => Device.RgbDevice == null
? new Rect()
: new Rect(Device.X, Device.Y, Device.RgbDevice.DeviceRectangle.Size.Width, Device.RgbDevice.DeviceRectangle.Size.Height);
@@ -1,21 +0,0 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Converters="clr-namespace:Artemis.UI.Converters"
xmlns:surfaceEditor="clr-namespace:Artemis.UI.Screens.SurfaceEditor.Visualization"
x:Class="Artemis.UI.Screens.SurfaceEditor.Visualization.SurfaceLedView"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance {x:Type surfaceEditor:SurfaceLedViewModel}}"
d:DesignHeight="25" d:DesignWidth="25">
<UserControl.Resources>
<Converters:NullToImageConverter x:Key="NullToImageConverter" />
</UserControl.Resources>
<Grid Width="{Binding Width}" Height="{Binding Height}">
<Grid.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center" Stretch="Fill"
ImageSource="{Binding Led.Image, Converter={StaticResource NullToImageConverter}}" />
</Grid.Background>
</Grid>
</UserControl>
@@ -1,38 +0,0 @@
using System.ComponentModel;
using RGB.NET.Core;
using Stylet;
namespace Artemis.UI.Screens.SurfaceEditor.Visualization
{
public class SurfaceLedViewModel : PropertyChangedBase
{
public SurfaceLedViewModel(Led led)
{
Led = led;
ApplyLedToViewModel();
Led.PropertyChanged += ApplyViewModelOnLedChange;
}
public Led Led { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public void ApplyLedToViewModel()
{
// Don't want ActualLocation here since rotation is done in XAML
X = Led.Location.X * Led.Device.Scale.Horizontal;
Y = Led.Location.Y * Led.Device.Scale.Vertical;
Width = Led.ActualSize.Width;
Height = Led.ActualSize.Height;
}
private void ApplyViewModelOnLedChange(object sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == "Location" || args.PropertyName == "ActualSize") ApplyLedToViewModel();
}
}
}