1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Merge pull request #507 from Artemis-RGB/feature/input

Adds a service for keyboard/mouse input events
This commit is contained in:
Robert Beekman 2020-11-23 21:27:04 +01:00 committed by GitHub
commit 29ee64e7a8
53 changed files with 2445 additions and 75 deletions

View File

@ -55,6 +55,10 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=rgb_002Enet/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Ccolorquantizer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Ccolorquantizer_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinput/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinput_005Cenums/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinput_005Cevents/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinput_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cregistration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cregistration_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.DeviceProviders;
@ -23,6 +24,9 @@ namespace Artemis.Core
DeviceProvider = deviceProvider;
Surface = surface;
DeviceEntity = new DeviceEntity();
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
_leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
Rotation = 0;
@ -39,6 +43,11 @@ namespace Artemis.Core
DeviceProvider = deviceProvider;
Surface = surface;
DeviceEntity = deviceEntity;
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
_leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
}
@ -84,6 +93,11 @@ namespace Artemis.Core
private set => SetAndNotify(ref _leds, value);
}
/// <summary>
/// Gets a list of input identifiers associated with this device
/// </summary>
public List<ArtemisDeviceInputIdentifier> InputIdentifiers { get; }
/// <summary>
/// Gets or sets the X-position of the device
/// </summary>
@ -174,6 +188,16 @@ namespace Artemis.Core
{
// Other properties are computed
DeviceEntity.DeviceIdentifier = RgbDevice.GetDeviceIdentifier();
DeviceEntity.InputIdentifiers.Clear();
foreach (ArtemisDeviceInputIdentifier identifier in InputIdentifiers)
{
DeviceEntity.InputIdentifiers.Add(new DeviceInputIdentifierEntity
{
InputProvider = identifier.InputProvider,
Identifier = identifier.Identifier
});
}
}
internal void ApplyToRgbDevice()
@ -186,6 +210,10 @@ namespace Artemis.Core
RgbDevice.Location = new Point(1, 1);
RgbDevice.Location = new Point(DeviceEntity.X, DeviceEntity.Y);
InputIdentifiers.Clear();
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
CalculateRenderProperties();
OnDeviceUpdated();
}

View File

@ -0,0 +1,31 @@
using Artemis.Core.Services;
namespace Artemis.Core
{
/// <summary>
/// Represents a device input identifier used by a specific <see cref="Services.InputProvider" /> to identify the device
/// </summary>
public class ArtemisDeviceInputIdentifier
{
/// <summary>
/// Creates a new instance of the <see cref="ArtemisDeviceInputIdentifier" /> class
/// </summary>
/// <param name="inputProvider">The full type and namespace of the <see cref="Services.InputProvider" /> this identifier is used by</param>
/// <param name="identifier">A value used to identify the device</param>
public ArtemisDeviceInputIdentifier(string inputProvider, object identifier)
{
InputProvider = inputProvider;
Identifier = identifier;
}
/// <summary>
/// Gets or sets the full type and namespace of the <see cref="Services.InputProvider" /> this identifier is used by
/// </summary>
public string InputProvider { get; set; }
/// <summary>
/// Gets or sets a value used to identify the device
/// </summary>
public object Identifier { get; set; }
}
}

View File

@ -62,5 +62,11 @@ namespace Artemis.Core
(RgbLed.AbsoluteLedRectangle.Size.Height * Device.Surface.Scale).RoundToInt()
);
}
/// <inheritdoc />
public override string ToString()
{
return RgbLed.ToString();
}
}
}

View File

@ -0,0 +1,23 @@
namespace Artemis.Core.Services
{
/// <summary>
/// Represents a device that provides input to the <see cref="IInputService" />
/// </summary>
public enum InputDeviceType
{
/// <summary>
/// None
/// </summary>
None,
/// <summary>
/// A keyboard
/// </summary>
Keyboard,
/// <summary>
/// A mouse
/// </summary>
Mouse
}
}

View File

