Input - Polished up UI

Input - Added events to service
This commit is contained in:
SpoinkyNL committed 2020-11-23 19:41:48 +01:00
1 parent 6ee5cbd09c
commit f1f0abfec5
40 files changed
+552 -203

No files matched your search

@@ -27,10 +27,5 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
Session.Close(SurfaceName);
}
public void Cancel()
{
Session.Close();
}
}
}
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Screens.SurfaceEditor.Visualization;
using Artemis.UI.Shared.Services;
using Stylet;
@@ -15,20 +15,21 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
private int _x;
private int _y;
public SurfaceDeviceConfigViewModel(SurfaceDeviceViewModel surfaceDeviceViewModel, ICoreService coreService, IModelValidator<SurfaceDeviceConfigViewModel> validator)
: base(validator)
public SurfaceDeviceConfigViewModel(ArtemisDevice device, ICoreService coreService, IModelValidator<SurfaceDeviceConfigViewModel> validator) : base(validator)
{
_coreService = coreService;
SurfaceDeviceViewModel = surfaceDeviceViewModel;
Title = $"{SurfaceDeviceViewModel.Device.RgbDevice.DeviceInfo.DeviceName} - Properties";
X = (int) SurfaceDeviceViewModel.Device.X;
Y = (int) SurfaceDeviceViewModel.Device.Y;
Scale = SurfaceDeviceViewModel.Device.Scale;
Rotation = (int) SurfaceDeviceViewModel.Device.Rotation;
Device = device;
Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Properties";
X = (int) Device.X;
Y = (int) Device.Y;
Scale = Device.Scale;
Rotation = (int) Device.Rotation;
}
public SurfaceDeviceViewModel SurfaceDeviceViewModel { get; }
public ArtemisDevice Device { get; }
public string Title
{
@@ -69,19 +70,14 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
_coreService.ModuleRenderingDisabled = true;
await Task.Delay(100);
SurfaceDeviceViewModel.Device.X = X;
SurfaceDeviceViewModel.Device.Y = Y;
SurfaceDeviceViewModel.Device.Scale = Scale;
SurfaceDeviceViewModel.Device.Rotation = Rotation;
Device.X = X;
Device.Y = Y;
Device.Scale = Scale;
Device.Rotation = Rotation;
_coreService.ModuleRenderingDisabled = false;
Session.Close(true);
}
public void Cancel()
{
Session.Close(false);
}
}
}
@@ -17,13 +17,39 @@
that is currently showing a <Bold Foreground="Yellow">yellow</Bold> color.
</TextBlock>
<materialDesign:PackIcon Kind="GestureDoubleTap" Width="300" Height="340" HorizontalAlignment="Center" />
<materialDesign:PackIcon Kind="Keyboard"
Width="300"
Height="340"
HorizontalAlignment="Center"
Visibility="{Binding IsMouse, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}" />
<materialDesign:PackIcon Kind="Mouse"
Width="250"
Height="340"
HorizontalAlignment="Center"
Visibility="{Binding IsMouse, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" TextWrapping="Wrap">
This will teach Artemis to associate button/key presses with this specific device.
</TextBlock>
<Button HorizontalAlignment="Right" Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">
<Button HorizontalAlignment="Right"
Style="{StaticResource MaterialDesignFlatButton}"
IsCancel="True"
Command="{s:Action Cancel}"
Visibility="{Binding IsMouse, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
<Button.CommandParameter>
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
False
</system:Boolean>
</Button.CommandParameter>
PRESS ESC TO CANCEL
</Button>
<Button HorizontalAlignment="Right"
Style="{StaticResource MaterialDesignFlatButton}"
IsCancel="True"
Command="{s:Action Cancel}"
Visibility="{Binding IsMouse, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
<Button.CommandParameter>
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
False
@@ -1,7 +1,7 @@
using System;
using System.Linq;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Screens.SurfaceEditor.Visualization;
using Artemis.UI.Shared.Services;
using MaterialDesignThemes.Wpf;
using RGB.NET.Brushes;
@@ -13,36 +13,31 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
public class SurfaceDeviceDetectInputViewModel : DialogViewModelBase
{
private readonly IInputService _inputService;
private readonly ListLedGroup _ledGroup;
private readonly ISnackbarMessageQueue _mainMessageQueue;
private string _title;
private ListLedGroup _ledGroup;
public SurfaceDeviceDetectInputViewModel(SurfaceDeviceViewModel surfaceDeviceViewModel, IInputService inputService, ISnackbarMessageQueue mainMessageQueue)
public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, ISnackbarMessageQueue mainMessageQueue)
{
SurfaceDeviceViewModel = surfaceDeviceViewModel;
Title = $"{SurfaceDeviceViewModel.Device.RgbDevice.DeviceInfo.DeviceName} - Detect input";
Device = device;
Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Detect input";
IsMouse = Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse;
_inputService = inputService;
_mainMessageQueue = mainMessageQueue;
_inputService.IdentifyDevice(Device);
_inputService.DeviceIdentified += InputServiceOnDeviceIdentified;
// Create a LED group way at the top
_ledGroup = new ListLedGroup(SurfaceDeviceViewModel.Device.Leds.Select(l => l.RgbLed))
_ledGroup = new ListLedGroup(Device.Leds.Select(l => l.RgbLed))
{
Brush = new SolidColorBrush(new Color(255, 255, 0)),
ZIndex = 999
};
_inputService = inputService;
_mainMessageQueue = mainMessageQueue;
_inputService.IdentifyDevice(surfaceDeviceViewModel.Device);
_inputService.DeviceIdentified += InputServiceOnDeviceIdentified;
}
public SurfaceDeviceViewModel SurfaceDeviceViewModel { get; }
public string Title
{
get => _title;
set => SetAndNotify(ref _title, value);
}
public ArtemisDevice Device { get; }
public string Title { get; }
public bool IsMouse { get; }
public override void OnDialogClosed(object sender, DialogClosingEventArgs e)
{
@@ -51,15 +46,10 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
_ledGroup.Detach();
}
public void Cancel()
{
Session?.Close(false);
}
private void InputServiceOnDeviceIdentified(object sender, EventArgs e)
{
Session?.Close(true);
_mainMessageQueue.Enqueue("Device identified.");
_mainMessageQueue.Enqueue($"{Device.RgbDevice.DeviceInfo.DeviceName} identified 😁");
}
}
}
@@ -144,9 +144,11 @@
</MenuItem.Icon>
</MenuItem>
<Separator />
<!-- Stylet can't disable it for us here, do it ourselves -->
<MenuItem Header="Identify input"
Command="{s:Action DetectInput}"
CommandParameter="{Binding}"
IsEnabled="{Binding CanDetectInput}"
ToolTip="Teach Artemis which keypresses and/or button presses belong to this device">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="GestureDoubleTap" />
@@ -16,6 +16,7 @@ using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
using MouseButton = System.Windows.Input.MouseButton;
using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs;
namespace Artemis.UI.Screens.SurfaceEditor
{
@@ -35,11 +36,11 @@ namespace Artemis.UI.Screens.SurfaceEditor
private ObservableCollection<ArtemisSurface> _surfaceConfigurations;
private PluginSetting<GridLength> _surfaceListWidth;
public SurfaceEditorViewModel(IRgbService rgbService,
ISurfaceService surfaceService,
IDialogService dialogService,
public SurfaceEditorViewModel(IRgbService rgbService,
ISurfaceService surfaceService,
IDialogService dialogService,
ISettingsService settingsService,
IDeviceService deviceService,
IDeviceService deviceService,
IInputService inputService)
{
DisplayName = "Surface Editor";
@@ -286,10 +287,9 @@ namespace Artemis.UI.Screens.SurfaceEditor
public async Task ViewProperties(SurfaceDeviceViewModel surfaceDeviceViewModel)
{
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceConfigViewModel>(new Dictionary<string, object>
{
{"surfaceDeviceViewModel", surfaceDeviceViewModel}
});
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceConfigViewModel>(
new Dictionary<string, object> {{"device", surfaceDeviceViewModel.Device}}
);
if ((bool) madeChanges)
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
@@ -297,12 +297,11 @@ namespace Artemis.UI.Screens.SurfaceEditor
public async Task DetectInput(SurfaceDeviceViewModel surfaceDeviceViewModel)
{
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>(new Dictionary<string, object>
{
{"surfaceDeviceViewModel", surfaceDeviceViewModel}
});
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>(
new Dictionary<string, object> {{"device", surfaceDeviceViewModel.Device}}
);
if ((bool)madeChanges)
if ((bool) madeChanges)
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
}
@@ -2,7 +2,9 @@
using System.Windows;
using System.Windows.Input;
using Artemis.Core;
using RGB.NET.Core;
using Stylet;
using Point = System.Windows.Point;
namespace Artemis.UI.Screens.SurfaceEditor.Visualization
{
@@ -45,6 +47,9 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
? new Rect()
: new Rect(Device.X, Device.Y, Device.RgbDevice.DeviceRectangle.Size.Width, Device.RgbDevice.DeviceRectangle.Size.Height);
public bool CanDetectInput => Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard ||
Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse;
public void StartMouseDrag(Point mouseStartPosition)
{
_dragOffsetX = Device.X - mouseStartPosition.X;