package org.saturnclient.ui.components; import org.saturnclient.config.Theme; import org.saturnclient.mod.HudMod; import org.saturnclient.mod.ModLayout; import org.saturnclient.ui.Element; import org.saturnclient.ui.ElementContext; import org.saturnclient.ui.RenderScope; /** * A card showing a HUD mod as it looks in game, following its settings live. * The mod is drawn at its in-game scale, shrunk if needed to fit the card. */ public class HudPreviewCard extends Element { private static final int PADDING = 16; private static final int TITLE_HEIGHT = 24; private static final float TITLE_SCALE = 0.6f; private final HudMod mod; private final HudModPreview preview; public HudPreviewCard(HudMod mod) { this.mod = mod; this.preview = new HudModPreview(mod); } @Override public void render(RenderScope renderScope, ElementContext ctx) { renderScope.drawRoundedRectangle(0, 0, width, height, Theme.WIDGET_RADIUS.value + 4, 1, Theme.withAlpha(0.72f, Theme.PRIMARY.value), Theme.withAlpha(0.06f, Theme.FOREGROUND.value)); renderScope.drawText(TITLE_SCALE, "PREVIEW", PADDING, PADDING, Theme.FONT.value, Theme.getMutedFg()); ModLayout layout = mod.getDimensions(); if (layout.width <= 0 || layout.height <= 0) { return; } // HUD mods are laid out in GUI pixels, which are two Saturn units. int areaWidth = width - PADDING * 2; int areaHeight = height - PADDING * 2 - TITLE_HEIGHT; float scale = Math.min(layout.scale.value * 2, Math.min((float) areaWidth / layout.width, (float) areaHeight / layout.height)); float x = PADDING + (areaWidth - layout.width * scale) / 2; float y = PADDING + TITLE_HEIGHT + (areaHeight - layout.height * scale) / 2; renderScope.getMatrixStack().push(); renderScope.getMatrixStack().translate(x, y); renderScope.getMatrixStack().scale(scale, scale); preview.render(renderScope, ctx); renderScope.getMatrixStack().pop(); } }