forked from MapStudioProject/MapStudio.UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputState.cs
More file actions
94 lines (76 loc) · 3.54 KB
/
Copy pathInputState.cs
File metadata and controls
94 lines (76 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Text;
using GLFrameworkEngine;
using ImGuiNET;
using OpenTK.Input;
namespace MapStudio.UI
{
/// <summary>
/// The input state of the application to determine what the current key/mouse state is.
/// </summary>
public class InputState
{
public static void UpdateKeyState()
{
KeyInfo.EventInfo = CreateKeyState();
}
public static KeyEventInfo CreateKeyState()
{
KeyEventInfo eventInfo = new KeyEventInfo();
eventInfo.KeyShift = ImGui.GetIO().KeyShift;
eventInfo.KeyCtrl = ImGui.GetIO().KeyCtrl;
eventInfo.KeyAlt = ImGui.GetIO().KeyAlt;
int index = 0;
for (char c = 'A'; c <= 'Z'; c++)
{
if (Keyboard.GetState().IsKeyDown(Key.A + index)) eventInfo.KeyChars.Add(c.ToString());
index++;
}
index = 0;
for (char c = '0'; c <= '9'; c++)
{
if (Keyboard.GetState().IsKeyDown(Key.Number0 + index)) eventInfo.KeyChars.Add(c.ToString());
index++;
}
if (Keyboard.GetState().IsKeyDown(Key.Period)) eventInfo.KeyChars.Add("period");
if (Keyboard.GetState().IsKeyDown(Key.Space)) eventInfo.KeyChars.Add("Space");
if (Keyboard.GetState().IsKeyDown(Key.BackSpace)) eventInfo.KeyChars.Add("backspace");
if (Keyboard.GetState().IsKeyDown(Key.Delete)) eventInfo.KeyChars.Add("Delete");
if (Keyboard.GetState().IsKeyDown(Key.Tab)) eventInfo.KeyChars.Add("Tab");
if (Keyboard.GetState().IsKeyDown(Key.Minus)) eventInfo.KeyChars.Add("-");
if (Keyboard.GetState().IsKeyDown(Key.Plus)) eventInfo.KeyChars.Add("+");
for (int i = 0; i < 10; i++)
if (Keyboard.GetState().IsKeyDown(Key.Keypad0 + i)) eventInfo.KeyChars.Add($"keypad{i}");
return eventInfo;
}
public static void UpdateMouseState()
{
var mouseInfo = new MouseEventInfo();
//Prepare info
if (ImGui.IsMouseDown(ImGuiMouseButton.Right))
MouseEventInfo.RightButton = ButtonState.Pressed;
else if (ImGui.IsMouseReleased(ImGuiMouseButton.Right))
MouseEventInfo.RightButton = ButtonState.Released;
if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
MouseEventInfo.LeftButton = ButtonState.Pressed;
else if (ImGui.IsMouseReleased(ImGuiMouseButton.Left))
MouseEventInfo.LeftButton = ButtonState.Released;
if (ImGui.IsMouseDown(ImGuiMouseButton.Middle))
MouseEventInfo.MiddleButton = ButtonState.Pressed;
else if (ImGui.IsMouseReleased(ImGuiMouseButton.Middle))
MouseEventInfo.MiddleButton = ButtonState.Released;
MouseState mouseState = Mouse.GetState();
MouseEventInfo.WheelPrecise = mouseState.WheelPrecise;
//Construct relative position
var windowPos = ImGui.GetWindowPos();
var pos = ImGui.GetIO().MousePos;
pos = new System.Numerics.Vector2(pos.X - windowPos.X, pos.Y - windowPos.Y);
if (ImGui.IsMousePosValid())
MouseEventInfo.Position = new System.Drawing.Point((int)pos.X, (int)pos.Y);
else
MouseEventInfo.HasValue = false;
MouseEventInfo.FullPosition = new System.Drawing.Point(Mouse.GetCursorState().X, Mouse.GetCursorState().Y);
}
}
}