diff options
author | crupest <crupest@outlook.com> | 2018-11-27 17:53:56 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-11-27 17:53:56 +0800 |
commit | 5b770e3bf0f3f9e22454d9e092630b22f5916ebe (patch) | |
tree | 19b39da16f155451d5817e82e045d69d7410acbe /CruUI-Generate/cru_ui.cpp | |
parent | 7ccb08ac09a83e81a822712b712dc0473c9b23cf (diff) | |
download | cru-5b770e3bf0f3f9e22454d9e092630b22f5916ebe.tar.gz cru-5b770e3bf0f3f9e22454d9e092630b22f5916ebe.tar.bz2 cru-5b770e3bf0f3f9e22454d9e092630b22f5916ebe.zip |
Update merged sources.
Diffstat (limited to 'CruUI-Generate/cru_ui.cpp')
-rw-r--r-- | CruUI-Generate/cru_ui.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/CruUI-Generate/cru_ui.cpp b/CruUI-Generate/cru_ui.cpp index 043eef5d..afd588d6 100644 --- a/CruUI-Generate/cru_ui.cpp +++ b/CruUI-Generate/cru_ui.cpp @@ -1514,6 +1514,16 @@ namespace cru::ui } + void Control::OnMouseWheel(events::MouseWheelEventArgs& args) + { + + } + + void Control::OnMouseWheelCore(events::MouseWheelEventArgs& args) + { + + } + void Control::RaiseMouseEnterEvent(MouseEventArgs& args) { OnMouseEnterCore(args); @@ -1556,6 +1566,13 @@ namespace cru::ui mouse_click_event.Raise(args); } + void Control::RaiseMouseWheelEvent(MouseWheelEventArgs& args) + { + OnMouseWheelCore(args); + OnMouseWheel(args); + mouse_wheel_event.Raise(args); + } + void Control::OnMouseClickBegin(MouseButton button) { @@ -2598,6 +2615,14 @@ namespace cru::ui result = 0; return true; } + case WM_MOUSEWHEEL: + POINT point; + point.x = GET_X_LPARAM(l_param); + point.y = GET_Y_LPARAM(l_param); + ScreenToClient(hwnd, &point); + OnMouseWheelInternal(GET_WHEEL_DELTA_WPARAM(w_param), point); + result = 0; + return true; case WM_KEYDOWN: OnKeyDownInternal(static_cast<int>(w_param)); result = 0; @@ -2908,6 +2933,20 @@ namespace cru::ui DispatchEvent(control, &Control::RaiseMouseUpEvent, nullptr, dip_point, button); } + void Window::OnMouseWheelInternal(short delta, POINT point) + { + const auto dip_point = PiToDip(point); + + Control* control; + + if (mouse_capture_control_) + control = mouse_capture_control_; + else + control = HitTest(dip_point); + + DispatchEvent(control, &Control::RaiseMouseWheelEvent, nullptr, dip_point, static_cast<float>(delta)); + } + void Window::OnKeyDownInternal(int virtual_code) { DispatchEvent(focus_control_, &Control::RaiseKeyDownEvent, nullptr, virtual_code); @@ -3770,6 +3809,29 @@ namespace cru::ui::controls } } + void ScrollControl::OnMouseWheelCore(events::MouseWheelEventArgs& args) + { + Control::OnMouseWheelCore(args); + + constexpr const auto view_delta = 30.0f; + + if (args.GetDelta() == 0.0f) + return; + + const auto content_rect = GetRect(RectRange::Content); + if (IsVerticalScrollEnabled() && GetScrollOffsetY() != (args.GetDelta() > 0.0f ? 0.0f : AtLeast0(GetViewHeight() - content_rect.height))) + { + SetScrollOffset(std::nullopt, GetScrollOffsetY() - args.GetDelta() / WHEEL_DELTA * view_delta); + return; + } + + if (IsHorizontalScrollEnabled() && GetScrollOffsetX() != (args.GetDelta() > 0.0f ? 0.0f : AtLeast0(GetViewWidth() - content_rect.width))) + { + SetScrollOffset(GetScrollOffsetX() - args.GetDelta() / WHEEL_DELTA * view_delta, std::nullopt); + return; + } + } + void ScrollControl::CoerceAndSetOffsets(const float offset_x, const float offset_y, const bool update_children) { const auto old_offset_x = offset_x_; |