@ -0,0 +1,537 @@
namespace Artemis.Core.Services
{
/// <summary>Specifies the possible key values on a keyboard.</summary>
public enum KeyboardKey
{
/// <summary>No key pressed.</summary>
None = 0,
/// <summary>The Cancel key.</summary>
Cancel = 1,
/// <summary>The Backspace key.</summary>
Back = 2,
/// <summary>The Tab key.</summary>
Tab = 3,
/// <summary>The Linefeed key.</summary>
LineFeed = 4,
/// <summary>The Clear key.</summary>
Clear = 5,
/// <summary>The Enter key.</summary>
Enter = 6,
/// <summary>The Return key.</summary>
Return = 6,
/// <summary>The Pause key.</summary>
Pause = 7,
/// <summary>The Caps Lock key.</summary>
CapsLock = 8,
/// <summary>The IME Hangul mode key.</summary>
HangulMode = 9,
/// <summary>The IME Junja mode key.</summary>
JunjaMode = 10, // 0x0000000A
/// <summary>The IME Final mode key.</summary>
FinalMode = 11, // 0x0000000B
/// <summary>The IME Hanja mode key.</summary>
HanjaMode = 12, // 0x0000000C
/// <summary>The ESC key.</summary>
Escape = 13, // 0x0000000D
/// <summary>The IME Convert key.</summary>
ImeConvert = 14, // 0x0000000E
/// <summary>The IME NonConvert key.</summary>
ImeNonConvert = 15, // 0x0000000F
/// <summary>The IME Accept key.</summary>
ImeAccept = 16, // 0x00000010
/// <summary>The IME Mode change request.</summary>
ImeModeChange = 17, // 0x00000011
/// <summary>The Spacebar key.</summary>
Space = 18, // 0x00000012
/// <summary>The Page Up key.</summary>
PageUp = 19, // 0x00000013
/// <summary>The Page Up key.</summary>
Prior = 19, // 0x00000013
/// <summary>The Page Down key.</summary>
Next = 20, // 0x00000014
/// <summary>The Page Down key.</summary>
PageDown = 20, // 0x00000014
/// <summary>The End key.</summary>
End = 21, // 0x00000015
/// <summary>The Home key.</summary>
Home = 22, // 0x00000016
/// <summary>The Left Arrow key.</summary>
Left = 23, // 0x00000017
/// <summary>The Up Arrow key.</summary>
Up = 24, // 0x00000018
/// <summary>The Right Arrow key.</summary>
Right = 25, // 0x00000019
/// <summary>The Down Arrow key.</summary>
Down = 26, // 0x0000001A
/// <summary>The Select key.</summary>
Select = 27, // 0x0000001B
/// <summary>The Print key.</summary>
Print = 28, // 0x0000001C
/// <summary>The Execute key.</summary>
Execute = 29, // 0x0000001D
/// <summary>The Print Screen key.</summary>
PrintScreen = 30, // 0x0000001E
/// <summary>The Insert key.</summary>
Insert = 31, // 0x0000001F
/// <summary>The Delete key.</summary>
Delete = 32, // 0x00000020
/// <summary>The Help key.</summary>
Help = 33, // 0x00000021
/// <summary>The 0 (zero) key.</summary>
D0 = 34, // 0x00000022
/// <summary>The 1 (one) key.</summary>
D1 = 35, // 0x00000023
/// <summary>The 2 key.</summary>
D2 = 36, // 0x00000024
/// <summary>The 3 key.</summary>
D3 = 37, // 0x00000025
/// <summary>The 4 key.</summary>
D4 = 38, // 0x00000026
/// <summary>The 5 key.</summary>
D5 = 39, // 0x00000027
/// <summary>The 6 key.</summary>
D6 = 40, // 0x00000028
/// <summary>The 7 key.</summary>
D7 = 41, // 0x00000029
/// <summary>The 8 key.</summary>
D8 = 42, // 0x0000002A
/// <summary>The 9 key.</summary>
D9 = 43, // 0x0000002B
/// <summary>The A key.</summary>
A = 44, // 0x0000002C
/// <summary>The B key.</summary>
B = 45, // 0x0000002D
/// <summary>The C key.</summary>
C = 46, // 0x0000002E
/// <summary>The D key.</summary>
D = 47, // 0x0000002F
/// <summary>The E key.</summary>
E = 48, // 0x00000030
/// <summary>The F key.</summary>
F = 49, // 0x00000031
/// <summary>The G key.</summary>
G = 50, // 0x00000032
/// <summary>The H key.</summary>
H = 51, // 0x00000033
/// <summary>The I key.</summary>
I = 52, // 0x00000034
/// <summary>The J key.</summary>
J = 53, // 0x00000035
/// <summary>The K key.</summary>
K = 54, // 0x00000036
/// <summary>The L key.</summary>
L = 55, // 0x00000037
/// <summary>The M key.</summary>
M = 56, // 0x00000038
/// <summary>The N key.</summary>
N = 57, // 0x00000039
/// <summary>The O key.</summary>
O = 58, // 0x0000003A
/// <summary>The P key.</summary>
P = 59, // 0x0000003B
/// <summary>The Q key.</summary>
Q = 60, // 0x0000003C
/// <summary>The R key.</summary>
R = 61, // 0x0000003D
/// <summary>The S key.</summary>
S = 62, // 0x0000003E
/// <summary>The T key.</summary>
T = 63, // 0x0000003F
/// <summary>The U key.</summary>
U = 64, // 0x00000040
/// <summary>The V key.</summary>
V = 65, // 0x00000041
/// <summary>The W key.</summary>
W = 66, // 0x00000042
/// <summary>The X key.</summary>
X = 67, // 0x00000043
/// <summary>The Y key.</summary>
Y = 68, // 0x00000044
/// <summary>The Z key.</summary>
Z = 69, // 0x00000045
/// <summary>The left Windows logo key (Microsoft Natural Keyboard).</summary>
LWin = 70, // 0x00000046
/// <summary>The right Windows logo key (Microsoft Natural Keyboard).</summary>
RWin = 71, // 0x00000047
/// <summary>
/// The Application key (Microsoft Natural Keyboard). Also known as the Menu key, as it displays an
/// application-specific context menu.
/// </summary>
Apps = 72, // 0x00000048
/// <summary>The Computer Sleep key.</summary>
Sleep = 73, // 0x00000049
/// <summary>The 0 key on the numeric keypad.</summary>
NumPad0 = 74, // 0x0000004A
/// <summary>The 1 key on the numeric keypad.</summary>
NumPad1 = 75, // 0x0000004B
/// <summary>The 2 key on the numeric keypad.</summary>
NumPad2 = 76, // 0x0000004C
/// <summary>The 3 key on the numeric keypad.</summary>
NumPad3 = 77, // 0x0000004D
/// <summary>The 4 key on the numeric keypad.</summary>
NumPad4 = 78, // 0x0000004E
/// <summary>The 5 key on the numeric keypad.</summary>
NumPad5 = 79, // 0x0000004F
/// <summary>The 6 key on the numeric keypad.</summary>
NumPad6 = 80, // 0x00000050
/// <summary>The 7 key on the numeric keypad.</summary>
NumPad7 = 81, // 0x00000051
/// <summary>The 8 key on the numeric keypad.</summary>
NumPad8 = 82, // 0x00000052
/// <summary>The 9 key on the numeric keypad.</summary>
NumPad9 = 83, // 0x00000053
/// <summary>The Multiply key.</summary>
Multiply = 84, // 0x00000054
/// <summary>The Add key.</summary>
Add = 85, // 0x00000055
/// <summary>The Separator key.</summary>
Separator = 86, // 0x00000056
/// <summary>The Subtract key.</summary>
Subtract = 87, // 0x00000057
/// <summary>The Decimal key.</summary>
Decimal = 88, // 0x00000058
/// <summary>The Divide key.</summary>
Divide = 89, // 0x00000059
/// <summary>The F1 key.</summary>
F1 = 90, // 0x0000005A
/// <summary>The F2 key.</summary>
F2 = 91, // 0x0000005B
/// <summary>The F3 key.</summary>
F3 = 92, // 0x0000005C
/// <summary>The F4 key.</summary>
F4 = 93, // 0x0000005D
/// <summary>The F5 key.</summary>
F5 = 94, // 0x0000005E
/// <summary>The F6 key.</summary>
F6 = 95, // 0x0000005F
/// <summary>The F7 key.</summary>
F7 = 96, // 0x00000060
/// <summary>The F8 key.</summary>
F8 = 97, // 0x00000061
/// <summary>The F9 key.</summary>
F9 = 98, // 0x00000062
/// <summary>The F10 key.</summary>
F10 = 99, // 0x00000063
/// <summary>The F11 key.</summary>
F11 = 100, // 0x00000064
/// <summary>The F12 key.</summary>
F12 = 101, // 0x00000065
/// <summary>The F13 key.</summary>
F13 = 102, // 0x00000066
/// <summary>The F14 key.</summary>
F14 = 103, // 0x00000067
/// <summary>The F15 key.</summary>
F15 = 104, // 0x00000068
/// <summary>The F16 key.</summary>
F16 = 105, // 0x00000069
/// <summary>The F17 key.</summary>
F17 = 106, // 0x0000006A
/// <summary>The F18 key.</summary>
F18 = 107, // 0x0000006B
/// <summary>The F19 key.</summary>
F19 = 108, // 0x0000006C
/// <summary>The F20 key.</summary>
F20 = 109, // 0x0000006D
/// <summary>The F21 key.</summary>
F21 = 110, // 0x0000006E
/// <summary>The F22 key.</summary>
F22 = 111, // 0x0000006F
/// <summary>The F23 key.</summary>
F23 = 112, // 0x00000070
/// <summary>The F24 key.</summary>
F24 = 113, // 0x00000071
/// <summary>The Num Lock key.</summary>
NumLock = 114, // 0x00000072
/// <summary>The Scroll Lock key.</summary>
Scroll = 115, // 0x00000073
/// <summary>The left Shift key.</summary>
LeftShift = 116, // 0x00000074
/// <summary>The right Shift key.</summary>
RightShift = 117, // 0x00000075
/// <summary>The left CTRL key.</summary>
LeftCtrl = 118, // 0x00000076
/// <summary>The right CTRL key.</summary>
RightCtrl = 119, // 0x00000077
/// <summary>The left ALT key.</summary>
LeftAlt = 120, // 0x00000078
/// <summary>The right ALT key.</summary>
RightAlt = 121, // 0x00000079
/// <summary>The Browser Back key.</summary>
BrowserBack = 122, // 0x0000007A
/// <summary>The Browser Forward key.</summary>
BrowserForward = 123, // 0x0000007B
/// <summary>The Browser Refresh key.</summary>
BrowserRefresh = 124, // 0x0000007C
/// <summary>The Browser Stop key.</summary>
BrowserStop = 125, // 0x0000007D
/// <summary>The Browser Search key.</summary>
BrowserSearch = 126, // 0x0000007E
/// <summary>The Browser Favorites key.</summary>
BrowserFavorites = 127, // 0x0000007F
/// <summary>The Browser Home key.</summary>
BrowserHome = 128, // 0x00000080
/// <summary>The Volume Mute key.</summary>
VolumeMute = 129, // 0x00000081
/// <summary>The Volume Down key.</summary>
VolumeDown = 130, // 0x00000082
/// <summary>The Volume Up key.</summary>
VolumeUp = 131, // 0x00000083
/// <summary>The Media Next Track key.</summary>
MediaNextTrack = 132, // 0x00000084
/// <summary>The Media Previous Track key.</summary>
MediaPreviousTrack = 133, // 0x00000085
/// <summary>The Media Stop key.</summary>
MediaStop = 134, // 0x00000086
/// <summary>The Media Play Pause key.</summary>
MediaPlayPause = 135, // 0x00000087
/// <summary>The Launch Mail key.</summary>
LaunchMail = 136, // 0x00000088
/// <summary>The Select Media key.</summary>
SelectMedia = 137, // 0x00000089
/// <summary>The Launch Application1 key.</summary>
LaunchApplication1 = 138, // 0x0000008A
/// <summary>The Launch Application2 key.</summary>
LaunchApplication2 = 139, // 0x0000008B
/// <summary>The OEM Semicolon key.</summary>
OemSemicolon = 140, // 0x0000008C
/// <summary>The OEM Addition key.</summary>
OemPlus = 141, // 0x0000008D
/// <summary>The OEM Comma key.</summary>
OemComma = 142, // 0x0000008E
/// <summary>The OEM Minus key.</summary>
OemMinus = 143, // 0x0000008F
/// <summary>The OEM Period key.</summary>
OemPeriod = 144, // 0x00000091
/// <summary>The OEM Question key.</summary>
OemQuestion = 145, // 0x00000092
/// <summary>The OEM Tilde key.</summary>
OemTilde = 146, // 0x00000092
/// <summary>The ABNT_C1 (Brazilian) key.</summary>
AbntC1 = 147, // 0x00000093
/// <summary>The ABNT_C2 (Brazilian) key.</summary>
AbntC2 = 148, // 0x00000095
/// <summary>The OEM Open Brackets key.</summary>
OemOpenBrackets = 149, // 0x00000096
/// <summary>The OEM Pipe key.</summary>
OemPipe = 150, // 0x00000096
/// <summary>The OEM Close Brackets key.</summary>
OemCloseBrackets = 151, // 0x00000097
/// <summary>The OEM Quotes key.</summary>
OemQuotes = 152, // 0x00000098
/// <summary>The OEM Backslash key.</summary>
OemBackslash = 154, // 0x0000009A
/// <summary>A special key masking the real key being processed by an IME.</summary>
ImeProcessed = 155, // 0x0000009B
/// <summary>A special key masking the real key being processed as a system key.</summary>
System = 156, // 0x0000009C
/// <summary>The OEM ATTN key.</summary>
OemAttn = 157, // 0x0000009D
/// <summary>The OEM FINISH key.</summary>
OemFinish = 158, // 0x0000009E
/// <summary>The OEM COPY key.</summary>
OemCopy = 159, // 0x0000009F
/// <summary>The OEM AUTO key.</summary>
OemAuto = 160, // 0x000000A0
/// <summary>The OEM ENLW key.</summary>
OemEnlw = 161, // 0x000000A1
/// <summary>The OEM BACKTAB key.</summary>
OemBackTab = 162, // 0x000000A2
/// <summary>The ATTN key.</summary>
Attn = 163, // 0x000000A3
/// <summary>The CRSEL key.</summary>
CrSel = 164, // 0x000000A4
/// <summary>The EXSEL key.</summary>
ExSel = 165, // 0x000000A5
/// <summary>The ERASE EOF key.</summary>
EraseEof = 166, // 0x000000A6
/// <summary>The PLAY key.</summary>
Play = 167, // 0x000000A7
/// <summary>The ZOOM key.</summary>
Zoom = 168, // 0x000000A8
/// <summary>A constant reserved for future use.</summary>
NoName = 169, // 0x000000A9
/// <summary>The PA1 key.</summary>
Pa1 = 170, // 0x000000AA
/// <summary>The OEM Clear key.</summary>
OemClear = 171, // 0x000000AB
/// <summary>The key is used with another key to create a single combined character.</summary>
DeadCharProcessed = 172, // 0x000000AC,
/// <summary>The NumPad enter key</summary>
NumPadEnter
}
}

View File

@ -0,0 +1,26 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Specifies the set of modifier keys.
/// </summary>
[Flags]
public enum KeyboardModifierKey
{
/// <summary>No modifiers are pressed.</summary>
None = 0,
/// <summary>The ALT key.</summary>
Alt = 1,
/// <summary>The CTRL key.</summary>
Control = 2,
/// <summary>The SHIFT key.</summary>
Shift = 4,
/// <summary>The Windows logo key.</summary>
Windows = 8
}
}

View File

@ -0,0 +1,33 @@
namespace Artemis.Core.Services
{
/// <summary>
/// Specifies the buttons on a mouse
/// </summary>
public enum MouseButton
{
/// <summary>
/// The left mouse button
/// </summary>
Left,
/// <summary>
/// The middle mouse button
/// </summary>
Middle,
/// <summary>
/// The right mouse button
/// </summary>
Right,
/// <summary>
/// Extra mouse button 4 (backwards)
/// </summary>
Button4,
/// <summary>
/// Extra mouse button 5 (forwards)
/// </summary>
Button5
}
}

View File

