Fix #3577: allow the mouse wheel to change volume in the DeskBar widget. Mouse

up increases volume, mouse down decreases it, by 5 at a time.

One issue is you must have the pointer directly over the slider for this to
work. I wonder if the B_POINTER_EVENTS in SetEventMask should also apply to
mouse wheel events?


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29620 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ryan Leavengood 2009-03-20 03:26:00 +00:00
parent f06f733751
commit 0237261547
2 changed files with 44 additions and 0 deletions

View File

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

View File

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