From 03e6434ec0ca4628c1192f0ef5f4d0c1ff7d61de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sun, 11 Apr 2010 12:57:58 +0000 Subject: [PATCH] * fixes a BSlider issue noticed by Matt on the mailing list: Invoke() wasn't called the first time you grab a slider and slide it all the way to the left. Thanks for the test case. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36145 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Slider.h | 2 +- src/kits/interface/Slider.cpp | 46 +++++++++++++++++------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/headers/os/interface/Slider.h b/headers/os/interface/Slider.h index 3ec1087f27..2ce286bc03 100644 --- a/headers/os/interface/Slider.h +++ b/headers/os/interface/Slider.h @@ -166,7 +166,7 @@ private: void _DrawTriangleThumb(); BPoint _Location() const; - void _SetLocation(BPoint point); + void _SetLocationForValue(int32 value); float _MinPosition() const; float _MaxPosition() const; diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index b864a3afc3..43a4acf9de 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -363,8 +363,6 @@ BSlider::AttachedToWindow() { ResizeToPreferred(); - fLocation.Set(9.0f, 0.0f); - #if USE_OFF_SCREEN_VIEW BRect bounds(Bounds()); @@ -395,8 +393,11 @@ BSlider::AttachedToWindow() view->UnlockLooper(); } - SetValue(Value()); + int32 value = Value(); + SetValue(value); // makes sure the value is within valid bounds + _SetLocationForValue(Value()); + // makes sure the location is correct UpdateTextChanged(); } @@ -672,22 +673,8 @@ BSlider::SetValue(int32 value) if (value == Value()) return; - - BPoint loc; - float range = (float)(fMaxValue - fMinValue); - if (range == 0) - range = 1; - - float pos = (float)(value - fMinValue) / range * - (_MaxPosition() - _MinPosition()); - - if (fOrientation == B_HORIZONTAL) { - loc.x = ceil(_MinPosition() + pos); - loc.y = 0; - } else { - loc.x = 0; - loc.y = floor(_MaxPosition() - pos); - } + + _SetLocationForValue(value); BRect oldThumbFrame = ThumbFrame(); @@ -698,8 +685,6 @@ BSlider::SetValue(int32 value) else oldThumbFrame.right = BarFrame().right; - _SetLocation(loc); - BControl::SetValueNoUpdate(value); BRect invalid = oldThumbFrame | ThumbFrame(); @@ -2030,9 +2015,24 @@ BSlider::_Location() const void -BSlider::_SetLocation(BPoint p) +BSlider::_SetLocationForValue(int32 value) { - fLocation = p; + BPoint loc; + float range = (float)(fMaxValue - fMinValue); + if (range == 0) + range = 1; + + float pos = (float)(value - fMinValue) / range * + (_MaxPosition() - _MinPosition()); + + if (fOrientation == B_HORIZONTAL) { + loc.x = ceil(_MinPosition() + pos); + loc.y = 0; + } else { + loc.x = 0; + loc.y = floor(_MaxPosition() - pos); + } + fLocation = loc; }