Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 3910fa6

Browse files
committed
Fixed knob position
1 parent 5268e4e commit 3910fa6

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

GUI/GUISlider.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -465,22 +465,23 @@ void GUISlider::OnMouseMove(int X, int Y, int Buttons, int Modifier)
465465

466466
void GUISlider::OnMouseWheelChange(int x, int y, int modifier, int mouseWheelChange) {
467467
m_OldValue = m_Value;
468-
const int size = (m_Orientation == Horizontal) ? m_Width : m_Height;
469-
470-
const float ratio = static_cast<float>(m_ValueResolution) / static_cast<float>(m_Maximum - m_Minimum);
471-
const int posRange = size - m_KnobSize - m_EndThickness;
472-
const int posDelta = std::max(static_cast<int>(ratio * static_cast<float>(posRange)),1);
468+
473469
if (mouseWheelChange < 0) {
474470
m_Value = std::max(m_Value - m_ValueResolution, m_Minimum);
475-
m_KnobPosition = std::max(m_KnobPosition - posDelta, m_EndThickness);
476471
} else {
477472
m_Value = std::min(m_Value + m_ValueResolution, m_Maximum);
478-
m_KnobPosition = std::min(m_KnobPosition + posDelta, posRange);
479473
}
474+
475+
if (m_Value != m_OldValue) {
476+
const int size = (m_Orientation == Horizontal) ? m_Width : m_Height;
477+
const int posRange = size - m_KnobSize - m_EndThickness;
478+
const float ratio = static_cast<float>(m_Value) / static_cast<float>(m_Maximum - m_Minimum);
479+
m_KnobPosition = m_EndThickness + static_cast<int>(std::round(static_cast<float>(posRange) * ratio));
480480

481-
if (m_Value != m_OldValue)
482481
AddEvent(GUIEvent::Notification, Changed, 0);
482+
}
483483
}
484+
484485
/*
485486
486487
//////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)