@ -0,0 +1,14 @@
namespace Artemis.Core.Services
{
/// <summary>
/// Specifies mouse scrolling directions
/// </summary>
public enum MouseScrollDirection
{
/// <summary>A vertical scroll direction</summary>
Vertical,
/// <summary>A horizontal scroll direction</summary>
Horizontal
}
}

View File

@ -0,0 +1,38 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for keyboard input events
/// </summary>
public class ArtemisKeyboardKeyEventArgs : EventArgs
{
internal ArtemisKeyboardKeyEventArgs(ArtemisDevice? device, ArtemisLed? led, KeyboardKey key, KeyboardModifierKey modifiers)
{
Device = device;
Led = led;
Key = key;
Modifiers = modifiers;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice? Device { get; }
/// <summary>
/// Gets the LED that corresponds to the pressed key
/// </summary>
public ArtemisLed? Led { get; }
/// <summary>
/// Gets the key that triggered the event
/// </summary>
public KeyboardKey Key { get; }
/// <summary>
/// Gets the modifiers that are pressed
/// </summary>
public KeyboardModifierKey Modifiers { get; }
}
}

View File

@ -0,0 +1,18 @@
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for keyboard input events
/// </summary>
public class ArtemisKeyboardKeyUpDownEventArgs : ArtemisKeyboardKeyEventArgs
{
internal ArtemisKeyboardKeyUpDownEventArgs(ArtemisDevice? device, ArtemisLed? led, KeyboardKey key, KeyboardModifierKey modifiers, bool isDown) : base(device, led, key, modifiers)
{
IsDown = isDown;
}
/// <summary>
/// Whether the key is being pressed down, if <see langword="false"/> the key is being released
/// </summary>
public bool IsDown { get; set; }
}
}

View File

@ -0,0 +1,32 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for mouse input events
/// </summary>
public class ArtemisMouseButtonEventArgs : EventArgs
{
internal ArtemisMouseButtonEventArgs(ArtemisDevice? device, ArtemisLed? led, MouseButton button)
{
Device = device;
Led = led;
Button = button;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice? Device { get; }
/// <summary>
/// Gets the LED that corresponds to the pressed key
/// </summary>
public ArtemisLed? Led { get; }
/// <summary>
/// Gets the button that triggered the event
/// </summary>
public MouseButton Button { get; }
}
}

View File

@ -0,0 +1,18 @@
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for mouse input events
/// </summary>
public class ArtemisMouseButtonUpDownEventArgs : ArtemisMouseButtonEventArgs
{
internal ArtemisMouseButtonUpDownEventArgs(ArtemisDevice? device, ArtemisLed? led, MouseButton button, bool isDown) : base(device, led, button)
{
IsDown = isDown;
}
/// <summary>
/// Whether the button is being pressed down, if <see langword="false"/> the button is being released
/// </summary>
public bool IsDown { get; set; }
}
}

View File

@ -0,0 +1,51 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for mouse movement events
/// </summary>
public class ArtemisMouseMoveEventArgs : EventArgs
{
/// <summary>
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="cursorX">The X position of the mouse cursor (not necessarily tied to the specific device)</param>
/// <param name="cursorY">The Y position of the mouse cursor (not necessarily tied to the specific device)</param>
/// <param name="deltaX">The movement delta in the horizontal direction</param>
/// <param name="deltaY">The movement delta in the vertical direction</param>
internal ArtemisMouseMoveEventArgs(ArtemisDevice? device, int cursorX, int cursorY, int deltaX, int deltaY)
{
Device = device;
CursorX = cursorX;
CursorY = cursorY;
DeltaX = deltaX;
DeltaY = deltaY;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice? Device { get; }
/// <summary>
/// Gets the X position of the mouse cursor (not necessarily tied to the specific device)
/// </summary>
public int CursorX { get; }
/// <summary>
/// Gets the Y position of the mouse cursor (not necessarily tied to the specific device)
/// </summary>
public int CursorY { get; }
/// <summary>
/// Gets the movement delta in the horizontal direction
/// </summary>
public int DeltaX { get; }
/// <summary>
/// Gets the movement delta in the vertical direction
/// </summary>
public int DeltaY { get; }
}
}

View File

@ -0,0 +1,57 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for mouse scroll events
/// </summary>
public class ArtemisMouseScrollEventArgs : EventArgs
{
/// <summary>
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="direction">The direction in which was scrolled</param>
/// <param name="delta">The scroll delta (can positive or negative)</param>
internal ArtemisMouseScrollEventArgs(ArtemisDevice? device, MouseScrollDirection direction, int delta)
{
Device = device;
Direction = direction;
Delta = delta;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice? Device { get; }
/// <summary>
/// Gets the direction in which was scrolled
/// </summary>
public MouseScrollDirection Direction { get; }
/// <summary>
/// Gets the scroll delta (can positive or negative)
/// </summary>
public int Delta { get; }
/// <summary>
/// Gets a boolean indicating whether the mouse scrolled up
/// </summary>
public bool IsScrollingUp => Direction == MouseScrollDirection.Vertical && Delta > 0;
/// <summary>
/// Gets a boolean indicating whether the mouse scrolled down
/// </summary>
public bool IsScrollingDown => Direction == MouseScrollDirection.Vertical && Delta < 0;
/// <summary>
/// Gets a boolean indicating whether the mouse scrolled right
/// </summary>
public bool IsScrollingRight => Direction == MouseScrollDirection.Horizontal && Delta > 0;
/// <summary>
/// Gets a boolean indicating whether the mouse scrolled left
/// </summary>
public bool IsScrollingLeft => Direction == MouseScrollDirection.Horizontal && Delta < 0;
}
}

View File

