@@ -123,9 +123,7 @@ void GUISlider::Create(GUIProperties *Props)
123
123
m_ValueResolution = std::max ((m_Maximum - m_Minimum) / 100 , 1 );
124
124
}
125
125
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);
129
127
130
128
// Re-Calculate the knob info
131
129
CalculateKnob ();
@@ -361,9 +359,7 @@ void GUISlider::OnMouseDown(int X, int Y, int Buttons, int Modifier)
361
359
Size = m_Height;
362
360
}
363
361
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);
367
363
368
364
// Calculate the new value
369
365
int Area = Size-m_KnobSize;
@@ -373,13 +369,7 @@ void GUISlider::OnMouseDown(int X, int Y, int Buttons, int Modifier)
373
369
m_Value = (float )MaxRange * p + m_Minimum;
374
370
}
375
371
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);
383
373
384
374
// If the value has changed, add the "Changed" notification
385
375
if (m_Value != m_OldValue)
@@ -694,17 +684,12 @@ void GUISlider::SetValue(int Value)
694
684
{
695
685
int OldValue = m_Value;
696
686
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);
702
688
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
+ }
708
693
}
709
694
710
695
0 commit comments