diff options
author | crupest <crupest@outlook.com> | 2018-10-07 17:15:32 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-10-07 17:15:32 +0800 |
commit | 00abb6f0c8678086860c07eedb17aa348b13fd76 (patch) | |
tree | 45976fd277758fbc6be8c2e38e1f560118ff8efc /src | |
parent | 508c69d6706ddfdba5bac7970ea95b8158992323 (diff) | |
download | cru-00abb6f0c8678086860c07eedb17aa348b13fd76.tar.gz cru-00abb6f0c8678086860c07eedb17aa348b13fd76.tar.bz2 cru-00abb6f0c8678086860c07eedb17aa348b13fd76.zip |
Add cursor.
Diffstat (limited to 'src')
-rw-r--r-- | src/application.cpp | 15 | ||||
-rw-r--r-- | src/ui/control.h | 4 | ||||
-rw-r--r-- | src/ui/cursor.cpp | 20 | ||||
-rw-r--r-- | src/ui/cursor.h | 33 |
4 files changed, 72 insertions, 0 deletions
diff --git a/src/application.cpp b/src/application.cpp index f53a002d..7658a340 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -5,6 +5,7 @@ #include "exception.h" #include "timer.h" #include "ui/window.h" +#include "ui/cursor.h" #include "graph/graph.h" #include "ui/animations/animation.h" @@ -86,6 +87,16 @@ namespace cru { return instance_; } + namespace + { + void LoadSystemCursor(HINSTANCE h_instance) + { + ui::cursors[ui::cursor_arrow_key] = std::make_shared<ui::Cursor>(::LoadCursorW(h_instance, MAKEINTRESOURCEW(IDC_ARROW)), false); + ui::cursors[ui::cursor_hand_key] = std::make_shared<ui::Cursor>(::LoadCursorW(h_instance, MAKEINTRESOURCEW(IDC_HAND)), false); + ui::cursors[ui::cursor_i_beam_key] = std::make_shared<ui::Cursor>(::LoadCursorW(h_instance, MAKEINTRESOURCEW(IDC_IBEAM)), false); + } + } + Application::Application(HINSTANCE h_instance) : h_instance_(h_instance) { @@ -112,10 +123,14 @@ namespace cru { if (!::SystemParametersInfoW(SPI_GETCARETWIDTH, 0 , &caret_width, 0)) throw Win32Error(::GetLastError(), "Failed to get system caret width."); caret_info_.half_caret_width = caret_width / 2.0f; + + LoadSystemCursor(h_instance); } Application::~Application() { + ui::cursors.clear(); + animation_manager_.reset(); instance_ = nullptr; } diff --git a/src/ui/control.h b/src/ui/control.h index b2321e2b..666d7f69 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -346,6 +346,10 @@ namespace cru virtual Size OnMeasureContent(const Size& available_size); virtual void OnLayoutContent(const Rect& rect); + + //*************** region: cursor *************** + //TODO! + private: // Only for layout manager to use. // Check if the old position is updated to current position. diff --git a/src/ui/cursor.cpp b/src/ui/cursor.cpp new file mode 100644 index 00000000..e0bd1814 --- /dev/null +++ b/src/ui/cursor.cpp @@ -0,0 +1,20 @@ +#include "cursor.h" + +#include "exception.h" + +namespace cru::ui +{ + Cursor::Cursor(HCURSOR handle, const bool auto_release) + : handle_(handle), auto_release_(auto_release) + { + + } + + Cursor::~Cursor() + { + if (auto_release_) + ::DestroyCursor(handle_); + } + + std::unordered_map<String, Cursor::Ptr> cursors; +} diff --git a/src/ui/cursor.h b/src/ui/cursor.h new file mode 100644 index 00000000..b57db9b7 --- /dev/null +++ b/src/ui/cursor.h @@ -0,0 +1,33 @@ +#pragma once + +#include "system_headers.h" +#include <memory> +#include <unordered_map> + +#include "base.h" + +namespace cru::ui +{ + class Cursor : public Object + { + public: + using Ptr = std::shared_ptr<Cursor>; + + Cursor(HCURSOR handle, bool auto_release); + Cursor(const Cursor& other) = delete; + Cursor(Cursor&& other) = delete; + Cursor& operator=(const Cursor& other) = delete; + Cursor& operator=(Cursor&& other) = delete; + ~Cursor() override; + + private: + HCURSOR handle_; + bool auto_release_; + }; + + + extern std::unordered_map<String, Cursor::Ptr> cursors; + constexpr auto cursor_arrow_key = L"System_Arrow"; + constexpr auto cursor_hand_key = L"System_Hand"; + constexpr auto cursor_i_beam_key = L"System_IBeam"; +} |