aboutsummaryrefslogtreecommitdiff
path: root/src/platform/gui/Input.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-10-17 12:06:14 +0800
committerYuqian Yang <crupest@crupest.life>2025-10-17 12:06:14 +0800
commit32aa6f116acc6e3e20a1ec76cef45b29f7005ad7 (patch)
tree892b71060a88b58d9293d78033000b05818783df /src/platform/gui/Input.cpp
parentfaf77949e19dc0d01f75bf8abb783eda70328048 (diff)
downloadcru-32aa6f116acc6e3e20a1ec76cef45b29f7005ad7.tar.gz
cru-32aa6f116acc6e3e20a1ec76cef45b29f7005ad7.tar.bz2
cru-32aa6f116acc6e3e20a1ec76cef45b29f7005ad7.zip
Remove String stage 1.
Diffstat (limited to 'src/platform/gui/Input.cpp')
-rw-r--r--src/platform/gui/Input.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/platform/gui/Input.cpp b/src/platform/gui/Input.cpp
new file mode 100644
index 00000000..a5e25dc8
--- /dev/null
+++ b/src/platform/gui/Input.cpp
@@ -0,0 +1,140 @@
+#include "cru/platform/gui/Input.h"
+
+#include <array>
+#include <string>
+#include <string_view>
+
+namespace cru::platform::gui {
+const std::array<std::string_view, static_cast<int>(KeyCode::NumPad9) + 1>
+ key_code_string_list{"Unknown",
+ "LeftButton",
+ "MiddleButton",
+ "RightButton",
+ "Escape",
+ "F1",
+ "F2",
+ "F3",
+ "F4",
+ "F5",
+ "F6",
+ "F7",
+ "F8",
+ "F9",
+ "F10",
+ "F11",
+ "F12",
+ "N0",
+ "N1",
+ "N2",
+ "N3",
+ "N4",
+ "N5",
+ "N6",
+ "N7",
+ "N8",
+ "N9",
+ "A",
+ "B",
+ "C",
+ "D",
+ "E",
+ "F",
+ "G",
+ "H",
+ "I",
+ "J",
+ "K",
+ "L",
+ "M",
+ "N",
+ "O",
+ "P",
+ "Q",
+ "R",
+ "S",
+ "T",
+ "U",
+ "V",
+ "W",
+ "X",
+ "Y",
+ "Z",
+ "GraveAccent",
+ "Tab",
+ "CapsLock",
+ "LeftShift",
+ "LeftCtrl",
+ "LeftSuper",
+ "LeftAlt",
+ "Minus",
+ "Equal",
+ "Backspace",
+ "LeftSquareBracket",
+ "RightSquareBracket",
+ "BackSlash",
+ "Semicolon",
+ "Quote",
+ "Comma",
+ "Period",
+ "Slash",
+ "RightShift",
+ "RightCtrl",
+ "RightSuper",
+ "RightAlt",
+ "Insert",
+ "Delete",
+ "Home",
+ "End",
+ "PageUp",
+ "PageDown",
+ "Up",
+ "Left",
+ "Down",
+ "Right",
+ "PrintScreen",
+ "ScrollLock",
+ "Pause",
+ "NumPad0",
+ "NumPad1",
+ "NumPad2",
+ "NumPad3",
+ "NumPad4",
+ "NumPad5",
+ "NumPad6",
+ "NumPad7",
+ "NumPad8",
+ "NumPad9"};
+
+std::string ToString(KeyCode key_code) {
+ if (static_cast<int>(key_code) < 0 ||
+ static_cast<int>(key_code) >=
+ static_cast<int>(key_code_string_list.size()))
+ return "UNKNOWN_KEYCODENAME";
+
+ return std::string(key_code_string_list[static_cast<int>(key_code)]);
+}
+
+std::string ToString(KeyModifier key_modifier, std::string_view separator) {
+ std::vector<std::string> list;
+ if (key_modifier & KeyModifiers::Shift) {
+ list.push_back("Shift");
+ }
+
+ if (key_modifier & KeyModifiers::Ctrl) {
+ list.push_back("Ctrl");
+ }
+
+ if (key_modifier & KeyModifiers::Alt) {
+ list.push_back("Shift");
+ }
+
+ if (list.empty()) return "";
+ std::string result = list.front();
+ for (auto iter = list.cbegin() + 1; iter != list.cend(); ++iter) {
+ result += separator;
+ result += *iter;
+ }
+
+ return result;
+}
+} // namespace cru::platform::gui