@ -0,0 +1,31 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for input provider identifier events
/// </summary>
public class InputProviderIdentifierEventArgs : EventArgs
{
/// <summary>
/// Creates a new instance of the <see cref="InputProviderIdentifierEventArgs" /> class
/// </summary>
/// <param name="identifier">A value that can be used to identify this device</param>
/// <param name="deviceType">The type of device this identifier belongs to</param>
public InputProviderIdentifierEventArgs(object identifier, InputDeviceType deviceType)
{
Identifier = identifier;
DeviceType = deviceType;
}
/// <summary>
/// Gets a value that can be used to identify this device
/// </summary>
public object Identifier { get; }
/// <summary>
/// Gets the type of device this identifier belongs to
/// </summary>
public InputDeviceType DeviceType { get; }
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for input provider keyboard events
/// </summary>
public class InputProviderKeyboardEventArgs : EventArgs
{
/// <summary>
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="key">The key that triggered the event</param>
/// <param name="isDown">Whether the key is pressed down</param>
public InputProviderKeyboardEventArgs(ArtemisDevice? device, KeyboardKey key, bool isDown)
{
Device = device;
Key = key;
IsDown = isDown;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice? Device { get; }
/// <summary>
/// Gets the key that triggered the event
/// </summary>
public KeyboardKey Key { get; }
/// <summary>
/// Gets whether the key is pressed down
/// </summary>
public bool IsDown { get; }
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for input provider mouse button events
/// </summary>
public class InputProviderMouseButtonEventArgs : EventArgs
{
/// <summary>
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="button">The button that triggered the event</param>
/// <param name="isDown">Whether the button is pressed down</param>
public InputProviderMouseButtonEventArgs(ArtemisDevice? device, MouseButton button, bool isDown)
{
Device = device;
Button = button;
IsDown = isDown;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice? Device { get; }
/// <summary>
/// Gets the button that triggered the event
/// </summary>
public MouseButton Button { get; }
/// <summary>
/// Gets whether the button is pressed down
/// </summary>
public bool IsDown { get; }
}
}

View File

@ -0,0 +1,51 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for input provider mouse movement events
/// </summary>
public class InputProviderMouseMoveEventArgs : EventArgs
{
/// <summary>
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="cursorX">The X position of the mouse cursor (not necessarily tied to the specific device)</param>
/// <param name="cursorY">The Y position of the mouse cursor (not necessarily tied to the specific device)</param>
/// <param name="deltaX">The movement delta in the horizontal direction</param>
/// <param name="deltaY">The movement delta in the vertical direction</param>
public InputProviderMouseMoveEventArgs(ArtemisDevice? device, int cursorX, int cursorY, int deltaX, int deltaY)
{
Device = device;
CursorX = cursorX;
CursorY = cursorY;
DeltaX = deltaX;
DeltaY = deltaY;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice? Device { get; }
/// <summary>
/// Gets the X position of the mouse cursor in pixels (not necessarily tied to the specific device)
/// </summary>
public int CursorX { get; }
/// <summary>
/// Gets the Y position of the mouse cursor in pixels (not necessarily tied to the specific device)
/// </summary>
public int CursorY { get; }
/// <summary>
/// Gets the movement delta in the horizontal direction in pixels
/// </summary>
public int DeltaX { get; }
/// <summary>
/// Gets the movement delta in the vertical direction in pixels
/// </summary>
public int DeltaY { get; }
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for input provider mouse button events
/// </summary>
public class InputProviderMouseScrollEventArgs : EventArgs
{
/// <summary>
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="direction">The direction in which was scrolled</param>
/// <param name="delta">The scroll delta (can positive or negative)</param>
public InputProviderMouseScrollEventArgs(ArtemisDevice? device, MouseScrollDirection direction, int delta)
{
Device = device;
Direction = direction;
Delta = delta;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice? Device { get; }
/// <summary>
/// Gets the direction in which was scrolled
/// </summary>
public MouseScrollDirection Direction { get; }
/// <summary>
/// Gets the scroll delta (can positive or negative)
/// </summary>
public int Delta { get; }
}
}

View File

@ -0,0 +1,194 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace Artemis.Core.Services
{
internal static class InputKeyUtilities
{
internal static readonly Dictionary<KeyboardKey, LedId> KeyboardKeyLedIdMap = new Dictionary<KeyboardKey, LedId>
{
{KeyboardKey.None, LedId.Keyboard_Custom1},
{KeyboardKey.Cancel, LedId.Keyboard_Custom2},
{KeyboardKey.Back, LedId.Keyboard_Backspace},
{KeyboardKey.Tab, LedId.Keyboard_Tab},
{KeyboardKey.LineFeed, LedId.Keyboard_Custom3},
{KeyboardKey.Clear, LedId.Keyboard_Custom4},
{KeyboardKey.Enter, LedId.Keyboard_Enter},
{KeyboardKey.Pause, LedId.Keyboard_PauseBreak},
{KeyboardKey.CapsLock, LedId.Keyboard_CapsLock},
{KeyboardKey.HangulMode, LedId.Keyboard_Custom4},
{KeyboardKey.JunjaMode, LedId.Keyboard_Custom5},
{KeyboardKey.FinalMode, LedId.Keyboard_Custom6},
{KeyboardKey.HanjaMode, LedId.Keyboard_Custom7},
{KeyboardKey.Escape, LedId.Keyboard_Escape},
{KeyboardKey.ImeConvert, LedId.Keyboard_Custom8},
{KeyboardKey.ImeNonConvert, LedId.Keyboard_Custom9},
{KeyboardKey.ImeAccept, LedId.Keyboard_Custom10},
{KeyboardKey.ImeModeChange, LedId.Keyboard_Custom11},
{KeyboardKey.Space, LedId.Keyboard_Space},
{KeyboardKey.PageUp, LedId.Keyboard_PageUp},
{KeyboardKey.PageDown, LedId.Keyboard_PageDown},
{KeyboardKey.End, LedId.Keyboard_End},
{KeyboardKey.Home, LedId.Keyboard_Home},
{KeyboardKey.Left, LedId.Keyboard_ArrowLeft},
{KeyboardKey.Up, LedId.Keyboard_ArrowUp},
{KeyboardKey.Right, LedId.Keyboard_ArrowRight},
{KeyboardKey.Down, LedId.Keyboard_ArrowDown},
{KeyboardKey.Select, LedId.Keyboard_Custom12},
{KeyboardKey.Print, LedId.Keyboard_Custom13},
{KeyboardKey.Execute, LedId.Keyboard_Custom14},
{KeyboardKey.PrintScreen, LedId.Keyboard_PrintScreen},
{KeyboardKey.Insert, LedId.Keyboard_Insert},
{KeyboardKey.Delete, LedId.Keyboard_Delete},
{KeyboardKey.Help, LedId.Keyboard_Custom15},
{KeyboardKey.D0, LedId.Keyboard_0},
{KeyboardKey.D1, LedId.Keyboard_1},
{KeyboardKey.D2, LedId.Keyboard_2},
{KeyboardKey.D3, LedId.Keyboard_3},
{KeyboardKey.D4, LedId.Keyboard_4},
{KeyboardKey.D5, LedId.Keyboard_5},
{KeyboardKey.D6, LedId.Keyboard_6},
{KeyboardKey.D7, LedId.Keyboard_7},
{KeyboardKey.D8, LedId.Keyboard_8},
{KeyboardKey.D9, LedId.Keyboard_9},
{KeyboardKey.A, LedId.Keyboard_A},
{KeyboardKey.B, LedId.Keyboard_B},
{KeyboardKey.C, LedId.Keyboard_C},
{KeyboardKey.D, LedId.Keyboard_D},
{KeyboardKey.E, LedId.Keyboard_E},
{KeyboardKey.F, LedId.Keyboard_F},
{KeyboardKey.G, LedId.Keyboard_G},
{KeyboardKey.H, LedId.Keyboard_H},
{KeyboardKey.I, LedId.Keyboard_I},
{KeyboardKey.J, LedId.Keyboard_J},
{KeyboardKey.K, LedId.Keyboard_K},
{KeyboardKey.L, LedId.Keyboard_L},
{KeyboardKey.M, LedId.Keyboard_M},
{KeyboardKey.N, LedId.Keyboard_N},
{KeyboardKey.O, LedId.Keyboard_O},
{KeyboardKey.P, LedId.Keyboard_P},
{KeyboardKey.Q, LedId.Keyboard_Q},
{KeyboardKey.R, LedId.Keyboard_R},
{KeyboardKey.S, LedId.Keyboard_S},
{KeyboardKey.T, LedId.Keyboard_T},
{KeyboardKey.U, LedId.Keyboard_U},
{KeyboardKey.V, LedId.Keyboard_V},
{KeyboardKey.W, LedId.Keyboard_W},
{KeyboardKey.X, LedId.Keyboard_X},
{KeyboardKey.Y, LedId.Keyboard_Y},
{KeyboardKey.Z, LedId.Keyboard_Z},
{KeyboardKey.LWin, LedId.Keyboard_LeftGui},
{KeyboardKey.RWin, LedId.Keyboard_RightGui},
{KeyboardKey.Apps, LedId.Keyboard_Application},
{KeyboardKey.Sleep, LedId.Keyboard_Custom16},
{KeyboardKey.NumPad0, LedId.Keyboard_Num0},
{KeyboardKey.NumPad1, LedId.Keyboard_Num1},
{KeyboardKey.NumPad2, LedId.Keyboard_Num2},
{KeyboardKey.NumPad3, LedId.Keyboard_Num3},
{KeyboardKey.NumPad4, LedId.Keyboard_Num4},
{KeyboardKey.NumPad5, LedId.Keyboard_Num5},
{KeyboardKey.NumPad6, LedId.Keyboard_Num6},
{KeyboardKey.NumPad7, LedId.Keyboard_Num7},
{KeyboardKey.NumPad8, LedId.Keyboard_Num8},
{KeyboardKey.NumPad9, LedId.Keyboard_Num9},
{KeyboardKey.Multiply, LedId.Keyboard_NumAsterisk},
{KeyboardKey.Add, LedId.Keyboard_NumPlus},
{KeyboardKey.Separator, LedId.Keyboard_NumEnter}, // unverified
{KeyboardKey.Subtract, LedId.Keyboard_NumMinus},
{KeyboardKey.Decimal, LedId.Keyboard_NumPeriodAndDelete},
{KeyboardKey.Divide, LedId.Keyboard_NumSlash},
{KeyboardKey.F1, LedId.Keyboard_F1},
{KeyboardKey.F2, LedId.Keyboard_F2},
{KeyboardKey.F3, LedId.Keyboard_F3},
{KeyboardKey.F4, LedId.Keyboard_F4},
{KeyboardKey.F5, LedId.Keyboard_F5},
{KeyboardKey.F6, LedId.Keyboard_F6},
{KeyboardKey.F7, LedId.Keyboard_F7},
{KeyboardKey.F8, LedId.Keyboard_F8},
{KeyboardKey.F9, LedId.Keyboard_F9},
{KeyboardKey.F10, LedId.Keyboard_F10},
{KeyboardKey.F11, LedId.Keyboard_F11},
{KeyboardKey.F12, LedId.Keyboard_F12},
{KeyboardKey.F13, LedId.Keyboard_Custom17},
{KeyboardKey.F14, LedId.Keyboard_Custom18},
{KeyboardKey.F15, LedId.Keyboard_Custom19},
{KeyboardKey.F16, LedId.Keyboard_Custom20},
{KeyboardKey.F17, LedId.Keyboard_Custom21},
{KeyboardKey.F18, LedId.Keyboard_Custom22},
{KeyboardKey.F19, LedId.Keyboard_Custom23},
{KeyboardKey.F20, LedId.Keyboard_Custom24},
{KeyboardKey.F21, LedId.Keyboard_Custom25},
{KeyboardKey.F22, LedId.Keyboard_Custom26},
{KeyboardKey.F23, LedId.Keyboard_Custom27},
{KeyboardKey.F24, LedId.Keyboard_Custom28},
{KeyboardKey.NumLock, LedId.Keyboard_NumLock},
{KeyboardKey.Scroll, LedId.Keyboard_ScrollLock},
{KeyboardKey.LeftShift, LedId.Keyboard_LeftShift},
{KeyboardKey.RightShift, LedId.Keyboard_RightShift},
{KeyboardKey.LeftCtrl, LedId.Keyboard_LeftCtrl},
{KeyboardKey.RightCtrl, LedId.Keyboard_RightCtrl},
{KeyboardKey.LeftAlt, LedId.Keyboard_LeftAlt},
{KeyboardKey.RightAlt, LedId.Keyboard_RightAlt},
{KeyboardKey.BrowserBack, LedId.Keyboard_Custom29},
{KeyboardKey.BrowserForward, LedId.Keyboard_Custom30},
{KeyboardKey.BrowserRefresh, LedId.Keyboard_Custom31},
{KeyboardKey.BrowserStop, LedId.Keyboard_Custom32},
{KeyboardKey.BrowserSearch, LedId.Keyboard_Custom33},
{KeyboardKey.BrowserFavorites, LedId.Keyboard_Custom34},
{KeyboardKey.BrowserHome, LedId.Keyboard_Custom35},
{KeyboardKey.VolumeMute, LedId.Keyboard_MediaMute},
{KeyboardKey.VolumeDown, LedId.Keyboard_MediaVolumeDown},
{KeyboardKey.VolumeUp, LedId.Keyboard_MediaVolumeUp},
{KeyboardKey.MediaNextTrack, LedId.Keyboard_MediaNextTrack},
{KeyboardKey.MediaPreviousTrack, LedId.Keyboard_MediaPreviousTrack},
{KeyboardKey.MediaStop, LedId.Keyboard_MediaStop},
{KeyboardKey.MediaPlayPause, LedId.Keyboard_MediaPlay},
{KeyboardKey.LaunchMail, LedId.Keyboard_Custom36},
{KeyboardKey.SelectMedia, LedId.Keyboard_Custom37},
{KeyboardKey.LaunchApplication1, LedId.Keyboard_Custom38},
{KeyboardKey.LaunchApplication2, LedId.Keyboard_Custom39},
{KeyboardKey.OemSemicolon, LedId.Keyboard_SemicolonAndColon},
{KeyboardKey.OemPlus, LedId.Keyboard_EqualsAndPlus},
{KeyboardKey.OemMinus, LedId.Keyboard_MinusAndUnderscore},
{KeyboardKey.OemComma, LedId.Keyboard_CommaAndLessThan},
{KeyboardKey.OemPeriod, LedId.Keyboard_PeriodAndBiggerThan},
{KeyboardKey.OemQuestion, LedId.Keyboard_SlashAndQuestionMark},
{KeyboardKey.OemTilde, LedId.Keyboard_GraveAccentAndTilde},
{KeyboardKey.AbntC1, LedId.Keyboard_Custom40},
{KeyboardKey.AbntC2, LedId.Keyboard_Custom41},
{KeyboardKey.OemOpenBrackets, LedId.Keyboard_BracketLeft},
{KeyboardKey.OemPipe, LedId.Keyboard_Backslash},
{KeyboardKey.OemCloseBrackets, LedId.Keyboard_BracketRight},
{KeyboardKey.OemQuotes, LedId.Keyboard_ApostropheAndDoubleQuote},
{KeyboardKey.OemBackslash, LedId.Keyboard_Custom42}, // unverified
{KeyboardKey.ImeProcessed, LedId.Keyboard_Custom43},
{KeyboardKey.System, LedId.Keyboard_Custom44},
{KeyboardKey.OemAttn, LedId.Keyboard_Custom45},
{KeyboardKey.OemFinish, LedId.Keyboard_Custom46},
{KeyboardKey.OemCopy, LedId.Keyboard_Custom47},
{KeyboardKey.OemAuto, LedId.Keyboard_Custom48},
{KeyboardKey.OemEnlw, LedId.Keyboard_Custom49},
{KeyboardKey.OemBackTab, LedId.Keyboard_Custom50},
{KeyboardKey.Attn, LedId.Keyboard_Custom51},
{KeyboardKey.CrSel, LedId.Keyboard_Custom52},
{KeyboardKey.ExSel, LedId.Keyboard_Custom53},
{KeyboardKey.EraseEof, LedId.Keyboard_Custom54},
{KeyboardKey.Play, LedId.Keyboard_MediaPlay},
{KeyboardKey.Zoom, LedId.Keyboard_Custom55},
{KeyboardKey.NoName, LedId.Keyboard_Custom56},
{KeyboardKey.Pa1, LedId.Keyboard_Custom57},
{KeyboardKey.OemClear, LedId.Keyboard_Custom58},
{KeyboardKey.DeadCharProcessed, LedId.Keyboard_Custom59},
{KeyboardKey.NumPadEnter, LedId.Keyboard_NumEnter}
};
internal static readonly Dictionary<MouseButton, LedId> MouseButtonLedIdMap = new Dictionary<MouseButton, LedId>
{
{MouseButton.Left, LedId.Mouse1},
{MouseButton.Middle, LedId.Mouse2},
{MouseButton.Right, LedId.Mouse3},
{MouseButton.Button4, LedId.Mouse4},
{MouseButton.Button5, LedId.Mouse5}
};
}
}

View File

@ -0,0 +1,123 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Represents an interface for an input provider that provides and implementation for sending and receiving device
/// input
/// </summary>
public abstract class InputProvider : IDisposable
{
/// <summary>
/// Occurs when the input provided has received keyboard data
/// </summary>
public event EventHandler<InputProviderKeyboardEventArgs>? KeyboardDataReceived;
/// <summary>
/// Occurs when the input provided has received mouse button data
/// </summary>
public event EventHandler<InputProviderMouseButtonEventArgs>? MouseButtonDataReceived;
/// <summary>
/// Occurs when the input provided has received mouse scroll data
/// </summary>
public event EventHandler<InputProviderMouseScrollEventArgs>? MouseScrollDataReceived;
/// <summary>
/// Occurs when the input provided has received mouse move data
/// </summary>
public event EventHandler<InputProviderMouseMoveEventArgs>? MouseMoveDataReceived;
/// <summary>
/// Occurs when the input provided received a device identifier
/// </summary>
public event EventHandler<InputProviderIdentifierEventArgs>? IdentifierReceived;
/// <summary>
/// Invokes the <see cref="KeyboardDataReceived" /> event which the <see cref="IInputService" /> listens to as long as
/// this provider is registered
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="key">The key that triggered the event</param>
/// <param name="isDown">Whether the key is pressed down</param>
protected virtual void OnKeyboardDataReceived(ArtemisDevice? device, KeyboardKey key, bool isDown)
{
KeyboardDataReceived?.Invoke(this, new InputProviderKeyboardEventArgs(device, key, isDown));
}
/// <summary>
/// Invokes the <see cref="MouseButtonDataReceived" /> event which the <see cref="IInputService" /> listens to as long
/// as this provider is registered
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="button">The button that triggered the event</param>
/// <param name="isDown">Whether the button is pressed down</param>
protected virtual void OnMouseButtonDataReceived(ArtemisDevice? device, MouseButton button, bool isDown)
{
MouseButtonDataReceived?.Invoke(this, new InputProviderMouseButtonEventArgs(device, button, isDown));
}
/// <summary>
/// Invokes the <see cref="MouseScrollDataReceived" /> event which the <see cref="IInputService" /> listens to as long
/// as this provider is registered
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="direction">The direction in which was scrolled</param>
/// <param name="delta">The scroll delta (can positive or negative)</param>
protected virtual void OnMouseScrollDataReceived(ArtemisDevice? device, MouseScrollDirection direction, int delta)
{
MouseScrollDataReceived?.Invoke(this, new InputProviderMouseScrollEventArgs(device, direction, delta));
}
/// <summary>
/// Invokes the <see cref="MouseMoveDataReceived" /> event which the <see cref="IInputService" /> listens to as long as
/// this provider is registered
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="cursorX">The X position of the mouse cursor (not necessarily tied to the specific device)</param>
/// <param name="cursorY">The Y position of the mouse cursor (not necessarily tied to the specific device)</param>
/// <param name="deltaX">The movement delta in the horizontal direction</param>
/// <param name="deltaY">The movement delta in the vertical direction</param>
protected virtual void OnMouseMoveDataReceived(ArtemisDevice? device, int cursorX, int cursorY, int deltaX, int deltaY)
{
MouseMoveDataReceived?.Invoke(this, new InputProviderMouseMoveEventArgs(device, cursorX, cursorY, deltaX, deltaY));
}
/// <summary>
/// Invokes the <see cref="IdentifierReceived" /> event which the <see cref="IInputService" /> listens to as long as
/// this provider is registered
/// <para>Except for on mouse movement, call this whenever you have an identifier ready for the core to process</para>
/// </summary>
/// <param name="identifier">A value that can be used to identify this device</param>
/// <param name="deviceType">The type of device this identifier belongs to</param>
protected virtual void OnIdentifierReceived(object identifier, InputDeviceType deviceType)
{
IdentifierReceived?.Invoke(this, new InputProviderIdentifierEventArgs(identifier, deviceType));
}
#region IDisposable
/// <summary>
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true" /> to release both managed and unmanaged resources;
/// <see langword="false" /> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
}
}
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -0,0 +1,375 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using Serilog;
namespace Artemis.Core.Services
{
internal class InputService : IInputService
{
private readonly ILogger _logger;
private readonly ISurfaceService _surfaceService;
public InputService(ILogger logger, ISurfaceService surfaceService)
{
_logger = logger;
_surfaceService = surfaceService;
_surfaceService.ActiveSurfaceConfigurationSelected += SurfaceConfigurationChanged;
_surfaceService.SurfaceConfigurationUpdated += SurfaceConfigurationChanged;
BustIdentifierCache();
}
#region IDisposable
/// <inheritdoc />
public void Dispose()
{
while (_inputProviders.Any())
RemoveInputProvider(_inputProviders.First());
}
#endregion
#region Providers
private readonly List<InputProvider> _inputProviders = new List<InputProvider>();
public void AddInputProvider(InputProvider inputProvider)
{
inputProvider.IdentifierReceived += InputProviderOnIdentifierReceived;
inputProvider.KeyboardDataReceived += InputProviderOnKeyboardDataReceived;
inputProvider.MouseButtonDataReceived += InputProviderOnMouseButtonDataReceived;
inputProvider.MouseScrollDataReceived += InputProviderOnMouseScrollDataReceived;
inputProvider.MouseMoveDataReceived += InputProviderOnMouseMoveDataReceived;
_inputProviders.Add(inputProvider);
}
public void RemoveInputProvider(InputProvider inputProvider)
{
if (!_inputProviders.Contains(inputProvider))
return;
_inputProviders.Remove(inputProvider);
inputProvider.IdentifierReceived -= InputProviderOnIdentifierReceived;
inputProvider.KeyboardDataReceived -= InputProviderOnKeyboardDataReceived;
inputProvider.MouseButtonDataReceived -= InputProviderOnMouseButtonDataReceived;
inputProvider.MouseScrollDataReceived -= InputProviderOnMouseScrollDataReceived;
inputProvider.MouseMoveDataReceived -= InputProviderOnMouseMoveDataReceived;
}
#endregion
#region Identification
private readonly Dictionary<Tuple<InputProvider, object>, ArtemisDevice> _deviceCache = new Dictionary<Tuple<InputProvider, object>, ArtemisDevice>();
private List<ArtemisDevice> _devices = new List<ArtemisDevice>();
private ArtemisDevice? _cachedFallbackKeyboard;
private ArtemisDevice? _cachedFallbackMouse;
private ArtemisDevice? _identifyingDevice;
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);
}
public void StopIdentify()
{
_logger.Debug("Stop identifying device {device}", _identifyingDevice);
_identifyingDevice = null;
_surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true);
BustIdentifierCache();
}
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));
// Try cache first
ArtemisDevice? cacheMatch = GetDeviceFromCache(provider, identifier);
if (cacheMatch != null)
return cacheMatch;
string providerName = provider.GetType().FullName!;
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)
{
AddDeviceToCache(match, provider, identifier);
return match;
}
// If there is no match, apply our fallback type
if (type == InputDeviceType.None)
return null;
if (type == InputDeviceType.Keyboard)
{
if (_cachedFallbackKeyboard != null)
return _cachedFallbackKeyboard;
_cachedFallbackKeyboard = _surfaceService.ActiveSurface.Devices.FirstOrDefault(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard);
return _cachedFallbackKeyboard;
}
if (type == InputDeviceType.Mouse)
{
if (_cachedFallbackMouse != null)
return _cachedFallbackMouse;
_cachedFallbackMouse = _surfaceService.ActiveSurface.Devices.FirstOrDefault(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse);
return _cachedFallbackMouse;
}
return null;
}
public void BustIdentifierCache()
{
_deviceCache.Clear();
_cachedFallbackKeyboard = null;
_cachedFallbackMouse = null;
_devices = _surfaceService.ActiveSurface.Devices.Where(d => d.InputIdentifiers.Any()).ToList();
}
private void AddDeviceToCache(ArtemisDevice match, InputProvider provider, object identifier)
{
_deviceCache.TryAdd(new Tuple<InputProvider, object>(provider, identifier), match);
}
private ArtemisDevice? GetDeviceFromCache(InputProvider provider, object identifier)
{
_deviceCache.TryGetValue(new Tuple<InputProvider, object>(provider, identifier), out ArtemisDevice? device);
return device;
}
private void SurfaceConfigurationChanged(object? sender, SurfaceConfigurationEventArgs e)
{
BustIdentifierCache();
}
private void InputProviderOnIdentifierReceived(object? sender, InputProviderIdentifierEventArgs e)
{
// 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))
return;
string providerName = inputProvider.GetType().FullName!;
// Remove existing identification
_identifyingDevice.InputIdentifiers.RemoveAll(i => i.InputProvider == providerName);
_identifyingDevice.InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(providerName, e.Identifier));
StopIdentify();
OnDeviceIdentified();
}
#endregion
#region Keyboard
private readonly Dictionary<ArtemisDevice, HashSet<KeyboardKey>> _pressedKeys = new Dictionary<ArtemisDevice, HashSet<KeyboardKey>>();
private readonly Dictionary<ArtemisDevice, KeyboardModifierKey> _keyboardModifier = new Dictionary<ArtemisDevice, KeyboardModifierKey>();
private KeyboardModifierKey _globalModifiers;
private void InputProviderOnKeyboardDataReceived(object? sender, InputProviderKeyboardEventArgs e)
{
KeyboardModifierKey keyboardModifierKey = UpdateModifierKeys(e.Device, e.Key, e.IsDown);
// if UpdatePressedKeys is true, the key is already pressed, then we skip this event
if (UpdatePressedKeys(e.Device, e.Key, e.IsDown))
return;
// Get the LED - TODO: leverage a lookup
bool foundLedId = InputKeyUtilities.KeyboardKeyLedIdMap.TryGetValue(e.Key, 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
ArtemisKeyboardKeyUpDownEventArgs eventArgs = new ArtemisKeyboardKeyUpDownEventArgs(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, keyboardModifierKey, e.Device);
}
private bool UpdatePressedKeys(ArtemisDevice? device, KeyboardKey key, bool isDown)
{
if (device != null)
{
// Ensure the device is in the dictionary
_pressedKeys.TryAdd(device, new HashSet<KeyboardKey>());
// Get the hash set of the device
HashSet<KeyboardKey> pressedDeviceKeys = _pressedKeys[device];
// See if the key is already pressed
bool alreadyPressed = pressedDeviceKeys.Contains(key);
// Prevent triggering already down keys again. When a key is held, we don't want to spam events like Windows does
if (isDown && alreadyPressed)
return true;
// Either add or remove the key depending on its status
if (isDown && !alreadyPressed)
pressedDeviceKeys.Add(key);
else if (!isDown && alreadyPressed)
pressedDeviceKeys.Remove(key);
}
return false;
}
private KeyboardModifierKey UpdateModifierKeys(ArtemisDevice? device, KeyboardKey key, in bool isDown)
{
KeyboardModifierKey modifiers = _globalModifiers;
if (device != null)
_keyboardModifier.TryGetValue(device, out modifiers);
if (key == KeyboardKey.LeftAlt || key == KeyboardKey.RightAlt)
{
if (isDown)
modifiers |= KeyboardModifierKey.Alt;
else
modifiers &= ~KeyboardModifierKey.Alt;
}
else if (key == KeyboardKey.LeftCtrl || key == KeyboardKey.RightCtrl)
{
if (isDown)
modifiers |= KeyboardModifierKey.Control;
else
modifiers &= ~KeyboardModifierKey.Control;
}
else if (key == KeyboardKey.LeftShift || key == KeyboardKey.RightShift)
{
if (isDown)
modifiers |= KeyboardModifierKey.Shift;
else
modifiers &= ~KeyboardModifierKey.Shift;
}
else if (key == KeyboardKey.LWin || key == KeyboardKey.RWin)
{
if (isDown)
modifiers |= KeyboardModifierKey.Windows;
else
modifiers &= ~KeyboardModifierKey.Windows;
}
if (device != null)
_keyboardModifier[device] = modifiers;
else
_globalModifiers = modifiers;
return modifiers;
}
#endregion
#region Mouse
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
ArtemisMouseButtonUpDownEventArgs eventArgs = new ArtemisMouseButtonUpDownEventArgs(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 ArtemisMouseScrollEventArgs(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 ArtemisMouseMoveEventArgs(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);
}
#endregion
#region Events
public event EventHandler<ArtemisKeyboardKeyUpDownEventArgs>? KeyboardKeyUpDown;
public event EventHandler<ArtemisKeyboardKeyEventArgs>? KeyboardKeyDown;
public event EventHandler<ArtemisKeyboardKeyEventArgs>? KeyboardKeyUp;
public event EventHandler<ArtemisMouseButtonUpDownEventArgs>? MouseButtonUpDown;
public event EventHandler<ArtemisMouseButtonEventArgs>? MouseButtonDown;
public event EventHandler<ArtemisMouseButtonEventArgs>? MouseButtonUp;
public event EventHandler<ArtemisMouseScrollEventArgs>? MouseScroll;
public event EventHandler<ArtemisMouseMoveEventArgs>? MouseMove;
public event EventHandler? DeviceIdentified;
protected virtual void OnKeyboardKeyUpDown(ArtemisKeyboardKeyUpDownEventArgs e)
{
KeyboardKeyUpDown?.Invoke(this, e);
}
protected virtual void OnKeyboardKeyDown(ArtemisKeyboardKeyEventArgs e)
{
KeyboardKeyDown?.Invoke(this, e);
}
protected virtual void OnKeyboardKeyUp(ArtemisKeyboardKeyEventArgs e)
{
KeyboardKeyUp?.Invoke(this, e);
}
protected virtual void OnMouseButtonUpDown(ArtemisMouseButtonUpDownEventArgs e)
{
MouseButtonUpDown?.Invoke(this, e);
}
protected virtual void OnMouseButtonDown(ArtemisMouseButtonEventArgs e)
{
MouseButtonDown?.Invoke(this, e);
}
protected virtual void OnMouseButtonUp(ArtemisMouseButtonEventArgs e)
{
MouseButtonUp?.Invoke(this, e);
}
protected virtual void OnMouseScroll(ArtemisMouseScrollEventArgs e)
{
MouseScroll?.Invoke(this, e);
}
protected virtual void OnMouseMove(ArtemisMouseMoveEventArgs e)
{
MouseMove?.Invoke(this, e);
}
protected virtual void OnDeviceIdentified()
{
DeviceIdentified?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}

View File

@ -0,0 +1,100 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that allows you to interact with keyboard and mice input events
/// </summary>
public interface IInputService : IArtemisService, IDisposable
{
/// <summary>
/// Adds an input provided
/// </summary>
/// <param name="inputProvider">The input provider the add</param>
void AddInputProvider(InputProvider inputProvider);
/// <summary>
/// Removes an input provided
/// </summary>
/// <param name="inputProvider">The input provider the remove</param>
void RemoveInputProvider(InputProvider inputProvider);
/// <summary>
/// Identifies the provided <paramref name="device" /> by assigning the next received device identification to it
/// </summary>
/// <param name="device">The device to identify - Must be a keyboard or mouse</param>
void IdentifyDevice(ArtemisDevice device);
/// <summary>
/// Cancels identifying the device last passed to <see cref="IdentifyDevice" />
/// </summary>
void StopIdentify();
#region Events
/// <summary>
/// Occurs whenever a key on a keyboard was pressed or released
/// </summary>
event EventHandler<ArtemisKeyboardKeyUpDownEventArgs> KeyboardKeyUpDown;
/// <summary>
/// Occurs whenever a key on a keyboard was pressed
/// </summary>
event EventHandler<ArtemisKeyboardKeyEventArgs> KeyboardKeyDown;
/// <summary>
/// Occurs whenever a key on a keyboard was released
/// </summary>
event EventHandler<ArtemisKeyboardKeyEventArgs> KeyboardKeyUp;
/// <summary>
/// Occurs whenever a button on a mouse was pressed or released
/// </summary>
event EventHandler<ArtemisMouseButtonUpDownEventArgs> MouseButtonUpDown;
/// <summary>
/// Occurs whenever a button on a mouse was pressed
/// </summary>
event EventHandler<ArtemisMouseButtonEventArgs> MouseButtonDown;
/// <summary>
/// Occurs whenever a button on a mouse was released
/// </summary>
event EventHandler<ArtemisMouseButtonEventArgs> MouseButtonUp;
/// <summary>
/// Occurs whenever a the scroll wheel of a mouse is turned
/// </summary>
event EventHandler<ArtemisMouseScrollEventArgs> MouseScroll;
/// <summary>
/// Occurs whenever a a mouse is moved
/// </summary>
event EventHandler<ArtemisMouseMoveEventArgs> MouseMove;
/// <summary>
/// Occurs when a device has been identified after calling <see cref="IdentifyDevice" />
/// </summary>
public event EventHandler DeviceIdentified;
#endregion
#region Identification
/// <summary>
/// Attempts to identify the device using the provided <paramref name="identifier" />
/// </summary>
/// <param name="provider">The input provider to identify the device for</param>
/// <param name="identifier">The value to use to identify the device</param>
/// <param name="type">A device type to fall back to if no match is found</param>
/// <returns>If found, the Artemis device matching the provider and identifier</returns>
ArtemisDevice? GetDeviceByIdentifier(InputProvider provider, object identifier, InputDeviceType type);
/// <summary>
/// Clears the identifier cache
/// </summary>
void BustIdentifierCache();
#endregion
}
}

View File

@ -245,7 +245,7 @@ namespace Artemis.Core.Services
// Load the entity and fall back on creating a new one
Plugin plugin = new Plugin(pluginInfo, directory, _pluginRepository.GetPluginByGuid(pluginInfo.Guid));
OnPluginLoading(new PluginEventArgs(plugin));
// Locate the main assembly entry
string? mainFile = plugin.ResolveRelativePath(plugin.Info.Main);
if (!File.Exists(mainFile))
@ -289,6 +289,8 @@ namespace Artemis.Core.Services
// Create the Ninject child kernel and load the module
plugin.Kernel = new ChildKernel(_kernel, new PluginModule(plugin));
OnPluginEnabling(new PluginEventArgs(plugin));
plugin.SetEnabled(true);
// Get the Plugin feature from the main assembly and if there is only one, instantiate it

View File

@ -1,12 +1,27 @@
namespace Artemis.Storage.Entities.Surface
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Surface
{
public class DeviceEntity
{
public DeviceEntity()
{
InputIdentifiers = new List<DeviceInputIdentifierEntity>();
}
public string DeviceIdentifier { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Rotation { get; set; }
public double Scale { get; set; }
public int ZIndex { get; set; }
public List<DeviceInputIdentifierEntity> InputIdentifiers { get; set; }
}
public class DeviceInputIdentifierEntity
{
public string InputProvider { get; set; }
public object Identifier { get; set; }
}
}

View File

@ -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<SurfaceEntity> GetAll()
{
return _repository.Query<SurfaceEntity>().Include(s => s.DeviceEntities).ToList();
return _repository.Query<SurfaceEntity>().Include(s => s.DeviceEntities.Select(de => de.InputIdentifiers)).ToList();
}
public void Save(SurfaceEntity surfaceEntity)

View File

@ -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;

View File

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

View File

@ -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)

View File

@ -49,6 +49,15 @@ namespace Artemis.UI.Shared.Services
{
}
/// <summary>
/// If not yet closed, closes the current session passing <see langword="false" />
/// </summary>
public virtual void Cancel()
{
if (Session != null && !Session.IsEnded)
Session.Close(false);
}
internal void OnDialogOpened(object sender, DialogOpenedEventArgs e)
{
Session = e.Session;

View File

@ -142,6 +142,7 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
<PackageReference Include="Ninject" Version="3.3.4" />
<PackageReference Include="Ninject.Extensions.Conventions" Version="3.3.0" />
<PackageReference Include="RawInput.Sharp" Version="0.0.3" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.80.2" />
<PackageReference Include="Stylet" Version="1.3.4" />

View File

@ -14,6 +14,7 @@ using Artemis.Core.Ninject;
using Artemis.Core.Services;
using Artemis.UI.Ninject;
using Artemis.UI.Screens;
using Artemis.UI.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Stylet;
@ -42,6 +43,7 @@ namespace Artemis.UI
ILogger logger = Kernel.Get<ILogger>();
IViewManager viewManager = Kernel.Get<IViewManager>();
IRegistrationService registrationService = Kernel.Get<IRegistrationService>();
StartupArguments = Args.ToList();
CreateDataDirectory(logger);
@ -70,7 +72,7 @@ namespace Artemis.UI
{
if (StartupArguments.Contains("--autorun"))
{
logger.Information("Sleeping for 15 seconds on auto run to allow applications like iCUE and LGS to start");
logger.Information("Sleeping for 15 seconds on auto run to allow vendor applications required for SDKs to start");
await Task.Delay(TimeSpan.FromSeconds(15));
}
@ -83,6 +85,8 @@ namespace Artemis.UI
throw;
}
});
registrationService.RegisterInputProvider();
}
protected override void ConfigureIoC(IKernel kernel)

