Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lt.ekgame.reflect.gui;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.GradientPaint;
- import java.awt.Graphics2D;
- import java.awt.Rectangle;
- import java.awt.RenderingHints;
- import java.awt.geom.Rectangle2D;
- import java.awt.image.BufferedImage;
- import net.minecraft.client.gui.Gui;
- import org.lwjgl.opengl.GL11;
- import lt.ekgame.reflect.Reflect;
- public class RTab {
- private int textureID;
- private int textureID_hover;
- private int animation = 0;
- int movement = 40;
- int maxDelay = 0;
- int delay = 0;
- public String text;
- public Rectangle bounds;
- int hoverAlpha = 0;
- public RTab(String text, int delay)
- {
- bounds = new Rectangle();
- this.maxDelay = delay;
- setText(text, bounds);
- }
- public void setText(String text, Rectangle bounds)
- {
- textureID = createTexture(text, bounds, false);
- textureID_hover = createTexture(text, bounds, true);
- }
- private int createTexture(String text, Rectangle bounds, boolean hover)
- {
- BufferedImage img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
- String string = text;
- int padding = 8;
- int offset = 3;
- Graphics2D g = (Graphics2D) img.getGraphics();
- Font font = new Font("arial", Font.PLAIN, 21);
- FontMetrics fontMetrics = g.getFontMetrics(font);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- if (hover)
- {
- g.setColor(new Color(25, 186, 255, 30));
- }
- else
- {
- g.setColor(new Color(0, 0, 0, 30));
- }
- for (int i = 0; i < offset; i++)
- {
- g.fillRoundRect(i, i, fontMetrics.stringWidth(string) + padding * 2 + offset * 2 - i * 2, fontMetrics.getHeight()/2 + padding * 2 + offset * 2 - i * 2, 15 + (offset - i) * 2, 15 + (offset - i) * 2);
- }
- if (hover)
- {
- g.setColor(new Color(25, 186, 255, 100));
- g.fillRoundRect(0 + offset, 0 + offset, fontMetrics.stringWidth(string) + padding * 2, fontMetrics.getHeight()/2 + padding * 2, 15, 15);
- }
- else
- {
- g.setPaint(new GradientPaint(0, 0, new Color(250, 250, 250), 0, fontMetrics.getHeight() - 5, new Color(200, 200, 200), true));
- g.fillRoundRect(0 + offset, 0 + offset, fontMetrics.stringWidth(string) + padding * 2, fontMetrics.getHeight()/2 + padding * 2, 15, 15);
- }
- g.setFont(font);
- g.setColor(new Color(0, 0, 0, 255));
- g.drawString(string, padding + offset + 1, fontMetrics.getHeight()/2 + padding + offset + 1);
- g.setPaint(new GradientPaint(0, 0, new Color(250, 250, 250), 0, fontMetrics.getHeight(), new Color(50, 50, 50), true));
- g.drawString(string, padding + offset, fontMetrics.getHeight()/2 + padding + offset);
- bounds.setSize(fontMetrics.stringWidth(string) + padding * 2 + offset * 2, fontMetrics.getHeight()/2 + padding * 2 + offset * 2);
- return Reflect.getMC().renderEngine.allocateAndSetupTexture(img);
- }
- public void setPos(int x, int y)
- {
- bounds.setLocation(x, y);
- System.out.println(x + " " + y);
- }
- public int getX()
- {
- return bounds.x;
- }
- public int getY()
- {
- return bounds.y;
- }
- public int getWidth()
- {
- return bounds.width;
- }
- public int getHeight()
- {
- return bounds.height;
- }
- private boolean pointInBounds(int x, int y)
- {
- return bounds.contains(x, y);
- }
- public void draw(int mouseX, int mouseY, Gui gui)
- {
- int speed = 20;
- if (Reflect.isGuiDispalyed())
- {
- if (delay < maxDelay)
- {
- delay = Math.min(delay + 1, maxDelay);
- }
- else
- {
- animation = Math.min(animation + speed, 100);
- }
- }
- else
- {
- if (delay > 0)
- {
- delay = Math.max(delay - 1, 0);
- }
- else
- {
- animation = Math.max(animation - speed, 0);
- }
- }
- //System.out.println(delay + "/" + maxDelay);
- int y = movement - (int)(((float)movement / 100) * animation);
- float alpha = (((float)1 / 100) * animation);
- if (pointInBounds(mouseX, mouseY))
- {
- hoverAlpha = 255;
- }
- else
- {
- if (hoverAlpha > 0)
- {
- int spd = 20;
- hoverAlpha -= Math.min(spd, hoverAlpha);
- }
- }
- GL11.glColor4f(1F, 1F, 1F, alpha);
- GL11.glBindTexture(3553, textureID);
- gui.drawTexturedModalRect(getX(), getY() - y, 0, 0, getWidth(), getHeight());
- if (hoverAlpha > 0)
- {
- GL11.glColor4f(1F, 1F, 1F, (float)hoverAlpha/255);
- GL11.glBindTexture(3553, textureID_hover);
- gui.drawTexturedModalRect(getX(), getY() - y, 0, 0, getWidth(), getHeight());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement