summaryrefslogtreecommitdiff
path: root/plugingui/slider.cc
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2017-04-17 16:47:24 +0200
committerAndré Nusser <andre.nusser@googlemail.com>2017-04-17 16:51:24 +0200
commit0a87eb7f746b39f0100a85cbb9dcf3a8d5c65e05 (patch)
treecd7decf3c50e2cb37670ef7e6a424e33b212fc91 /plugingui/slider.cc
parentcbb0f0f34e71630cb59ac4a831daf445f58a6427 (diff)
Introduce scrolling to Slider.
Diffstat (limited to 'plugingui/slider.cc')
-rw-r--r--plugingui/slider.cc52
1 files changed, 22 insertions, 30 deletions
diff --git a/plugingui/slider.cc b/plugingui/slider.cc
index 6a764b8..7d5cdb4 100644
--- a/plugingui/slider.cc
+++ b/plugingui/slider.cc
@@ -104,16 +104,6 @@ void Slider::buttonEvent(ButtonEvent* buttonEvent)
state = State::down;
recomputeCurrentValue(buttonEvent->x);
- if(current_value < 0)
- {
- current_value = 0;
- }
-
- if(current_value > 1)
- {
- current_value = 1;
- }
-
redraw();
clickNotifier();
}
@@ -123,16 +113,6 @@ void Slider::buttonEvent(ButtonEvent* buttonEvent)
state = State::up;
recomputeCurrentValue(buttonEvent->x);
- if(current_value < 0)
- {
- current_value = 0;
- }
-
- if(current_value > 1)
- {
- current_value = 1;
- }
-
redraw();
clickNotifier();
}
@@ -144,21 +124,25 @@ void Slider::mouseMoveEvent(MouseMoveEvent* mouseMoveEvent)
{
recomputeCurrentValue(mouseMoveEvent->x);
- if(current_value < 0)
- {
- current_value = 0;
- }
-
- if(current_value > 1)
- {
- current_value = 1;
- }
-
redraw();
clickNotifier();
}
}
+void Slider::scrollEvent(ScrollEvent* scrollEvent)
+{
+ current_value += scrollEvent->delta/(float)getControlWidth();
+ if (current_value < 0.)
+ {
+ current_value = 0.;
+ }
+ else if (current_value > 1.0) {
+ current_value = 1.0;
+ }
+
+ redraw();
+}
+
std::size_t Slider::getControlWidth() const
{
if(width() < 2 * button_offset)
@@ -179,6 +163,14 @@ void Slider::recomputeCurrentValue(float x)
{
current_value = (maximum / getControlWidth()) * (x - button_offset);
}
+
+ if (current_value < 0.)
+ {
+ current_value = 0.;
+ }
+ else if (current_value > 1.0) {
+ current_value = 1.0;
+ }
}
} // GUI::