diff options
author | André Nusser <andre.nusser@googlemail.com> | 2017-04-17 16:47:24 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2017-04-17 16:51:24 +0200 |
commit | 0a87eb7f746b39f0100a85cbb9dcf3a8d5c65e05 (patch) | |
tree | cd7decf3c50e2cb37670ef7e6a424e33b212fc91 | |
parent | cbb0f0f34e71630cb59ac4a831daf445f58a6427 (diff) |
Introduce scrolling to Slider.
-rw-r--r-- | plugingui/slider.cc | 52 | ||||
-rw-r--r-- | plugingui/slider.h | 1 |
2 files changed, 23 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:: diff --git a/plugingui/slider.h b/plugingui/slider.h index 9620fd0..ff2db29 100644 --- a/plugingui/slider.h +++ b/plugingui/slider.h @@ -63,6 +63,7 @@ protected: virtual void repaintEvent(RepaintEvent* repaintEvent) override; virtual void buttonEvent(ButtonEvent* buttonEvent) override; virtual void mouseMoveEvent(MouseMoveEvent* mouseMoveEvent) override; + virtual void scrollEvent(ScrollEvent* scrollEvent) override; private: enum class State |