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
This commit is contained in:
Axel Dörfler 2006-03-19 21:42:29 +00:00
parent db823da57e
commit 5eae27a4d0

View File

@ -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);
}