From f1f0abfec5366652eb5f77f53e7866b5c6ec3cec Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 23 Nov 2020 19:41:48 +0100 Subject: [PATCH] Input - Polished up UI Input - Added events to service --- .../Models/Surface/ArtemisDevice.cs | 16 +- ...llbackDeviceType.cs => InputDeviceType.cs} | 2 +- ...ModifierKeys.cs => KeyboardModifierKey.cs} | 2 +- .../InputProviderIdentifierEventArgs.cs | 31 ++++ .../Events/InputProviderMouseMoveEventArgs.cs | 8 +- ...rdEventArgs.cs => KeyboardKeyEventArgs.cs} | 22 +-- .../Events/KeyboardKeyUpDownEventArgs.cs | 18 +++ .../Input/Events/MouseButtonEventArgs.cs | 32 ++++ .../Events/MouseButtonUpDownEventArgs.cs | 18 +++ .../Input/Events/MouseMoveEventArgs.cs | 51 +++++++ .../Input/Events/MouseScrollEventArgs.cs | 57 +++++++ .../Services/Input/InputProvider.cs | 39 +++-- .../Services/Input/InputService.cs | 140 ++++++++++++------ .../Input/Interfaces/IInputService.cs | 35 ++++- .../Entities/Surface/DeviceEntity.cs | 4 +- .../Repositories/SurfaceRepository.cs | 3 +- .../Shared/DataModelListViewModel.cs | 1 + .../Screens/Dialogs/ConfirmDialogViewModel.cs | 6 - .../GradientEditor/GradientEditorViewModel.cs | 5 +- .../Services/Dialog/DialogViewModelBase.cs | 9 ++ .../NativeWindowInputProvider.cs | 18 +-- .../Dialogs/ProfileCreateViewModel.cs | 5 - .../Dialogs/ProfileExportViewModel.cs | 5 - .../Dialogs/ProfileImportViewModel.cs | 5 - .../ProfileEditor/Dialogs/RenameViewModel.cs | 5 - .../LayerPropertiesViewModel.cs | 1 + .../Dialogs/TimelineSegmentDialogViewModel.cs | 5 - .../Visualization/ProfileViewModel.cs | 1 + .../Tools/SelectionToolViewModel.cs | 1 + src/Artemis.UI/Screens/RootViewModel.cs | 1 + .../Tabs/Devices/DeviceSettingsView.xaml | 27 +++- .../Tabs/Devices/DeviceSettingsViewModel.cs | 38 ++++- .../Screens/Splash/SplashViewModel.cs | 1 + .../Dialogs/SurfaceCreateViewModel.cs | 5 - .../Dialogs/SurfaceDeviceConfigViewModel.cs | 34 ++--- .../Dialogs/SurfaceDeviceDetectInputView.xaml | 30 +++- .../SurfaceDeviceDetectInputViewModel.cs | 42 ++---- .../SurfaceEditor/SurfaceEditorView.xaml | 2 + .../SurfaceEditor/SurfaceEditorViewModel.cs | 25 ++-- .../Visualization/SurfaceDeviceViewModel.cs | 5 + 40 files changed, 552 insertions(+), 203 deletions(-) rename src/Artemis.Core/Services/Input/Enums/{InputFallbackDeviceType.cs => InputDeviceType.cs} (91%) rename src/Artemis.Core/Services/Input/Enums/{KeyboardModifierKeys.cs => KeyboardModifierKey.cs} (93%) create mode 100644 src/Artemis.Core/Services/Input/Events/InputProviderIdentifierEventArgs.cs rename src/Artemis.Core/Services/Input/Events/{KeyboardEventArgs.cs => KeyboardKeyEventArgs.cs} (50%) create mode 100644 src/Artemis.Core/Services/Input/Events/KeyboardKeyUpDownEventArgs.cs create mode 100644 src/Artemis.Core/Services/Input/Events/MouseButtonEventArgs.cs create mode 100644 src/Artemis.Core/Services/Input/Events/MouseButtonUpDownEventArgs.cs create mode 100644 src/Artemis.Core/Services/Input/Events/MouseMoveEventArgs.cs create mode 100644 src/Artemis.Core/Services/Input/Events/MouseScrollEventArgs.cs diff --git a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs index 8bffa761d..953fda3d2 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs @@ -23,8 +23,10 @@ namespace Artemis.Core RgbDevice = rgbDevice; DeviceProvider = deviceProvider; Surface = surface; - InputIdentifiers = new List(); DeviceEntity = new DeviceEntity(); + + InputIdentifiers = new List(); + _leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly(); Rotation = 0; @@ -40,8 +42,12 @@ namespace Artemis.Core RgbDevice = rgbDevice; DeviceProvider = deviceProvider; Surface = surface; - InputIdentifiers = new List(); DeviceEntity = deviceEntity; + + InputIdentifiers = new List(); + foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers) + InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier)); + _leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly(); } @@ -183,10 +189,10 @@ namespace Artemis.Core // Other properties are computed DeviceEntity.DeviceIdentifier = RgbDevice.GetDeviceIdentifier(); - DeviceEntity.InputIdentifier.Clear(); + DeviceEntity.InputIdentifiers.Clear(); foreach (ArtemisDeviceInputIdentifier identifier in InputIdentifiers) { - DeviceEntity.InputIdentifier.Add(new DeviceInputIdentifierEntity + DeviceEntity.InputIdentifiers.Add(new DeviceInputIdentifierEntity { InputProvider = identifier.InputProvider, Identifier = identifier.Identifier @@ -205,7 +211,7 @@ namespace Artemis.Core RgbDevice.Location = new Point(DeviceEntity.X, DeviceEntity.Y); InputIdentifiers.Clear(); - foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifier) + foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers) InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier)); CalculateRenderProperties(); diff --git a/src/Artemis.Core/Services/Input/Enums/InputFallbackDeviceType.cs b/src/Artemis.Core/Services/Input/Enums/InputDeviceType.cs similarity index 91% rename from src/Artemis.Core/Services/Input/Enums/InputFallbackDeviceType.cs rename to src/Artemis.Core/Services/Input/Enums/InputDeviceType.cs index b1590f7b4..3d7ef1149 100644 --- a/src/Artemis.Core/Services/Input/Enums/InputFallbackDeviceType.cs +++ b/src/Artemis.Core/Services/Input/Enums/InputDeviceType.cs @@ -3,7 +3,7 @@ /// /// Represents a device that provides input to the /// - public enum InputFallbackDeviceType + public enum InputDeviceType { /// /// None diff --git a/src/Artemis.Core/Services/Input/Enums/KeyboardModifierKeys.cs b/src/Artemis.Core/Services/Input/Enums/KeyboardModifierKey.cs similarity index 93% rename from src/Artemis.Core/Services/Input/Enums/KeyboardModifierKeys.cs rename to src/Artemis.Core/Services/Input/Enums/KeyboardModifierKey.cs index 4cc0c7f5d..2ebde89e7 100644 --- a/src/Artemis.Core/Services/Input/Enums/KeyboardModifierKeys.cs +++ b/src/Artemis.Core/Services/Input/Enums/KeyboardModifierKey.cs @@ -6,7 +6,7 @@ namespace Artemis.Core.Services /// Specifies the set of modifier keys. /// [Flags] - public enum KeyboardModifierKeys + public enum KeyboardModifierKey { /// No modifiers are pressed. None = 0, diff --git a/src/Artemis.Core/Services/Input/Events/InputProviderIdentifierEventArgs.cs b/src/Artemis.Core/Services/Input/Events/InputProviderIdentifierEventArgs.cs new file mode 100644 index 000000000..277778a8b --- /dev/null +++ b/src/Artemis.Core/Services/Input/Events/InputProviderIdentifierEventArgs.cs @@ -0,0 +1,31 @@ +using System; + +namespace Artemis.Core.Services +{ + /// + /// Contains data for input provider identifier events + /// + public class InputProviderIdentifierEventArgs : EventArgs + { + /// + /// Creates a new instance of the class + /// + /// A value that can be used to identify this device + /// The type of device this identifier belongs to + public InputProviderIdentifierEventArgs(object identifier, InputDeviceType deviceType) + { + Identifier = identifier; + DeviceType = deviceType; + } + + /// + /// Gets a value that can be used to identify this device + /// + public object Identifier { get; } + + /// + /// Gets the type of device this identifier belongs to + /// + public InputDeviceType DeviceType { get; } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Input/Events/InputProviderMouseMoveEventArgs.cs b/src/Artemis.Core/Services/Input/Events/InputProviderMouseMoveEventArgs.cs index ceeb8823d..e0231af91 100644 --- a/src/Artemis.Core/Services/Input/Events/InputProviderMouseMoveEventArgs.cs +++ b/src/Artemis.Core/Services/Input/Events/InputProviderMouseMoveEventArgs.cs @@ -29,22 +29,22 @@ namespace Artemis.Core.Services public ArtemisDevice? Device { get; } /// - /// Gets the X position of the mouse cursor (not necessarily tied to the specific device) + /// Gets the X position of the mouse cursor in pixels (not necessarily tied to the specific device) /// public int CursorX { get; } /// - /// Gets the Y position of the mouse cursor (not necessarily tied to the specific device) + /// Gets the Y position of the mouse cursor in pixels (not necessarily tied to the specific device) /// public int CursorY { get; } /// - /// Gets the movement delta in the horizontal direction + /// Gets the movement delta in the horizontal direction in pixels /// public int DeltaX { get; } /// - /// Gets the movement delta in the vertical direction + /// Gets the movement delta in the vertical direction in pixels /// public int DeltaY { get; } } diff --git a/src/Artemis.Core/Services/Input/Events/KeyboardEventArgs.cs b/src/Artemis.Core/Services/Input/Events/KeyboardKeyEventArgs.cs similarity index 50% rename from src/Artemis.Core/Services/Input/Events/KeyboardEventArgs.cs rename to src/Artemis.Core/Services/Input/Events/KeyboardKeyEventArgs.cs index 3372555ed..2a53e4d78 100644 --- a/src/Artemis.Core/Services/Input/Events/KeyboardEventArgs.cs +++ b/src/Artemis.Core/Services/Input/Events/KeyboardKeyEventArgs.cs @@ -5,9 +5,9 @@ namespace Artemis.Core.Services /// /// Contains data for keyboard input events /// - public class KeyboardEventArgs : EventArgs + public class KeyboardKeyEventArgs : EventArgs { - internal KeyboardEventArgs(ArtemisDevice? device, ArtemisLed? led, KeyboardKey key, KeyboardModifierKeys modifiers) + internal KeyboardKeyEventArgs(ArtemisDevice? device, ArtemisLed? led, KeyboardKey key, KeyboardModifierKey modifiers) { Device = device; Led = led; @@ -33,22 +33,6 @@ namespace Artemis.Core.Services /// /// Gets the modifiers that are pressed /// - public KeyboardModifierKeys Modifiers { get; } - } - - /// - /// Contains data for keyboard input events - /// - public class KeyboardKeyUpDownEventArgs : KeyboardEventArgs - { - internal KeyboardKeyUpDownEventArgs(ArtemisDevice? device, ArtemisLed? led, KeyboardKey key, KeyboardModifierKeys modifiers, bool isDown) : base(device, led, key, modifiers) - { - IsDown = isDown; - } - - /// - /// Whether the key is being pressed down, if the key is being released - /// - public bool IsDown { get; set; } + public KeyboardModifierKey Modifiers { get; } } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/Input/Events/KeyboardKeyUpDownEventArgs.cs b/src/Artemis.Core/Services/Input/Events/KeyboardKeyUpDownEventArgs.cs new file mode 100644 index 000000000..8e3168e5c --- /dev/null +++ b/src/Artemis.Core/Services/Input/Events/KeyboardKeyUpDownEventArgs.cs @@ -0,0 +1,18 @@ +namespace Artemis.Core.Services +{ + /// + /// Contains data for keyboard input events + /// + public class KeyboardKeyUpDownEventArgs : KeyboardKeyEventArgs + { + internal KeyboardKeyUpDownEventArgs(ArtemisDevice? device, ArtemisLed? led, KeyboardKey key, KeyboardModifierKey modifiers, bool isDown) : base(device, led, key, modifiers) + { + IsDown = isDown; + } + + /// + /// Whether the key is being pressed down, if the key is being released + /// + public bool IsDown { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Input/Events/MouseButtonEventArgs.cs b/src/Artemis.Core/Services/Input/Events/MouseButtonEventArgs.cs new file mode 100644 index 000000000..050589822 --- /dev/null +++ b/src/Artemis.Core/Services/Input/Events/MouseButtonEventArgs.cs @@ -0,0 +1,32 @@ +using System; + +namespace Artemis.Core.Services +{ + /// + /// Contains data for mouse input events + /// + public class MouseButtonEventArgs : EventArgs + { + internal MouseButtonEventArgs(ArtemisDevice? device, ArtemisLed? led, MouseButton button) + { + Device = device; + Led = led; + Button = button; + } + + /// + /// Gets the device that triggered the event + /// + public ArtemisDevice? Device { get; } + + /// + /// Gets the LED that corresponds to the pressed key + /// + public ArtemisLed? Led { get; } + + /// + /// Gets the button that triggered the event + /// + public MouseButton Button { get; } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Input/Events/MouseButtonUpDownEventArgs.cs b/src/Artemis.Core/Services/Input/Events/MouseButtonUpDownEventArgs.cs new file mode 100644 index 000000000..0b045bf03 --- /dev/null +++ b/src/Artemis.Core/Services/Input/Events/MouseButtonUpDownEventArgs.cs @@ -0,0 +1,18 @@ +namespace Artemis.Core.Services +{ + /// + /// Contains data for mouse input events + /// + public class MouseButtonUpDownEventArgs : MouseButtonEventArgs + { + internal MouseButtonUpDownEventArgs(ArtemisDevice? device, ArtemisLed? led, MouseButton button, bool isDown) : base(device, led, button) + { + IsDown = isDown; + } + + /// + /// Whether the button is being pressed down, if the button is being released + /// + public bool IsDown { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Input/Events/MouseMoveEventArgs.cs b/src/Artemis.Core/Services/Input/Events/MouseMoveEventArgs.cs new file mode 100644 index 000000000..fa2c582b6 --- /dev/null +++ b/src/Artemis.Core/Services/Input/Events/MouseMoveEventArgs.cs @@ -0,0 +1,51 @@ +using System; + +namespace Artemis.Core.Services +{ + /// + /// Contains data for mouse movement events + /// + public class MouseMoveEventArgs : EventArgs + { + /// + /// + /// The device that triggered the event + /// The X position of the mouse cursor (not necessarily tied to the specific device) + /// The Y position of the mouse cursor (not necessarily tied to the specific device) + /// The movement delta in the horizontal direction + /// The movement delta in the vertical direction + internal MouseMoveEventArgs(ArtemisDevice? device, int cursorX, int cursorY, int deltaX, int deltaY) + { + Device = device; + CursorX = cursorX; + CursorY = cursorY; + DeltaX = deltaX; + DeltaY = deltaY; + } + + /// + /// Gets the device that triggered the event + /// + public ArtemisDevice? Device { get; } + + /// + /// Gets the X position of the mouse cursor (not necessarily tied to the specific device) + /// + public int CursorX { get; } + + /// + /// Gets the Y position of the mouse cursor (not necessarily tied to the specific device) + /// + public int CursorY { get; } + + /// + /// Gets the movement delta in the horizontal direction + /// + public int DeltaX { get; } + + /// + /// Gets the movement delta in the vertical direction + /// + public int DeltaY { get; } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Input/Events/MouseScrollEventArgs.cs b/src/Artemis.Core/Services/Input/Events/MouseScrollEventArgs.cs new file mode 100644 index 000000000..50373b6e7 --- /dev/null +++ b/src/Artemis.Core/Services/Input/Events/MouseScrollEventArgs.cs @@ -0,0 +1,57 @@ +using System; + +namespace Artemis.Core.Services +{ + /// + /// Contains data for mouse scroll events + /// + public class MouseScrollEventArgs : EventArgs + { + /// + /// + /// The device that triggered the event + /// The direction in which was scrolled + /// The scroll delta (can positive or negative) + internal MouseScrollEventArgs(ArtemisDevice? device, MouseScrollDirection direction, int delta) + { + Device = device; + Direction = direction; + Delta = delta; + } + + /// + /// Gets the device that triggered the event + /// + public ArtemisDevice? Device { get; } + + /// + /// Gets the direction in which was scrolled + /// + public MouseScrollDirection Direction { get; } + + /// + /// Gets the scroll delta (can positive or negative) + /// + public int Delta { get; } + + /// + /// Gets a boolean indicating whether the mouse scrolled up + /// + public bool IsScrollingUp => Direction == MouseScrollDirection.Vertical && Delta > 0; + + /// + /// Gets a boolean indicating whether the mouse scrolled down + /// + public bool IsScrollingDown => Direction == MouseScrollDirection.Vertical && Delta < 0; + + /// + /// Gets a boolean indicating whether the mouse scrolled right + /// + public bool IsScrollingRight => Direction == MouseScrollDirection.Horizontal && Delta > 0; + + /// + /// Gets a boolean indicating whether the mouse scrolled left + /// + public bool IsScrollingLeft => Direction == MouseScrollDirection.Horizontal && Delta < 0; + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Input/InputProvider.cs b/src/Artemis.Core/Services/Input/InputProvider.cs index 12246f2a9..b71722309 100644 --- a/src/Artemis.Core/Services/Input/InputProvider.cs +++ b/src/Artemis.Core/Services/Input/InputProvider.cs @@ -31,51 +31,68 @@ namespace Artemis.Core.Services /// /// Occurs when the input provided received a device identifier /// - public event EventHandler? IdentifierReceived; + public event EventHandler? IdentifierReceived; /// /// Invokes the event which the listens to as long as /// this provider is registered /// - protected virtual void OnKeyboardDataReceived(InputProviderKeyboardEventArgs e) + /// The device that triggered the event + /// The key that triggered the event + /// Whether the key is pressed down + protected virtual void OnKeyboardDataReceived(ArtemisDevice? device, KeyboardKey key, bool isDown) { - KeyboardDataReceived?.Invoke(this, e); + KeyboardDataReceived?.Invoke(this, new InputProviderKeyboardEventArgs(device, key, isDown)); } /// /// Invokes the event which the listens to as long /// as this provider is registered /// - protected virtual void OnMouseButtonDataReceived(InputProviderMouseButtonEventArgs e) + /// The device that triggered the event + /// The button that triggered the event + /// Whether the button is pressed down + protected virtual void OnMouseButtonDataReceived(ArtemisDevice? device, MouseButton button, bool isDown) { - MouseButtonDataReceived?.Invoke(this, e); + MouseButtonDataReceived?.Invoke(this, new InputProviderMouseButtonEventArgs(device, button, isDown)); } /// /// Invokes the event which the listens to as long /// as this provider is registered /// - protected virtual void OnMouseScrollDataReceived(InputProviderMouseScrollEventArgs e) + /// The device that triggered the event + /// The direction in which was scrolled + /// The scroll delta (can positive or negative) + protected virtual void OnMouseScrollDataReceived(ArtemisDevice? device, MouseScrollDirection direction, int delta) { - MouseScrollDataReceived?.Invoke(this, e); + MouseScrollDataReceived?.Invoke(this, new InputProviderMouseScrollEventArgs(device, direction, delta)); } /// /// Invokes the event which the listens to as long as /// this provider is registered /// - protected virtual void OnMouseMoveDataReceived(InputProviderMouseMoveEventArgs e) + /// The device that triggered the event + /// The X position of the mouse cursor (not necessarily tied to the specific device) + /// The Y position of the mouse cursor (not necessarily tied to the specific device) + /// The movement delta in the horizontal direction + /// The movement delta in the vertical direction + protected virtual void OnMouseMoveDataReceived(ArtemisDevice? device, int cursorX, int cursorY, int deltaX, int deltaY) { - MouseMoveDataReceived?.Invoke(this, e); + MouseMoveDataReceived?.Invoke(this, new InputProviderMouseMoveEventArgs(device, cursorX, cursorY, deltaX, deltaY)); } /// /// Invokes the event which the listens to as long as /// this provider is registered + /// Except for on mouse movement, call this whenever you have an identifier ready for the core to process /// - protected virtual void OnIdentifierReceived(object identifier) + /// A value that can be used to identify this device + /// The type of device this identifier belongs to + protected virtual void OnIdentifierReceived(object identifier, InputDeviceType deviceType) { - IdentifierReceived?.Invoke(this, identifier); + IdentifierReceived?.Invoke(this, new InputProviderIdentifierEventArgs(identifier, deviceType)); } #region IDisposable diff --git a/src/Artemis.Core/Services/Input/InputService.cs b/src/Artemis.Core/Services/Input/InputService.cs index a1e87bc19..4bc608fb8 100644 --- a/src/Artemis.Core/Services/Input/InputService.cs +++ b/src/Artemis.Core/Services/Input/InputService.cs @@ -10,14 +10,13 @@ namespace Artemis.Core.Services { private readonly ILogger _logger; private readonly ISurfaceService _surfaceService; - private readonly List _inputProviders; public InputService(ILogger logger, ISurfaceService surfaceService) { _logger = logger; _surfaceService = surfaceService; _inputProviders = new List(); - _keyboardModifier = new Dictionary(); + _keyboardModifier = new Dictionary(); _deviceCache = new Dictionary, ArtemisDevice>(); _devices = new List(); @@ -26,6 +25,21 @@ namespace Artemis.Core.Services BustIdentifierCache(); } + #region IDisposable + + /// + public void Dispose() + { + while (_inputProviders.Any()) + RemoveInputProvider(_inputProviders.First()); + } + + #endregion + + #region Providers + + private readonly List _inputProviders; + public void AddInputProvider(InputProvider inputProvider) { inputProvider.IdentifierReceived += InputProviderOnIdentifierReceived; @@ -49,6 +63,8 @@ namespace Artemis.Core.Services inputProvider.MouseMoveDataReceived -= InputProviderOnMouseMoveDataReceived; } + #endregion + #region Identification private readonly Dictionary, ArtemisDevice> _deviceCache; @@ -59,6 +75,10 @@ namespace Artemis.Core.Services public void IdentifyDevice(ArtemisDevice device) { + if (device.RgbDevice.DeviceInfo.DeviceType != RGBDeviceType.Keyboard && device.RgbDevice.DeviceInfo.DeviceType != RGBDeviceType.Mouse) + throw new ArtemisCoreException($"Cannot initialize input-identification for a device of type {device.RgbDevice.DeviceInfo.DeviceType}. \r\n" + + "Only keyboard and mouse is supported."); + _identifyingDevice = device; _logger.Debug("Start identifying device {device}", device); } @@ -73,7 +93,7 @@ namespace Artemis.Core.Services BustIdentifierCache(); } - public ArtemisDevice? GetDeviceByIdentifier(InputProvider provider, object identifier, InputFallbackDeviceType fallbackType) + public ArtemisDevice? GetDeviceByIdentifier(InputProvider provider, object identifier, InputDeviceType type) { if (provider == null) throw new ArgumentNullException(nameof(provider)); if (identifier == null) throw new ArgumentNullException(nameof(identifier)); @@ -84,7 +104,7 @@ namespace Artemis.Core.Services return cacheMatch; string providerName = provider.GetType().FullName!; - ArtemisDevice? match = _devices.FirstOrDefault(m => m.InputIdentifiers.Any(i => Equals(i.InputProvider,providerName) && Equals(i.Identifier, identifier))); + ArtemisDevice? match = _devices.FirstOrDefault(m => m.InputIdentifiers.Any(i => Equals(i.InputProvider, providerName) && Equals(i.Identifier, identifier))); // If a match was found cache it to speed up the next event and return the match if (match != null) @@ -94,9 +114,9 @@ namespace Artemis.Core.Services } // If there is no match, apply our fallback type - if (fallbackType == InputFallbackDeviceType.None) + if (type == InputDeviceType.None) return null; - if (fallbackType == InputFallbackDeviceType.Keyboard) + if (type == InputDeviceType.Keyboard) { if (_cachedFallbackKeyboard != null) return _cachedFallbackKeyboard; @@ -104,7 +124,7 @@ namespace Artemis.Core.Services return _cachedFallbackKeyboard; } - if (fallbackType == InputFallbackDeviceType.Mouse) + if (type == InputDeviceType.Mouse) { if (_cachedFallbackMouse != null) return _cachedFallbackMouse; @@ -140,18 +160,21 @@ namespace Artemis.Core.Services BustIdentifierCache(); } - private void InputProviderOnIdentifierReceived(object? sender, object identifier) + private void InputProviderOnIdentifierReceived(object? sender, InputProviderIdentifierEventArgs e) { - if (_identifyingDevice == null) + // Don't match if there is no device or if the device type differs from the event device type + if (_identifyingDevice == null || + _identifyingDevice.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard && e.DeviceType == InputDeviceType.Mouse || + _identifyingDevice.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse && e.DeviceType == InputDeviceType.Keyboard) return; - if (!(sender is InputProvider inputProvider)) + if (!(sender is InputProvider inputProvider)) return; string providerName = inputProvider.GetType().FullName!; // Remove existing identification _identifyingDevice.InputIdentifiers.RemoveAll(i => i.InputProvider == providerName); - _identifyingDevice.InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(providerName, identifier)); + _identifyingDevice.InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(providerName, e.Identifier)); StopIdentify(); OnDeviceIdentified(); @@ -161,12 +184,12 @@ namespace Artemis.Core.Services #region Keyboard - private readonly Dictionary _keyboardModifier; - private KeyboardModifierKeys _globalModifiers; - + private readonly Dictionary _keyboardModifier; + private KeyboardModifierKey _globalModifiers; + private void InputProviderOnKeyboardDataReceived(object? sender, InputProviderKeyboardEventArgs e) { - KeyboardModifierKeys keyboardModifierKeys = UpdateModifierKeys(e.Device, e.Key, e.IsDown); + KeyboardModifierKey keyboardModifierKey = UpdateModifierKeys(e.Device, e.Key, e.IsDown); // Get the LED - TODO: leverage a lookup bool foundLedId = InputKeyUtilities.KeyboardKeyLedIdMap.TryGetValue(e.Key, out LedId ledId); @@ -175,49 +198,49 @@ namespace Artemis.Core.Services led = e.Device.Leds.FirstOrDefault(l => l.RgbLed.Id == ledId); // Create the UpDown event args because it can be used for every event - KeyboardKeyUpDownEventArgs eventArgs = new KeyboardKeyUpDownEventArgs(e.Device, led, e.Key, keyboardModifierKeys, e.IsDown); + KeyboardKeyUpDownEventArgs eventArgs = new KeyboardKeyUpDownEventArgs(e.Device, led, e.Key, keyboardModifierKey, e.IsDown); OnKeyboardKeyUpDown(eventArgs); if (e.IsDown) OnKeyboardKeyDown(eventArgs); else OnKeyboardKeyUp(eventArgs); - _logger.Verbose("Keyboard data: LED ID: {ledId}, key: {key}, is down: {isDown}, modifiers: {modifiers}, device: {device} ", ledId, e.Key, e.IsDown, keyboardModifierKeys, e.Device); + // _logger.Verbose("Keyboard data: LED ID: {ledId}, key: {key}, is down: {isDown}, modifiers: {modifiers}, device: {device} ", ledId, e.Key, e.IsDown, keyboardModifierKey, e.Device); } - private KeyboardModifierKeys UpdateModifierKeys(ArtemisDevice? device, KeyboardKey key, in bool isDown) + private KeyboardModifierKey UpdateModifierKeys(ArtemisDevice? device, KeyboardKey key, in bool isDown) { - KeyboardModifierKeys modifiers = _globalModifiers; + KeyboardModifierKey modifiers = _globalModifiers; if (device != null) _keyboardModifier.TryGetValue(device, out modifiers); if (key == KeyboardKey.LeftAlt || key == KeyboardKey.RightAlt) { if (isDown) - modifiers = modifiers | KeyboardModifierKeys.Alt; + modifiers |= KeyboardModifierKey.Alt; else - modifiers = modifiers & ~KeyboardModifierKeys.Alt; + modifiers &= ~KeyboardModifierKey.Alt; } else if (key == KeyboardKey.LeftCtrl || key == KeyboardKey.RightCtrl) { if (isDown) - modifiers = modifiers | KeyboardModifierKeys.Control; + modifiers |= KeyboardModifierKey.Control; else - modifiers = modifiers & ~KeyboardModifierKeys.Control; + modifiers &= ~KeyboardModifierKey.Control; } else if (key == KeyboardKey.LeftShift || key == KeyboardKey.RightShift) { if (isDown) - modifiers = modifiers | KeyboardModifierKeys.Shift; + modifiers |= KeyboardModifierKey.Shift; else - modifiers = modifiers & ~KeyboardModifierKeys.Shift; + modifiers &= ~KeyboardModifierKey.Shift; } else if (key == KeyboardKey.LWin || key == KeyboardKey.RWin) { if (isDown) - modifiers = modifiers | KeyboardModifierKeys.Windows; + modifiers |= KeyboardModifierKey.Windows; else - modifiers = modifiers & ~KeyboardModifierKeys.Windows; + modifiers &= ~KeyboardModifierKey.Windows; } if (device != null) @@ -235,16 +258,30 @@ namespace Artemis.Core.Services private void InputProviderOnMouseButtonDataReceived(object? sender, InputProviderMouseButtonEventArgs e) { bool foundLedId = InputKeyUtilities.MouseButtonLedIdMap.TryGetValue(e.Button, out LedId ledId); + ArtemisLed? led = null; + if (foundLedId && e.Device != null) + led = e.Device.Leds.FirstOrDefault(l => l.RgbLed.Id == ledId); + + // Create the UpDown event args because it can be used for every event + MouseButtonUpDownEventArgs eventArgs = new MouseButtonUpDownEventArgs(e.Device, led, e.Button, e.IsDown); + OnMouseButtonUpDown(eventArgs); + if (e.IsDown) + OnMouseButtonDown(eventArgs); + else + OnMouseButtonUp(eventArgs); + // _logger.Verbose("Mouse button data: LED ID: {ledId}, button: {button}, is down: {isDown}, device: {device} ", ledId, e.Button, e.IsDown, e.Device); } private void InputProviderOnMouseScrollDataReceived(object? sender, InputProviderMouseScrollEventArgs e) { + OnMouseScroll(new MouseScrollEventArgs(e.Device, e.Direction, e.Delta)); // _logger.Verbose("Mouse scroll data: Direction: {direction}, delta: {delta}, device: {device} ", e.Direction, e.Delta, e.Device); } private void InputProviderOnMouseMoveDataReceived(object? sender, InputProviderMouseMoveEventArgs e) { + OnMouseMove(new MouseMoveEventArgs(e.Device, e.CursorX, e.CursorY, e.DeltaX, e.DeltaY)); // _logger.Verbose("Mouse move data: XY: {X},{Y} - delta XY: {deltaX},{deltaY} - device: {device} ", e.CursorX, e.CursorY, e.DeltaX, e.DeltaY, e.Device); } @@ -253,8 +290,13 @@ namespace Artemis.Core.Services #region Events public event EventHandler? KeyboardKeyUpDown; - public event EventHandler? KeyboardKeyDown; - public event EventHandler? KeyboardKeyUp; + public event EventHandler? KeyboardKeyDown; + public event EventHandler? KeyboardKeyUp; + public event EventHandler? MouseButtonUpDown; + public event EventHandler? MouseButtonDown; + public event EventHandler? MouseButtonUp; + public event EventHandler? MouseScroll; + public event EventHandler? MouseMove; public event EventHandler? DeviceIdentified; protected virtual void OnKeyboardKeyUpDown(KeyboardKeyUpDownEventArgs e) @@ -262,32 +304,46 @@ namespace Artemis.Core.Services KeyboardKeyUpDown?.Invoke(this, e); } - protected virtual void OnKeyboardKeyDown(KeyboardEventArgs e) + protected virtual void OnKeyboardKeyDown(KeyboardKeyEventArgs e) { KeyboardKeyDown?.Invoke(this, e); } - protected virtual void OnKeyboardKeyUp(KeyboardEventArgs e) + protected virtual void OnKeyboardKeyUp(KeyboardKeyEventArgs e) { KeyboardKeyUp?.Invoke(this, e); } + protected virtual void OnMouseButtonUpDown(MouseButtonUpDownEventArgs e) + { + MouseButtonUpDown?.Invoke(this, e); + } + + protected virtual void OnMouseButtonDown(MouseButtonEventArgs e) + { + MouseButtonDown?.Invoke(this, e); + } + + protected virtual void OnMouseButtonUp(MouseButtonEventArgs e) + { + MouseButtonUp?.Invoke(this, e); + } + + protected virtual void OnMouseScroll(MouseScrollEventArgs e) + { + MouseScroll?.Invoke(this, e); + } + + protected virtual void OnMouseMove(MouseMoveEventArgs e) + { + MouseMove?.Invoke(this, e); + } + protected virtual void OnDeviceIdentified() { DeviceIdentified?.Invoke(this, EventArgs.Empty); } #endregion - - #region IDisposable - - /// - public void Dispose() - { - while (_inputProviders.Any()) - RemoveInputProvider(_inputProviders.First()); - } - - #endregion } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/Input/Interfaces/IInputService.cs b/src/Artemis.Core/Services/Input/Interfaces/IInputService.cs index 8b0897edf..12e01601c 100644 --- a/src/Artemis.Core/Services/Input/Interfaces/IInputService.cs +++ b/src/Artemis.Core/Services/Input/Interfaces/IInputService.cs @@ -22,7 +22,7 @@ namespace Artemis.Core.Services /// /// Identifies the provided by assigning the next received device identification to it /// - /// The device to identify + /// The device to identify - Must be a keyboard or mouse void IdentifyDevice(ArtemisDevice device); /// @@ -40,12 +40,37 @@ namespace Artemis.Core.Services /// /// Occurs whenever a key on a keyboard was pressed /// - event EventHandler KeyboardKeyDown; + event EventHandler KeyboardKeyDown; /// /// Occurs whenever a key on a keyboard was released /// - event EventHandler KeyboardKeyUp; + event EventHandler KeyboardKeyUp; + + /// + /// Occurs whenever a button on a mouse was pressed or released + /// + event EventHandler MouseButtonUpDown; + + /// + /// Occurs whenever a button on a mouse was pressed + /// + event EventHandler MouseButtonDown; + + /// + /// Occurs whenever a button on a mouse was released + /// + event EventHandler MouseButtonUp; + + /// + /// Occurs whenever a the scroll wheel of a mouse is turned + /// + event EventHandler MouseScroll; + + /// + /// Occurs whenever a a mouse is moved + /// + event EventHandler MouseMove; /// /// Occurs when a device has been identified after calling @@ -61,9 +86,9 @@ namespace Artemis.Core.Services /// /// The input provider to identify the device for /// The value to use to identify the device - /// A device type to fall back to if no match is found + /// A device type to fall back to if no match is found /// If found, the Artemis device matching the provider and identifier - ArtemisDevice? GetDeviceByIdentifier(InputProvider provider, object identifier, InputFallbackDeviceType fallbackType); + ArtemisDevice? GetDeviceByIdentifier(InputProvider provider, object identifier, InputDeviceType type); /// /// Clears the identifier cache diff --git a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs index 38712cf13..dc2c481d3 100644 --- a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs +++ b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs @@ -6,7 +6,7 @@ namespace Artemis.Storage.Entities.Surface { public DeviceEntity() { - InputIdentifier = new List(); + InputIdentifiers = new List(); } public string DeviceIdentifier { get; set; } @@ -16,7 +16,7 @@ namespace Artemis.Storage.Entities.Surface public double Scale { get; set; } public int ZIndex { get; set; } - public List InputIdentifier { get; set; } + public List InputIdentifiers { get; set; } } public class DeviceInputIdentifierEntity diff --git a/src/Artemis.Storage/Repositories/SurfaceRepository.cs b/src/Artemis.Storage/Repositories/SurfaceRepository.cs index 85f5c6cbd..46b8b9e6b 100644 --- a/src/Artemis.Storage/Repositories/SurfaceRepository.cs +++ b/src/Artemis.Storage/Repositories/SurfaceRepository.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Artemis.Storage.Entities.Surface; using Artemis.Storage.Repositories.Interfaces; using LiteDB; @@ -32,7 +33,7 @@ namespace Artemis.Storage.Repositories public List GetAll() { - return _repository.Query().Include(s => s.DeviceEntities).ToList(); + return _repository.Query().Include(s => s.DeviceEntities.Select(de => de.InputIdentifiers)).ToList(); } public void Save(SurfaceEntity surfaceEntity) diff --git a/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelListViewModel.cs b/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelListViewModel.cs index d590df5ca..22eeb33a1 100644 --- a/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelListViewModel.cs +++ b/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelListViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Windows.Documents; using Artemis.Core; using Artemis.Core.DataModelExpansions; using Artemis.UI.Shared.Services; diff --git a/src/Artemis.UI.Shared/Screens/Dialogs/ConfirmDialogViewModel.cs b/src/Artemis.UI.Shared/Screens/Dialogs/ConfirmDialogViewModel.cs index 4d65fe81c..d53436ae0 100644 --- a/src/Artemis.UI.Shared/Screens/Dialogs/ConfirmDialogViewModel.cs +++ b/src/Artemis.UI.Shared/Screens/Dialogs/ConfirmDialogViewModel.cs @@ -22,11 +22,5 @@ namespace Artemis.UI.Shared.Screens.Dialogs if (Session != null && !Session.IsEnded) Session.Close(true); } - - public void Cancel() - { - if (Session != null && !Session.IsEnded) - Session.Close(false); - } } } \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs b/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs index c2cec49dd..d95ee175d 100644 --- a/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs +++ b/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs @@ -91,15 +91,14 @@ namespace Artemis.UI.Shared.Screens.GradientEditor Session.Close(true); } - public void Cancel() + public override void Cancel() { // Restore the saved state ColorGradient.Stops.Clear(); ColorGradient.Stops.AddRange(_originalStops); ColorGradient.OnColorValuesUpdated(); - if (Session != null && !Session.IsEnded) - Session.Close(false); + base.Cancel(); } private void UpdateColorStopViewModels(object? sender, PropertyChangedEventArgs e) diff --git a/src/Artemis.UI.Shared/Services/Dialog/DialogViewModelBase.cs b/src/Artemis.UI.Shared/Services/Dialog/DialogViewModelBase.cs index 5a93b3767..3cdddba3b 100644 --- a/src/Artemis.UI.Shared/Services/Dialog/DialogViewModelBase.cs +++ b/src/Artemis.UI.Shared/Services/Dialog/DialogViewModelBase.cs @@ -49,6 +49,15 @@ namespace Artemis.UI.Shared.Services { } + /// + /// If not yet closed, closes the current session passing + /// + public virtual void Cancel() + { + if (Session != null && !Session.IsEnded) + Session.Close(false); + } + internal void OnDialogOpened(object sender, DialogOpenedEventArgs e) { Session = e.Session; diff --git a/src/Artemis.UI/InputProviders/NativeWindowInputProvider.cs b/src/Artemis.UI/InputProviders/NativeWindowInputProvider.cs index 8d8c79264..a0e8b4d39 100644 --- a/src/Artemis.UI/InputProviders/NativeWindowInputProvider.cs +++ b/src/Artemis.UI/InputProviders/NativeWindowInputProvider.cs @@ -81,11 +81,11 @@ namespace Artemis.UI.InputProviders // Let the core know there is an identifier so it can store new identifications if applicable if (identifier != null) - OnIdentifierReceived(identifier); + OnIdentifierReceived(identifier, InputDeviceType.Keyboard); ArtemisDevice device = null; if (identifier != null) - device = _inputService.GetDeviceByIdentifier(this, identifier, InputFallbackDeviceType.Keyboard); + device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard); // Duplicate keys with different positions can be identified by the LeftKey flag (even though its set of the key that's physically on the right) if (keyboardData.Keyboard.Flags == RawKeyboardFlags.LeftKey || keyboardData.Keyboard.Flags == (RawKeyboardFlags.LeftKey | RawKeyboardFlags.Up)) @@ -105,7 +105,7 @@ namespace Artemis.UI.InputProviders keyboardData.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.LeftKey) && keyboardData.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.RightKey); - OnKeyboardDataReceived(new InputProviderKeyboardEventArgs(device, key, isDown)); + OnKeyboardDataReceived(device, key, isDown); } #endregion @@ -130,7 +130,7 @@ namespace Artemis.UI.InputProviders ArtemisDevice device = null; string identifier = data.Device?.DevicePath; if (identifier != null) - device = _inputService.GetDeviceByIdentifier(this, identifier, InputFallbackDeviceType.Mouse); + device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Mouse); // Debug.WriteLine($"Buttons: {data.Mouse.Buttons}, Data: {data.Mouse.ButtonData}, Flags: {data.Mouse.Flags}, XY: {data.Mouse.LastX},{data.Mouse.LastY}"); @@ -138,7 +138,7 @@ namespace Artemis.UI.InputProviders if (mouseData.Mouse.Buttons == RawMouseButtonFlags.None) { Win32Point cursorPosition = GetCursorPosition(); - OnMouseMoveDataReceived(new InputProviderMouseMoveEventArgs(device, cursorPosition.X, cursorPosition.Y, _mouseDeltaX, _mouseDeltaY)); + OnMouseMoveDataReceived(device, cursorPosition.X, cursorPosition.Y, _mouseDeltaX, _mouseDeltaY); _mouseDeltaX = 0; _mouseDeltaY = 0; _lastMouseUpdate = DateTime.Now; @@ -147,15 +147,15 @@ namespace Artemis.UI.InputProviders // Now we know its not movement, let the core know there is an identifier so it can store new identifications if applicable if (identifier != null) - OnIdentifierReceived(identifier); + OnIdentifierReceived(identifier, InputDeviceType.Mouse); // Scrolling if (mouseData.Mouse.ButtonData != 0) { if (mouseData.Mouse.Buttons == RawMouseButtonFlags.MouseWheel) - OnMouseScrollDataReceived(new InputProviderMouseScrollEventArgs(device, MouseScrollDirection.Vertical, mouseData.Mouse.ButtonData)); + OnMouseScrollDataReceived(device, MouseScrollDirection.Vertical, mouseData.Mouse.ButtonData); else if (mouseData.Mouse.Buttons == RawMouseButtonFlags.MouseHorizontalWheel) - OnMouseScrollDataReceived(new InputProviderMouseScrollEventArgs(device, MouseScrollDirection.Horizontal, mouseData.Mouse.ButtonData)); + OnMouseScrollDataReceived(device, MouseScrollDirection.Horizontal, mouseData.Mouse.ButtonData); return; } @@ -178,7 +178,7 @@ namespace Artemis.UI.InputProviders else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.Button5Down, RawMouseButtonFlags.Button5Up, ref isDown)) button = MouseButton.Button5; - OnMouseButtonDataReceived(new InputProviderMouseButtonEventArgs(device, button, isDown)); + OnMouseButtonDataReceived(device, button, isDown); } private bool DetermineMouseButton(RawInputMouseData data, RawMouseButtonFlags downButton, RawMouseButtonFlags upButton, ref bool isDown) diff --git a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileCreateViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileCreateViewModel.cs index 3f38e24a4..75be9f097 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileCreateViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileCreateViewModel.cs @@ -28,11 +28,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs Session.Close(ProfileName); } - - public void Cancel() - { - Session.Close(); - } } public class ProfileCreateViewModelValidator : AbstractValidator diff --git a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileExportViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileExportViewModel.cs index 4e7a82817..a85b85046 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileExportViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileExportViewModel.cs @@ -30,10 +30,5 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs Session.Close(); } - - public void Cancel() - { - Session.Close(); - } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileImportViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileImportViewModel.cs index 3c824de7e..cab90345a 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileImportViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/ProfileImportViewModel.cs @@ -37,10 +37,5 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs _mainMessageQueue.Enqueue("Profile imported."); Session.Close(descriptor); } - - public void Cancel() - { - Session.Close(); - } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/RenameViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/RenameViewModel.cs index f970097de..214513c10 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Dialogs/RenameViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Dialogs/RenameViewModel.cs @@ -32,11 +32,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs Session.Close(ElementName); } - - public void Cancel() - { - Session.Close(); - } } public class ProfileElementRenameViewModelValidator : AbstractValidator diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs index f687f8eb9..a4df1b62b 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs @@ -19,6 +19,7 @@ using Artemis.UI.Shared.Services; using GongSolutions.Wpf.DragDrop; using Stylet; using static Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree.TreeGroupViewModel.LayerPropertyGroupType; +using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs; namespace Artemis.UI.Screens.ProfileEditor.LayerProperties { diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/Timeline/Dialogs/TimelineSegmentDialogViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/Timeline/Dialogs/TimelineSegmentDialogViewModel.cs index d6575636e..fb4959405 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/Timeline/Dialogs/TimelineSegmentDialogViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/Timeline/Dialogs/TimelineSegmentDialogViewModel.cs @@ -38,11 +38,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Dialogs Segment.UpdateLength(TimelineSegmentDialogViewModelValidator.CreateTime(InputValue)); Session.Close(); } - - public void Cancel() - { - Session.Close(); - } } public class TimelineSegmentDialogViewModelValidator : AbstractValidator diff --git a/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs index 780aac675..724831cd2 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs @@ -12,6 +12,7 @@ using Artemis.UI.Screens.ProfileEditor.Visualization.Tools; using Artemis.UI.Screens.Shared; using Artemis.UI.Shared.Services; using Stylet; +using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs; namespace Artemis.UI.Screens.ProfileEditor.Visualization { diff --git a/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs index cf09e35ec..479169ea6 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs @@ -8,6 +8,7 @@ using Artemis.Core.LayerBrushes; using Artemis.Core.Services; using Artemis.UI.Properties; using Artemis.UI.Shared.Services; +using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs; namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools { diff --git a/src/Artemis.UI/Screens/RootViewModel.cs b/src/Artemis.UI/Screens/RootViewModel.cs index c021e1542..a8a5e4146 100644 --- a/src/Artemis.UI/Screens/RootViewModel.cs +++ b/src/Artemis.UI/Screens/RootViewModel.cs @@ -17,6 +17,7 @@ using Artemis.UI.Utilities; using MaterialDesignExtensions.Controls; using MaterialDesignThemes.Wpf; using Stylet; +using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs; namespace Artemis.UI.Screens { diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsView.xaml index 46c27a1e5..d452a4fd0 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsView.xaml @@ -54,8 +54,31 @@ - + + + + diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs index e2b2333ba..42f2121e1 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsViewModel.cs @@ -1,10 +1,15 @@ using System; +using System.Collections.Generic; using System.Diagnostics; +using System.Threading.Tasks; using Artemis.Core; using Artemis.Core.Services; using Artemis.UI.Ninject.Factories; +using Artemis.UI.Screens.SurfaceEditor.Dialogs; +using Artemis.UI.Screens.SurfaceEditor.Visualization; using Artemis.UI.Shared.Services; using Humanizer; +using RGB.NET.Core; using Stylet; namespace Artemis.UI.Screens.Settings.Tabs.Devices @@ -12,18 +17,24 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices public class DeviceSettingsViewModel : PropertyChangedBase { private readonly IDeviceDebugVmFactory _deviceDebugVmFactory; + private readonly ISurfaceService _surfaceService; private readonly IDeviceService _deviceService; private readonly IDialogService _dialogService; private readonly IWindowManager _windowManager; private bool _isDeviceEnabled; - public DeviceSettingsViewModel(ArtemisDevice device, IDeviceService deviceService, IDialogService dialogService, - IWindowManager windowManager, IDeviceDebugVmFactory deviceDebugVmFactory) + public DeviceSettingsViewModel(ArtemisDevice device, + IDeviceService deviceService, + IDialogService dialogService, + IWindowManager windowManager, + IDeviceDebugVmFactory deviceDebugVmFactory, + ISurfaceService surfaceService) { _deviceService = deviceService; _dialogService = dialogService; _windowManager = windowManager; _deviceDebugVmFactory = deviceDebugVmFactory; + _surfaceService = surfaceService; Device = device; Type = Device.RgbDevice.DeviceInfo.DeviceType.ToString().Humanize(); @@ -40,6 +51,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices public string Name { get; } public string Manufacturer { get; } + public bool CanDetectInput => Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || + Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse; + public bool IsDeviceEnabled { get => _isDeviceEnabled; @@ -67,5 +81,25 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices _dialogService.ShowExceptionDialog("Welp, we couldn't open the device's plugin folder for you", e); } } + + public async Task DetectInput() + { + object madeChanges = await _dialogService.ShowDialog( + new Dictionary { { "device", Device } } + ); + + if ((bool)madeChanges) + _surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true); + } + + public async Task ViewProperties() + { + object madeChanges = await _dialogService.ShowDialog( + new Dictionary {{"device", Device}} + ); + + if ((bool) madeChanges) + _surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true); + } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Splash/SplashViewModel.cs b/src/Artemis.UI/Screens/Splash/SplashViewModel.cs index f80543a79..81ad13825 100644 --- a/src/Artemis.UI/Screens/Splash/SplashViewModel.cs +++ b/src/Artemis.UI/Screens/Splash/SplashViewModel.cs @@ -6,6 +6,7 @@ using Humanizer; using MaterialDesignExtensions.Controls; using Stylet; using MouseButton = System.Windows.Input.MouseButton; +using MouseButtonEventArgs = System.Windows.Input.MouseButtonEventArgs; namespace Artemis.UI.Screens.Splash { diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceCreateViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceCreateViewModel.cs index c92ebc24b..92c03e995 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceCreateViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceCreateViewModel.cs @@ -27,10 +27,5 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs Session.Close(SurfaceName); } - - public void Cancel() - { - Session.Close(); - } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigViewModel.cs index 8553748d8..bd74d1076 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigViewModel.cs @@ -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 validator) - : base(validator) + public SurfaceDeviceConfigViewModel(ArtemisDevice device, ICoreService coreService, IModelValidator 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); - } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputView.xaml b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputView.xaml index 16e93aca1..54349c2f4 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputView.xaml +++ b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputView.xaml @@ -17,13 +17,39 @@ that is currently showing a yellow color. - + + This will teach Artemis to associate button/key presses with this specific device. - + +