Deprecated keyvalue floats pt3
This commit is contained in:
parent
17ccd88881
commit
0f3b06cb9f
@ -37,8 +37,8 @@ public:
|
|||||||
[[deprecated]] void SetBool(const std::string& s, int v) { this->stored_bools[s] = v; }
|
[[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]] 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; }
|
[[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); }
|
[[deprecated]] 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]] 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); }
|
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; }
|
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); }
|
glez::rgba GetColor(const std::string& s) { return this->stored_colors.at(s); }
|
||||||
|
@ -43,4 +43,7 @@ public:
|
|||||||
int m_nLastX;
|
int m_nLastX;
|
||||||
bool m_bDragInit;
|
bool m_bDragInit;
|
||||||
int m_nSliderPos;
|
int m_nSliderPos;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float value_min, value_max, value, step;
|
||||||
};
|
};
|
||||||
|
@ -36,15 +36,15 @@ CSlider::CSlider(std::string name, IWidget* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CSlider::Setup(float min, float max) {
|
void CSlider::Setup(float min, float max) {
|
||||||
Props()->SetFloat("value_min", min);
|
this->value_min = min;
|
||||||
Props()->SetFloat("value_max", max);
|
this->value_max = max;
|
||||||
Props()->SetFloat("value", 0);
|
this->value = 0;
|
||||||
Props()->SetFloat("step", 0);
|
this->step = 0;
|
||||||
SetValue((min + max) / 2.0f);
|
SetValue((min + max) / 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSlider::SetStep(float step) {
|
void CSlider::SetStep(float _step) {
|
||||||
Props()->SetFloat("step", step);
|
this->step = _step;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSlider::SetCallback(SliderCallbackFn_t callback) {
|
void CSlider::SetCallback(SliderCallbackFn_t callback) {
|
||||||
@ -53,20 +53,20 @@ void CSlider::SetCallback(SliderCallbackFn_t callback) {
|
|||||||
|
|
||||||
void CSlider::SetValue(float value) {
|
void CSlider::SetValue(float value) {
|
||||||
float old = Value();
|
float old = Value();
|
||||||
if (Props()->GetFloat("step")) {
|
if (this->step) {
|
||||||
value -= fmod(value, Props()->GetFloat("step"));
|
value -= fmod(value, this->step);
|
||||||
}
|
}
|
||||||
Props()->SetFloat("value", value);
|
this->value = value;
|
||||||
if (old != value) {
|
if (old != value) {
|
||||||
if (m_pCallback) {
|
if (m_pCallback) {
|
||||||
m_pCallback(this, old, value);
|
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() {
|
float CSlider::Value() {
|
||||||
return Props()->GetFloat("value");
|
return this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSlider::Update() {
|
void CSlider::Update() {
|
||||||
@ -81,7 +81,7 @@ void CSlider::Update() {
|
|||||||
mv = 0;
|
mv = 0;
|
||||||
if (mv > size.first)
|
if (mv > size.first)
|
||||||
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;
|
m_nSliderPos = mv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user