diff --git a/src/bin/desklink/VolumeSlider.cpp b/src/bin/desklink/VolumeSlider.cpp index 6749710a97..4a40949a0f 100644 --- a/src/bin/desklink/VolumeSlider.cpp +++ b/src/bin/desklink/VolumeSlider.cpp @@ -379,6 +379,48 @@ SliderView::Draw(BRect updateRect) } +void +SliderView::MessageReceived(BMessage* msg) +{ + switch (msg->what) { + case B_MOUSE_WHEEL_CHANGED: + { + if (Value() == -1) + return; + + // Even though the volume bar is horizontal, we use the more common + // vertical mouse wheel change + float deltaY = 0.0f; + + msg->FindFloat("be:wheel_delta_y", &deltaY); + + if (deltaY == 0.0f) + return; + + int32 currentValue = Value(); + // deltaY is generally 1 or -1, so this should increase or decrease + // the 0-100 volume value by 5 each time. Also -5 is used because + // mousewheel up is negative but should increase the volume. + int32 newValue = MAX(MIN(currentValue + static_cast(deltaY * -5.0), 100), 0); + + if (newValue != currentValue) { + SetValue(newValue); + Draw(Bounds()); + Flush(); + + if (Window()) + Window()->PostMessage(VOLUME_UPDATED); + } + + break; + } + + default: + return BView::MessageReceived(msg); + } +} + + void SliderView::MouseDown(BPoint point) { @@ -437,3 +479,4 @@ SliderView::MouseUp(BPoint point) Draw(Bounds()); Flush(); } + diff --git a/src/bin/desklink/VolumeSlider.h b/src/bin/desklink/VolumeSlider.h index 8ea4f17fcb..a1805e46ae 100644 --- a/src/bin/desklink/VolumeSlider.h +++ b/src/bin/desklink/VolumeSlider.h @@ -40,6 +40,7 @@ class SliderView : public BControl { ~SliderView(); virtual void Draw(BRect); + virtual void MessageReceived(BMessage*); virtual void MouseDown(BPoint point); virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message); virtual void MouseUp(BPoint point);