Class GuiUtils

java.lang.Object
me.hackware.api.gui.GuiUtils

public final class GuiUtils extends Object
Static utility methods shared across the ClickGUI system.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Recursively adds all descendants of a SettingGroup to the given set.
    static float
    animateToward(float current, float target, float speed)
    Animate a float value toward a target at the given speed (per frame).
    static float
    animateTowardTimed(float current, float target, float deltaMs, float durationMs)
    Animate toward a target so the value effectively settles within the given duration.
    static int
    applyAlpha(int argb, float opacity)
    Apply an opacity multiplier to the alpha channel of an ARGB color.
    static void
    drawShadowLg(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit)
    Tailwind CSS shadow-lg, exactly: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1).
    static void
    drawShadowMd(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit)
    Tailwind CSS shadow-md, exactly: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1).
    static void
    drawShadowModal(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit, float intensity)
    The confirm-dialog lift: exactly drawShadowXl(net.minecraft.client.gui.GuiGraphics, int, int, int, int, float)'s shape, drawn a little darker so a modal still separates from the frosted, dimmed backdrop behind it (where a popover only has to separate from a flat card).
    static void
    drawShadowXl(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit)
     
    static void
    drawShadowXl(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit, float intensity)
    drawShadowXl(net.minecraft.client.gui.GuiGraphics, int, int, int, int, float) scaled by an intensity multiplier (0..1) on the penumbra alpha — so the shadow can fade in and out with a surface that is itself animating its opacity.
    static float
    easeInOutCubic(float t)
    Ease-in-out cubic for smooth expand/collapse animation.
    static void
    fillBottomRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radius, int color)
    Fill a rectangle whose top edge stays square but whose bottom two corners are rounded, drawn at physical-pixel resolution for smooth arcs.
    static void
    fillBottomRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radius, int color, int trimPx)
    fillBottomRoundedRect(net.minecraft.client.gui.GuiGraphics, double, int, int, int, int, int, int) with trimPx unscaled (physical) pixels shaved off the bottom edge.
    static void
    fillBottomRoundedRectPx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, boolean roundBL, boolean roundBR, int color)
    Fills a rectangle rounding only the chosen bottom corners, at physical-pixel resolution.
    static void
    fillCircleGui(net.minecraft.client.gui.GuiGraphics graphics, int cx, int cy, int r, int color)
    Fills a circle with one span per LOGICAL row — cheap enough for large radii (a radius-150 disc is ~300 quads, not thousands).
    static void
    fillCircleInRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int rx1, int ry1, int rx2, int ry2, int cornerPx, double cx, double cy, double radius, int color)
    Fills a circle clipped to a rounded rectangle (the ripple surface): per physical scanline, the circle's span is intersected with the rounded rect's span, so the ripple hugs the surface's rounded corners instead of painting past them.
    static void
    fillCircleInRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int rx1, int ry1, int rx2, int ry2, int topCornerPx, int botCornerPx, double cx, double cy, double radius, int color)
    Variant with independent top / bottom corner radii (e.g.
    static void
    fillCircleInRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int rx1, int ry1, int rx2, int ry2, int tlPx, int trPx, int blPx, int brPx, double cx, double cy, double radius, int color)
    Variant with independent per-corner radii (top-left, top-right, bottom-left, bottom-right).
    static void
    fillCirclePhysical(net.minecraft.client.gui.GuiGraphics graphics, double res, float cx, float cy, float r, int color)
    Small anti-aliased-ish circle rasterized at physical-pixel rows — a port of HudPropertiesWindow's fillCircleSmooth (slider thumbs, halos).
    static void
    fillPillPhysical(net.minecraft.client.gui.GuiGraphics graphics, double res, float x1, float y1, float x2, float y2, int color, boolean roundRight)
    Pill (fully-rounded height/2 caps) rasterized at physical pixels — a port of SliderPropComponent's fillPillSmooth, for surfaces that draw a material track without a properties window to hang off.
    static void
    fillRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radius, int color)
    Fill a rectangle with all four corners rounded, drawn at physical-pixel resolution for smooth arcs.
    static void
    fillRoundedRectPx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, int color)
    Like fillRoundedRect(net.minecraft.client.gui.GuiGraphics, double, int, int, int, int, int, int) but the corner radiusPx is in physical pixels (unscaled) rather than GUI pixels — so a given radius looks the same regardless of the window GUI scale.
    static int
    findWordBoundary(String text, int pos, int direction)
    Find the next word boundary in the given direction (-1 = left, +1 = right).
    static String
    formatNumber(double value)
     
    static String
    formatNumber(double value, double step)
    Formats a number with enough decimal places to represent the given step size.
    static int
    hslToRgb(float h, float s, float l)
    Converts HSL to packed 0xRRGGBB.
    static int
    hsvToRgb(float h, float s, float v)
    Convert HSV (h=0-360, s=0-1, v=0-1) to packed 0xRRGGBB.
    static int
    lerpColor(int a, int b, float t)
    Linearly interpolate between two ARGB colors by factor t (0 = a, 1 = b).
    static int
    pxRound(double v)
    First physical pixel a fill edge at v rasterizes into — equivalently the exclusive end of coverage for a fill ending at v (pixel centers at .5).
    static void
    renderEntityIsometric(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, net.minecraft.world.entity.Entity entity)
    True isometric GUI preview of any entity: Z-flip for gui space, slight downward pitch and a 45° yaw — the classic three-quarter view block items use.
    static float[]
    rgbToHsl(int r, int g, int b)
    Convert RGB (0-255 each) to HSL [h=0-360, s=0-1, l=0-1].
    static float[]
    rgbToHsv(int r, int g, int b)
    Convert RGB (0-255 each) to HSV [h=0-360, s=0-1, v=0-1].
    static void
    ringCircleGui(net.minecraft.client.gui.GuiGraphics graphics, int cx, int cy, int r, int thickness, int color)
    Draws a circle ring of the given logical thickness, two spans per row — the large-radius companion to fillCircleGui(net.minecraft.client.gui.GuiGraphics, int, int, int, int).
    static void
    roundedRectBorderPx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, int fill, int border)
    Fills a rounded rect with a fill colour and a hairline border of exactly one physical pixel (unscaled), with the corner radiusPx also in physical pixels.
    static void
    roundedRectOutlinePx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, int color)
    Draws a 1-physical-pixel anti-aliased rounded outline (ring only, no fill) — for outlined buttons / transparent-bodied controls.
    static void
    roundedRectOutlinePx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, int thicknessPx, int color)
    Outline with a configurable thickness in physical pixels (single solid ring).
    static int
    spotlightDim(float factor)
    Spotlight dim color: the active theme's spotlight background color (+ base alpha) scaled by factor (0..1).

    Methods inherited from class java.lang.Object

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

    • renderEntityIsometric

      public static void renderEntityIsometric(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, net.minecraft.world.entity.Entity entity)
      True isometric GUI preview of any entity: Z-flip for gui space, slight downward pitch and a 45° yaw — the classic three-quarter view block items use. Living entities get their body squared to the camera (no mouse-follow) so every preview renders from the same fixed angle. The scale is normalized per entity so the whole projected model fits the box.

      Coordinates are absolute gui-space ints (pose-independent — transform first).

    • pxRound

      public static int pxRound(double v)
      First physical pixel a fill edge at v rasterizes into — equivalently the exclusive end of coverage for a fill ending at v (pixel centers at .5). Use this instead of Math.round when anchoring physical-pixel chrome (borders, dividers, shadows) to scaled fills, so they can never detach.
    • drawShadowMd

      public static void drawShadowMd(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit)
      Tailwind CSS shadow-md, exactly: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1).

      Coordinates are physical pixels (call inside a pose scaled to 1/guiScale); unit is how many physical pixels one CSS px maps to (panel/editor scale × gui scale), so the shadow scales with the surface it belongs to. Each layer is drawn as concentric 1-physical-px rings with linear falloff across the blur span; ring strips never overlap, so corners can't double-darken where the fades meet. Draw before the surface background — the interior ring segments are covered by the surface fill.

    • drawShadowLg

      public static void drawShadowLg(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit)
      Tailwind CSS shadow-lg, exactly: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1).

      Same conventions as drawShadowMd(net.minecraft.client.gui.GuiGraphics, int, int, int, int, float); a larger, softer penumbra for surfaces that float clearly above the page (menus, autocomplete popups). Alpha bumped from the spec's 10% for legibility over busy backgrounds.

    • drawShadowXl

      public static void drawShadowXl(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit)
    • drawShadowXl

      public static void drawShadowXl(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit, float intensity)
      drawShadowXl(net.minecraft.client.gui.GuiGraphics, int, int, int, int, float) scaled by an intensity multiplier (0..1) on the penumbra alpha — so the shadow can fade in and out with a surface that is itself animating its opacity.
    • drawShadowModal

      public static void drawShadowModal(net.minecraft.client.gui.GuiGraphics graphics, int x1, int y1, int x2, int y2, float unit, float intensity)
      The confirm-dialog lift: exactly drawShadowXl(net.minecraft.client.gui.GuiGraphics, int, int, int, int, float)'s shape, drawn a little darker so a modal still separates from the frosted, dimmed backdrop behind it (where a popover only has to separate from a flat card).
    • animateToward

      public static float animateToward(float current, float target, float speed)
      Animate a float value toward a target at the given speed (per frame). Negative speed = snap.
    • animateTowardTimed

      public static float animateTowardTimed(float current, float target, float deltaMs, float durationMs)
      Animate toward a target so the value effectively settles within the given duration. Negative/zero duration or delta snaps immediately.
    • spotlightDim

      public static int spotlightDim(float factor)
      Spotlight dim color: the active theme's spotlight background color (+ base alpha) scaled by factor (0..1). Falls back to the shared GuiConstants.DIM_OVERLAY_BASE before the theme instance exists.
    • easeInOutCubic

      public static float easeInOutCubic(float t)
      Ease-in-out cubic for smooth expand/collapse animation.
    • lerpColor

      public static int lerpColor(int a, int b, float t)
      Linearly interpolate between two ARGB colors by factor t (0 = a, 1 = b).
    • fillBottomRoundedRect

      public static void fillBottomRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radius, int color)
      Fill a rectangle whose top edge stays square but whose bottom two corners are rounded, drawn at physical-pixel resolution for smooth arcs.

      Coordinates are in GUI space; res is the window GUI scale so the arcs quantise to real pixels. Must be called outside any additional pose.scale() transform (raw GUI space).

    • fillBottomRoundedRect

      public static void fillBottomRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radius, int color, int trimPx)
      fillBottomRoundedRect(net.minecraft.client.gui.GuiGraphics, double, int, int, int, int, int, int) with trimPx unscaled (physical) pixels shaved off the bottom edge. The trim is applied after scaling, so it stays a true hairline at any GUI scale (subtracting it from the GUI-space y2 instead would shave res physical pixels).
    • fillRoundedRect

      public static void fillRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radius, int color)
      Fill a rectangle with all four corners rounded, drawn at physical-pixel resolution for smooth arcs.

      Coordinates are in GUI space; res is the window GUI scale so the arcs quantise to real pixels. Must be called outside any additional pose.scale() transform (raw GUI space).

    • fillRoundedRectPx

      public static void fillRoundedRectPx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, int color)
      Like fillRoundedRect(net.minecraft.client.gui.GuiGraphics, double, int, int, int, int, int, int) but the corner radiusPx is in physical pixels (unscaled) rather than GUI pixels — so a given radius looks the same regardless of the window GUI scale. Coordinates stay in GUI space. Pass a very large radius for a full pill (clamped to half the shorter side).
    • roundedRectBorderPx

      public static void roundedRectBorderPx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, int fill, int border)
      Fills a rounded rect with a fill colour and a hairline border of exactly one physical pixel (unscaled), with the corner radiusPx also in physical pixels. Coordinates are GUI space.
    • roundedRectOutlinePx

      public static void roundedRectOutlinePx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, int color)
      Draws a 1-physical-pixel anti-aliased rounded outline (ring only, no fill) — for outlined buttons / transparent-bodied controls. Radius in physical pixels; coordinates in GUI space.
    • roundedRectOutlinePx

      public static void roundedRectOutlinePx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, int thicknessPx, int color)
      Outline with a configurable thickness in physical pixels (single solid ring).
    • fillCircleInRoundedRect

      public static void fillCircleInRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int rx1, int ry1, int rx2, int ry2, int cornerPx, double cx, double cy, double radius, int color)
      Fills a circle clipped to a rounded rectangle (the ripple surface): per physical scanline, the circle's span is intersected with the rounded rect's span, so the ripple hugs the surface's rounded corners instead of painting past them. All coordinates in GUI space; cornerPx in physical pixels.
    • fillCircleInRoundedRect

      public static void fillCircleInRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int rx1, int ry1, int rx2, int ry2, int topCornerPx, int botCornerPx, double cx, double cy, double radius, int color)
      Variant with independent top / bottom corner radii (e.g. bottom-only rounding).
    • fillCircleInRoundedRect

      public static void fillCircleInRoundedRect(net.minecraft.client.gui.GuiGraphics graphics, double res, int rx1, int ry1, int rx2, int ry2, int tlPx, int trPx, int blPx, int brPx, double cx, double cy, double radius, int color)
      Variant with independent per-corner radii (top-left, top-right, bottom-left, bottom-right).
    • fillBottomRoundedRectPx

      public static void fillBottomRoundedRectPx(net.minecraft.client.gui.GuiGraphics graphics, double res, int x1, int y1, int x2, int y2, int radiusPx, boolean roundBL, boolean roundBR, int color)
      Fills a rectangle rounding only the chosen bottom corners, at physical-pixel resolution. Coordinates are logical; res is physical px per logical unit. Safe to call inside an outer pose.scale() (self-consistent, like the other *Px helpers).
    • fillCircleGui

      public static void fillCircleGui(net.minecraft.client.gui.GuiGraphics graphics, int cx, int cy, int r, int color)
      Fills a circle with one span per LOGICAL row — cheap enough for large radii (a radius-150 disc is ~300 quads, not thousands). No AA; use the physical-pixel helpers only for small shapes.
    • fillCirclePhysical

      public static void fillCirclePhysical(net.minecraft.client.gui.GuiGraphics graphics, double res, float cx, float cy, float r, int color)
      Small anti-aliased-ish circle rasterized at physical-pixel rows — a port of HudPropertiesWindow's fillCircleSmooth (slider thumbs, halos). Coordinates and radius in logical units; cheap only for SMALL radii.
    • fillPillPhysical

      public static void fillPillPhysical(net.minecraft.client.gui.GuiGraphics graphics, double res, float x1, float y1, float x2, float y2, int color, boolean roundRight)
      Pill (fully-rounded height/2 caps) rasterized at physical pixels — a port of SliderPropComponent's fillPillSmooth, for surfaces that draw a material track without a properties window to hang off.

      roundRight=false squares the right end — used by slider progress so it terminates cleanly where the thumb sits instead of leaving a rounded nub mid-track. The cap radius is fixed by the height, never the width, so the shape doesn't morph as the fill narrows. Coordinates in logical units.

    • ringCircleGui

      public static void ringCircleGui(net.minecraft.client.gui.GuiGraphics graphics, int cx, int cy, int r, int thickness, int color)
      Draws a circle ring of the given logical thickness, two spans per row — the large-radius companion to fillCircleGui(net.minecraft.client.gui.GuiGraphics, int, int, int, int).
    • applyAlpha

      public static int applyAlpha(int argb, float opacity)
      Apply an opacity multiplier to the alpha channel of an ARGB color.
    • formatNumber

      public static String formatNumber(double value)
    • formatNumber

      public static String formatNumber(double value, double step)
      Formats a number with enough decimal places to represent the given step size.
    • findWordBoundary

      public static int findWordBoundary(String text, int pos, int direction)
      Find the next word boundary in the given direction (-1 = left, +1 = right).
    • hsvToRgb

      public static int hsvToRgb(float h, float s, float v)
      Convert HSV (h=0-360, s=0-1, v=0-1) to packed 0xRRGGBB.
    • rgbToHsv

      public static float[] rgbToHsv(int r, int g, int b)
      Convert RGB (0-255 each) to HSV [h=0-360, s=0-1, v=0-1].
    • rgbToHsl

      public static float[] rgbToHsl(int r, int g, int b)
      Convert RGB (0-255 each) to HSL [h=0-360, s=0-1, l=0-1].
    • hslToRgb

      public static int hslToRgb(float h, float s, float l)
      Converts HSL to packed 0xRRGGBB. h=0-360, s/l=0-1.
    • addAllDescendants

      public static void addAllDescendants(SettingGroup group, Set<Setting<?>> set)
      Recursively adds all descendants of a SettingGroup to the given set.