float height = getHeight() - bg.getTopHeight() - bg.getBottomHeight();\r
float knobHeight = knob == null ? 0 : knob.getMinHeight();\r
sliderPos = y - bg.getBottomHeight() - knobHeight * 0.5f;\r
+ value = min + (max - min) * (sliderPos / (height - knobHeight));\r
sliderPos = Math.max(0, sliderPos);\r
sliderPos = Math.min(height - knobHeight, sliderPos);\r
- value = min + (max - min) * (sliderPos / (height - knobHeight));\r
} else {\r
float width = getWidth() - bg.getLeftWidth() - bg.getRightWidth();\r
float knobWidth = knob == null ? 0 : knob.getMinWidth();\r
sliderPos = x - bg.getLeftWidth() - knobWidth * 0.5f;\r
+ value = min + (max - min) * (sliderPos / (width - knobWidth));\r
sliderPos = Math.max(0, sliderPos);\r
sliderPos = Math.min(width - knobWidth, sliderPos);\r
- value = min + (max - min) * (sliderPos / (width - knobWidth));\r
}\r
\r
float oldValue = value;\r
}\r
\r
/** Sets the slider position, rounded to the nearest step size and clamped to the minumum and maximim values.\r
+ * {@link #clamp(float)} can be overidden to allow values outside of the sliders min/max range.\r
* @return false if the value was not changed because the slider already had the value or it was canceled by a listener. */\r
public boolean setValue (float value) {\r
- value = snap(MathUtils.clamp(Math.round(value / stepSize) * stepSize, min, max));\r
+ value = snap(clamp(Math.round(value / stepSize) * stepSize));\r
float oldValue = this.value;\r
if (value == oldValue) return false;\r
float oldVisualValue = getVisualValue();\r
return !cancelled;\r
}\r
\r
+ /** Clamps the value to the sliders min/max range. This can be overidden to allow a range different from the slider knob's\r
+ * range. */\r
+ protected float clamp (float value) {\r
+ return MathUtils.clamp(value, min, max);\r
+ }\r
+\r
/** Sets the range of this slider. The slider's current value is reset to min. */\r
public void setRange (float min, float max) {\r
if (min > max) throw new IllegalArgumentException("min must be <= max");\r