From 1497b881c6d13c5e037dcd57988029df0b0e50eb Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 12 May 2021 08:57:45 +0800 Subject: ... --- include/cru/platform/gui/Base.hpp | 7 +++++++ include/cru/platform/gui/Window.hpp | 1 + include/cru/ui/events/UiEvent.hpp | 10 ++++++++-- include/cru/ui/host/WindowHost.hpp | 2 ++ include/cru/win/gui/Window.hpp | 11 +++++++---- 5 files changed, 25 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/cru/platform/gui/Base.hpp b/include/cru/platform/gui/Base.hpp index 7a9d1889..fd9d265c 100644 --- a/include/cru/platform/gui/Base.hpp +++ b/include/cru/platform/gui/Base.hpp @@ -31,6 +31,13 @@ struct NativeMouseButtonEventArgs { KeyModifier modifier; }; +struct NativeMouseWheelEventArgs { + // Positive means down. Negative means up. + float delta; + Point point; + KeyModifier modifier; +}; + struct NativeKeyEventArgs { KeyCode key; KeyModifier modifier; diff --git a/include/cru/platform/gui/Window.hpp b/include/cru/platform/gui/Window.hpp index 26d1a476..b2129322 100644 --- a/include/cru/platform/gui/Window.hpp +++ b/include/cru/platform/gui/Window.hpp @@ -49,6 +49,7 @@ struct INativeWindow : virtual INativeResource { virtual IEvent* MouseMoveEvent() = 0; virtual IEvent* MouseDownEvent() = 0; virtual IEvent* MouseUpEvent() = 0; + virtual IEvent* MouseWheelEvent() = 0; virtual IEvent* KeyDownEvent() = 0; virtual IEvent* KeyUpEvent() = 0; diff --git a/include/cru/ui/events/UiEvent.hpp b/include/cru/ui/events/UiEvent.hpp index 22ad0150..33bc0a60 100644 --- a/include/cru/ui/events/UiEvent.hpp +++ b/include/cru/ui/events/UiEvent.hpp @@ -122,18 +122,24 @@ class MouseButtonEventArgs : public MouseEventArgs { class MouseWheelEventArgs : public MouseEventArgs { public: MouseWheelEventArgs(Object* sender, Object* original_sender, - const Point& point, const float delta) - : MouseEventArgs(sender, original_sender, point), delta_(delta) {} + const Point& point, const float delta, + platform::gui::KeyModifier key_modifier) + : MouseEventArgs(sender, original_sender, point), + delta_(delta), + key_modifier_(key_modifier) {} MouseWheelEventArgs(const MouseWheelEventArgs& other) = default; MouseWheelEventArgs(MouseWheelEventArgs&& other) = default; MouseWheelEventArgs& operator=(const MouseWheelEventArgs& other) = default; MouseWheelEventArgs& operator=(MouseWheelEventArgs&& other) = default; ~MouseWheelEventArgs() override = default; + // Positive means down; Negative means up. float GetDelta() const { return delta_; } + platform::gui::KeyModifier GetKeyModifier() const { return key_modifier_; } private: float delta_; + platform::gui::KeyModifier key_modifier_; }; class PaintEventArgs : public UiEventArgs { diff --git a/include/cru/ui/host/WindowHost.hpp b/include/cru/ui/host/WindowHost.hpp index cd9093bc..258b0c4c 100644 --- a/include/cru/ui/host/WindowHost.hpp +++ b/include/cru/ui/host/WindowHost.hpp @@ -139,6 +139,8 @@ class WindowHost : public Object { const platform::gui::NativeMouseButtonEventArgs& args); void OnNativeMouseUp(platform::gui::INativeWindow* window, const platform::gui::NativeMouseButtonEventArgs& args); + void OnNativeMouseWheel(platform::gui::INativeWindow* window, + const platform::gui::NativeMouseWheelEventArgs& args); void OnNativeKeyDown(platform::gui::INativeWindow* window, const platform::gui::NativeKeyEventArgs& args); diff --git a/include/cru/win/gui/Window.hpp b/include/cru/win/gui/Window.hpp index 3ba9ef68..97a74fa7 100644 --- a/include/cru/win/gui/Window.hpp +++ b/include/cru/win/gui/Window.hpp @@ -59,14 +59,16 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { return &mouse_enter_leave_event_; } IEvent* MouseMoveEvent() override { return &mouse_move_event_; } - IEvent* MouseDownEvent() - override { + IEvent* MouseDownEvent() override { return &mouse_down_event_; } - IEvent* MouseUpEvent() - override { + IEvent* MouseUpEvent() override { return &mouse_up_event_; } + IEvent* MouseWheelEvent() override { + return &mouse_wheel_event_; + } + IEvent* KeyDownEvent() override { return &key_down_event_; } @@ -170,6 +172,7 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { Event mouse_move_event_; Event mouse_down_event_; Event mouse_up_event_; + Event mouse_wheel_event_; Event key_down_event_; Event key_up_event_; -- cgit v1.2.3