diff options
-rw-r--r-- | include/cru/common/bitmask.hpp | 6 | ||||
-rw-r--r-- | include/cru/ui/ui_event.hpp | 31 | ||||
-rw-r--r-- | include/cru/ui/window.hpp | 5 | ||||
-rw-r--r-- | src/ui/window.cpp | 14 |
4 files changed, 37 insertions, 19 deletions
diff --git a/include/cru/common/bitmask.hpp b/include/cru/common/bitmask.hpp index 6dfb651c..95edee13 100644 --- a/include/cru/common/bitmask.hpp +++ b/include/cru/common/bitmask.hpp @@ -19,15 +19,15 @@ struct Bitmask final { Bitmask operator^(Bitmask rhs) const { return Bitmask(value ^ rhs.value); } Bitmask operator~() const { return Bitmask(~value); } Bitmask& operator|=(Bitmask rhs) { - value |= rhs; + value |= rhs.value; return *this; } Bitmask& operator&=(Bitmask rhs) { - value &= rhs; + value &= rhs.value; return *this; } Bitmask& operator^=(Bitmask rhs) { - value ^= rhs; + value ^= rhs.value; return *this; } diff --git a/include/cru/ui/ui_event.hpp b/include/cru/ui/ui_event.hpp index d7ab4543..a9d6028a 100644 --- a/include/cru/ui/ui_event.hpp +++ b/include/cru/ui/ui_event.hpp @@ -2,6 +2,7 @@ #include "base.hpp" #include "cru/common/event.hpp" +#include "cru/platform/native/keyboard.hpp" #include <memory> #include <optional> @@ -93,11 +94,17 @@ class MouseEventArgs : public UiEventArgs { class MouseButtonEventArgs : public MouseEventArgs { public: MouseButtonEventArgs(Object* sender, Object* original_sender, - const Point& point, const MouseButton button) - : MouseEventArgs(sender, original_sender, point), button_(button) {} + const Point& point, const MouseButton button, + platform::native::KeyModifier key_modifier) + : MouseEventArgs(sender, original_sender, point), + button_(button), + key_modifier_(key_modifier) {} MouseButtonEventArgs(Object* sender, Object* original_sender, - const MouseButton button) - : MouseEventArgs(sender, original_sender), button_(button) {} + const MouseButton button, + platform::native::KeyModifier key_modifier) + : MouseEventArgs(sender, original_sender), + button_(button), + key_modifier_(key_modifier) {} MouseButtonEventArgs(const MouseButtonEventArgs& other) = default; MouseButtonEventArgs(MouseButtonEventArgs&& other) = default; MouseButtonEventArgs& operator=(const MouseButtonEventArgs& other) = default; @@ -105,9 +112,11 @@ class MouseButtonEventArgs : public MouseEventArgs { ~MouseButtonEventArgs() override = default; MouseButton GetButton() const { return button_; } + platform::native::KeyModifier GetKeyModifier() const { return key_modifier_; } private: MouseButton button_; + platform::native::KeyModifier key_modifier_; }; class MouseWheelEventArgs : public MouseEventArgs { @@ -182,18 +191,24 @@ class ToggleEventArgs : public UiEventArgs { class KeyEventArgs : public UiEventArgs { public: - KeyEventArgs(Object* sender, Object* original_sender, int virtual_code) - : UiEventArgs(sender, original_sender), virtual_code_(virtual_code) {} + KeyEventArgs(Object* sender, Object* original_sender, + platform::native::KeyCode key_code, + platform::native::KeyModifier key_modifier) + : UiEventArgs(sender, original_sender), + key_code_(key_code), + key_modifier_(key_modifier) {} KeyEventArgs(const KeyEventArgs& other) = default; KeyEventArgs(KeyEventArgs&& other) = default; KeyEventArgs& operator=(const KeyEventArgs& other) = default; KeyEventArgs& operator=(KeyEventArgs&& other) = default; ~KeyEventArgs() override = default; - int GetVirtualCode() const { return virtual_code_; } + platform::native::KeyCode GetKeyCode() const { return key_code_; } + platform::native::KeyModifier GetKeyModifier() const { return key_modifier_; } private: - int virtual_code_; + platform::native::KeyCode key_code_; + platform::native::KeyModifier key_modifier_; }; class CharEventArgs : public UiEventArgs { diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp index ae54d006..86112189 100644 --- a/include/cru/ui/window.hpp +++ b/include/cru/ui/window.hpp @@ -94,8 +94,9 @@ class Window final : public ContentControl, public SelfResolvable<Window> { const platform::native::NativeMouseButtonEventArgs& args); void OnNativeKeyDown(platform::native::INativeWindow* window, - int virtual_code); - void OnNativeKeyUp(platform::native::INativeWindow* window, int virtual_code); + const platform::native::NativeKeyEventArgs& args); + void OnNativeKeyUp(platform::native::INativeWindow* window, + const platform::native::NativeKeyEventArgs& args); void OnNativeChar(platform::native::INativeWindow* window, std::string c); //*************** region: event dispatcher helper *************** diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 03c33cf3..dbe90478 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -289,7 +289,7 @@ void Window::OnNativeMouseDown( Control* control = mouse_captured_control_ ? mouse_captured_control_ : HitTest(args.point); DispatchEvent(event_names::MouseDown, control, &Control::MouseDownEvent, - nullptr, args.point, args.button); + nullptr, args.point, args.button, args.modifier); } void Window::OnNativeMouseUp( @@ -300,21 +300,23 @@ void Window::OnNativeMouseUp( Control* control = mouse_captured_control_ ? mouse_captured_control_ : HitTest(args.point); DispatchEvent(event_names::MouseUp, control, &Control::MouseUpEvent, nullptr, - args.point, args.button); + args.point, args.button, args.modifier); } -void Window::OnNativeKeyDown(INativeWindow* window, int virtual_code) { +void Window::OnNativeKeyDown(INativeWindow* window, + const platform::native::NativeKeyEventArgs& args) { CRU_UNUSED(window) DispatchEvent(event_names::KeyDown, focus_control_, &Control::KeyDownEvent, - nullptr, virtual_code); + nullptr, args.key, args.modifier); } -void Window::OnNativeKeyUp(INativeWindow* window, int virtual_code) { +void Window::OnNativeKeyUp(INativeWindow* window, + const platform::native::NativeKeyEventArgs& args) { CRU_UNUSED(window) DispatchEvent(event_names::KeyUp, focus_control_, &Control::KeyUpEvent, - nullptr, virtual_code); + nullptr, args.key, args.modifier); } void Window::OnNativeChar(platform::native::INativeWindow* window, |