diff options
Diffstat (limited to 'scene/gui/scroll_bar.cpp')
-rw-r--r-- | scene/gui/scroll_bar.cpp | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 79a0de35fc..4a3a6837d5 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -41,10 +41,12 @@ void ScrollBar::set_can_focus_by_default(bool p_can_focus) { focus_by_default = p_can_focus; } -void ScrollBar::_gui_input(Ref<InputEvent> p_event) { +void ScrollBar::gui_input(const Ref<InputEvent> &p_event) { + ERR_FAIL_COND(p_event.is_null()); + Ref<InputEventMouseMotion> m = p_event; if (!m.is_valid() || drag.active) { - emit_signal("scrolling"); + emit_signal(SNAME("scrolling")); } Ref<InputEventMouseButton> b = p_event; @@ -52,24 +54,24 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (b.is_valid()) { accept_event(); - if (b->get_button_index() == BUTTON_WHEEL_DOWN && b->is_pressed()) { + if (b->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN && b->is_pressed()) { set_value(get_value() + get_page() / 4.0); accept_event(); } - if (b->get_button_index() == BUTTON_WHEEL_UP && b->is_pressed()) { + if (b->get_button_index() == MOUSE_BUTTON_WHEEL_UP && b->is_pressed()) { set_value(get_value() - get_page() / 4.0); accept_event(); } - if (b->get_button_index() != BUTTON_LEFT) { + if (b->get_button_index() != MOUSE_BUTTON_LEFT) { return; } if (b->is_pressed()) { double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x; - Ref<Texture2D> decr = get_theme_icon("decrement"); - Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -78,12 +80,16 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { double total = orientation == VERTICAL ? get_size().height : get_size().width; if (ofs < decr_size) { + decr_active = true; set_value(get_value() - (custom_step >= 0 ? custom_step : get_step())); + update(); return; } if (ofs > total - incr_size) { + incr_active = true; set_value(get_value() + (custom_step >= 0 ? custom_step : get_step())); + update(); return; } @@ -128,6 +134,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { } } else { + incr_active = false; + decr_active = false; drag.active = false; update(); } @@ -138,7 +146,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (drag.active) { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); ofs -= decr_size; @@ -148,8 +156,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { set_as_ratio(drag.value_at_click + diff); } else { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture2D> decr = get_theme_icon("decrement"); - Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -213,17 +221,33 @@ void ScrollBar::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { RID ci = get_canvas_item(); - Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon("decrement_highlight") : get_theme_icon("decrement"); - Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_theme_icon("increment_highlight") : get_theme_icon("increment"); - Ref<StyleBox> bg = has_focus() ? get_theme_stylebox("scroll_focus") : get_theme_stylebox("scroll"); + Ref<Texture2D> decr, incr; + + if (decr_active) { + decr = get_theme_icon(SNAME("decrement_pressed")); + } else if (highlight == HIGHLIGHT_DECR) { + decr = get_theme_icon(SNAME("decrement_highlight")); + } else { + decr = get_theme_icon(SNAME("decrement")); + } + + if (incr_active) { + incr = get_theme_icon(SNAME("increment_pressed")); + } else if (highlight == HIGHLIGHT_INCR) { + incr = get_theme_icon(SNAME("increment_highlight")); + } else { + incr = get_theme_icon(SNAME("increment")); + } + + Ref<StyleBox> bg = has_focus() ? get_theme_stylebox(SNAME("scroll_focus")) : get_theme_stylebox(SNAME("scroll")); Ref<StyleBox> grabber; if (drag.active) { - grabber = get_theme_stylebox("grabber_pressed"); + grabber = get_theme_stylebox(SNAME("grabber_pressed")); } else if (highlight == HIGHLIGHT_RANGE) { - grabber = get_theme_stylebox("grabber_highlight"); + grabber = get_theme_stylebox(SNAME("grabber_highlight")); } else { - grabber = get_theme_stylebox("grabber"); + grabber = get_theme_stylebox(SNAME("grabber")); } Point2 ofs; @@ -387,7 +411,7 @@ void ScrollBar::_notification(int p_what) { } double ScrollBar::get_grabber_min_size() const { - Ref<StyleBox> grabber = get_theme_stylebox("grabber"); + Ref<StyleBox> grabber = get_theme_stylebox(SNAME("grabber")); Size2 gminsize = grabber->get_minimum_size() + grabber->get_center_size(); return (orientation == VERTICAL) ? gminsize.height : gminsize.width; } @@ -413,17 +437,17 @@ double ScrollBar::get_area_size() const { switch (orientation) { case VERTICAL: { double area = get_size().height; - area -= get_theme_stylebox("scroll")->get_minimum_size().height; - area -= get_theme_icon("increment")->get_height(); - area -= get_theme_icon("decrement")->get_height(); + area -= get_theme_stylebox(SNAME("scroll"))->get_minimum_size().height; + area -= get_theme_icon(SNAME("increment"))->get_height(); + area -= get_theme_icon(SNAME("decrement"))->get_height(); area -= get_grabber_min_size(); return area; } break; case HORIZONTAL: { double area = get_size().width; - area -= get_theme_stylebox("scroll")->get_minimum_size().width; - area -= get_theme_icon("increment")->get_width(); - area -= get_theme_icon("decrement")->get_width(); + area -= get_theme_stylebox(SNAME("scroll"))->get_minimum_size().width; + area -= get_theme_icon(SNAME("increment"))->get_width(); + area -= get_theme_icon(SNAME("decrement"))->get_width(); area -= get_grabber_min_size(); return area; } break; @@ -434,16 +458,16 @@ double ScrollBar::get_area_size() const { } double ScrollBar::get_area_offset() const { - double ofs = 0; + double ofs = 0.0; if (orientation == VERTICAL) { - ofs += get_theme_stylebox("hscroll")->get_margin(SIDE_TOP); - ofs += get_theme_icon("decrement")->get_height(); + ofs += get_theme_stylebox(SNAME("hscroll"))->get_margin(SIDE_TOP); + ofs += get_theme_icon(SNAME("decrement"))->get_height(); } if (orientation == HORIZONTAL) { - ofs += get_theme_stylebox("hscroll")->get_margin(SIDE_LEFT); - ofs += get_theme_icon("decrement")->get_width(); + ofs += get_theme_stylebox(SNAME("hscroll"))->get_margin(SIDE_LEFT); + ofs += get_theme_icon(SNAME("decrement"))->get_width(); } return ofs; @@ -454,9 +478,9 @@ double ScrollBar::get_grabber_offset() const { } Size2 ScrollBar::get_minimum_size() const { - Ref<Texture2D> incr = get_theme_icon("increment"); - Ref<Texture2D> decr = get_theme_icon("decrement"); - Ref<StyleBox> bg = get_theme_stylebox("scroll"); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); + Ref<StyleBox> bg = get_theme_stylebox(SNAME("scroll")); Size2 minsize; if (orientation == VERTICAL) { @@ -536,7 +560,7 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) { if (mm.is_valid()) { if (drag_node_touching && !drag_node_touching_deaccel) { - Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y); + Vector2 motion = mm->get_relative(); drag_node_accum -= motion; Vector2 diff = drag_node_from + drag_node_accum; @@ -595,7 +619,6 @@ bool ScrollBar::is_smooth_scroll_enabled() const { } void ScrollBar::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollBar::_gui_input); ClassDB::bind_method(D_METHOD("set_custom_step", "step"), &ScrollBar::set_custom_step); ClassDB::bind_method(D_METHOD("get_custom_step"), &ScrollBar::get_custom_step); |