diff --git a/src/main/java/mcp/mobius/waila/gui/widgets/LabelFixedFont.java b/src/main/java/mcp/mobius/waila/gui/widgets/LabelFixedFont.java index 96ba4b0a..c56cdc2f 100644 --- a/src/main/java/mcp/mobius/waila/gui/widgets/LabelFixedFont.java +++ b/src/main/java/mcp/mobius/waila/gui/widgets/LabelFixedFont.java @@ -10,17 +10,20 @@ public class LabelFixedFont extends WidgetBase { protected String text = ""; protected int color; + protected boolean shadow; public LabelFixedFont(IWidget parent, String text) { super(parent); this.setText(text); this.color = 0xFFFFFF; + this.shadow = false; } public LabelFixedFont(IWidget parent, String text, int color) { super(parent); this.setText(text); this.color = color; + this.shadow = false; } @Override @@ -39,6 +42,10 @@ public void setColor(int color) { this.color = color; } + public void setShadow(boolean shadow) { + this.shadow = shadow; + } + private void updateGeometry() { if (this.geom == null) this.geom = new WidgetGeometry(0, 0, 50, 50, CType.ABSXY, CType.ABSXY); @@ -56,7 +63,8 @@ private void updateGeometry() { @Override public void draw(Point pos) { this.saveGLState(); - this.mc.fontRenderer.drawString(this.text, pos.getX(), pos.getY(), this.color); + if (this.shadow) this.mc.fontRenderer.drawStringWithShadow(this.text, pos.getX(), pos.getY(), this.color); + else this.mc.fontRenderer.drawString(this.text, pos.getX(), pos.getY(), this.color); this.loadGLState(); } } diff --git a/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBase.java b/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBase.java index 782f2aef..967f9931 100644 --- a/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBase.java +++ b/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBase.java @@ -15,8 +15,17 @@ public abstract class ButtonBase extends WidgetBase { + protected static final int BUTTON_TEX_U = 0; + protected static final int BUTTON_TEX_V_BASE = 66; + protected static final int BUTTON_TEX_V_STEP = 20; + protected static final int BUTTON_TEX_W = 200; + protected static final int BUTTON_TEX_H = 20; + protected static final int BUTTON_BORDER = 2; + protected static final int COLOR_TEXT = 0xffffff; + protected static final int COLOR_TEXT_HOVER = 0xffffa0; + protected boolean mouseOver = false; - protected static ResourceLocation widgetsTexture = new ResourceLocation("textures/gui/widgets.png"); + protected static final ResourceLocation widgetsTexture = new ResourceLocation("textures/gui/widgets.png"); public ButtonBase(IWidget parent) { super(parent); @@ -25,10 +34,14 @@ public ButtonBase(IWidget parent) { @Override public void draw() { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + int textColor = this.mouseOver ? COLOR_TEXT_HOVER : COLOR_TEXT; - for (IWidget widget : this.widgets.values()) - if (widget instanceof LabelFixedFont) if (this.mouseOver) ((LabelFixedFont) widget).setColor(0xffffa0); - else((LabelFixedFont) widget).setColor(0xffffff); + for (IWidget widget : this.widgets.values()) { + if (!(widget instanceof LabelFixedFont)) continue; + LabelFixedFont label = (LabelFixedFont) widget; + label.setShadow(true); + label.setColor(textColor); + } super.draw(); } @@ -40,20 +53,108 @@ public void draw(Point pos) { if (this.mouseOver) texOffset = 1; - this.mc.getTextureManager().bindTexture(widgetsTexture); - UIHelper.drawTexture( - this.getPos().getX(), - this.getPos().getY(), - this.getSize().getX(), - this.getSize().getY(), - 0, - 66 + texOffset * 20, - 200, - 20); + this.drawVanillaButton(texOffset); this.loadGLState(); } + protected void drawVanillaButton(int texOffset) { + int x = this.getPos().getX(); + int y = this.getPos().getY(); + int width = this.getSize().getX(); + int height = this.getSize().getY(); + int v = BUTTON_TEX_V_BASE + texOffset * BUTTON_TEX_V_STEP; + + this.mc.getTextureManager().bindTexture(widgetsTexture); + if (width <= 0 || height <= 0) return; + + int borderX = Math.min(BUTTON_BORDER, width / 2); + int borderY = Math.min(BUTTON_BORDER, height / 2); + int midW = width - borderX * 2; + int midH = height - borderY * 2; + int srcMidW = BUTTON_TEX_W - BUTTON_BORDER * 2; + int srcMidH = BUTTON_TEX_H - BUTTON_BORDER * 2; + + // Corners + UIHelper.drawTexture(x, y, borderX, borderY, BUTTON_TEX_U, v, BUTTON_BORDER, BUTTON_BORDER); + UIHelper.drawTexture( + x + width - borderX, + y, + borderX, + borderY, + BUTTON_TEX_W - BUTTON_BORDER, + v, + BUTTON_BORDER, + BUTTON_BORDER); + UIHelper.drawTexture( + x, + y + height - borderY, + borderX, + borderY, + BUTTON_TEX_U, + v + BUTTON_TEX_H - BUTTON_BORDER, + BUTTON_BORDER, + BUTTON_BORDER); + UIHelper.drawTexture( + x + width - borderX, + y + height - borderY, + borderX, + borderY, + BUTTON_TEX_W - BUTTON_BORDER, + v + BUTTON_TEX_H - BUTTON_BORDER, + BUTTON_BORDER, + BUTTON_BORDER); + + if (midW > 0) { + // Top + bottom edges + UIHelper.drawTexture(x + borderX, y, midW, borderY, BUTTON_BORDER, v, srcMidW, BUTTON_BORDER); + UIHelper.drawTexture( + x + borderX, + y + height - borderY, + midW, + borderY, + BUTTON_BORDER, + v + BUTTON_TEX_H - BUTTON_BORDER, + srcMidW, + BUTTON_BORDER); + } + + if (midH > 0) { + // Left + right edges + UIHelper.drawTexture( + x, + y + borderY, + borderX, + midH, + BUTTON_TEX_U, + v + BUTTON_BORDER, + BUTTON_BORDER, + srcMidH); + UIHelper.drawTexture( + x + width - borderX, + y + borderY, + borderX, + midH, + BUTTON_TEX_W - BUTTON_BORDER, + v + BUTTON_BORDER, + BUTTON_BORDER, + srcMidH); + } + + if (midW > 0 && midH > 0) { + // Center + UIHelper.drawTexture( + x + borderX, + y + borderY, + midW, + midH, + BUTTON_BORDER, + v + BUTTON_BORDER, + srcMidW, + srcMidH); + } + } + @Override public void onMouseEnter(MouseEvent event) { mouseOver = true; diff --git a/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfig.java b/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfig.java index 438a4de8..3831b81b 100644 --- a/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfig.java +++ b/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfig.java @@ -4,7 +4,6 @@ import mcp.mobius.waila.api.impl.ConfigHandler; import mcp.mobius.waila.gui.events.MouseEvent; -import mcp.mobius.waila.gui.helpers.UIHelper; import mcp.mobius.waila.gui.interfaces.IWidget; public class ButtonBooleanConfig extends ButtonBoolean { @@ -47,17 +46,7 @@ public void draw(Point pos) { if (!ConfigHandler.instance().forcedConfigs.containsKey(this.configKey)) super.draw(pos); else { this.saveGLState(); - int texOffset = -1; - this.mc.getTextureManager().bindTexture(widgetsTexture); - UIHelper.drawTexture( - this.getPos().getX(), - this.getPos().getY(), - this.getSize().getX(), - this.getSize().getY(), - 0, - 66 + texOffset * 20, - 200, - 20); + this.drawVanillaButton(-1); this.loadGLState(); } } diff --git a/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfigRemote.java b/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfigRemote.java index c896886d..b02758e2 100644 --- a/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfigRemote.java +++ b/src/main/java/mcp/mobius/waila/gui/widgets/buttons/ButtonBooleanConfigRemote.java @@ -5,7 +5,6 @@ import mcp.mobius.waila.Waila; import mcp.mobius.waila.api.impl.ConfigHandler; import mcp.mobius.waila.gui.events.MouseEvent; -import mcp.mobius.waila.gui.helpers.UIHelper; import mcp.mobius.waila.gui.interfaces.IWidget; public class ButtonBooleanConfigRemote extends ButtonBooleanConfig { @@ -41,17 +40,7 @@ public void draw(Point pos) { super.draw(pos); else { this.saveGLState(); - int texOffset = -1; - this.mc.getTextureManager().bindTexture(widgetsTexture); - UIHelper.drawTexture( - this.getPos().getX(), - this.getPos().getY(), - this.getSize().getX(), - this.getSize().getY(), - 0, - 66 + texOffset * 20, - 200, - 20); + this.drawVanillaButton(-1); this.loadGLState(); } }