aboutsummaryrefslogtreecommitdiff
path: root/src/platform/gui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-30 00:07:57 +0800
committercrupest <crupest@outlook.com>2020-10-30 00:07:57 +0800
commit6aa2201797a9ed64ce0178215ae941d0c5f09579 (patch)
tree9a74ee8d9f616afbe693ef7825a71474850831b5 /src/platform/gui
parentb4cb4fb7552d35c267bdb66913e4c822f16346ab (diff)
downloadcru-6aa2201797a9ed64ce0178215ae941d0c5f09579.tar.gz
cru-6aa2201797a9ed64ce0178215ae941d0c5f09579.tar.bz2
cru-6aa2201797a9ed64ce0178215ae941d0c5f09579.zip
...
Diffstat (limited to 'src/platform/gui')
-rw-r--r--src/platform/gui/CMakeLists.txt14
-rw-r--r--src/platform/gui/Keyboard.cpp142
-rw-r--r--src/platform/gui/UiApplication.cpp15
3 files changed, 171 insertions, 0 deletions
diff --git a/src/platform/gui/CMakeLists.txt b/src/platform/gui/CMakeLists.txt
new file mode 100644
index 00000000..aca7620c
--- /dev/null
+++ b/src/platform/gui/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(CRU_PLATFORM_GUI_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform/gui)
+add_library(cru_platform_gui STATIC
+ Keyboard.cpp
+ UiApplication.cpp
+)
+target_sources(cru_platform_gui PUBLIC
+ ${CRU_PLATFORM_GUI_INCLUDE_DIR}/Base.hpp
+ ${CRU_PLATFORM_GUI_INCLUDE_DIR}/Cursor.hpp
+ ${CRU_PLATFORM_GUI_INCLUDE_DIR}/InputMethod.hpp
+ ${CRU_PLATFORM_GUI_INCLUDE_DIR}/Keyboard.hpp
+ ${CRU_PLATFORM_GUI_INCLUDE_DIR}/Window.hpp
+ ${CRU_PLATFORM_GUI_INCLUDE_DIR}/UiApplication.hpp
+)
+target_link_libraries(cru_platform_gui PUBLIC cru_platform_graphics)
diff --git a/src/platform/gui/Keyboard.cpp b/src/platform/gui/Keyboard.cpp
new file mode 100644
index 00000000..24880e00
--- /dev/null
+++ b/src/platform/gui/Keyboard.cpp
@@ -0,0 +1,142 @@
+#include "cru/platform/gui/Keyboard.hpp"
+
+#include <array>
+#include <string>
+#include <string_view>
+
+namespace cru::platform::gui {
+constexpr std::array<std::u16string_view,
+ static_cast<int>(KeyCode::NumPad9) + 1>
+ key_code_string_list{u"Unknown",
+ u"LeftButton",
+ u"MiddleButton",
+ u"RightButton",
+ u"Escape",
+ u"F1",
+ u"F2",
+ u"F3",
+ u"F4",
+ u"F5",
+ u"F6",
+ u"F7",
+ u"F8",
+ u"F9",
+ u"F10",
+ u"F11",
+ u"F12",
+ u"N0",
+ u"N1",
+ u"N2",
+ u"N3",
+ u"N4",
+ u"N5",
+ u"N6",
+ u"N7",
+ u"N8",
+ u"N9",
+ u"A",
+ u"B",
+ u"C",
+ u"D",
+ u"E",
+ u"F",
+ u"G",
+ u"H",
+ u"I",
+ u"J",
+ u"K",
+ u"L",
+ u"M",
+ u"N",
+ u"O",
+ u"P",
+ u"Q",
+ u"R",
+ u"S",
+ u"T",
+ u"U",
+ u"V",
+ u"W",
+ u"X",
+ u"Y",
+ u"Z",
+ u"GraveAccent",
+ u"Tab",
+ u"CapsLock",
+ u"LeftShift",
+ u"LeftCtrl",
+ u"LeftSuper",
+ u"LeftAlt",
+ u"Minus",
+ u"Equal",
+ u"Backspace",
+ u"LeftSquareBracket",
+ u"RightSquareBracket",
+ u"BackSlash",
+ u"Semicolon",
+ u"Quote",
+ u"Comma",
+ u"Period",
+ u"Slash",
+ u"RightShift",
+ u"RightCtrl",
+ u"RightSuper",
+ u"RightAlt",
+ u"Insert",
+ u"Delete",
+ u"Home",
+ u"End",
+ u"PageUp",
+ u"PageDown",
+ u"Up",
+ u"Left",
+ u"Down",
+ u"Right",
+ u"PrintScreen",
+ u"ScrollLock",
+ u"Pause",
+ u"NumPad0",
+ u"NumPad1",
+ u"NumPad2",
+ u"NumPad3",
+ u"NumPad4",
+ u"NumPad5",
+ u"NumPad6",
+ u"NumPad7",
+ u"NumPad8",
+ u"NumPad9"};
+
+std::u16string_view 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 u"UNKNOWN_KEYCODENAME";
+
+ return key_code_string_list[static_cast<int>(key_code)];
+}
+
+std::u16string ToString(KeyModifier key_modifier,
+ std::u16string_view separator) {
+ std::vector<std::u16string> list;
+ if (key_modifier & KeyModifiers::shift) {
+ list.push_back(u"Shift");
+ }
+
+ if (key_modifier & KeyModifiers::ctrl) {
+ list.push_back(u"Ctrl");
+ }
+
+ if (key_modifier & KeyModifiers::alt) {
+ list.push_back(u"Shift");
+ }
+
+ if (list.empty()) return u"";
+ std::u16string result = list.front();
+ for (auto iter = list.cbegin() + 1; iter != list.cend(); ++iter) {
+ result += separator;
+ result += *iter;
+ }
+
+ return result;
+}
+} // namespace cru::platform::gui
diff --git a/src/platform/gui/UiApplication.cpp b/src/platform/gui/UiApplication.cpp
new file mode 100644
index 00000000..f095361e
--- /dev/null
+++ b/src/platform/gui/UiApplication.cpp
@@ -0,0 +1,15 @@
+#include "cru/platform/gui/UiApplication.hpp"
+
+namespace cru::platform::gui {
+IUiApplication* IUiApplication::instance = nullptr;
+
+IUiApplication::IUiApplication() {
+ if (instance) {
+ throw std::runtime_error("An ui application has already been created.");
+ }
+
+ instance = this;
+}
+
+IUiApplication::~IUiApplication() { instance = nullptr; }
+} // namespace cru::platform::gui