From 1a98ef62d3999df68065bc2559ec5667a2f1400c Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 13 Nov 2019 22:52:24 +0100 Subject: [PATCH] Fix device ZIndex application --- src/Artemis.Core/Models/Surface/Device.cs | 5 ++++ .../ProfileEditor/ProfileEditorViewModel.cs | 9 +++++-- .../ProfileEditor/ProfileLedViewModel.cs | 20 ++++---------- .../ViewModels/Screens/ModuleRootViewModel.cs | 17 +++++++----- .../Screens/SurfaceEditorViewModel.cs | 7 +++++ .../Views/Screens/ModuleRootView.xaml | 5 ++-- .../Views/Screens/SurfaceEditorView.xaml | 26 +++++++++---------- 7 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/Artemis.Core/Models/Surface/Device.cs b/src/Artemis.Core/Models/Surface/Device.cs index 8bd82320d..0977939ca 100644 --- a/src/Artemis.Core/Models/Surface/Device.cs +++ b/src/Artemis.Core/Models/Surface/Device.cs @@ -114,5 +114,10 @@ namespace Artemis.Core.Models.Surface RgbDevice = null; Surface = null; } + + public override string ToString() + { + return $"[{RgbDevice.DeviceInfo.DeviceType}] {RgbDevice.DeviceInfo.DeviceName} - {X}.{Y}.{ZIndex}"; + } } } \ No newline at end of file diff --git a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs index 19b6bb2aa..0e2b11a75 100644 --- a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs +++ b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs @@ -37,8 +37,6 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor var targetFps = Math.Min(settingsService.GetSetting("TargetFrameRate", 25).Value, 25); _updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / targetFps}; _updateTrigger.Update += UpdateLeds; - - _updateTrigger.Start(); } public ObservableCollection Devices { get; set; } @@ -69,6 +67,13 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor else viewModel.Device = surfaceDeviceConfiguration; } + + // Sort the devices by ZIndex + Execute.OnUIThread(() => + { + foreach (var device in Devices.OrderBy(d => d.ZIndex).ToList()) + Devices.Move(Devices.IndexOf(device), device.ZIndex - 1); + }); } protected override void OnActivate() diff --git a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs index 42e13bb2b..108b746d0 100644 --- a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs +++ b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs @@ -13,8 +13,12 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor public ProfileLedViewModel(Led led) { Led = led; + X = Led.LedRectangle.X; + Y = Led.LedRectangle.Y; + Width = Led.LedRectangle.Width; + Height = Led.LedRectangle.Height; - Execute.OnUIThread(() => { CreateLedGeometry(); }); + Execute.OnUIThread(CreateLedGeometry); } public Led Led { get; } @@ -28,8 +32,6 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor public Geometry StrokeGeometry { get; private set; } public Color DisplayColor { get; private set; } - public string Tooltip => $"{Led.Id} - {Led.LedRectangle}"; - private void CreateLedGeometry() { switch (Led.Shape) @@ -103,18 +105,6 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor if (!DisplayColor.Equals(newColor)) DisplayColor = newColor; }); - - if (Math.Abs(Led.LedRectangle.X - X) > 0.1) - X = Led.LedRectangle.X; - - if (Math.Abs(Led.LedRectangle.Y - Y) > 0.1) - Y = Led.LedRectangle.Y; - - if (Math.Abs(Led.LedRectangle.Width - Width) > 0.1) - Width = Led.LedRectangle.Width; - - if (Math.Abs(Led.LedRectangle.Height - Height) > 0.1) - Height = Led.LedRectangle.Height; } } } \ No newline at end of file diff --git a/src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs b/src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs index b978ddd2b..f2a2abb49 100644 --- a/src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs +++ b/src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs @@ -4,18 +4,23 @@ using Stylet; namespace Artemis.UI.ViewModels.Screens { - public class ModuleRootViewModel : Screen + public class ModuleRootViewModel : Conductor.Collection.OneActive { public ModuleRootViewModel(Module module, IProfileEditorViewModelFactory profileEditorViewModelFactory) { Module = module; - ModuleViewModels = new BindableCollection {profileEditorViewModelFactory.CreateModuleViewModel(Module)}; - ModuleViewModels.AddRange(Module.GetViewModels()); + + // Add the profile editor and module VMs + var profileEditor = profileEditorViewModelFactory.CreateModuleViewModel(Module); + Items.Add(profileEditor); + Items.AddRange(Module.GetViewModels()); + + // Activate the profile editor + ActiveItem = profileEditor; } public Module Module { get; } - public BindableCollection ModuleViewModels { get; set; } - - public int FixedHeaderCount => ModuleViewModels.Count; + + public int FixedHeaderCount => Items.Count; } } \ No newline at end of file diff --git a/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs b/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs index 7d2979125..74a02b95b 100644 --- a/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs +++ b/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs @@ -101,6 +101,13 @@ namespace Artemis.UI.ViewModels.Screens viewModel.Device = surfaceDeviceConfiguration; } + // Sort the devices by ZIndex + Execute.OnUIThread(() => + { + foreach (var device in Devices.OrderBy(d => d.ZIndex).ToList()) + Devices.Move(Devices.IndexOf(device), device.ZIndex - 1); + }); + _surfaceService.SetActiveSurfaceConfiguration(SelectedSurface); } diff --git a/src/Artemis.UI/Views/Screens/ModuleRootView.xaml b/src/Artemis.UI/Views/Screens/ModuleRootView.xaml index e246a6734..cad55cdf7 100644 --- a/src/Artemis.UI/Views/Screens/ModuleRootView.xaml +++ b/src/Artemis.UI/Views/Screens/ModuleRootView.xaml @@ -10,8 +10,7 @@ mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance screens:ModuleRootViewModel}"> - + @@ -19,7 +18,7 @@ - + diff --git a/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml b/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml index cf4a397ea..0a592bc60 100644 --- a/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml +++ b/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml @@ -22,8 +22,9 @@ - - + + + @@ -175,27 +176,24 @@ - - + - - + + - + - + - - + + - +