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

Commit f890192

Browse files
committed
Misc. cleanup in GUISlider
1 parent dbb46ec commit f890192

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

GUI/GUISlider.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ void GUISlider::Create(GUIProperties *Props)
123123
m_ValueResolution = std::max((m_Maximum - m_Minimum) / 100, 1);
124124
}
125125

126-
// Clamp the value
127-
m_Value = MAX(m_Value, m_Minimum);
128-
m_Value = MIN(m_Value, m_Maximum);
126+
m_Value = std::clamp(m_Value, m_Minimum,m_Maximum);
129127

130128
// Re-Calculate the knob info
131129
CalculateKnob();
@@ -361,9 +359,7 @@ void GUISlider::OnMouseDown(int X, int Y, int Buttons, int Modifier)
361359
Size = m_Height;
362360
}
363361

364-
// Clamp the knob position
365-
m_KnobPosition = MAX(m_KnobPosition, 0);
366-
m_KnobPosition = MIN(m_KnobPosition, Size-m_KnobSize);
362+
m_KnobPosition = std::clamp(m_KnobPosition, m_EndThickness, Size - m_KnobSize - m_EndThickness);
367363

368364
// Calculate the new value
369365
int Area = Size-m_KnobSize;
@@ -373,13 +369,7 @@ void GUISlider::OnMouseDown(int X, int Y, int Buttons, int Modifier)
373369
m_Value = (float)MaxRange * p + m_Minimum;
374370
}
375371

376-
// Clamp the value
377-
m_Value = MAX(m_Value, m_Minimum);
378-
m_Value = MIN(m_Value, m_Maximum);
379-
380-
// Clamp the knob position again for the graphics
381-
m_KnobPosition = MAX(m_KnobPosition, m_EndThickness);
382-
m_KnobPosition = MIN(m_KnobPosition, Size-m_KnobSize-m_EndThickness);
372+
m_Value = std::clamp(m_Value, m_Minimum, m_Maximum);
383373

384374
// If the value has changed, add the "Changed" notification
385375
if (m_Value != m_OldValue)
@@ -694,17 +684,12 @@ void GUISlider::SetValue(int Value)
694684
{
695685
int OldValue = m_Value;
696686

697-
m_Value = Value;
698-
699-
// Clamp it
700-
m_Value = MAX(m_Value, m_Minimum);
701-
m_Value = MIN(m_Value, m_Maximum);
687+
m_Value = std::clamp(Value, m_Minimum, m_Maximum);
702688

703-
if (m_Value != OldValue)
704-
AddEvent(GUIEvent::Notification, Changed, 0);
705-
706-
// Re-Calculate the knob info
707-
CalculateKnob();
689+
if (m_Value != OldValue) {
690+
CalculateKnob();
691+
AddEvent(GUIEvent::Notification, Changed, 0);
692+
}
708693
}
709694

710695

0 commit comments

Comments
 (0)