Skip to content

Commit f9531d2

Browse files
committed
Add shadow argument to ITextColoring
1 parent 8084cfd commit f9531d2

File tree

6 files changed

+51
-13
lines changed

6 files changed

+51
-13
lines changed

src/main/java/mchorse/mclib/client/gui/framework/elements/buttons/GuiButtonElement.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
import mchorse.mclib.McLib;
44
import mchorse.mclib.client.gui.framework.elements.utils.GuiContext;
55
import mchorse.mclib.client.gui.framework.elements.utils.GuiDraw;
6+
import mchorse.mclib.client.gui.framework.elements.utils.ITextColoring;
67
import mchorse.mclib.client.gui.utils.keys.IKey;
78
import mchorse.mclib.utils.ColorUtils;
89
import net.minecraft.client.Minecraft;
910

1011
import java.util.function.Consumer;
1112

12-
public class GuiButtonElement extends GuiClickElement<GuiButtonElement>
13+
public class GuiButtonElement extends GuiClickElement<GuiButtonElement> implements ITextColoring
1314
{
1415
public IKey label;
1516

17+
public int textColor = 0xffffff;
18+
public boolean textShadow = true;
19+
1620
public boolean custom;
1721
public int customColor;
1822

@@ -32,6 +36,21 @@ public GuiButtonElement color(int color)
3236
return this;
3337
}
3438

39+
public GuiButtonElement textColor(int color, boolean shadow)
40+
{
41+
this.textColor = color;
42+
this.textShadow = shadow;
43+
44+
return this;
45+
}
46+
47+
@Override
48+
public void setColor(int color, boolean shadow)
49+
{
50+
this.textColor = color;
51+
this.textShadow = shadow;
52+
}
53+
3554
@Override
3655
protected GuiButtonElement get()
3756
{
@@ -54,7 +73,7 @@ protected void drawSkin(GuiContext context)
5473
int x = this.area.mx(this.font.getStringWidth(label));
5574
int y = this.area.my(this.font.FONT_HEIGHT - 1);
5675

57-
this.font.drawStringWithShadow(label, x, y, this.hover ? 16777120 : 0xffffff);
76+
this.font.drawString(label, x, y, ColorUtils.multiplyColor(this.textColor, this.hover ? 0.9F : 1F), this.textShadow);
5877

5978
GuiDraw.drawLockedArea(this);
6079
}

src/main/java/mchorse/mclib/client/gui/framework/elements/buttons/GuiToggleElement.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class GuiToggleElement extends GuiClickElement<GuiToggleElement> implemen
1717
{
1818
public IKey label;
1919
public int color = 0xffffff;
20+
public boolean textShadow = true;
2021
private boolean state;
2122

2223
public GuiToggleElement(Minecraft mc, ValueBoolean value)
@@ -49,9 +50,9 @@ public GuiToggleElement(Minecraft mc, IKey label, boolean state, Consumer<GuiTog
4950
}
5051

5152
@Override
52-
public void setColor(int color)
53+
public void setColor(int color, boolean shadow)
5354
{
54-
this.color(color);
55+
this.color(color, shadow);
5556
}
5657

5758
public GuiToggleElement label(IKey label)
@@ -69,8 +70,14 @@ public GuiToggleElement toggled(boolean state)
6970
}
7071

7172
public GuiToggleElement color(int color)
73+
{
74+
return this.color(color, true);
75+
}
76+
77+
public GuiToggleElement color(int color, boolean textShadow)
7278
{
7379
this.color = color;
80+
this.textShadow = textShadow;
7481

7582
return this;
7683
}
@@ -110,10 +117,10 @@ protected void drawSkin(GuiContext context)
110117

111118
if (this.state)
112119
{
113-
this.font.drawStringWithShadow("x", this.area.x + 3, y - 2, 0xffffff);
120+
this.font.drawString("x", this.area.x + 3, y - 2, 0xffffff, this.textShadow);
114121
}
115122

