-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHelperWindow.cpp
More file actions
153 lines (127 loc) · 5.47 KB
/
Copy pathInputHelperWindow.cpp
File metadata and controls
153 lines (127 loc) · 5.47 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// Created by Alex on 1/16/2021.
//
#include "InputHelperWindow.hpp"
#include "../engine/core/input/InputManager.hpp"
#include "../engine/core/Time.hpp"
using RPG::InputHelperWindow;
struct InputHelperWindow::Internal {
bool isOpened;
Internal() : isOpened(true) {}
void Render(ImGuiID dockID) {
if (!isOpened) return;
ImGui::SetNextWindowDockID(dockID, ImGuiCond_FirstUseEver);
ImGui::Begin("Input Helper", &isOpened);
bool isOpen = ImGui::TreeNodeEx("Current State", ImGuiTreeNodeFlags_OpenOnArrow);
if (isOpen) {
auto state = RPG::InputManager::GetInstance().GetState();
if (ImGui::TreeNodeEx("Keyboard", ImGuiTreeNodeFlags_OpenOnArrow)) {
for (int i = 0; i < RPG::Input::MAX_KEYBOARD_KEYS; ++i) {
bool isPressed = state.keyboard.pressed[i];
bool isDown = state.keyboard.down[i];
bool isReleased = state.keyboard.released[i];
uint64_t timeStamp = state.keyboard.timestamp[i];
uint64_t heldSeconds = (timeStamp == 0) ? 0 : RPG::Time::milliseconds - timeStamp;
float hs = heldSeconds / 10000000.0f;
std::string keyName = RPG::InputManager::GetInstance().GetNameOf((RPG::Input::Key)i);
if (keyName != "Unknown") {
std::string str = keyName + ": Pressed-" + (isPressed ? "True" : "False") + " Down-" +
(isDown ? "True" : "False") + " Released-" + (isReleased ? "True" : "False") +
" Time-" + std::to_string(hs);
ImGui::TreeNodeEx(str.c_str(), ImGuiTreeNodeFlags_Leaf);
ImGui::TreePop();
}
}
ImGui::TreePop();
}
if (ImGui::TreeNodeEx("Mouse", ImGuiTreeNodeFlags_OpenOnArrow)) {
for (int i = 0; i < RPG::Input::MAX_MOUSE_BUTTONS; ++i) {
bool isPressed = state.mouse.pressed[i];
bool isDown = state.mouse.down[i];
bool isReleased = state.mouse.released[i];
uint64_t timeStamp = state.mouse.timestamp[i];
uint64_t heldSeconds = (timeStamp == 0) ? 0 : RPG::Time::milliseconds - timeStamp;
float hs = heldSeconds / 10000000.0f;
std::string keyName = RPG::InputManager::GetInstance().GetNameOf((RPG::Input::MouseButton)i);
if (keyName != "Unknown") {
std::string str = keyName + ": Pressed-" + (isPressed ? "True" : "False") + " Down-" +
(isDown ? "True" : "False") + " Released-" + (isReleased ? "True" : "False") +
" Time-" + std::to_string(hs);
ImGui::TreeNodeEx(str.c_str(), ImGuiTreeNodeFlags_Leaf);
ImGui::TreePop();
}
}
std::string mouseWheel = "Mouse Wheel-(" + std::to_string(state.mouse.wheel.x) + "," + std::to_string(state.mouse.wheel.y) + ")";
ImGui::TreeNodeEx(mouseWheel.c_str(), ImGuiTreeNodeFlags_Leaf);
ImGui::TreePop();
std::string mousePosition = "Mouse Position-(" + std::to_string(state.mouse.position.x) + "," + std::to_string(state.mouse.position.y) + ")";
ImGui::TreeNodeEx(mousePosition.c_str(), ImGuiTreeNodeFlags_Leaf);
ImGui::TreePop();
ImGui::TreePop();
}
if (ImGui::TreeNodeEx("Controllers", ImGuiTreeNodeFlags_OpenOnArrow)) {
for (int i = 0; i < RPG::Input::MAX_CONTROLLERS; ++i) {
std::string controllerID = "Controller " + std::to_string(i) + "##Controller" + std::to_string(i);
if (ImGui::TreeNodeEx(controllerID.c_str(), ImGuiTreeNodeFlags_OpenOnArrow)) {
if (!state.controllers[i].isConnected) {
ImGui::Text("Not Connected");
} else {
for (int j = 0; j < RPG::Input::MAX_CONTROLLER_BUTTONS; j++) {
bool isPressed = state.controllers[i].pressed[j];
bool isDown = state.controllers[i].down[j];
bool isReleased = state.controllers[i].released[j];
uint64_t timeStamp = state.controllers[i].buttonTimestamp[j];
uint64_t heldSeconds = (timeStamp == 0) ? 0 : RPG::Time::milliseconds - timeStamp;
float hs = heldSeconds / 10000000.0f;
std::string keyName = RPG::InputManager::GetInstance().GetNameOf(
(RPG::Input::ControllerButton) j);
if (keyName != "Unknown") {
std::string str =
keyName + ": Pressed-" + (isPressed ? "True" : "False") + " Down-" +
(isDown ? "True" : "False") + " Released-" +
(isReleased ? "True" : "False") +
" Time-" + std::to_string(hs);
ImGui::TreeNodeEx(str.c_str(), ImGuiTreeNodeFlags_Leaf);
ImGui::TreePop();
}
}
ImGui::Spacing();
for (int k = 0; k < Input::MAX_CONTROLLER_AXIS; ++k) {
float axis = state.controllers[i].axis[k];
uint64_t timeStamp = state.controllers[i].axisTimestamp[k];
uint64_t heldSeconds = (timeStamp == 0) ? 0 : RPG::Time::milliseconds - timeStamp;
float hs = heldSeconds / 10000000.0f;
std::string keyName = RPG::InputManager::GetInstance().GetNameOf(
(RPG::Input::ControllerAxis) k);
if (keyName != "Unknown") {
std::string str = keyName + ": Axis-" + std::to_string(axis) +
" Time-" + std::to_string(hs);
ImGui::TreeNodeEx(str.c_str(), ImGuiTreeNodeFlags_Leaf);
ImGui::TreePop();
}
}
}
ImGui::TreePop();
}
}
ImGui::TreePop();
}
ImGui::TreePop();
}
ImGui::End();
}
};
InputHelperWindow::InputHelperWindow() : internal(RPG::MakeInternalPointer<Internal>()) {}
void InputHelperWindow::Render(ImGuiID dockID) {
internal->Render(dockID);
}
RPG::Action<>::Callback InputHelperWindow::ToggleIsOpen() {
return [this] () {
internal->isOpened = !internal->isOpened;
};
}
RPG::Action<>::Func<bool> InputHelperWindow::IsOpen() {
return [this] () -> bool {
return internal->isOpened;
};
}