aboutsummaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/CMakeLists.txt4
-rw-r--r--src/platform/graph/CMakeLists.txt14
-rw-r--r--src/platform/graphics/CMakeLists.txt14
-rw-r--r--src/platform/gui/CMakeLists.txt14
-rw-r--r--src/platform/gui/Keyboard.cpp142
-rw-r--r--src/platform/gui/UiApplication.cpp (renamed from src/platform/native/UiApplication.cpp)6
-rw-r--r--src/platform/native/CMakeLists.txt13
7 files changed, 175 insertions, 32 deletions
diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt
index 51253b56..623ec08f 100644
--- a/src/platform/CMakeLists.txt
+++ b/src/platform/CMakeLists.txt
@@ -10,5 +10,5 @@ target_sources(cru_platform_base INTERFACE
)
target_link_libraries(cru_platform_base INTERFACE cru_base)
-add_subdirectory(graph)
-add_subdirectory(native)
+add_subdirectory(graphics)
+add_subdirectory(gui)
diff --git a/src/platform/graph/CMakeLists.txt b/src/platform/graph/CMakeLists.txt
deleted file mode 100644
index 3bf11e8d..00000000
--- a/src/platform/graph/CMakeLists.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-set(CRU_PLATFORM_GRAPH_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform/graph)
-add_library(cru_platform_graph INTERFACE)
-target_sources(cru_platform_graph INTERFACE
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/Base.hpp
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/Brush.hpp
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/Font.hpp
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/Geometry.hpp
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/Factory.hpp
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/Resource.hpp
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/Painter.hpp
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/TextLayout.hpp
- ${CRU_PLATFORM_GRAPH_INCLUDE_DIR}/util/Painter.hpp
-)
-target_link_libraries(cru_platform_graph INTERFACE cru_platform_base)
diff --git a/src/platform/graphics/CMakeLists.txt b/src/platform/graphics/CMakeLists.txt
new file mode 100644
index 00000000..5f841267
--- /dev/null
+++ b/src/platform/graphics/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(CRU_PLATFORM_GRAPHICS_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform/graphics)
+add_library(cru_platform_graphics INTERFACE)
+target_sources(cru_platform_graphics INTERFACE
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/Base.hpp
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/Brush.hpp
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/Font.hpp
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/Geometry.hpp
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/Factory.hpp
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/Resource.hpp
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/Painter.hpp
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/TextLayout.hpp
+ ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/util/Painter.hpp
+)
+target_link_libraries(cru_platform_graphics INTERFACE cru_platform_base)
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/native/UiApplication.cpp b/src/platform/gui/UiApplication.cpp
index 200b10e0..f095361e 100644
--- a/src/platform/native/UiApplication.cpp
+++ b/src/platform/gui/UiApplication.cpp
@@ -1,6 +1,6 @@
-#include "cru/platform/native/UiApplication.hpp"
+#include "cru/platform/gui/UiApplication.hpp"
-namespace cru::platform::native {
+namespace cru::platform::gui {
IUiApplication* IUiApplication::instance = nullptr;
IUiApplication::IUiApplication() {
@@ -12,4 +12,4 @@ IUiApplication::IUiApplication() {
}
IUiApplication::~IUiApplication() { instance = nullptr; }
-} // namespace cru::platform::native
+} // namespace cru::platform::gui
diff --git a/src/platform/native/CMakeLists.txt b/src/platform/native/CMakeLists.txt
deleted file mode 100644
index c68a0958..00000000
--- a/src/platform/native/CMakeLists.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-set(CRU_PLATFORM_NATIVE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform/native)
-add_library(cru_platform_native STATIC
- UiApplication.cpp
-)
-target_sources(cru_platform_native PUBLIC
- ${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/Base.hpp
- ${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/Cursor.hpp
- ${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/InputMethod.hpp
- ${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/Keyboard.hpp
- ${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/Window.hpp
- ${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/UiApplication.hpp
-)
-target_link_libraries(cru_platform_native PUBLIC cru_platform_graph)