View File

@ -0,0 +1,221 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Input;
using Artemis.Core;
using Artemis.Core.Services;
using Linearstar.Windows.RawInput;
using Linearstar.Windows.RawInput.Native;
using MouseButton = Artemis.Core.Services.MouseButton;
namespace Artemis.UI.InputProviders
{
public class NativeWindowInputProvider : InputProvider
{
private const int WM_INPUT = 0x00FF;
private readonly IInputService _inputService;
private DateTime _lastMouseUpdate;
private SpongeWindow _sponge;
public NativeWindowInputProvider(IInputService inputService)
{
_inputService = inputService;
_sponge = new SpongeWindow();
_sponge.WndProcCalled += SpongeOnWndProcCalled;
RawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard, RawInputDeviceFlags.InputSink, _sponge.Handle);
RawInputDevice.RegisterDevice(HidUsageAndPage.Mouse, RawInputDeviceFlags.InputSink, _sponge.Handle);
}
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (disposing)
{
_sponge?.DestroyHandle();
_sponge = null;
}
base.Dispose(disposing);
}
#endregion
private void SpongeOnWndProcCalled(object sender, Message message)
{
if (message.Msg != WM_INPUT)
return;
RawInputData data = RawInputData.FromHandle(message.LParam);
switch (data)
{
case RawInputMouseData mouse:
HandleMouseData(data, mouse);
break;
case RawInputKeyboardData keyboard:
HandleKeyboardData(data, keyboard);
break;
}
}
#region Keyboard
private void HandleKeyboardData(RawInputData data, RawInputKeyboardData keyboardData)
{
KeyboardKey key = (KeyboardKey) KeyInterop.KeyFromVirtualKey(keyboardData.Keyboard.VirutalKey);
// Debug.WriteLine($"VK: {key} ({keyboardData.Keyboard.VirutalKey}), Flags: {keyboardData.Keyboard.Flags}, Scan code: {keyboardData.Keyboard.ScanCode}");
// Sometimes we get double hits and they resolve to None, ignore those
if (key == KeyboardKey.None)
return;
// Right alt triggers LeftCtrl with a different scan code for some reason, ignore those
if (key == KeyboardKey.LeftCtrl && keyboardData.Keyboard.ScanCode == 56)
return;
string identifier = data.Device?.DevicePath;
// Let the core know there is an identifier so it can store new identifications if applicable
if (identifier != null)
OnIdentifierReceived(identifier, InputDeviceType.Keyboard);
ArtemisDevice device = null;
if (identifier != null)
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))
{
if (key == KeyboardKey.Enter)
key = KeyboardKey.NumPadEnter;
if (key == KeyboardKey.LeftCtrl)
key = KeyboardKey.RightCtrl;
if (key == KeyboardKey.LeftAlt)
key = KeyboardKey.RightAlt;
}
if (key == KeyboardKey.LeftShift && keyboardData.Keyboard.ScanCode == 54)
key = KeyboardKey.RightShift;
bool isDown = keyboardData.Keyboard.Flags != RawKeyboardFlags.Up &&
keyboardData.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.LeftKey) &&
keyboardData.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.RightKey);
OnKeyboardDataReceived(device, key, isDown);
}
#endregion
#region Mouse
private int _mouseDeltaX;
private int _mouseDeltaY;
private void HandleMouseData(RawInputData data, RawInputMouseData mouseData)
{
// Only submit mouse movement 25 times per second but increment the delta
// This can create a small inaccuracy of course, but Artemis is not a shooter :')
if (mouseData.Mouse.Buttons == RawMouseButtonFlags.None)
{
_mouseDeltaX += mouseData.Mouse.LastX;
_mouseDeltaY += mouseData.Mouse.LastY;
if (DateTime.Now - _lastMouseUpdate < TimeSpan.FromMilliseconds(40))
return;
}
ArtemisDevice device = null;
string identifier = data.Device?.DevicePath;
if (identifier != null)
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}");
// Movement
if (mouseData.Mouse.Buttons == RawMouseButtonFlags.None)
{
Win32Point cursorPosition = GetCursorPosition();
OnMouseMoveDataReceived(device, cursorPosition.X, cursorPosition.Y, _mouseDeltaX, _mouseDeltaY);
_mouseDeltaX = 0;
_mouseDeltaY = 0;
_lastMouseUpdate = DateTime.Now;
return;
}
// 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, InputDeviceType.Mouse);
// Scrolling
if (mouseData.Mouse.ButtonData != 0)
{
if (mouseData.Mouse.Buttons == RawMouseButtonFlags.MouseWheel)
OnMouseScrollDataReceived(device, MouseScrollDirection.Vertical, mouseData.Mouse.ButtonData);
else if (mouseData.Mouse.Buttons == RawMouseButtonFlags.MouseHorizontalWheel)
OnMouseScrollDataReceived(device, MouseScrollDirection.Horizontal, mouseData.Mouse.ButtonData);
return;
}
// Button presses
MouseButton button = MouseButton.Left;
bool isDown = false;
// Left
if (DetermineMouseButton(mouseData, RawMouseButtonFlags.LeftButtonDown, RawMouseButtonFlags.LeftButtonUp, ref isDown))
button = MouseButton.Left;
// Middle
else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.MiddleButtonDown, RawMouseButtonFlags.MiddleButtonUp, ref isDown))
button = MouseButton.Middle;
// Right
else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.RightButtonDown, RawMouseButtonFlags.RightButtonUp, ref isDown))
button = MouseButton.Right;
// Button 4
else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.Button4Down, RawMouseButtonFlags.Button4Up, ref isDown))
button = MouseButton.Button4;
else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.Button5Down, RawMouseButtonFlags.Button5Up, ref isDown))
button = MouseButton.Button5;
OnMouseButtonDataReceived(device, button, isDown);
}
private bool DetermineMouseButton(RawInputMouseData data, RawMouseButtonFlags downButton, RawMouseButtonFlags upButton, ref bool isDown)
{
if (data.Mouse.Buttons == downButton || data.Mouse.Buttons == upButton)
{
isDown = data.Mouse.Buttons == downButton;
return true;
}
isDown = false;
return false;
}
#endregion
#region Native
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetCursorPos(ref Win32Point pt);
[StructLayout(LayoutKind.Sequential)]
private struct Win32Point
{
public readonly int X;
public readonly int Y;
}
private static Win32Point GetCursorPosition()
{
Win32Point w32Mouse = new Win32Point();
GetCursorPos(ref w32Mouse);
return w32Mouse;
}
#endregion
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Windows.Forms;
namespace Artemis.UI.InputProviders
{
public sealed class SpongeWindow : NativeWindow
{
public SpongeWindow()
{
CreateHandle(new CreateParams());
}
public event EventHandler<Message> WndProcCalled;
protected override void WndProc(ref Message m)
{
OnWndProcCalled(m);
base.WndProc(ref m);
}
private void OnWndProcCalled(Message e)
{
WndProcCalled?.Invoke(this, e);
}
}
}