116-
this.font.drawStringWithShadow(this.label.get(), this.area.x + 14, y, this.color);
123+
this.font.drawString(this.label.get(), this.area.x + 14, y, this.color, this.textShadow);
117124

118125
if (!this.isEnabled())
119126
{
@@ -123,7 +130,7 @@ protected void drawSkin(GuiContext context)
123130
}
124131
else
125132
{
126-
this.font.drawStringWithShadow(this.label.get(), this.area.x, this.area.my(this.font.FONT_HEIGHT - 1), this.color);
133+
this.font.drawString(this.label.get(), this.area.x, this.area.my(this.font.FONT_HEIGHT - 1), this.color, this.textShadow);
127134

128135
/* Draw toggle switch */
129136
int w = 16;

src/main/java/mchorse/mclib/client/gui/framework/elements/utils/GuiDraw.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ public static void drawTextBackground(FontRenderer font, String text, int x, int
520520
}
521521

522522
public static void drawTextBackground(FontRenderer font, String text, int x, int y, int color, int background, int offset)
523+
{
524+
drawTextBackground(font, text, x, y, color, background, offset, true);
525+
}
526+
527+
public static void drawTextBackground(FontRenderer font, String text, int x, int y, int color, int background, int offset, boolean shadow)
523528
{
524529
int a = background >> 24 & 0xff;
525530

@@ -528,7 +533,7 @@ public static void drawTextBackground(FontRenderer font, String text, int x, int
528533
Gui.drawRect(x - offset, y - offset, x + font.getStringWidth(text) + offset, y + font.FONT_HEIGHT + offset, background);
529534
}
530535

531-
font.drawStringWithShadow(text, x, y, color);
536+
font.drawString(text, x, y, color, shadow);
532537
}
533538

534539
public static void drawCustomBackground(int x, int y, int width, int height)

src/main/java/mchorse/mclib/client/gui/framework/elements/utils/GuiLabel.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class GuiLabel extends GuiElement implements ITextColoring
1111
{
1212
public IKey label;
1313
public int color;
14+
public boolean textShadow = true;
1415
public float anchorX;
1516
public float anchorY;
1617
public int background;
@@ -30,13 +31,19 @@ public GuiLabel(Minecraft mc, IKey label, int color)
3031
}
3132

3233
@Override
33-
public void setColor(int color)
34+
public void setColor(int color, boolean shadow)
3435
{
35-
this.color(color);
36+
this.color(color, shadow);
3637
}
3738

3839
public GuiLabel color(int color)
3940
{
41+
return this.color(color, true);
42+
}
43+
44+
public GuiLabel color(int color, boolean textShadow)
45+
{
46+
this.textShadow = textShadow;
4047
this.color = color;
4148

4249
return this;
@@ -81,7 +88,7 @@ public void draw(GuiContext context)
8188
int x = this.area.x(this.anchorX, this.font.getStringWidth(label));
8289
int y = this.area.y(this.anchorY, this.font.FONT_HEIGHT);
8390

84-
GuiDraw.drawTextBackground(this.font, label, x, y, this.color, this.getColor());
91+
GuiDraw.drawTextBackground(this.font, label, x, y, this.color, this.getColor(), 3, this.textShadow);
8592

8693
super.draw(context);
8794
}

src/main/java/mchorse/mclib/client/gui/framework/elements/utils/ITextColoring.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
public interface ITextColoring
44
{
5-
public void setColor(int color);
5+
public void setColor(int color, boolean shadow);
66
}

src/main/java/mchorse/mclib/config/gui/GuiConfigPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void refresh()
208208
{
209209
for (ITextColoring elem : element.getChildren(ITextColoring.class, new ArrayList<ITextColoring>(), true))
210210
{
211-
elem.setColor(0x999999);
211+
elem.setColor(0x999999, true);
212212
}
213213
}
214214
}

0 commit comments

Comments
 (0)