aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/win/native/CMakeLists.txt2
-rw-r--r--src/win/native/cursor.cpp51
-rw-r--r--src/win/native/ui_application.cpp6
4 files changed, 60 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0507ee2b..ece4ca7e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -39,6 +39,7 @@ set(CRU_PLATFORM_NATIVE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform/native)
add_library(cru_platform_native INTERFACE)
target_sources(cru_platform_native INTERFACE
${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/basic_types.hpp
+ ${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/cursor.hpp
${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/native_event.hpp
${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/native_window.hpp
${CRU_PLATFORM_NATIVE_INCLUDE_DIR}/ui_application.hpp
diff --git a/src/win/native/CMakeLists.txt b/src/win/native/CMakeLists.txt
index 757eae57..02f3afce 100644
--- a/src/win/native/CMakeLists.txt
+++ b/src/win/native/CMakeLists.txt
@@ -7,6 +7,7 @@ add_library(cru_win_native STATIC
window_d2d_painter.hpp
window_manager.hpp
+ cursor.cpp
god_window.cpp
native_window.cpp
timer.cpp
@@ -17,6 +18,7 @@ add_library(cru_win_native STATIC
window_render_target.cpp
)
target_sources(cru_win_native PUBLIC
+ ${CRU_WIN_NATIVE_INCLUDE_DIR}/cursor.hpp
${CRU_WIN_NATIVE_INCLUDE_DIR}/exception.hpp
${CRU_WIN_NATIVE_INCLUDE_DIR}/god_window.hpp
${CRU_WIN_NATIVE_INCLUDE_DIR}/native_window.hpp
diff --git a/src/win/native/cursor.cpp b/src/win/native/cursor.cpp
new file mode 100644
index 00000000..987d2d54
--- /dev/null
+++ b/src/win/native/cursor.cpp
@@ -0,0 +1,51 @@
+#include "cru/win/native/cursor.hpp"
+
+#include "cru/common/format.hpp"
+#include "cru/platform/debug.hpp"
+#include "cru/win/native/exception.hpp"
+
+#include <stdexcept>
+
+namespace cru::platform::native::win {
+WinCursor::WinCursor(HCURSOR handle, bool auto_delete) {
+ handle_ = handle;
+ auto_delete_ = auto_delete;
+}
+
+WinCursor::~WinCursor() {
+ if (auto_delete_) {
+ if (!::DestroyCursor(handle_)) {
+ DebugMessage(
+ util::Format(L"Failed to destroy a cursor. Last error code: {}",
+ ::GetLastError())); // This is not a fetal error but
+ // might still need notice.
+ }
+ }
+}
+
+namespace {
+WinCursor* LoadWinCursor(const wchar_t* name) {
+ const auto handle = ::LoadCursorW(NULL, name);
+ if (handle == NULL) {
+ throw Win32Error(::GetLastError(), "Failed to get system cursor.");
+ }
+ return new WinCursor(handle, false);
+}
+} // namespace
+
+WinCursorManager::WinCursorManager()
+ : sys_arrow_(LoadWinCursor(IDC_ARROW)),
+ sys_hand_(LoadWinCursor(IDC_HAND)) {}
+
+std::shared_ptr<WinCursor> WinCursorManager::GetSystemWinCursor(
+ SystemCursor type) {
+ switch (type) {
+ case SystemCursor::Arrow:
+ return sys_arrow_;
+ case SystemCursor::Hand:
+ return sys_hand_;
+ default:
+ throw std::runtime_error("Unknown system cursor value.");
+ }
+}
+} // namespace cru::platform::native::win
diff --git a/src/win/native/ui_application.cpp b/src/win/native/ui_application.cpp
index 360f6e41..fdc0aace 100644
--- a/src/win/native/ui_application.cpp
+++ b/src/win/native/ui_application.cpp
@@ -47,6 +47,8 @@ WinUiApplication::WinUiApplication(HINSTANCE h_instance)
god_window_ = std::make_shared<GodWindow>(this);
timer_manager_ = std::make_shared<TimerManager>(god_window_.get());
window_manager_ = std::make_shared<WindowManager>(this);
+
+ cursor_manager_.reset(new WinCursorManager());
}
WinUiApplication::~WinUiApplication() { instance = nullptr; }
@@ -118,4 +120,8 @@ NativeWindow* WinUiApplication::CreateWindow(NativeWindow* parent) {
return new WinNativeWindow(this, window_manager_->GetGeneralWindowClass(),
WS_OVERLAPPEDWINDOW, p);
}
+
+WinCursorManager* WinUiApplication::GetCursorManager() {
+ return cursor_manager_.get();
+}
} // namespace cru::platform::native::win