From 5ef6c4b8a7b459e0dfc36db8bfc2bfe227d4ef41 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Wed, 21 Jun 2023 23:07:56 +0100 Subject: [PATCH] Made the UI save automatically, removed apply and reset buttons --- .../Device/Tabs/DeviceGeneralTabView.axaml | 207 ++---------------- .../Device/Tabs/DeviceGeneralTabViewModel.cs | 67 +++--- 2 files changed, 55 insertions(+), 219 deletions(-) diff --git a/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabView.axaml b/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabView.axaml index a62df0f73..5512743c0 100644 --- a/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabView.axaml +++ b/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabView.axaml @@ -5,7 +5,7 @@ xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia" xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared" xmlns:device="clr-namespace:Artemis.UI.Screens.Device" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="1450" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="650" x:Class="Artemis.UI.Screens.Device.DeviceGeneralTabView" x:DataType="device:DeviceGeneralTabViewModel"> @@ -138,7 +138,7 @@ - + + + + - - - diff --git a/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabViewModel.cs index 642e0dfd6..40945c443 100644 --- a/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabViewModel.cs +++ b/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabViewModel.cs @@ -6,6 +6,7 @@ using System.ComponentModel; using System.Linq; using System.Reactive.Disposables; using System.Text; +using System.Threading; using System.Threading.Tasks; using Artemis.Core; using Artemis.Core.Services; @@ -15,28 +16,29 @@ using RGB.NET.Core; using SkiaSharp; namespace Artemis.UI.Screens.Device; + public class DeviceGeneralTabViewModel : ActivatableViewModelBase { private readonly ICoreService _coreService; private readonly IRgbService _rgbService; private readonly IWindowService _windowService; private readonly List _categories; - + private readonly float _initialBlueScale; private readonly float _initialGreenScale; private readonly float _initialRedScale; - + private int _rotation; private float _scale; private int _x; private int _y; - + private float _redScale; private float _greenScale; private float _blueScale; private SKColor _currentColor; private bool _displayOnDevices; - + public DeviceGeneralTabViewModel(ArtemisDevice device, ICoreService coreService, IRgbService rgbService, IWindowService windowService) { _coreService = coreService; @@ -46,10 +48,10 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase Device = device; DisplayName = "General"; - X = (int) Device.X; - Y = (int) Device.Y; + X = (int)Device.X; + Y = (int)Device.Y; Scale = Device.Scale; - Rotation = (int) Device.Rotation; + Rotation = (int)Device.Rotation; RedScale = Device.RedScale * 100f; GreenScale = Device.GreenScale * 100f; BlueScale = Device.BlueScale * 100f; @@ -66,19 +68,20 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase { Device.PropertyChanged += DeviceOnPropertyChanged; _coreService.FrameRendering += OnFrameRendering; - + Disposable.Create(() => { _coreService.FrameRendering -= OnFrameRendering; Device.PropertyChanged -= DeviceOnPropertyChanged; + Apply(); }).DisposeWith(d); }); } - + public bool RequiresManualSetup => !Device.DeviceProvider.CanDetectPhysicalLayout || !Device.DeviceProvider.CanDetectLogicalLayout; public ArtemisDevice Device { get; } - + public int X { get => _x; @@ -102,9 +105,9 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase get => _rotation; set => RaiseAndSetIfChanged(ref _rotation, value); } - + public bool IsKeyboard => Device.DeviceType == RGBDeviceType.Keyboard; - + public bool HasDeskCategory { get => GetCategory(DeviceCategory.Desk); @@ -134,7 +137,7 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase get => GetCategory(DeviceCategory.Peripherals); set => SetCategory(DeviceCategory.Peripherals, value); } - + public float RedScale { get => _redScale; @@ -164,15 +167,6 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase get => _displayOnDevices; set => RaiseAndSetIfChanged(ref _displayOnDevices, value); } - - public void ApplyScaling() - { - Device.RedScale = RedScale / 100f; - Device.GreenScale = GreenScale / 100f; - Device.BlueScale = BlueScale / 100f; - - _rgbService.FlushLeds = true; - } private bool GetCategory(DeviceCategory category) { @@ -188,7 +182,7 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase this.RaisePropertyChanged($"Has{category}Category"); } - + public async Task RestartSetup() { if (!RequiresManualSetup) @@ -202,13 +196,13 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase _rgbService.SaveDevice(Device); _rgbService.ApplyBestDeviceLayout(Device); } - - public async Task Apply() + + private void Apply() { // TODO: Validation _coreService.ProfileRenderingDisabled = true; - await Task.Delay(100); + Thread.Sleep(100); Device.X = X; Device.Y = Y; @@ -226,25 +220,28 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase _coreService.ProfileRenderingDisabled = false; } - public void Reset() + public void ApplyScaling() { - HasDeskCategory = Device.Categories.Contains(DeviceCategory.Desk); - HasMonitorCategory = Device.Categories.Contains(DeviceCategory.Monitor); - HasCaseCategory = Device.Categories.Contains(DeviceCategory.Case); - HasRoomCategory = Device.Categories.Contains(DeviceCategory.Room); - HasPeripheralsCategory = Device.Categories.Contains(DeviceCategory.Peripherals); + Device.RedScale = RedScale / 100f; + Device.GreenScale = GreenScale / 100f; + Device.BlueScale = BlueScale / 100f; + _rgbService.FlushLeds = true; + } + + public void ResetScaling() + { RedScale = _initialRedScale * 100; GreenScale = _initialGreenScale * 100; BlueScale = _initialBlueScale * 100; } - + private void OnFrameRendering(object? sender, FrameRenderingEventArgs e) { if (!DisplayOnDevices) return; - using SKPaint overlayPaint = new() {Color = CurrentColor}; + using SKPaint overlayPaint = new() { Color = CurrentColor }; e.Canvas.DrawRect(0, 0, e.Canvas.LocalClipBounds.Width, e.Canvas.LocalClipBounds.Height, overlayPaint); } @@ -253,4 +250,4 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase if (e.PropertyName == nameof(Device.CustomLayoutPath) || e.PropertyName == nameof(Device.DisableDefaultLayout)) Task.Run(() => _rgbService.ApplyBestDeviceLayout(Device)); } -} +} \ No newline at end of file