Class ScaleUtil

java.lang.Object
me.hackware.api.util.ScaleUtil

public final class ScaleUtil extends Object
Shared helpers for client UI scale values.

Client surfaces (HUD, HUD editor, ClickGUI) render on top of Minecraft's already gui-scaled coordinate space, so a scale of 1.0 matches the player's Minecraft GUI scale exactly and any other value multiplies that base (e.g. 2.0 = twice the Minecraft GUI scale, 0.5 = half).

When fractional scaling is enabled, raw slider values snap to fractions n/d. The available denominators scale with the Minecraft GUI scale: a GUI scale of 5 allows denominators 2..5, a GUI scale of 6 allows 2..6, and so on (denominator 1 = whole numbers, always available). Higher GUI scales therefore unlock finer steps, since each fractional step still lands on a whole physical pixel boundary.

  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(double v)
    Format a scale value for display, e.g.
    static String
    label(double v)
    Convenience: format(double) with a trailing "x".
    static int
    maxDenominator(double guiScale)
    Largest fraction denominator available for the given Minecraft GUI scale.
    static double
    parse(String s, double fallback)
    Parse a value that may be a decimal ("1.25") or a fraction ("2/3").
    static double
    snap(double raw, boolean fractional, double min, double max, int maxDenom)
    Snap a raw scale value to the nearest valid stop within [min, max].
    static double
    step(double value, int dir, boolean fractional, double min, double max, int maxDenom)
    Move one stop up (dir > 0) or down (dir < 0) from the current value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • maxDenominator

      public static int maxDenominator(double guiScale)
      Largest fraction denominator available for the given Minecraft GUI scale. GUI scale 5 → 5 (denominators 2..5), GUI scale 6 → 6, etc. Always ≥ 1.
    • snap

      public static double snap(double raw, boolean fractional, double min, double max, int maxDenom)
      Snap a raw scale value to the nearest valid stop within [min, max].
      Parameters:
      raw - raw (continuous) value, typically straight off a slider
      fractional - when true, snap to fractions; otherwise to whole numbers
      min - lower clamp bound
      max - upper clamp bound
      maxDenom - largest fraction denominator (see maxDenominator(double))
    • step

      public static double step(double value, int dir, boolean fractional, double min, double max, int maxDenom)
      Move one stop up (dir > 0) or down (dir < 0) from the current value. Used by scroll-to-adjust handlers so each notch advances to the next valid stop.
    • format

      public static String format(double v)
      Format a scale value for display, e.g. "1", "1/2", "3/2", "1.25".
    • label

      public static String label(double v)
      Convenience: format(double) with a trailing "x".
    • parse

      public static double parse(String s, double fallback)
      Parse a value that may be a decimal ("1.25") or a fraction ("2/3"). Returns fallback if the text can't be parsed.