View File

@ -28,11 +28,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
Session.Close(ProfileName);
}
public void Cancel()
{
Session.Close();
}
}
public class ProfileCreateViewModelValidator : AbstractValidator<ProfileCreateViewModel>

View File

@ -30,10 +30,5 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
Session.Close();
}
public void Cancel()
{
Session.Close();
}
}
}

View File

@ -37,10 +37,5 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
_mainMessageQueue.Enqueue("Profile imported.");
Session.Close(descriptor);
}
public void Cancel()
{
Session.Close();
}
}
}

View File

@ -32,11 +32,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Dialogs
Session.Close(ElementName);
}
public void Cancel()
{
Session.Close();
}
}
public class ProfileElementRenameViewModelValidator : AbstractValidator<RenameViewModel>

View File

@ -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
{

View File

@ -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<TimelineSegmentDialogViewModel>

View File

@ -54,8 +54,31 @@
</CheckBox>
<materialDesign:PopupBox Style="{StaticResource MaterialDesignToolPopupBox}" Padding="2 0 2 0">
<StackPanel>
<Button Content="Show device debugger" Command="{s:Action ShowDeviceDebugger}" />
<Button Content="Open plugin directory" Command="{s:Action OpenPluginDirectory}" />
<Button Command="{s:Action ShowDeviceDebugger}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Tools" Margin="0 0 10 0 " VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Center">Show device debugger</TextBlock>
</StackPanel>
</Button>
<Button Command="{s:Action OpenPluginDirectory}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="FolderOpen" Margin="0 0 10 0 " VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Center">Open plugin directory</TextBlock>
</StackPanel>
</Button>
<Separator/>
<Button Command="{s:Action DetectInput}" ToolTip="Teach Artemis which keypresses and/or button presses belong to this device">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="GestureDoubleTap" Margin="0 0 10 0 " VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Center">Identify input</TextBlock>
</StackPanel>
</Button>
<Button Command="{s:Action ViewProperties}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Gear" Margin="0 0 10 0 " VerticalAlignment="Center"/>
<TextBlock VerticalAlignment="Center">View surface properties</TextBlock>
</StackPanel>
</Button>
</StackPanel>
</materialDesign:PopupBox>
</StackPanel>

View File

@ -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<SurfaceDeviceDetectInputViewModel>(
new Dictionary<string, object> { { "device", Device } }
);
if ((bool)madeChanges)
_surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true);
}
public async Task ViewProperties()
{
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceConfigViewModel>(
new Dictionary<string, object> {{"device", Device}}
);
if ((bool) madeChanges)
_surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true);
}
}
}

