GuiHoverLabel.java
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.client.gui;
import com.mumfrey.liteloader.client.api.LiteLoaderBrandingProvider;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
public class GuiHoverLabel extends GuiButton
{
private FontRenderer fontRenderer;
private int colour;
private int hoverColour;
public GuiHoverLabel(int id, int xPosition, int yPosition, FontRenderer fontRenderer, String displayText)
{
this(id, xPosition, yPosition, fontRenderer, displayText, LiteLoaderBrandingProvider.BRANDING_COLOUR);
}
public GuiHoverLabel(int id, int xPosition, int yPosition, FontRenderer fontRenderer, String displayText, int colour)
{
this(id, xPosition, yPosition, fontRenderer, displayText, colour, 0xFFFFFFAA);
}
public GuiHoverLabel(int id, int xPosition, int yPosition, FontRenderer fontRenderer, String displayText, int colour, int hoverColour)
{
super(id, xPosition, yPosition, GuiHoverLabel.getStringWidth(fontRenderer, displayText), 8, displayText);
this.fontRenderer = fontRenderer;
this.colour = colour;
this.hoverColour = hoverColour;
}
@Override
public void drawButton(Minecraft minecraft, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
this.hovered = mouseX >= this.x
&& mouseY >= this.y
&& mouseX < this.x + this.width
&& mouseY < this.y + this.height;
this.fontRenderer.drawString(this.displayString, this.x, this.y, this.hovered ? this.hoverColour : this.colour);
}
else
{
this.hovered = false;
}
}
private static int getStringWidth(FontRenderer fontRenderer, String text)
{
return fontRenderer.getStringWidth(text);
}
}