feat(ui): add CSimpleSlider::OnLayerUpdate

This commit is contained in:
fallenoak 2025-11-29 22:40:11 -06:00
parent eca8ed6a32
commit 92a85cc5ce
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 27 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include "util/Lua.hpp" #include "util/Lua.hpp"
#include "util/StringTo.hpp" #include "util/StringTo.hpp"
#include <common/XML.hpp> #include <common/XML.hpp>
#include <tempest/Math.hpp>
int32_t CSimpleSlider::s_metatable; int32_t CSimpleSlider::s_metatable;
int32_t CSimpleSlider::s_objectType; int32_t CSimpleSlider::s_objectType;
@ -80,6 +81,31 @@ void CSimpleSlider::LoadXML(XMLNode* node, CStatus* status) {
// TODO // TODO
} }
void CSimpleSlider::OnLayerUpdate(float elapsedSec) {
this->CSimpleFrame::OnLayerUpdate(elapsedSec);
if (this->m_changed && this->m_thumbTexture && this->m_rangeSet && this->m_valueSet) {
auto valueRange = this->m_range + this->m_baseValue - this->m_baseValue;
auto valueOffset = CMath::fequal(valueRange, 0.0f)
? 0.0f
: (this->m_value - this->m_baseValue) / valueRange;
if (this->m_orientation == SLIDER_VERTICAL) {
auto rangeY = (this->m_rect.maxY - this->m_rect.minY) / this->m_layoutScale;
auto offsetY = -((rangeY - this->m_thumbTexture->GetHeight()) * valueOffset);
this->m_thumbTexture->SetPoint(FRAMEPOINT_TOP, this, FRAMEPOINT_TOP, 0.0f, offsetY, 1);
} else {
auto rangeX = (this->m_rect.maxX - this->m_rect.minX) / this->m_layoutScale;
auto offsetX = (rangeX - this->m_thumbTexture->GetWidth()) * valueOffset;
this->m_thumbTexture->SetPoint(FRAMEPOINT_LEFT, this, FRAMEPOINT_LEFT, offsetX, 0.0f, 1);
}
this->m_changed = 0;
}
}
void CSimpleSlider::RunOnMinMaxChangedScript() { void CSimpleSlider::RunOnMinMaxChangedScript() {
if (!this->m_onMinMaxChanged.luaRef) { if (!this->m_onMinMaxChanged.luaRef) {
return; return;

View File

@ -33,6 +33,7 @@ class CSimpleSlider : public CSimpleFrame {
virtual bool IsA(int32_t type); virtual bool IsA(int32_t type);
virtual int32_t GetScriptMetaTable(); virtual int32_t GetScriptMetaTable();
virtual void LoadXML(XMLNode* node, CStatus* status); virtual void LoadXML(XMLNode* node, CStatus* status);
virtual void OnLayerUpdate(float elapsedSec);
// Member functions // Member functions
CSimpleSlider(CSimpleFrame* parent) CSimpleSlider(CSimpleFrame* parent)