From 5eae27a4d058b2b61e222e66547f52c7ba2ca4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 19 Mar 2006 21:42:29 +0000 Subject: [PATCH] Fixed ValueForPoint() to correctly limit the value to the slider bounds. This fixes bug #294. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16839 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Slider.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index 0cc25bb859..04027ea642 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -632,9 +632,16 @@ BSlider::SetValue(int32 value) int32 BSlider::ValueForPoint(BPoint location) const { - return (int32)(((fOrientation == B_HORIZONTAL ? location.x : location.y) - - _MinPosition()) - * (fMaxValue - fMinValue) / (_MaxPosition() - _MinPosition())) + fMinValue; + float position = fOrientation == B_HORIZONTAL ? location.x : location.y; + float min = _MinPosition(); + float max = _MaxPosition(); + + if (position < min) + position = min; + if (position > max) + position = max; + + return (int32)roundf(((position - min) * (fMaxValue - fMinValue) / (max - min)) + fMinValue); }