From 79482ea860bd3ac8ac547cbd959f23dc7515040d Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sun, 30 Nov 2025 11:47:33 -0600 Subject: [PATCH] feat(ui): add CSimpleSlider::OnLayerTrackUpdate --- src/ui/CSimpleSlider.cpp | 23 +++++++++++++++++++++++ src/ui/CSimpleSlider.hpp | 1 + 2 files changed, 24 insertions(+) diff --git a/src/ui/CSimpleSlider.cpp b/src/ui/CSimpleSlider.cpp index 9364f1c..da999a9 100644 --- a/src/ui/CSimpleSlider.cpp +++ b/src/ui/CSimpleSlider.cpp @@ -133,6 +133,29 @@ void CSimpleSlider::OnLayerHide() { this->CSimpleFrame::OnLayerHide(); } +int32_t CSimpleSlider::OnLayerTrackUpdate(const CMouseEvent& evt) { + if (this->m_buttonDown && this->m_thumbTexture) { + auto thumbTexture = this->m_thumbTexture; + + float area; + float offset; + + if (this->m_orientation == SLIDER_VERTICAL) { + area = this->m_rect.maxY - this->m_rect.minY - thumbTexture->GetHeight(); + offset = this->m_rect.maxY - (thumbTexture->GetHeight() / 2.0f) - evt.y; + } else { + area = this->m_rect.maxX - this->m_rect.minX - thumbTexture->GetWidth(); + offset = evt.x - ((thumbTexture->GetWidth() / 2.0f) + this->m_rect.minX); + } + + float value = (this->m_range + this->m_baseValue - this->m_baseValue) * (offset / area) + this->m_baseValue; + + this->SetValue(value); + } + + return this->CSimpleFrame::OnLayerTrackUpdate(evt); +} + void CSimpleSlider::OnLayerUpdate(float elapsedSec) { this->CSimpleFrame::OnLayerUpdate(elapsedSec); diff --git a/src/ui/CSimpleSlider.hpp b/src/ui/CSimpleSlider.hpp index de0d42d..ae91efe 100644 --- a/src/ui/CSimpleSlider.hpp +++ b/src/ui/CSimpleSlider.hpp @@ -35,6 +35,7 @@ class CSimpleSlider : public CSimpleFrame { virtual void LoadXML(XMLNode* node, CStatus* status); virtual void OnLayerHide(); virtual void OnLayerUpdate(float elapsedSec); + virtual int32_t OnLayerTrackUpdate(const CMouseEvent& evt); // Member functions CSimpleSlider(CSimpleFrame* parent)