1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Surface editor - Display temporary color in device list

This commit is contained in:
Robert 2021-02-20 23:13:28 +01:00
parent b154badd9c
commit 0464abfafe
4 changed files with 98 additions and 100 deletions

View File

@ -234,11 +234,7 @@
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="1" Grid.Column="2" VerticalAlignment="Stretch" Margin="5,0,0,0">
<materialDesign:DialogHost Identifier="SurfaceListDialogHost" DialogTheme="Inherit" CloseOnClickAway="True">
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox Grid.Row="0" HorizontalContentAlignment="Stretch" ItemsSource="{Binding ListDeviceViewModels}" SelectionMode="Multiple">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
@ -299,16 +295,6 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Grid.Row="0"
Style="{StaticResource MaterialDesignFloatingActionButton}"
Command="{s:Action AddSurfaceConfiguration}"
Margin="0 0 10 10"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
ToolTip="Add a new surface layout">
<materialDesign:PackIcon Kind="Add" Height="24" Width="24" />
</Button>
</Grid>
</materialDesign:DialogHost>
</materialDesign:Card>

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
@ -24,17 +23,16 @@ namespace Artemis.UI.Screens.SurfaceEditor
{
public class SurfaceEditorViewModel : Screen, IMainScreenViewModel
{
private readonly IDeviceService _deviceService;
private readonly IInputService _inputService;
private readonly IDialogService _dialogService;
private readonly IRgbService _rgbService;
private readonly ICoreService _coreService;
private readonly IDeviceService _deviceService;
private readonly IDialogService _dialogService;
private readonly IInputService _inputService;
private readonly IRgbService _rgbService;
private readonly ISettingsService _settingsService;
private Cursor _cursor;
private PanZoomViewModel _panZoomViewModel;
private RectangleGeometry _selectionRectangle;
private PluginSetting<GridLength> _surfaceListWidth;
private List<ArtemisDevice> _shuffledDevices;
public SurfaceEditorViewModel(IRgbService rgbService,
ICoreService coreService,
@ -113,17 +111,9 @@ namespace Artemis.UI.Screens.SurfaceEditor
private void CoreServiceOnFrameRendering(object sender, FrameRenderingEventArgs e)
{
float amount = 360f / _shuffledDevices.Count;
for (int i = 0; i < _shuffledDevices.Count; i++)
{
ArtemisDevice rgbServiceDevice = _shuffledDevices[i];
foreach (ArtemisLed artemisLed in rgbServiceDevice.Leds)
{
SKColor color = SKColor.FromHsv(amount * i, 100, 100);
e.Canvas.DrawRect(artemisLed.AbsoluteRectangle, new SKPaint(){Color = color});
}
}
foreach (ListDeviceViewModel listDeviceViewModel in ListDeviceViewModels)
foreach (ArtemisLed artemisLed in listDeviceViewModel.Device.Leds)
e.Canvas.DrawRect(artemisLed.AbsoluteRectangle, new SKPaint {Color = listDeviceViewModel.Color});
}
#region Overrides of Screen
@ -133,7 +123,15 @@ namespace Artemis.UI.Screens.SurfaceEditor
LoadWorkspaceSettings();
SurfaceDeviceViewModels.AddRange(_rgbService.EnabledDevices.OrderBy(d => d.ZIndex).Select(d => new SurfaceDeviceViewModel(d, _rgbService)));
ListDeviceViewModels.AddRange(_rgbService.EnabledDevices.OrderBy(d => d.ZIndex * -1).Select(d => new ListDeviceViewModel(d)));
_shuffledDevices = _rgbService.EnabledDevices.OrderBy(d => Guid.NewGuid()).ToList();
List<ArtemisDevice> shuffledDevices = _rgbService.EnabledDevices.OrderBy(d => Guid.NewGuid()).ToList();
float amount = 360f / shuffledDevices.Count;
for (int i = 0; i < shuffledDevices.Count; i++)
{
ArtemisDevice rgbServiceDevice = shuffledDevices[i];
ListDeviceViewModel vm = ListDeviceViewModels.First(l => l.Device == rgbServiceDevice);
vm.Color = SKColor.FromHsv(amount * i, 100, 100);
}
_coreService.FrameRendering += CoreServiceOnFrameRendering;
@ -169,6 +167,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
SurfaceDeviceViewModel deviceViewModel = SurfaceDeviceViewModels[i];
deviceViewModel.Device.ZIndex = i + 1;
}
ListDeviceViewModels.Sort(l => l.Device.ZIndex * -1);
_rgbService.SaveDevices();
@ -186,6 +185,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
SurfaceDeviceViewModel deviceViewModel = SurfaceDeviceViewModels[i];
deviceViewModel.Device.ZIndex = i + 1;
}
ListDeviceViewModels.Sort(l => l.Device.ZIndex * -1);
_rgbService.SaveDevices();
@ -200,6 +200,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
SurfaceDeviceViewModel deviceViewModel = SurfaceDeviceViewModels[i];
deviceViewModel.Device.ZIndex = i + 1;
}
ListDeviceViewModels.Sort(l => l.Device.ZIndex * -1);
_rgbService.SaveDevices();
@ -216,6 +217,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
SurfaceDeviceViewModel deviceViewModel = SurfaceDeviceViewModels[i];
deviceViewModel.Device.ZIndex = i + 1;
}
ListDeviceViewModels.Sort(l => l.Device.ZIndex * -1);
_rgbService.SaveDevices();
@ -299,10 +301,8 @@ namespace Artemis.UI.Screens.SurfaceEditor
if (device.SelectionStatus != SelectionStatus.Selected)
{
if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
{
foreach (SurfaceDeviceViewModel others in SurfaceDeviceViewModels)
others.SelectionStatus = SelectionStatus.None;
}
device.SelectionStatus = SelectionStatus.Selected;
}
@ -329,13 +329,11 @@ namespace Artemis.UI.Screens.SurfaceEditor
RectangleGeometry selectedRect = new(new Rect(_mouseDragStartPoint, position));
List<SurfaceDeviceViewModel> devices = HitTestUtilities.GetHitViewModels<SurfaceDeviceViewModel>((Visual) sender, selectedRect);
foreach (SurfaceDeviceViewModel device in SurfaceDeviceViewModels)
{
if (devices.Contains(device))
device.SelectionStatus = SelectionStatus.Selected;
else if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
device.SelectionStatus = SelectionStatus.None;
}
}
else
{
_rgbService.SaveDevices();
@ -356,12 +354,10 @@ namespace Artemis.UI.Screens.SurfaceEditor
List<SurfaceDeviceViewModel> devices = HitTestUtilities.GetHitViewModels<SurfaceDeviceViewModel>((Visual) sender, SelectionRectangle);
foreach (SurfaceDeviceViewModel device in SurfaceDeviceViewModels)
{
if (devices.Contains(device))
device.SelectionStatus = SelectionStatus.Selected;
else if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
device.SelectionStatus = SelectionStatus.None;
}
ApplySurfaceSelection();
}

