Slider value accounts for grabber offset

(cherry picked from commit fb54ba6397)
This commit is contained in:
Mason Ashbridge 2016-08-24 03:17:54 -04:00 committed by Rémi Verschelde
parent 6df46803a7
commit 07caf4438d

View file

@ -47,12 +47,15 @@ void Slider::_input_event(InputEvent p_event) {
if (mb.button_index==BUTTON_LEFT) {
if (mb.pressed) {
Ref<Texture> grabber = get_icon(mouse_inside||has_focus()?"grabber_hilite":"grabber");
grab.pos=orientation==VERTICAL?mb.y:mb.x;
double max = orientation==VERTICAL ? get_size().height : get_size().width ;
double grab_width = (double)grabber->get_size().width;
double grab_height = (double)grabber->get_size().height;
double max = orientation==VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
if (orientation==VERTICAL)
set_unit_value( 1 - ((double)grab.pos / max) );
set_unit_value( 1 - (((double)grab.pos - (grab_height / 2.0)) / max) );
else
set_unit_value((double)grab.pos / max);
set_unit_value(((double)grab.pos - (grab_width/2.0)) / max);
grab.active=true;
grab.uvalue=get_unit_value();
} else {