diff options
author | crupest <crupest@outlook.com> | 2019-03-23 23:52:07 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-03-23 23:52:07 +0800 |
commit | e8be3841457853daefc26d0ca00256ad8c44f593 (patch) | |
tree | 66d9204423c3887ebc7d781d13d815ae0443d620 /src | |
parent | 2ecfdaa20d8436948e4a73da73d6a11b78e88371 (diff) | |
download | cru-e8be3841457853daefc26d0ca00256ad8c44f593.tar.gz cru-e8be3841457853daefc26d0ca00256ad8c44f593.tar.bz2 cru-e8be3841457853daefc26d0ca00256ad8c44f593.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/application.cpp | 5 | ||||
-rw-r--r-- | src/application.hpp | 2 | ||||
-rw-r--r-- | src/cru_debug.cpp | 2 | ||||
-rw-r--r-- | src/exception.hpp | 2 | ||||
-rw-r--r-- | src/graph/graph.hpp | 8 | ||||
-rw-r--r-- | src/system_headers.hpp | 20 | ||||
-rw-r--r-- | src/timer.hpp | 2 | ||||
-rw-r--r-- | src/ui/control.cpp | 9 | ||||
-rw-r--r-- | src/ui/control.hpp | 14 | ||||
-rw-r--r-- | src/ui/controls/button.cpp | 0 | ||||
-rw-r--r-- | src/ui/controls/button.hpp | 8 | ||||
-rw-r--r-- | src/ui/controls/text_block.cpp | 2 | ||||
-rw-r--r-- | src/ui/cursor.cpp | 24 | ||||
-rw-r--r-- | src/ui/cursor.hpp | 37 | ||||
-rw-r--r-- | src/ui/d2d_util.hpp | 2 | ||||
-rw-r--r-- | src/ui/events/ui_event.cpp | 6 | ||||
-rw-r--r-- | src/ui/events/ui_event.hpp | 45 | ||||
-rw-r--r-- | src/ui/events/window_event.cpp | 3 | ||||
-rw-r--r-- | src/ui/events/window_event.hpp | 42 | ||||
-rw-r--r-- | src/ui/input_util.cpp | 2 | ||||
-rw-r--r-- | src/ui/render/text_render_object.cpp | 2 | ||||
-rw-r--r-- | src/ui/ui_manager.cpp | 2 | ||||
-rw-r--r-- | src/ui/ui_manager.hpp | 3 | ||||
-rw-r--r-- | src/ui/window.cpp | 23 | ||||
-rw-r--r-- | src/ui/window.hpp | 6 | ||||
-rw-r--r-- | src/ui/window_class.hpp | 2 | ||||
-rw-r--r-- | src/util/string_util.cpp | 5 |
27 files changed, 90 insertions, 188 deletions
diff --git a/src/application.cpp b/src/application.cpp index e580b56b..aafca6fe 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -1,8 +1,9 @@ #include "application.hpp" +#include <VersionHelpers.h> + #include "exception.hpp" #include "timer.hpp" -#include "ui/cursor.hpp" #include "ui/window_class.hpp" namespace cru { @@ -79,8 +80,6 @@ Application::Application(HINSTANCE h_instance) : h_instance_(h_instance) { throw std::runtime_error("Must run on Windows 8 or later."); god_window_ = std::make_unique<GodWindow>(this); - - ui::cursors::LoadSystemCursors(); } Application::~Application() { diff --git a/src/application.hpp b/src/application.hpp index acf264c3..f5f69ea4 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -1,12 +1,12 @@ #pragma once #include "pre.hpp" +#include <Windows.h> #include <functional> #include <memory> #include <optional> #include <type_traits> #include <typeindex> -#include "system_headers.hpp" #include "base.hpp" diff --git a/src/cru_debug.cpp b/src/cru_debug.cpp index 331d2bce..81945227 100644 --- a/src/cru_debug.cpp +++ b/src/cru_debug.cpp @@ -1,6 +1,6 @@ #include "cru_debug.hpp" -#include "system_headers.hpp" +#include <Windows.h> namespace cru::debug { #ifdef CRU_DEBUG diff --git a/src/exception.hpp b/src/exception.hpp index db2572f1..ade51d54 100644 --- a/src/exception.hpp +++ b/src/exception.hpp @@ -1,8 +1,8 @@ #pragma once #include "pre.hpp" +#include <Windows.h> #include <optional> -#include "system_headers.hpp" #include "base.hpp" diff --git a/src/graph/graph.hpp b/src/graph/graph.hpp index bad5b6d0..af14cc50 100644 --- a/src/graph/graph.hpp +++ b/src/graph/graph.hpp @@ -1,9 +1,13 @@ #pragma once #include "pre.hpp" +#include <d2d1_2.h> +#include <dxgi1_2.h> +#include <d3d11.h> +#include <dwrite.h> +#include <wrl/client.h> #include <functional> #include <memory> -#include "system_headers.hpp" #include "base.hpp" @@ -101,7 +105,7 @@ class GraphManager final : public Object { Microsoft::WRL::ComPtr<IDWriteFontCollection> GetSystemFontCollection() const { - return dwrite_system_font_collection_.Get(); + return dwrite_system_font_collection_; } private: diff --git a/src/system_headers.hpp b/src/system_headers.hpp deleted file mode 100644 index 5517d71a..00000000 --- a/src/system_headers.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "pre.hpp" - -//include system headers -#include <Windows.h> -#include <windowsx.h> - -#pragma comment(lib, "D3D11.lib") -#include <d3d11.h> - -#pragma comment(lib, "D2d1.lib") -#include <d2d1_1.h> - -#pragma comment(lib, "DWrite.lib") -#include <dwrite.h> - -#include <dxgi1_2.h> -#include <wrl/client.h> - -#include <VersionHelpers.h> diff --git a/src/timer.hpp b/src/timer.hpp index 685e83b9..7199adc2 100644 --- a/src/timer.hpp +++ b/src/timer.hpp @@ -1,11 +1,11 @@ #pragma once #include "pre.hpp" +#include <Windows.h> #include <chrono> #include <functional> #include <map> #include <optional> -#include "system_headers.hpp" #include "base.hpp" diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 5c629fd6..318d591a 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -55,15 +55,6 @@ bool Control::HasFocus() { return window->GetFocusControl() == this; } -void Control::SetCursor(const Cursor::Ptr& cursor) { - if (cursor != cursor_) { - cursor_ = cursor; - const auto window = GetWindow(); - if (window && window->GetMouseHoverControl() == this) - window->UpdateCursor(); - } -} - void Control::OnParentChanged(Control* old_parent, Control* new_parent) {} void Control::OnAttachToWindow(Window* window) {} diff --git a/src/ui/control.hpp b/src/ui/control.hpp index 8454e981..a44399bf 100644 --- a/src/ui/control.hpp +++ b/src/ui/control.hpp @@ -1,12 +1,8 @@ #pragma once #include "pre.hpp" -#include "system_headers.hpp" - #include "base.hpp" -#include "cursor.hpp" #include "events/ui_event.hpp" -#include "input_util.hpp" #include "ui_base.hpp" namespace cru::ui { @@ -60,14 +56,6 @@ class Control : public Object { bool HasFocus(); - //*************** region: cursor *************** - // If cursor is set to null, then it uses parent's cursor. - // Window's cursor can't be null. - public: - Cursor::Ptr GetCursor() const { return cursor_; } - - void SetCursor(const Cursor::Ptr& cursor); - //*************** region: events *************** public: // Raised when mouse enter the control. @@ -107,7 +95,5 @@ class Control : public Object { private: Window* window_ = nullptr; Control* parent_ = nullptr; - - Cursor::Ptr cursor_{}; }; } // namespace cru::ui diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/ui/controls/button.cpp diff --git a/src/ui/controls/button.hpp b/src/ui/controls/button.hpp new file mode 100644 index 00000000..010c3f5b --- /dev/null +++ b/src/ui/controls/button.hpp @@ -0,0 +1,8 @@ +#pragma once +#include "pre.hpp" + +#include "ui/control.hpp" + +namespace cru::ui::controls { + +} diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp index c891b832..85116910 100644 --- a/src/ui/controls/text_block.cpp +++ b/src/ui/controls/text_block.cpp @@ -1,5 +1,7 @@ #include "text_block.hpp" +#include <dwrite.h> + #include "ui/render/text_render_object.hpp" #include "ui/ui_manager.hpp" diff --git a/src/ui/cursor.cpp b/src/ui/cursor.cpp deleted file mode 100644 index d8c362ed..00000000 --- a/src/ui/cursor.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "cursor.hpp" - -#include "exception.hpp" - -namespace cru::ui { -Cursor::Cursor(HCURSOR handle, const bool auto_release) - : handle_(handle), auto_release_(auto_release) {} - -Cursor::~Cursor() { - if (auto_release_) ::DestroyCursor(handle_); -} - -namespace cursors { -Cursor::Ptr arrow{}; -Cursor::Ptr hand{}; -Cursor::Ptr i_beam{}; - -void LoadSystemCursors() { - arrow = std::make_shared<Cursor>(::LoadCursorW(nullptr, IDC_ARROW), false); - hand = std::make_shared<Cursor>(::LoadCursorW(nullptr, IDC_HAND), false); - i_beam = std::make_shared<Cursor>(::LoadCursorW(nullptr, IDC_IBEAM), false); -} -} // namespace cursors -} // namespace cru::ui diff --git a/src/ui/cursor.hpp b/src/ui/cursor.hpp deleted file mode 100644 index aec3fc40..00000000 --- a/src/ui/cursor.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -// ReSharper disable once CppUnusedIncludeDirective -#include "pre.hpp" - -#include <memory> -#include "system_headers.hpp" - -#include "base.hpp" - -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; - - HCURSOR GetHandle() const { return handle_; } - - private: - HCURSOR handle_; - bool auto_release_; -}; - -namespace cursors { -extern Cursor::Ptr arrow; -extern Cursor::Ptr hand; -extern Cursor::Ptr i_beam; - -void LoadSystemCursors(); -} // namespace cursors -} // namespace cru::ui diff --git a/src/ui/d2d_util.hpp b/src/ui/d2d_util.hpp index 96a017dc..2ec8ba98 100644 --- a/src/ui/d2d_util.hpp +++ b/src/ui/d2d_util.hpp @@ -1,7 +1,7 @@ #pragma once #include "pre.hpp" -#include "system_headers.hpp" +#include <d2d1.h> #include "ui_base.hpp" diff --git a/src/ui/events/ui_event.cpp b/src/ui/events/ui_event.cpp index ee3a68dc..78d56a83 100644 --- a/src/ui/events/ui_event.cpp +++ b/src/ui/events/ui_event.cpp @@ -1,7 +1,3 @@ #include "ui_event.hpp" -#include "ui/control.hpp" - -namespace cru::ui::events -{ -} +namespace cru::ui::events {} diff --git a/src/ui/events/ui_event.hpp b/src/ui/events/ui_event.hpp index 572cf8d6..7fe4e6eb 100644 --- a/src/ui/events/ui_event.hpp +++ b/src/ui/events/ui_event.hpp @@ -2,13 +2,14 @@ #include "pre.hpp" #include <optional> -#include "system_headers.hpp" #include "base.hpp" #include "cru_event.hpp" #include "ui/ui_base.hpp" #include "ui/input_util.hpp" +struct ID2D1RenderTarget; + namespace cru::ui { class Control; } @@ -112,18 +113,18 @@ class MouseWheelEventArgs : public MouseEventArgs { class DrawEventArgs : public UiEventArgs { public: DrawEventArgs(Object* sender, Object* original_sender, - ID2D1DeviceContext* device_context) - : UiEventArgs(sender, original_sender), device_context_(device_context) {} + ID2D1RenderTarget* render_target) + : UiEventArgs(sender, original_sender), render_target_(render_target) {} DrawEventArgs(const DrawEventArgs& other) = default; DrawEventArgs(DrawEventArgs&& other) = default; DrawEventArgs& operator=(const DrawEventArgs& other) = default; DrawEventArgs& operator=(DrawEventArgs&& other) = default; ~DrawEventArgs() = default; - ID2D1DeviceContext* GetDeviceContext() const { return device_context_; } + ID2D1RenderTarget* GetRenderTarget() const { return render_target_; } private: - ID2D1DeviceContext* device_context_; + ID2D1RenderTarget* render_target_; }; class FocusChangeEventArgs : public UiEventArgs { @@ -160,40 +161,6 @@ class ToggleEventArgs : public UiEventArgs { bool new_state_; }; -struct WindowNativeMessage { - HWND hwnd; - int msg; - WPARAM w_param; - LPARAM l_param; -}; - -class WindowNativeMessageEventArgs : public UiEventArgs { - public: - WindowNativeMessageEventArgs(Object* sender, Object* original_sender, - const WindowNativeMessage& message) - : UiEventArgs(sender, original_sender), - message_(message), - result_(std::nullopt) {} - WindowNativeMessageEventArgs(const WindowNativeMessageEventArgs& other) = - default; - WindowNativeMessageEventArgs(WindowNativeMessageEventArgs&& other) = default; - WindowNativeMessageEventArgs& operator=( - const WindowNativeMessageEventArgs& other) = default; - WindowNativeMessageEventArgs& operator=( - WindowNativeMessageEventArgs&& other) = default; - ~WindowNativeMessageEventArgs() override = default; - - WindowNativeMessage GetWindowMessage() const { return message_; } - - std::optional<LRESULT> GetResult() const { return result_; } - - void SetResult(const std::optional<LRESULT> result) { result_ = result; } - - private: - WindowNativeMessage message_; - std::optional<LRESULT> result_; -}; - class KeyEventArgs : public UiEventArgs { public: KeyEventArgs(Object* sender, Object* original_sender, int virtual_code) diff --git a/src/ui/events/window_event.cpp b/src/ui/events/window_event.cpp new file mode 100644 index 00000000..a217136c --- /dev/null +++ b/src/ui/events/window_event.cpp @@ -0,0 +1,3 @@ +#include "window_event.hpp" + +namespace cru::ui::events {} diff --git a/src/ui/events/window_event.hpp b/src/ui/events/window_event.hpp new file mode 100644 index 00000000..21c644af --- /dev/null +++ b/src/ui/events/window_event.hpp @@ -0,0 +1,42 @@ +#pragma once +#include "pre.hpp" + +#include <Windows.h> + +#include "ui_event.hpp" + +namespace cru::ui::events { +struct WindowNativeMessage { + HWND hwnd; + int msg; + WPARAM w_param; + LPARAM l_param; +}; + +class WindowNativeMessageEventArgs : public UiEventArgs { + public: + WindowNativeMessageEventArgs(Object* sender, Object* original_sender, + const WindowNativeMessage& message) + : UiEventArgs(sender, original_sender), + message_(message), + result_(std::nullopt) {} + WindowNativeMessageEventArgs(const WindowNativeMessageEventArgs& other) = + default; + WindowNativeMessageEventArgs(WindowNativeMessageEventArgs&& other) = default; + WindowNativeMessageEventArgs& operator=( + const WindowNativeMessageEventArgs& other) = default; + WindowNativeMessageEventArgs& operator=( + WindowNativeMessageEventArgs&& other) = default; + ~WindowNativeMessageEventArgs() override = default; + + WindowNativeMessage GetWindowMessage() const { return message_; } + + std::optional<LRESULT> GetResult() const { return result_; } + + void SetResult(const std::optional<LRESULT> result) { result_ = result; } + + private: + WindowNativeMessage message_; + std::optional<LRESULT> result_; +}; +} diff --git a/src/ui/input_util.cpp b/src/ui/input_util.cpp index 3fe34f10..193cba4a 100644 --- a/src/ui/input_util.cpp +++ b/src/ui/input_util.cpp @@ -1,6 +1,6 @@ #include "input_util.hpp" -#include "system_headers.hpp" +#include <Windows.h> namespace cru::ui { bool IsKeyDown(const int virtual_code) { diff --git a/src/ui/render/text_render_object.cpp b/src/ui/render/text_render_object.cpp index d57335ad..e8967d48 100644 --- a/src/ui/render/text_render_object.cpp +++ b/src/ui/render/text_render_object.cpp @@ -1,5 +1,7 @@ #include "text_render_object.hpp" +#include <d2d1.h> +#include <dwrite.h> #include <algorithm> #include "exception.hpp" diff --git a/src/ui/ui_manager.cpp b/src/ui/ui_manager.cpp index bcda4133..26b1fe62 100644 --- a/src/ui/ui_manager.cpp +++ b/src/ui/ui_manager.cpp @@ -1,5 +1,7 @@ #include "ui_manager.hpp" +#include <Windows.h> + #include "application.hpp" #include "exception.hpp" #include "graph/graph.hpp" diff --git a/src/ui/ui_manager.hpp b/src/ui/ui_manager.hpp index 3fd2adc9..c2331dd4 100644 --- a/src/ui/ui_manager.hpp +++ b/src/ui/ui_manager.hpp @@ -1,7 +1,8 @@ #pragma once #include "pre.hpp" -#include "system_headers.hpp" +#include <d2d1.h> +#include <wrl/client.h> #include "base.hpp" diff --git a/src/ui/window.cpp b/src/ui/window.cpp index ca3356ff..7b00ca05 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -1,7 +1,8 @@ #include "window.hpp" +#include <windowsx.h> + #include "application.hpp" -#include "cursor.hpp" #include "exception.hpp" #include "graph/graph.hpp" #include "render/window_render_object.hpp" @@ -153,17 +154,6 @@ inline POINT DipToPi(const Point& dip_point) { return result; } -namespace { -Cursor::Ptr GetCursorInherit(Control* control) { - while (control != nullptr) { - const auto cursor = control->GetCursor(); - if (cursor != nullptr) return cursor; - control = control->GetParent(); - } - return cursors::arrow; -} -} // namespace - Window* Window::CreateOverlapped() { return new Window(tag_overlapped_constructor{}); } @@ -220,8 +210,6 @@ void Window::AfterCreateHwnd(WindowManager* window_manager) { render_target_ = graph::GraphManager::GetInstance()->CreateWindowRenderTarget(hwnd_); - SetCursor(cursors::arrow); - render_object_ = new render::WindowRenderObject(this); } @@ -522,12 +510,6 @@ Control* Window::ReleaseCurrentMouseCapture() { } } -void Window::UpdateCursor() { - if (IsWindowValid() && mouse_hover_control_ != nullptr) { - SetCursorInternal(GetCursorInherit(mouse_hover_control_)->GetHandle()); - } -} - #ifdef CRU_DEBUG_LAYOUT void Window::SetDebugLayout(const bool value) { if (debug_layout_ != value) { @@ -719,7 +701,6 @@ void Window::DispatchMouseHoverControlChangeEvent(Control* old_control, DispatchEvent(new_control, &Control::mouse_enter_event, lowest_common_ancestor, point); // dispatch mouse enter event. - UpdateCursor(); } } } diff --git a/src/ui/window.hpp b/src/ui/window.hpp index 3e0422b1..1c48bf43 100644 --- a/src/ui/window.hpp +++ b/src/ui/window.hpp @@ -1,12 +1,13 @@ #pragma once #include "pre.hpp" +#include <Windows.h> #include <map> #include <memory> -#include "system_headers.hpp" #include "content_control.hpp" #include "events/ui_event.hpp" +#include "events/window_event.hpp" #include "window_class.hpp" namespace cru::graph { @@ -164,9 +165,6 @@ class Window final : public ContentControl { Control* CaptureMouseFor(Control* control); Control* ReleaseCurrentMouseCapture(); - //*************** region: cursor *************** - void UpdateCursor(); - public: //*************** region: events *************** Event<events::UiEventArgs> activated_event; diff --git a/src/ui/window_class.hpp b/src/ui/window_class.hpp index 66babd94..72a7c431 100644 --- a/src/ui/window_class.hpp +++ b/src/ui/window_class.hpp @@ -1,7 +1,7 @@ #pragma once #include "pre.hpp" -#include "system_headers.hpp" +#include <Windows.h> #include "base.hpp" diff --git a/src/util/string_util.cpp b/src/util/string_util.cpp index 3c765259..c9391fc6 100644 --- a/src/util/string_util.cpp +++ b/src/util/string_util.cpp @@ -1,6 +1,7 @@ #include "string_util.hpp" -#include "system_headers.hpp" +#include <Windows.h> + #include "exception.hpp" namespace cru::util { @@ -18,4 +19,4 @@ MultiByteString ToUtf8String(const StringView& string) { "Failed to convert wide string to UTF-8."); return result; } -} +} // namespace cru::util |