1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00

Made the UI save automatically, removed apply and reset buttons

This commit is contained in:
Diogo Trindade 2023-06-21 23:07:56 +01:00
parent 480e0b9b12
commit 5ef6c4b8a7
2 changed files with 55 additions and 219 deletions

View File

@ -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">
<UserControl.Resources>
@ -138,7 +138,7 @@
<Border Grid.Row="1" Grid.Column="1" Classes="card" Margin="5" x:Name="CalibrationBorder">
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" Text="Use the sliders below to adjust the colors of your device so that it matches your other devices." />
<Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="*,*,*,*">
<Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="*,*,*">
<Label Grid.Row="0" Grid.Column="0" Content="R" VerticalAlignment="Center" />
<Slider Grid.Row="0" Grid.Column="1" Minimum="0" Maximum="200" Value="{CompiledBinding RedScale}" Margin="10 0" VerticalAlignment="Center" />
<NumericUpDown Grid.Row="0"
@ -177,194 +177,33 @@
Minimum="0"
Maximum="200"
ClipValueToMinMax="True" />
<CheckBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" IsChecked="{CompiledBinding DisplayOnDevices}" Content="Show preview" VerticalAlignment="Center" />
<controls:ColorPickerButton Grid.Row="3"
Grid.Column="2"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Color="{CompiledBinding CurrentColor, Converter={StaticResource SKColorToColorConverter}}"
ShowAcceptDismissButtons="False" />
</Grid>
<Grid ColumnDefinitions="Auto,*,Auto">
<Button
Grid.Column="0"
Content="Reset"
ToolTip.Tip="Reset the color scaling to what it had previously"
Command="{CompiledBinding ResetScaling}"
HorizontalAlignment="Center"/>
<CheckBox Grid.Column="1" IsChecked="{CompiledBinding DisplayOnDevices}" Content="Preview specific color" VerticalAlignment="Center" HorizontalAlignment="Right" />
<controls:ColorPickerButton Grid.Column="2"
VerticalAlignment="Center"
Color="{CompiledBinding CurrentColor, Converter={StaticResource SKColorToColorConverter}}"
ShowAcceptDismissButtons="False" />
</Grid>
</StackPanel>
</Border>
</Grid>
</StackPanel>
<!-- Stacked instead of grid here: -->
<!-- <StackPanel Grid.Row="0"> -->
<!-- <TextBlock Classes="card-title" Text="Information" Margin="10,0,0,0" /> -->
<!-- <Border Classes="card" Margin="5" x:Name="InformationBorder"> -->
<!-- <Grid ColumnDefinitions="*,Auto" RowDefinitions="*,*,*,*,*,*"> -->
<!-- <TextBlock Grid.Column="0" Grid.Row="0" Text="Model" /> -->
<!-- <TextBlock Grid.Column="1" Grid.Row="0" Classes="subtitle" TextWrapping="Wrap" Text="{CompiledBinding Device.RgbDevice.DeviceInfo.Model}" /> -->
<!-- -->
<!-- <TextBlock Grid.Column="0" Grid.Row="1" Text="Manufacturer" /> -->
<!-- <TextBlock Grid.Column="1" Grid.Row="1" Classes="subtitle" TextWrapping="Wrap" Text="{CompiledBinding Device.RgbDevice.DeviceInfo.Manufacturer}" /> -->
<!-- -->
<!-- <TextBlock Grid.Column="0" Grid.Row="2" Text="Device Type" /> -->
<!-- <TextBlock Grid.Column="1" Grid.Row="2" Classes="subtitle" TextWrapping="Wrap" Text="{CompiledBinding Device.RgbDevice.DeviceInfo.DeviceType}" /> -->
<!-- -->
<!-- <TextBlock Grid.Column="0" Grid.Row="3" Text="Size (1px = 1mm)" /> -->
<!-- <TextBlock Grid.Column="1" Grid.Row="3" Classes="subtitle" TextWrapping="Wrap" Text="{CompiledBinding Device.RgbDevice.Size}" /> -->
<!-- -->
<!-- <TextBlock IsVisible="{CompiledBinding IsKeyboard}" Grid.Column="0" Grid.Row="4" Text="Physical Layout" /> -->
<!-- <TextBlock IsVisible="{CompiledBinding IsKeyboard}" Grid.Column="1" Grid.Row="4" Classes="subtitle" TextWrapping="Wrap" Text="{CompiledBinding Device.PhysicalLayout}" /> -->
<!-- -->
<!-- <TextBlock IsVisible="{CompiledBinding IsKeyboard}" Grid.Column="0" Grid.Row="5" Text="Logical Layout" /> -->
<!-- <TextBlock IsVisible="{CompiledBinding IsKeyboard}" Grid.Column="1" Grid.Row="5" Classes="subtitle" TextWrapping="Wrap" Text="{CompiledBinding Device.LogicalLayout}" /> -->
<!-- </Grid> -->
<!-- </Border> -->
<!-- -->
<!-- <TextBlock Classes="card-title" Text="Categories" Margin="10,0,0,0" /> -->
<!-- <Border Classes="card" Margin="5" x:Name="CategoryBorder"> -->
<!-- <StackPanel> -->
<!-- <TextBlock TextWrapping="Wrap" Text="Artemis uses categories to determine where the layers of imported profiles are applied to." /> -->
<!-- <Grid ColumnDefinitions="*,Auto" RowDefinitions="*,*,*,*,*" Margin="0,10,0,0"> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="0" Margin="0,0,0,10"> -->
<!-- <TextBlock Text="Peripheral" /> -->
<!-- <TextBlock Classes="subtitle" FontSize="12" TextWrapping="Wrap" Text="A peripheral such as a mouse or keyboard" /> -->
<!-- </StackPanel> -->
<!-- <CheckBox Grid.Row="0" Grid.Column="1" IsChecked="{CompiledBinding HasPeripheralsCategory}" /> -->
<!-- -->
<!-- <StackPanel Grid.Row="1" Grid.Column="0" Margin="0,0,0,10"> -->
<!-- <TextBlock Text="Desk" /> -->
<!-- <TextBlock Classes="subtitle" FontSize="12" TextWrapping="Wrap" Text="A device acting as desk ornamentation such as a LED strip" /> -->
<!-- </StackPanel> -->
<!-- <CheckBox Grid.Row="1" Grid.Column="1" IsChecked="{CompiledBinding HasDeskCategory}" /> -->
<!-- -->
<!-- <StackPanel Grid.Row="2" Grid.Column="0" Margin="0,0,0,10"> -->
<!-- <TextBlock Text="Monitor" /> -->
<!-- <TextBlock Classes="subtitle" FontSize="12" TextWrapping="Wrap" Text="A device attached to the monitor such as ambilight LEDs" /> -->
<!-- </StackPanel> -->
<!-- <CheckBox Grid.Row="2" Grid.Column="1" IsChecked="{CompiledBinding HasMonitorCategory}" /> -->
<!-- -->
<!-- <StackPanel Grid.Row="3" Grid.Column="0" Margin="0,0,0,10"> -->
<!-- <TextBlock Text="Case" /> -->
<!-- <TextBlock Classes="subtitle" FontSize="12" TextWrapping="Wrap" Text="A device inside your computer case" /> -->
<!-- </StackPanel> -->
<!-- <CheckBox Grid.Row="3" Grid.Column="1" IsChecked="{CompiledBinding HasCaseCategory}" /> -->
<!-- -->
<!-- <StackPanel Grid.Row="4" Grid.Column="0" Margin="0,0,0,10"> -->
<!-- <TextBlock Text="Room" /> -->
<!-- <TextBlock Classes="subtitle" FontSize="12" TextWrapping="Wrap" Text="A device elsewhere in the room" /> -->
<!-- </StackPanel> -->
<!-- <CheckBox Grid.Row="4" Grid.Column="1" IsChecked="{CompiledBinding HasRoomCategory}" /> -->
<!-- </Grid> -->
<!-- </StackPanel> -->
<!-- </Border> -->
<!-- -->
<!-- <TextBlock Classes="card-title" Text="Surface" Margin="10,0,0,0" /> -->
<!-- <Border Classes="card" Margin="5" x:Name="SurfaceBorder"> -->
<!-- <StackPanel Orientation="Vertical"> -->
<!-- <TextBlock TextWrapping="Wrap" Text="The device can be rotated and scaled on the surface with the values below." /> -->
<!-- <Grid ColumnDefinitions="*,Auto,Auto" RowDefinitions="*,*,*,*"> -->
<!-- <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">X-coordinate</TextBlock> -->
<!-- <NumericUpDown Grid.Row="0" -->
<!-- Grid.Column="1" -->
<!-- Margin="10 5" -->
<!-- VerticalAlignment="Center" -->
<!-- Value="{CompiledBinding X}" /> -->
<!-- <TextBlock Grid.Row="0" Grid.Column="2" VerticalAlignment="Center">mm</TextBlock> -->
<!-- -->
<!-- <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">Y-coordinate</TextBlock> -->
<!-- <NumericUpDown Grid.Row="1" -->
<!-- Grid.Column="1" -->
<!-- Margin="10 5" -->
<!-- VerticalAlignment="Center" -->
<!-- Value="{CompiledBinding Y}" /> -->
<!-- <TextBlock Grid.Row="1" Grid.Column="2" VerticalAlignment="Center">mm</TextBlock> -->
<!-- -->
<!-- <TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center">Scale</TextBlock> -->
<!-- <NumericUpDown Grid.Row="2" -->
<!-- Grid.Column="1" -->
<!-- Margin="10 5" -->
<!-- VerticalAlignment="Center" -->
<!-- Increment="0.1" -->
<!-- FormatString="F1" -->
<!-- Value="{CompiledBinding Scale}" /> -->
<!-- <TextBlock Grid.Row="2" Grid.Column="2" VerticalAlignment="Center">times</TextBlock> -->
<!-- -->
<!-- <TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center">Rotation</TextBlock> -->
<!-- <NumericUpDown Grid.Row="3" -->
<!-- Grid.Column="1" -->
<!-- Margin="10 5" -->
<!-- VerticalAlignment="Center" -->
<!-- Value="{CompiledBinding Rotation}" /> -->
<!-- <TextBlock Grid.Row="3" Grid.Column="2" VerticalAlignment="Center">deg</TextBlock> -->
<!-- </Grid> -->
<!-- </StackPanel> -->
<!-- </Border> -->
<!-- -->
<!-- <TextBlock Classes="card-title" Text="Calibration" Margin="10,0,0,0" /> -->
<!-- <Border Classes="card" Margin="5" x:Name="CalibrationBorder"> -->
<!-- <StackPanel Orientation="Vertical"> -->
<!-- <TextBlock TextWrapping="Wrap" Text="Use the sliders below to adjust the colors of your device so that it matches your other devices." /> -->
<!-- <Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="*,*,*,*"> -->
<!-- <Label Grid.Row="0" Grid.Column="0" Content="R" VerticalAlignment="Center" /> -->
<!-- <Slider Grid.Row="0" Grid.Column="1" Minimum="0" Maximum="200" Value="{CompiledBinding RedScale}" Margin="10 0" VerticalAlignment="Center" /> -->
<!-- <NumericUpDown Grid.Row="0" -->
<!-- Grid.Column="2" -->
<!-- VerticalAlignment="Center" -->
<!-- Width="65" -->
<!-- Value="{CompiledBinding RedScale}" -->
<!-- ShowButtonSpinner="False" -->
<!-- FormatString="{}{0:0.0}" -->
<!-- Minimum="0" -->
<!-- Maximum="200" -->
<!-- ClipValueToMinMax="True" /> -->
<!-- -->
<!-- <Label Grid.Row="1" Grid.Column="0" Content="G" VerticalAlignment="Center" /> -->
<!-- <Slider Grid.Row="1" Grid.Column="1" Minimum="0" Maximum="200" Value="{CompiledBinding GreenScale}" Margin="10 0" VerticalAlignment="Center" /> -->
<!-- <NumericUpDown Grid.Row="1" -->
<!-- Grid.Column="2" -->
<!-- VerticalAlignment="Center" -->
<!-- Width="65" -->
<!-- Value="{CompiledBinding GreenScale}" -->
<!-- ShowButtonSpinner="False" -->
<!-- FormatString="{}{0:0.0}" -->
<!-- Minimum="0" -->
<!-- Maximum="200" -->
<!-- ClipValueToMinMax="True" /> -->
<!-- -->
<!-- <Label Grid.Row="2" Grid.Column="0" Content="B" VerticalAlignment="Center" /> -->
<!-- <Slider Grid.Row="2" Grid.Column="1" Minimum="0" Maximum="200" Value="{CompiledBinding BlueScale}" Margin="10 0" Ticks="100" VerticalAlignment="Center" /> -->
<!-- <NumericUpDown Grid.Row="2" -->
<!-- Grid.Column="2" -->
<!-- VerticalAlignment="Center" -->
<!-- Width="65" -->
<!-- Value="{CompiledBinding BlueScale}" -->
<!-- ShowButtonSpinner="False" -->
<!-- FormatString="{}{0:0.0}" -->
<!-- Minimum="0" -->
<!-- Maximum="200" -->
<!-- ClipValueToMinMax="True" /> -->
<!-- -->
<!-- <CheckBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" IsChecked="{CompiledBinding DisplayOnDevices}" Content="Show preview" VerticalAlignment="Center" /> -->
<!-- <controls:ColorPickerButton Grid.Row="3" -->
<!-- Grid.Column="2" -->
<!-- VerticalAlignment="Center" -->
<!-- HorizontalAlignment="Right" -->
<!-- Color="{CompiledBinding CurrentColor, Converter={StaticResource SKColorToColorConverter}}" -->
<!-- ShowAcceptDismissButtons="False" /> -->
<!-- </Grid> -->
<!-- </StackPanel> -->
<!-- </Border> -->
<!-- </StackPanel> -->
<Grid Grid.Row="1" ColumnDefinitions="Auto,*" Margin="5">
<Button Grid.Column="0"
IsVisible="{CompiledBinding RequiresManualSetup}"
Command="{CompiledBinding RestartSetup}"
ToolTip.Tip="Restart device setup, allowing you to select a new physical and logical layout">
Restart setup
</Button>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button IsCancel="True" Command="{CompiledBinding Reset}" Margin="0 0 5 0" Content="Reset" />
<Button Classes="accent" IsDefault="True" Command="{CompiledBinding Apply}" Content="Apply" />
</StackPanel>
</Grid>
<Button Grid.Row="1" Margin="5"
IsVisible="{CompiledBinding RequiresManualSetup}"
Command="{CompiledBinding RestartSetup}"
ToolTip.Tip="Restart device setup, allowing you to select a new physical and logical layout">
Restart setup
</Button>
</Grid>
</ScrollViewer>

View File

@ -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<DeviceCategory> _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));
}
}
}