mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 06:41:31 +01:00
Basic element system & added some helper functions to RenderUtil
This commit is contained in:
parent
3d5049d662
commit
b6faa000aa
@ -18,9 +18,13 @@ import org.lwjgl.opengl.GL11;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class RenderUtil {
|
||||
final static Minecraft mc = Minecraft.getMinecraft();
|
||||
final static Minecraft mc = Minecraft.getMinecraft();
|
||||
final static FontRenderer fr = mc.fontRendererObj;
|
||||
|
||||
public static void drawRoundXYWH(float x, float y, float width, float height, float r, int col) {
|
||||
drawRoundedRect(x, y, x + width, y + height, r, col);
|
||||
}
|
||||
|
||||
public static void drawRoundedRect(float x, float y, float x1, float y1, float radius, int color) {
|
||||
x1 = x + x1;
|
||||
y1 = y + y1;
|
||||
@ -65,7 +69,12 @@ public class RenderUtil {
|
||||
glPopAttrib();
|
||||
glLineWidth(1);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawRoundOutlineXYWH(float x, float y, float w, float h, float r, float lw, int col) {
|
||||
drawRoundedOutline(x, y, x + w, y + h, r, lw, col);
|
||||
}
|
||||
|
||||
public static void drawRoundedOutline(float x, float y, float x1, float y1, float radius,float lineWidth, int color) {
|
||||
x1 = x + x1;
|
||||
y1 = y + y1;
|
||||
|
@ -0,0 +1,25 @@
|
||||
package net.silentclient.client.ui.framework;
|
||||
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* @author refactoring
|
||||
*/
|
||||
public abstract class UIElement extends Gui {
|
||||
public float x, y, w, h;
|
||||
|
||||
public UIElement(float x, float y, float w, float h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
public boolean isMouseInside(float mx, float my) {
|
||||
return mx >= this.x && my >= this.y && mx < this.x + this.w && my < this.y + this.h;
|
||||
}
|
||||
|
||||
public void render(float mouseX, float mouseY) {}
|
||||
public void click(float mouseX, float mouseY, int button) {}
|
||||
public void released(float mouseX, float mouseY, int button) {}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package net.silentclient.client.ui.framework;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
/**
|
||||
* Solely exists for the purpose of making everything custom ;)
|
||||
*
|
||||
* @author refactoring
|
||||
*/
|
||||
public class UIScreen extends GuiScreen { }
|
@ -0,0 +1,13 @@
|
||||
package net.silentclient.client.ui.screen;
|
||||
|
||||
import net.silentclient.client.ui.framework.UIScreen;
|
||||
|
||||
/**
|
||||
* @author refactoring
|
||||
*/
|
||||
public class ScreenModMenu extends UIScreen {
|
||||
@Override
|
||||
public void drawScreen(int mx, int my, float btn) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package net.silentclient.client.ui.screen.component;
|
||||
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.gui.animation.SimpleAnimation;
|
||||
import net.silentclient.client.gui.font.SilentFontRenderer;
|
||||
import net.silentclient.client.gui.util.RenderUtil;
|
||||
import net.silentclient.client.ui.framework.UIElement;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author refactoring
|
||||
*/
|
||||
public class ElementIconButton extends UIElement {
|
||||
private final Runnable clickHandler;
|
||||
private final String icon;
|
||||
private final SimpleAnimation anim = new SimpleAnimation(0f);
|
||||
|
||||
public ElementIconButton(String icon, float x, float y, float w, float h, Runnable handler) {
|
||||
super(x, y, w, h);
|
||||
this.icon = icon;
|
||||
this.clickHandler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float mouseX, float mouseY) {
|
||||
RenderUtil.drawRoundXYWH(x, y, w, h, 7f, new Color(0, 0, 0, 125).getRGB());
|
||||
RenderUtil.drawRoundOutlineXYWH(x, y, w, h, 7f, 1f, new Color(255, 255, 255, 125).getRGB());
|
||||
RenderUtil.drawRoundXYWH(x, y, w, h, 7f, new Color(255, 255, 255, (int)anim.getValue()).getRGB());
|
||||
|
||||
Client.getInstance().getSilentFontRenderer().drawCenteredString(icon, (int) (x + w / 2), (int) (y + h / 2), 25, SilentFontRenderer.FontType.TEXT, 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(float mouseX, float mouseY, int button) {
|
||||
if(isMouseInside(mouseX, mouseY) && button == 0) {
|
||||
clickHandler.run();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user