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:
@@ -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
|
void
|
||||||
SliderView::MouseDown(BPoint point)
|
SliderView::MouseDown(BPoint point)
|
||||||
{
|
{
|
||||||
@@ -437,3 +479,4 @@ SliderView::MouseUp(BPoint point)
|
|||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
Flush();
|
Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class SliderView : public BControl {
|
|||||||
~SliderView();
|
~SliderView();
|
||||||
|
|
||||||
virtual void Draw(BRect);
|
virtual void Draw(BRect);
|
||||||
|
virtual void MessageReceived(BMessage*);
|
||||||
virtual void MouseDown(BPoint point);
|
virtual void MouseDown(BPoint point);
|
||||||
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
|
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
|
||||||
virtual void MouseUp(BPoint point);
|
virtual void MouseUp(BPoint point);
|
||||||
|
|||||||
Reference in New Issue
Block a user