From f90d6dffed2ecbec09b2451e3ec84d9cd417a1c5 Mon Sep 17 00:00:00 2001 From: Mounir Tohami <53877170+WhalesState@users.noreply.github.com> Date: Wed, 7 Feb 2024 17:19:13 +0000 Subject: [PATCH] Fix `Slider`'s drag mouse position when grabber is centered (cherry picked from commit e6a42e3fc58e5bf6a4e8d04cbf1ab53bd7c7930d) --- scene/gui/slider.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 586334a0b44..94427cf4e5f 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -65,8 +65,8 @@ void Slider::gui_input(const Ref &p_event) { grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x; - double grab_width = (double)grabber->get_width(); - double grab_height = (double)grabber->get_height(); + double grab_width = theme_cache.center_grabber ? 0.0 : (double)grabber->get_width(); + double grab_height = theme_cache.center_grabber ? 0.0 : (double)grabber->get_height(); double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width; set_block_signals(true); if (orientation == VERTICAL) { @@ -106,12 +106,14 @@ void Slider::gui_input(const Ref &p_event) { if (mm.is_valid()) { if (grab.active) { Size2i size = get_size(); - Ref grabber = theme_cache.grabber_icon; + Ref grabber = theme_cache.grabber_hl_icon; + double grab_width = theme_cache.center_grabber ? 0.0 : (double)grabber->get_width(); + double grab_height = theme_cache.center_grabber ? 0.0 : (double)grabber->get_height(); double motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos; if (orientation == VERTICAL) { motion = -motion; } - double areasize = orientation == VERTICAL ? size.height - grabber->get_height() : size.width - grabber->get_width(); + double areasize = orientation == VERTICAL ? size.height - grab_height : size.width - grab_width; if (areasize <= 0) { return; }