diff options
Diffstat (limited to 'scene/gui/scroll_bar.cpp')
-rw-r--r-- | scene/gui/scroll_bar.cpp | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 2ccdbb05a9..6519cde6d3 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -98,7 +98,18 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (ofs < grabber_ofs) { - set_value(get_value() - get_page()); + if (scrolling) { + target_scroll = target_scroll - get_page(); + } else { + target_scroll = get_value() - get_page(); + } + + if (smooth_scroll_enabled) { + scrolling = true; + set_fixed_process(true); + } else { + set_value(target_scroll); + } return; } @@ -111,8 +122,18 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { drag.value_at_click = get_as_ratio(); update(); } else { + if (scrolling) { + target_scroll = target_scroll + get_page(); + } else { + target_scroll = get_value() + get_page(); + } - set_value(get_value() + get_page()); + if (smooth_scroll_enabled) { + scrolling = true; + set_fixed_process(true); + } else { + set_value(target_scroll); + } } } else { @@ -311,7 +332,22 @@ void ScrollBar::_notification(int p_what) { if (p_what == NOTIFICATION_FIXED_PROCESS) { - if (drag_slave_touching) { + if (scrolling) { + if (get_value() != target_scroll) { + double target = target_scroll - get_value(); + double dist = sqrt(target * target); + double vel = ((target / dist) * 500) * get_fixed_process_delta_time(); + + if (vel >= dist) { + set_value(target_scroll); + } else { + set_value(get_value() + vel); + } + } else { + scrolling = false; + set_fixed_process(false); + } + } else if (drag_slave_touching) { if (drag_slave_touching_deaccel) { @@ -639,6 +675,14 @@ NodePath ScrollBar::get_drag_slave() const { return drag_slave_path; } +void ScrollBar::set_smooth_scroll_enabled(bool p_enable) { + smooth_scroll_enabled = p_enable; +} + +bool ScrollBar::is_smooth_scroll_enabled() const { + return smooth_scroll_enabled; +} + #if 0 void ScrollBar::mouse_button(const Point2& p_pos, int b->get_button_index(),bool b->is_pressed(),int p_modifier_mask) { @@ -795,6 +839,10 @@ ScrollBar::ScrollBar(Orientation p_orientation) { drag_slave_touching = false; drag_slave_touching_deaccel = false; + scrolling = false; + target_scroll = 0; + smooth_scroll_enabled = false; + if (focus_by_default) set_focus_mode(FOCUS_ALL); set_step(0); |