View File

@ -8,16 +8,24 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type local:ListDeviceViewModel}}">
<UserControl.Resources>
<shared:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<shared:DeviceVisualizer Device="{Binding Device}" Width="30" Height="30" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" />
<StackPanel Grid.Column="1" VerticalAlignment="Center" >
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="{Binding Device.RgbDevice.DeviceInfo.Model}" />
<TextBlock Text="{Binding Device.RgbDevice.DeviceInfo.Manufacturer}" Foreground="{DynamicResource MaterialDesignBodyLight}" />
</StackPanel>
<Ellipse Grid.Column="2" Width="20" Height="20" Stroke="{DynamicResource MaterialDesignBody}" StrokeThickness="1">
<Ellipse.Fill>
<SolidColorBrush Color="{Binding Color, Converter={StaticResource SKColorToColorConverter}}" />
</Ellipse.Fill>
</Ellipse>
</Grid>
</UserControl>

View File

@ -1,4 +1,5 @@
using Artemis.Core;
using SkiaSharp;
using Stylet;
namespace Artemis.UI.Screens.SurfaceEditor.Visualization
@ -6,6 +7,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
public class ListDeviceViewModel : PropertyChangedBase
{
private bool _isSelected;
private SKColor _color;
public ArtemisDevice Device { get; }
public bool IsSelected
@ -14,6 +16,12 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
set => SetAndNotify(ref _isSelected, value);
}
public SKColor Color
{
get => _color;
set => SetAndNotify(ref _color, value);
}
public ListDeviceViewModel(ArtemisDevice device)
{
Device = device;