aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-03-23 23:52:07 +0800
committercrupest <crupest@outlook.com>2019-03-23 23:52:07 +0800
commite8be3841457853daefc26d0ca00256ad8c44f593 (patch)
tree66d9204423c3887ebc7d781d13d815ae0443d620 /src/ui
parent2ecfdaa20d8436948e4a73da73d6a11b78e88371 (diff)
downloadcru-e8be3841457853daefc26d0ca00256ad8c44f593.tar.gz
cru-e8be3841457853daefc26d0ca00256ad8c44f593.tar.bz2
cru-e8be3841457853daefc26d0ca00256ad8c44f593.zip
...
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/control.cpp9
-rw-r--r--src/ui/control.hpp14
-rw-r--r--src/ui/controls/button.cpp0
-rw-r--r--src/ui/controls/button.hpp8
-rw-r--r--src/ui/controls/text_block.cpp2
-rw-r--r--src/ui/cursor.cpp24
-rw-r--r--src/ui/cursor.hpp37
-rw-r--r--src/ui/d2d_util.hpp2
-rw-r--r--src/ui/events/ui_event.cpp6
-rw-r--r--src/ui/events/ui_event.hpp45
-rw-r--r--src/ui/events/window_event.cpp3
-rw-r--r--src/ui/events/window_event.hpp42
-rw-r--r--src/ui/input_util.cpp2
-rw-r--r--src/ui/render/text_render_object.cpp2
-rw-r--r--src/ui/ui_manager.cpp2
-rw-r--r--src/ui/ui_manager.hpp3
-rw-r--r--src/ui/window.cpp23
-rw-r--r--src/ui/window.hpp6
-rw-r--r--src/ui/window_class.hpp2
19 files changed, 75 insertions, 157 deletions
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"