From 0a87eb7f746b39f0100a85cbb9dcf3a8d5c65e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Mon, 17 Apr 2017 16:47:24 +0200 Subject: Introduce scrolling to Slider. --- plugingui/slider.cc | 52 ++++++++++++++++++++++------------------------------ plugingui/slider.h | 1 + 2 files changed, 23 insertions(+), 30 deletions(-) (limited to 'plugingui') 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 -- cgit v1.2.3