feat(ui): add CSimpleSlider::OnLayerTrackUpdate

This commit is contained in:
fallenoak 2025-11-30 11:47:33 -06:00
parent c2e1bd19b8
commit 79482ea860
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 24 additions and 0 deletions

View File

@ -133,6 +133,29 @@ void CSimpleSlider::OnLayerHide() {
this->CSimpleFrame::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) { void CSimpleSlider::OnLayerUpdate(float elapsedSec) {
this->CSimpleFrame::OnLayerUpdate(elapsedSec); this->CSimpleFrame::OnLayerUpdate(elapsedSec);

View File

@ -35,6 +35,7 @@ class CSimpleSlider : public CSimpleFrame {
virtual void LoadXML(XMLNode* node, CStatus* status); virtual void LoadXML(XMLNode* node, CStatus* status);
virtual void OnLayerHide(); virtual void OnLayerHide();
virtual void OnLayerUpdate(float elapsedSec); virtual void OnLayerUpdate(float elapsedSec);
virtual int32_t OnLayerTrackUpdate(const CMouseEvent& evt);
// Member functions // Member functions
CSimpleSlider(CSimpleFrame* parent) CSimpleSlider(CSimpleFrame* parent)