From 52bd0792d15e9a814cd38cf77b26784003b8569f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 29 Jan 2012 15:16:17 +0000 Subject: --- src/ui/slider.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/ui/slider.cc') diff --git a/src/ui/slider.cc b/src/ui/slider.cc index 1fa999b..c1b473c 100644 --- a/src/ui/slider.cc +++ b/src/ui/slider.cc @@ -160,16 +160,15 @@ void Slider::on_mousemove(const math::Vector2f &cursor) } if (slider_dragging && (slider_maximum > slider_minimum)) { - // total width of dragable area - if ((cursor.x() >= 2.0f * height()) && (cursor.x() <= width() - 2.0f * height())) { - const float w = (width() - 4.0f * height()); - const float s = w / (slider_maximum - slider_minimum); - const float p = cursor.x() - 2.0f * height(); - const float newvalue = slider_minimum + round(p /s); - if (slider_value != newvalue) { - slider_value = newvalue; - emit(EventSliderChanged, this); - } + float x = cursor.x(); + math::clamp(x, 2.0f * height(), width() - 2.0f * height()); + const float w = (width() - 4.0f * height()); + const float s = w / (slider_maximum - slider_minimum); + const float p = cursor.x() - 2.0f * height(); + const float newvalue = slider_minimum + round(p /s); + if (slider_value != newvalue) { + slider_value = newvalue; + emit(EventSliderChanged, this); } } } -- cgit v1.2.3