View File

@ -5,6 +5,7 @@ using Artemis.Core.Services;
using Humanizer;
using MaterialDesignExtensions.Controls;
using Stylet;
using MouseButton = System.Windows.Input.MouseButton;
namespace Artemis.UI.Screens.Splash
{

View File

@ -27,10 +27,5 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
Session.Close(SurfaceName);
}
public void Cancel()
{
Session.Close();
}
}
}

View File

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

View File

@ -0,0 +1,61 @@
<UserControl x:Class="Artemis.UI.Screens.SurfaceEditor.Dialogs.SurfaceDeviceDetectInputView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.SurfaceEditor.Dialogs"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type local:SurfaceDeviceDetectInputViewModel}}">
<StackPanel Margin="16" Width="500">
<TextBlock Text="{Binding Title}" Style="{StaticResource MaterialDesignHeadline6TextBlock}" Margin="0 0 0 25" TextWrapping="Wrap" />
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" TextWrapping="Wrap">
Press a button/key on your <Run Text="{Binding SurfaceDeviceViewModel.Device.RgbDevice.DeviceInfo.DeviceName, Mode=OneWay}" />
that is currently showing a <Bold Foreground="Yellow">yellow</Bold> color.
</TextBlock>
<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"
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
</system:Boolean>
</Button.CommandParameter>
CANCEL
</Button>
</StackPanel>
</UserControl>

