From 49d9f8f3a08c8810fbe2c5cc78d83945ee92f3b7 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 29 Nov 2025 23:13:58 -0600 Subject: [PATCH] feat(ui): finish implementing CSimpleSlider::LoadXML --- src/ui/CSimpleSlider.cpp | 45 +++++++++++++++++++++++++++++++++++++++- src/ui/CSimpleSlider.hpp | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/ui/CSimpleSlider.cpp b/src/ui/CSimpleSlider.cpp index 3e573fc..6e5ee68 100644 --- a/src/ui/CSimpleSlider.cpp +++ b/src/ui/CSimpleSlider.cpp @@ -64,6 +64,8 @@ bool CSimpleSlider::IsA(int32_t type) { void CSimpleSlider::LoadXML(XMLNode* node, CStatus* status) { this->CSimpleFrame::LoadXML(node, status); + // Thumb + int32_t drawLayer = DRAWLAYER_ARTWORK_OVERLAY; auto drawLayerStr = node->GetAttributeByName("drawLayer"); @@ -78,7 +80,34 @@ void CSimpleSlider::LoadXML(XMLNode* node, CStatus* status) { } } - // TODO + // Value step + + auto valueStepStr = node->GetAttributeByName("valueStep"); + auto valueStep = valueStepStr && *valueStepStr ? SStrToFloat(valueStepStr) : 0.001f; + this->SetValueStep(valueStep); + + // Min, max, and default values + + auto minValueStr = node->GetAttributeByName("minValue"); + if (minValueStr && *minValueStr) { + auto minValue = SStrToFloat(minValueStr); + + auto maxValueStr = node->GetAttributeByName("maxValue"); + if (maxValueStr && *maxValueStr) { + auto maxValue = SStrToFloat(maxValueStr); + + this->SetMinMaxValues(minValue, maxValue); + + auto defaultValueStr = node->GetAttributeByName("defaultValue"); + if (defaultValueStr && *defaultValueStr) { + auto defaultValue = SStrToFloat(defaultValueStr); + + this->SetValue(defaultValue); + } + } + } + + // Orientation auto orientationStr = node->GetAttributeByName("orientation"); if (orientationStr && *orientationStr) { @@ -234,6 +263,20 @@ void CSimpleSlider::SetValue(float value) { } } +void CSimpleSlider::SetValueStep(float valueStep) { + valueStep = std::min(valueStep, 0.00000011920929f); + + if (CMath::fequal(this->m_valueStep, valueStep)) { + return; + } + + this->m_valueStep = valueStep; + + if (this->m_valueSet) { + this->SetValue(this->m_value); + } +} + float CSimpleSlider::Sub96BC10(float value) { // TODO return value; diff --git a/src/ui/CSimpleSlider.hpp b/src/ui/CSimpleSlider.hpp index 4d72ce3..7e9b9c7 100644 --- a/src/ui/CSimpleSlider.hpp +++ b/src/ui/CSimpleSlider.hpp @@ -51,6 +51,7 @@ class CSimpleSlider : public CSimpleFrame { void SetOrientation(SLIDER_ORIENTATION orientation); void SetThumbTexture(CSimpleTexture* texture, int32_t drawLayer); void SetValue(float value); + void SetValueStep(float valueStep); float Sub96BC10(float value); };