Class ForgeSlider

All Implemented Interfaces:
GuiEventListener, Renderable, TabOrderedElement, LayoutElement, NarratableEntry, NarrationSupplier

public class ForgeSlider extends AbstractSliderButton
Slider widget implementation which allows inputting values in a certain range with optional step size.
  • Field Details

    • prefix

      protected Component prefix
    • suffix

      protected Component suffix
    • minValue

      protected double minValue
    • maxValue

      protected double maxValue
    • stepSize

      protected double stepSize
      Allows input of discontinuous values with a certain step
    • drawString

      protected boolean drawString
    • format

      private final DecimalFormat format
  • Constructor Details

    • ForgeSlider

      public ForgeSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString)
      Parameters:
      x - x position of upper left corner
      y - y position of upper left corner
      width - Width of the widget
      height - Height of the widget
      prefix - Component displayed before the value string
      suffix - Component displayed after the value string
      minValue - Minimum (left) value of slider
      maxValue - Maximum (right) value of slider
      currentValue - Starting value when widget is first displayed
      stepSize - Size of step used. Precision will automatically be calculated based on this value if this value is not 0.
      precision - Only used when stepSize is 0. Limited to a maximum of 4 (inclusive).
      drawString - Should text be displayed on the widget
    • ForgeSlider

      public ForgeSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, boolean drawString)
      Overload with stepSize set to 1, useful for sliders with whole number values.
  • Method Details

    • getValue

      public double getValue()
      Returns:
      Current slider value as a double
    • getValueLong

      public long getValueLong()
      Returns:
      Current slider value as an long
    • getValueInt

      public int getValueInt()
      Returns:
      Current slider value as an int
    • setValue

      public void setValue(double value)
      Parameters:
      value - The new slider value
    • getValueString

      public String getValueString()
    • onClick

      public void onClick(double mouseX, double mouseY)
      Overrides:
      onClick in class AbstractSliderButton
    • onDrag

      protected void onDrag(double mouseX, double mouseY, double dragX, double dragY)
      Overrides:
      onDrag in class AbstractSliderButton
    • keyPressed

      public boolean keyPressed(int keyCode, int scanCode, int modifiers)
      Specified by:
      keyPressed in interface GuiEventListener
      Overrides:
      keyPressed in class AbstractSliderButton
    • setValueFromMouse

      private void setValueFromMouse(double mouseX)
    • setSliderValue

      private void setSliderValue(double value)
      Parameters:
      value - Percentage of slider range
    • snapToNearest

      private double snapToNearest(double value)
      Snaps the value, so that the displayed value is the nearest multiple of stepSize. If stepSize is 0, no snapping occurs.
    • updateMessage

      protected void updateMessage()
      Specified by:
      updateMessage in class AbstractSliderButton
    • applyValue

      protected void applyValue()
      Specified by:
      applyValue in class AbstractSliderButton
    • renderWidget

      public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
      Overrides:
      renderWidget in class AbstractSliderButton