From 0f3b06cb9fb89d4435921a5ca160a2aafb390ae3 Mon Sep 17 00:00:00 2001 From: Rebekah Rowe Date: Mon, 11 Apr 2022 12:48:41 -0400 Subject: [PATCH] Deprecated keyvalue floats pt3 --- include/libpdraw/gui/widgets/keyvalues.hpp | 4 ++-- include/libpdraw/gui/widgets/slider.hpp | 3 +++ src/gui/widgets/slider.cpp | 24 +++++++++++----------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/libpdraw/gui/widgets/keyvalues.hpp b/include/libpdraw/gui/widgets/keyvalues.hpp index 42d637c..e31378c 100644 --- a/include/libpdraw/gui/widgets/keyvalues.hpp +++ b/include/libpdraw/gui/widgets/keyvalues.hpp @@ -37,8 +37,8 @@ public: [[deprecated]] void SetBool(const std::string& s, int v) { this->stored_bools[s] = v; } [[deprecated]] int GetInt(const std::string& s) { return this->stored_ints.at(s); } [[deprecated]] void SetInt(const std::string& s, int v) { this->stored_ints[s] = v; } - float GetFloat(const std::string& s) { return this->stored_floats.at(s); } - void SetFloat(const std::string& s, float v) { this->stored_floats[s] = v; } + [[deprecated]] float GetFloat(const std::string& s) { return this->stored_floats.at(s); } + [[deprecated]] void SetFloat(const std::string& s, float v) { this->stored_floats[s] = v; } std::string GetString(const std::string& s) { return this->stored_strings.at(s); } void SetString(const std::string& s, const std::string& v) { this->stored_strings[s] = v; } glez::rgba GetColor(const std::string& s) { return this->stored_colors.at(s); } diff --git a/include/libpdraw/gui/widgets/slider.hpp b/include/libpdraw/gui/widgets/slider.hpp index 144f1a8..43edf17 100644 --- a/include/libpdraw/gui/widgets/slider.hpp +++ b/include/libpdraw/gui/widgets/slider.hpp @@ -43,4 +43,7 @@ public: int m_nLastX; bool m_bDragInit; int m_nSliderPos; + +private: + float value_min, value_max, value, step; }; diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 610278e..35a702a 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -36,15 +36,15 @@ CSlider::CSlider(std::string name, IWidget* parent) } void CSlider::Setup(float min, float max) { - Props()->SetFloat("value_min", min); - Props()->SetFloat("value_max", max); - Props()->SetFloat("value", 0); - Props()->SetFloat("step", 0); + this->value_min = min; + this->value_max = max; + this->value = 0; + this->step = 0; SetValue((min + max) / 2.0f); } -void CSlider::SetStep(float step) { - Props()->SetFloat("step", step); +void CSlider::SetStep(float _step) { + this->step = _step; } void CSlider::SetCallback(SliderCallbackFn_t callback) { @@ -53,20 +53,20 @@ void CSlider::SetCallback(SliderCallbackFn_t callback) { void CSlider::SetValue(float value) { float old = Value(); - if (Props()->GetFloat("step")) { - value -= fmod(value, Props()->GetFloat("step")); + if (this->step) { + value -= fmod(value, this->step); } - Props()->SetFloat("value", value); + this->value = value; if (old != value) { if (m_pCallback) { m_pCallback(this, old, value); } } - m_nSliderPos = (GetSize().first) * (float)(value - Props()->GetFloat("value_min")) / (float)(Props()->GetFloat("value_max") - Props()->GetFloat("value_min")); + m_nSliderPos = (GetSize().first) * (float)(value - this->value_min) / (float)(this->value_max - this->value_min); } float CSlider::Value() { - return Props()->GetFloat("value"); + return this->value; } void CSlider::Update() { @@ -81,7 +81,7 @@ void CSlider::Update() { mv = 0; if (mv > size.first) mv = size.first; - SetValue(((float)mv / (float)size.first) * (Props()->GetFloat("value_max") - Props()->GetFloat("value_min")) + Props()->GetFloat("value_min")); + SetValue(((float)mv / (float)size.first) * (this->value_max - this->value_min) + this->value_min); m_nSliderPos = mv; } }