From 11e2bda54641c1ef4cad38c11d742524966c7e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Wed, 19 Apr 2017 22:47:08 +0200 Subject: Take memory specific code out of Slider and fix a bug on the way. --- plugingui/diskstreamingframecontent.cc | 6 +++--- plugingui/diskstreamingframecontent.h | 5 ++++- plugingui/slider.cc | 16 +++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/plugingui/diskstreamingframecontent.cc b/plugingui/diskstreamingframecontent.cc index af21bca..f2536f7 100644 --- a/plugingui/diskstreamingframecontent.cc +++ b/plugingui/diskstreamingframecontent.cc @@ -81,16 +81,16 @@ void DiskstreamingframeContent::resize(std::size_t width, std::size_t height) label_size.resize(slider_width, 15); } -void DiskstreamingframeContent::limitSettingsValueChanged(float value) +void DiskstreamingframeContent::limitSettingsValueChanged(std::size_t value) { int value_in_mb = value/(1024 * 1024); label_size.setText(std::to_string(value_in_mb) + " MB"); - slider.setValue(value); + slider.setValue((float)value/max_limit); } void DiskstreamingframeContent::limitValueChanged(float value) { - settings.disk_cache_upper_limit.store(value); + settings.disk_cache_upper_limit.store(value * max_limit); } void DiskstreamingframeContent::reloadClicked() diff --git a/plugingui/diskstreamingframecontent.h b/plugingui/diskstreamingframecontent.h index bcdbef9..2b34bc5 100644 --- a/plugingui/diskstreamingframecontent.h +++ b/plugingui/diskstreamingframecontent.h @@ -48,10 +48,13 @@ public: virtual void resize(std::size_t width, std::size_t height) override; private: - void limitSettingsValueChanged(float value); + void limitSettingsValueChanged(std::size_t value); void limitValueChanged(float value); void reloadClicked(); + // For now the maximum disk streaming limit is 4GB + static constexpr std::size_t max_limit = 1024.0 * 1024.0 * 1024.0 * 4.0; + Label label_text{this}; Label label_size{this}; diff --git a/plugingui/slider.cc b/plugingui/slider.cc index ed23fad..b558468 100644 --- a/plugingui/slider.cc +++ b/plugingui/slider.cc @@ -34,8 +34,6 @@ namespace GUI { -static constexpr float _4GB = 1024.0 * 1024.0 * 1024.0 * 4.0; - Slider::Slider(Widget* parent) : Widget(parent) { state = State::up; @@ -47,10 +45,12 @@ Slider::Slider(Widget* parent) : Widget(parent) void Slider::setValue(float new_value) { - current_value = new_value / (float)_4GB; // TODO: Scale to [0, 1] range + // TODO make sure that we get values in range [0, 1] + + current_value = new_value; redraw(); clickNotifier(); - valueChangedNotifier(current_value * _4GB); // TODO: Scale up to full range + valueChangedNotifier(current_value); } float Slider::value() const @@ -109,6 +109,7 @@ void Slider::buttonEvent(ButtonEvent* buttonEvent) redraw(); clickNotifier(); + valueChangedNotifier(current_value); } if(buttonEvent->direction == Direction::up) @@ -118,6 +119,7 @@ void Slider::buttonEvent(ButtonEvent* buttonEvent) redraw(); clickNotifier(); + valueChangedNotifier(current_value); } } @@ -129,7 +131,7 @@ void Slider::mouseMoveEvent(MouseMoveEvent* mouseMoveEvent) redraw(); clickNotifier(); - valueChangedNotifier(current_value * _4GB); // TODO: Scale up to full range + valueChangedNotifier(current_value); } } @@ -146,7 +148,7 @@ void Slider::scrollEvent(ScrollEvent* scrollEvent) redraw(); clickNotifier(); - valueChangedNotifier(current_value * _4GB); // TODO: Scale up to full range + valueChangedNotifier(current_value); } std::size_t Slider::getControlWidth() const @@ -167,7 +169,7 @@ void Slider::recomputeCurrentValue(float x) } else { - current_value = (maximum / getControlWidth()) * (x - button_offset); + current_value = (x - button_offset) / getControlWidth(); } if (current_value < 0.) -- cgit v1.2.3