View File

@ -0,0 +1,55 @@
using System;
using System.Linq;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared.Services;
using MaterialDesignThemes.Wpf;
using RGB.NET.Brushes;
using RGB.NET.Core;
using RGB.NET.Groups;
namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
{
public class SurfaceDeviceDetectInputViewModel : DialogViewModelBase
{
private readonly IInputService _inputService;
private readonly ListLedGroup _ledGroup;
private readonly ISnackbarMessageQueue _mainMessageQueue;
public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, ISnackbarMessageQueue mainMessageQueue)
{
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(Device.Leds.Select(l => l.RgbLed))
{
Brush = new SolidColorBrush(new Color(255, 255, 0)),
ZIndex = 999
};
}
public ArtemisDevice Device { get; }
public string Title { get; }
public bool IsMouse { get; }
public override void OnDialogClosed(object sender, DialogClosingEventArgs e)
{
base.OnDialogClosed(sender, e);
_inputService.DeviceIdentified -= InputServiceOnDeviceIdentified;
_ledGroup.Detach();
}
private void InputServiceOnDeviceIdentified(object sender, EventArgs e)
{
Session?.Close(true);
_mainMessageQueue.Enqueue($"{Device.RgbDevice.DeviceInfo.DeviceName} identified 😁");
}
}
}

View File

@ -144,6 +144,16 @@
</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" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="View properties" Command="{s:Action ViewProperties}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Gear" />

View File

@ -15,12 +15,14 @@ using Artemis.UI.Screens.SurfaceEditor.Visualization;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
using MouseButton = System.Windows.Input.MouseButton;
namespace Artemis.UI.Screens.SurfaceEditor
{
public class SurfaceEditorViewModel : Screen, IMainScreenViewModel
{
private readonly IDeviceService _deviceService;
private readonly IInputService _inputService;
private readonly IDialogService _dialogService;
private readonly IRgbService _rgbService;
private readonly ISettingsService _settingsService;
@ -33,8 +35,12 @@ namespace Artemis.UI.Screens.SurfaceEditor
private ObservableCollection<ArtemisSurface> _surfaceConfigurations;
private PluginSetting<GridLength> _surfaceListWidth;
public SurfaceEditorViewModel(IRgbService rgbService, ISurfaceService surfaceService, IDialogService dialogService, ISettingsService settingsService,
IDeviceService deviceService)
public SurfaceEditorViewModel(IRgbService rgbService,
ISurfaceService surfaceService,
IDialogService dialogService,
ISettingsService settingsService,
IDeviceService deviceService,
IInputService inputService)
{
DisplayName = "Surface Editor";
@ -49,6 +55,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
_dialogService = dialogService;
_settingsService = settingsService;
_deviceService = deviceService;
_inputService = inputService;
}
public ObservableCollection<SurfaceDeviceViewModel> Devices
@ -279,10 +286,19 @@ 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);
}
public async Task DetectInput(SurfaceDeviceViewModel surfaceDeviceViewModel)
{
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>(
new Dictionary<string, object> {{"device", surfaceDeviceViewModel.Device}}
);
if ((bool) madeChanges)
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);

View File

@ -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;

View File

@ -3,6 +3,7 @@ using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.DefaultTypes.DataModel.Display;
using Artemis.UI.DefaultTypes.DataModel.Input;
using Artemis.UI.InputProviders;
using Artemis.UI.Ninject;
using Artemis.UI.PropertyInput;
using Artemis.UI.Services.Interfaces;
@ -15,18 +16,26 @@ namespace Artemis.UI.Services
private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService;
private readonly IPluginManagementService _pluginManagementService;
private readonly ISurfaceService _surfaceService;
private readonly IInputService _inputService;
private bool _registeredBuiltInDataModelDisplays;
private bool _registeredBuiltInDataModelInputs;
private bool _registeredBuiltInPropertyEditors;
public RegistrationService(IDataModelUIService dataModelUIService, IProfileEditorService profileEditorService, IPluginManagementService pluginManagementService)
public RegistrationService(IDataModelUIService dataModelUIService,
IProfileEditorService profileEditorService,
IPluginManagementService pluginManagementService,
ISurfaceService surfaceService,
IInputService inputService)
{
_dataModelUIService = dataModelUIService;
_profileEditorService = profileEditorService;
_pluginManagementService = pluginManagementService;
_surfaceService = surfaceService;
_inputService = inputService;
LoadPluginModules();
pluginManagementService.PluginLoaded += PluginServiceOnPluginLoaded;
pluginManagementService.PluginEnabling += PluginServiceOnPluginEnabling;
}
public void RegisterBuiltInDataModelDisplays()
@ -74,7 +83,12 @@ namespace Artemis.UI.Services
_registeredBuiltInPropertyEditors = true;
}
private void PluginServiceOnPluginLoaded(object sender, PluginEventArgs e)
public void RegisterInputProvider()
{
_inputService.AddInputProvider(new NativeWindowInputProvider(_inputService));
}
private void PluginServiceOnPluginEnabling(object sender, PluginEventArgs e)
{
e.Plugin.Kernel.Load(new[] {new PluginUIModule(e.Plugin)});
}
@ -91,5 +105,6 @@ namespace Artemis.UI.Services
void RegisterBuiltInDataModelDisplays();
void RegisterBuiltInDataModelInputs();
void RegisterBuiltInPropertyEditors();
void RegisterInputProvider();
}
}

View File

@ -80,6 +80,15 @@
"Ninject.Extensions.Factory": "3.3.2"
}
},
"RawInput.Sharp": {
"type": "Direct",
"requested": "[0.0.3, )",
"resolved": "0.0.3",
"contentHash": "X5EuJYuU0RWzOnA68cHmLEJ4czhgu0EsQj3o5RtYSdTNnTnXo/zVNAXQWPWbBXgoLsws1WTsT567yX0HKjS4aA==",
"dependencies": {
"NETStandard.Library": "1.6.1"
}
},
"Serilog": {
"type": "Direct",
"requested": "[2.9.0, )",