From 52bd0792d15e9a814cd38cf77b26784003b8569f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 29 Jan 2012 15:16:17 +0000 Subject: --- src/ui/scrollbar.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/ui/scrollbar.cc') diff --git a/src/ui/scrollbar.cc b/src/ui/scrollbar.cc index 9be1432..a8826a5 100644 --- a/src/ui/scrollbar.cc +++ b/src/ui/scrollbar.cc @@ -160,17 +160,16 @@ void ScrollBar::on_mousemove(const math::Vector2f &cursor) } if (scrollbar_dragging && (scrollbar_maximum > scrollbar_minimum)) { - // total width of dragable area - if ((cursor.y() >= 2.0f * width()) && (cursor.y() <= height() - 2.0f * width())) { + float y = cursor.y(); + math::clamp(y, 2.0f * width() , height() - 2.0f * width()); - const float h = (height() - 4.0f * width()); - const float s = h / (scrollbar_maximum - scrollbar_minimum); - const float p = cursor.y() - 2.0f * width(); - const float newvalue = scrollbar_minimum + round(p / s); - if (scrollbar_value != newvalue) { - scrollbar_value = newvalue; - emit(EventScrollBarChanged, this); - } + const float h = (height() - 4.0f * width()); + const float s = h / (scrollbar_maximum - scrollbar_minimum); + const float p = y - 2.0f * width(); + const float newvalue = scrollbar_minimum + round(p / s); + if (scrollbar_value != newvalue) { + scrollbar_value = newvalue; + emit(EventScrollBarChanged, this); } } -- cgit v1.2.3