(enhancement) Color picker

This commit is contained in:
refactoring 2024-01-02 05:50:26 -05:00
parent ceae54160c
commit f1b642c88d
33 changed files with 2651 additions and 68 deletions

View File

@ -4,7 +4,7 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="zulu-1.8 (3)" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="zulu-1.8 (3)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,35 @@
package me.djtheredstoner.lwjgl;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.system.FunctionProvider;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
public class Lwjgl2FunctionProvider implements FunctionProvider {
private final Method m_getFunctionAddress;
public Lwjgl2FunctionProvider() {
try {
m_getFunctionAddress = GLContext.class.getDeclaredMethod("getFunctionAddress", String.class);
m_getFunctionAddress.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public long getFunctionAddress(CharSequence functionName) {
try {
return (long) m_getFunctionAddress.invoke(null, functionName.toString());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public long getFunctionAddress(ByteBuffer byteBuffer) {
throw new UnsupportedOperationException();
}
}

View File

@ -34,6 +34,7 @@ import net.silentclient.client.mods.settings.GeneralMod;
import net.silentclient.client.mods.util.PingSource; import net.silentclient.client.mods.util.PingSource;
import net.silentclient.client.mods.util.Server; import net.silentclient.client.mods.util.Server;
import net.silentclient.client.mods.util.Utils; import net.silentclient.client.mods.util.Utils;
import net.silentclient.client.nanovg.UI;
import net.silentclient.client.premium.PremiumCosmeticsGui; import net.silentclient.client.premium.PremiumCosmeticsGui;
import net.silentclient.client.premium.PremiumUtils; import net.silentclient.client.premium.PremiumUtils;
import net.silentclient.client.skillissue.SkillIssue; import net.silentclient.client.skillissue.SkillIssue;
@ -278,6 +279,8 @@ public class Client {
Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(mod.getIcon())); Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(mod.getIcon()));
} }
}); });
logger.info("STARTING > ui");
UI.init();
logger.info("STARTING > servers"); logger.info("STARTING > servers");
ArrayList<FeaturedServers.FeaturedServerInfo> servers = FeaturedServers.get(); ArrayList<FeaturedServers.FeaturedServerInfo> servers = FeaturedServers.get();
featuredServers.clear(); featuredServers.clear();

View File

@ -0,0 +1,276 @@
package net.silentclient.client.gui.elements;
import net.minecraft.client.gui.Gui;
import net.silentclient.client.gui.animation.SimpleAnimation;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.util.RenderUtil;
import org.lwjgl.opengl.GL11;
import java.awt.*;
public class HSBPicker extends Gui {
public float[] color;
private boolean pickingColor;
private boolean pickingHue;
private boolean pickingAlpha;
private int pickerX, pickerY, pickerWidth, pickerHeight;
private int hueSliderX, hueSliderY, hueSliderWidth, hueSliderHeight;
private int alphaSliderX, alphaSliderY, alphaSliderWidth, alphaSliderHeight;
private boolean rainbowState = false;
private final int x, y, width, height;
private int selectedColorFinal = -1;
private Color selectedColorFinalAsColor;
public int cursorX;
public int cursorY;
public boolean alphaSlider = true;
public String text;
public SimpleAnimation sx = new SimpleAnimation(0f);
public SimpleAnimation sy = new SimpleAnimation(0f);
public HSBPicker(int x, int y, int width, int height, boolean alphaSlider, String text) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.color = new float[]{0.4f, 1.0f, 1.0f, 1.0f};
this.pickingColor = false;
this.alphaSlider = alphaSlider;
this.text = text;
}
public void init() {
this.pickerWidth = width;
this.pickerHeight = height;
this.pickerX = x;
this.pickerY = y;
this.hueSliderX = pickerX;
this.hueSliderY = pickerY + pickerHeight + 6;
this.hueSliderWidth = pickerWidth;
this.hueSliderHeight = 6;
this.alphaSliderX = pickerX + pickerWidth + 6;
this.alphaSliderY = pickerY;
this.alphaSliderWidth = 6;
this.alphaSliderHeight = pickerHeight;
}
public void render(int mouseX, int mouseY) {
if (this.rainbowState) {
double rainbowState = Math.ceil((System.currentTimeMillis() + 200) / 20.0);
rainbowState %= 360.0;
this.color[0] = (float) (rainbowState / 360.0);
}
if (this.pickingHue) {
if (this.hueSliderWidth > this.hueSliderHeight) {
float restrictedX = (float) Math.min(Math.max(hueSliderX, mouseX), hueSliderX + hueSliderWidth);
this.color[0] = (restrictedX - (float) hueSliderX) / hueSliderWidth;
} else {
float restrictedY = (float) Math.min(Math.max(hueSliderY, mouseY), hueSliderY + hueSliderHeight);
this.color[0] = (restrictedY - (float) hueSliderY) / hueSliderHeight;
}
}
if (this.pickingAlpha) {
if (this.alphaSliderWidth > this.alphaSliderHeight) {
float restrictedX = (float) Math.min(Math.max(alphaSliderX, mouseX), alphaSliderX + alphaSliderWidth);
this.color[3] = 1 - (restrictedX - (float) alphaSliderX) / alphaSliderWidth;
} else {
float restrictedY = (float) Math.min(Math.max(alphaSliderY, mouseY), alphaSliderY + alphaSliderHeight);
this.color[3] = 1 - (restrictedY - (float) alphaSliderY) / alphaSliderHeight;
}
}
if (this.pickingColor) {
float restrictedX = (float) Math.min(Math.max(pickerX, mouseX), pickerX + pickerWidth);
float restrictedY = (float) Math.min(Math.max(pickerY, mouseY), pickerY + pickerHeight);
this.color[1] = (restrictedX - (float) pickerX) / pickerWidth;
this.color[2] = 1 - (restrictedY - (float) pickerY) / pickerHeight;
}
int selectedX = pickerX + pickerWidth + 6;
int selectedY = pickerY + pickerHeight + 6;
int selectedWidth = 6;
int selectedHeight = 6;
Gui.drawRect(pickerX - 1, pickerY - 1, pickerX + pickerWidth + 1, pickerY + pickerHeight + 1, new Color(0, 0, 0, 0).getRGB());
Gui.drawRect(hueSliderX - 1, hueSliderY - 1, hueSliderX + hueSliderWidth + 1, hueSliderY + hueSliderHeight + 1, new Color(0, 0, 0, 0).getRGB());
Gui.drawRect(alphaSliderX - 1, alphaSliderY - 1, alphaSliderX + alphaSliderWidth + 1, alphaSliderY + alphaSliderHeight + 1, new Color(0, 0, 0, 0).getRGB());
int selectedColor = Color.HSBtoRGB(this.color[0], 1.0f, 1.0f);
float selectedRed = (selectedColor >> 16 & 0xFF) / 255.0f;
float selectedGreen = (selectedColor >> 8 & 0xFF) / 255.0f;
float selectedBlue = (selectedColor & 0xFF) / 255.0f;
this.drawPickerBase(pickerX, pickerY, pickerWidth, pickerHeight, selectedRed, selectedGreen, selectedBlue, 255);
this.drawHueSlider(hueSliderX, hueSliderY, hueSliderWidth, hueSliderHeight, this.color[0]);
if (alphaSlider) {
this.drawAlphaSlider(alphaSliderX, alphaSliderY, alphaSliderWidth, alphaSliderHeight, selectedRed, selectedGreen, selectedBlue, this.color[3]);
}
selectedColorFinal = alpha(new Color(Color.HSBtoRGB(this.color[0], this.color[1], this.color[2])), this.color[3]);
selectedColorFinalAsColor = color(new Color(Color.HSBtoRGB(this.color[0], this.color[1], this.color[2])), this.color[3]);
Gui.drawRect(selectedX - 1, selectedY - 1, selectedX + selectedWidth + 1, selectedY + selectedHeight + 1, new Color(0, 0, 0, 0).getRGB());
Gui.drawRect(selectedX, selectedY, selectedX + selectedWidth, selectedY + selectedHeight, selectedColorFinal);
cursorX = (int) (pickerX + color[1] * pickerWidth);
cursorY = (int) ((pickerY + pickerHeight) - color[2] * pickerHeight);
sx.setAnimation(cursorX, 25f);
sy.setAnimation(cursorY, 25f);
RenderUtils.drawRect(sx.getValue() - 1, sy.getValue() - 1, 2, 2, Color.WHITE.getRGB());
}
final int alpha(Color color, float alpha) {
final float red = (float) color.getRed() / 255;
final float green = (float) color.getGreen() / 255;
final float blue = (float) color.getBlue() / 255;
return new Color(red, green, blue, alpha).getRGB();
}
final Color color(Color color, float alpha) {
final float red = (float) color.getRed() / 255;
final float green = (float) color.getGreen() / 255;
final float blue = (float) color.getBlue() / 255;
return new Color(red, green, blue, alpha);
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
this.pickingColor = check(pickerX, pickerY, pickerX + pickerWidth, pickerY + pickerHeight, mouseX, mouseY);
this.pickingHue = check(hueSliderX, hueSliderY, hueSliderX + hueSliderWidth, hueSliderY + hueSliderHeight, mouseX, mouseY);
if (alphaSlider) {
this.pickingAlpha = check(alphaSliderX, alphaSliderY, alphaSliderX + alphaSliderWidth, alphaSliderY + alphaSliderHeight, mouseX, mouseY);
}
}
public void mouseReleased(int mouseX, int mouseY, int state) {
this.pickingColor = this.pickingHue = this.pickingAlpha = false;
}
private void drawHueSlider(int x, int y, int width, int height, float hue) {
int step = 0;
if (height > width) {
Gui.drawRect(x, y, x + width, y + 4, 0xFFFF0000);
y += 4;
for (int colorIndex = 0; colorIndex < 6; colorIndex++) {
int previousStep = Color.HSBtoRGB((float) step / 6, 1.0f, 1.0f);
int nextStep = Color.HSBtoRGB((float) (step + 1) / 6, 1.0f, 1.0f);
this.drawGradientRect(x, y + step * (height / 6), x + width, y + (step + 1) * (height / 6), previousStep, nextStep);
step++;
}
final int sliderMinY = (int) (y + (height * hue)) - 4;
Gui.drawRect(x, sliderMinY - 1, x + width, sliderMinY + 1, -1);
} else {
for (int colorIndex = 0; colorIndex < 6; colorIndex++) {
int previousStep = Color.HSBtoRGB((float) step / 6, 1.0f, 1.0f);
int nextStep = Color.HSBtoRGB((float) (step + 1) / 6, 1.0f, 1.0f);
this.gradient(x + step * (width / 6), y, x + (step + 1) * (width / 6), y + height, previousStep, nextStep, true);
step++;
}
final int sliderMinX = (int) (x + (width * hue));
Gui.drawRect(sliderMinX - 1, y, sliderMinX, y + height, -1);
}
}
private void drawAlphaSlider(int x, int y, int width, int height, float red, float green, float blue, float alpha) {
boolean left = true;
int checkerBoardSquareSize = width / 2;
for (int squareIndex = -checkerBoardSquareSize; squareIndex < height; squareIndex += checkerBoardSquareSize) {
if (!left) {
Gui.drawRect(x, y + squareIndex, x + width, y + squareIndex + checkerBoardSquareSize, 0xFFFFFFFF);
Gui.drawRect(x + checkerBoardSquareSize, y + squareIndex, x + width, y + squareIndex + checkerBoardSquareSize, 0xFF909090);
if (squareIndex < height - checkerBoardSquareSize) {
int minY = y + squareIndex + checkerBoardSquareSize;
int maxY = Math.min(y + height, y + squareIndex + checkerBoardSquareSize * 2);
Gui.drawRect(x, minY, x + width, maxY, 0xFF909090);
Gui.drawRect(x + checkerBoardSquareSize, minY, x + width, maxY, 0xFFFFFFFF);
}
}
left = !left;
}
this.gradient(x, y, x + width, y + height, new Color((int)red, (int)green, (int)blue, 255).getRGB(), 0, false);
final int sliderMinY = (int) (y + height - (height * alpha));
Gui.drawRect(x, sliderMinY - 1, x + width, sliderMinY, -1);
}
private void drawPickerBase(int pickerX, int pickerY, int pickerWidth, int pickerHeight, float red, float green, float blue, float alpha) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glBegin(GL11.GL_POLYGON);
{
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glVertex2f(pickerX, pickerY);
GL11.glVertex2f(pickerX, pickerY + pickerHeight);
GL11.glColor4f(red, green, blue, alpha);
GL11.glVertex2f(pickerX + pickerWidth, pickerY + pickerHeight);
GL11.glVertex2f(pickerX + pickerWidth, pickerY);
}
GL11.glEnd();
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glBegin(GL11.GL_POLYGON);
{
GL11.glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glVertex2f(pickerX, pickerY);
GL11.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
GL11.glVertex2f(pickerX, pickerY + pickerHeight);
GL11.glVertex2f(pickerX + pickerWidth, pickerY + pickerHeight);
GL11.glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glVertex2f(pickerX + pickerWidth, pickerY);
}
GL11.glEnd();
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
protected void gradient(int minX, int minY, int maxX, int maxY, int startColor, int endColor, boolean left) {
if (left) {
final float startA = (startColor >> 24 & 0xFF) / 255.0f;
final float startR = (startColor >> 16 & 0xFF) / 255.0f;
final float startG = (startColor >> 8 & 0xFF) / 255.0f;
final float startB = (startColor & 0xFF) / 255.0f;
final float endA = (endColor >> 24 & 0xFF) / 255.0f;
final float endR = (endColor >> 16 & 0xFF) / 255.0f;
final float endG = (endColor >> 8 & 0xFF) / 255.0f;
final float endB = (endColor & 0xFF) / 255.0f;
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glBegin(GL11.GL_POLYGON);
{
GL11.glColor4f(startR, startG, startB, startA);
GL11.glVertex2f(minX, minY);
GL11.glVertex2f(minX, maxY);
GL11.glColor4f(endR, endG, endB, endA);
GL11.glVertex2f(maxX, maxY);
GL11.glVertex2f(maxX, minY);
}
GL11.glEnd();
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
} else drawGradientRect(minX, minY, maxX, maxY, startColor, endColor);
}
protected boolean check(int minX, int minY, int maxX, int maxY, int curX, int curY) {
return curX >= minX && curY >= minY && curX < maxX && curY < maxY;
}
public Color getSelectedColorFinal() {
return new Color(selectedColorFinal);
}
public void setFinalColor(Color color) {
float r = color.getRed() / 255.0F;
float g = color.getGreen() / 255.0F;
float b = color.getBlue() / 255.0F;
float a = color.getAlpha() / 255.0F;
this.color[0] = r;
this.color[1] = g;
this.color[2] = b;
this.color[3] = a;
}
}

View File

@ -1,10 +1,12 @@
package net.silentclient.client.gui.modmenu; package net.silentclient.client.gui.modmenu;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.silentclient.client.gui.elements.IconButton;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils; import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.util.RenderUtil; import net.silentclient.client.gui.util.RenderUtil;
import net.silentclient.client.mods.Setting; import net.silentclient.client.mods.Setting;
import org.lwjgl.input.Mouse;
import java.awt.*; import java.awt.*;
@ -12,6 +14,11 @@ import java.awt.*;
* @author refactoring * @author refactoring
*/ */
public class CellGrid { public class CellGrid {
private static IconButton trashBtn = new IconButton(0,0,0,new ResourceLocation("silentclient/icons/trash-icon.png"));
private static boolean rmb;
private static boolean lmb;
public static void render(float mouseX, float mouseY, float x, float y, Setting grid) { public static void render(float mouseX, float mouseY, float x, float y, Setting grid) {
for (int row = 0; row < 11; row++) { for (int row = 0; row < 11; row++) {
for (int col = 0; col < 11; col++) { for (int col = 0; col < 11; col++) {
@ -25,14 +32,36 @@ public class CellGrid {
MouseUtils.isInside((int) mouseX, (int) mouseY, rx, ry, 11, 11) ? 0x20ffffff : 0x00ffffff MouseUtils.isInside((int) mouseX, (int) mouseY, rx, ry, 11, 11) ? 0x20ffffff : 0x00ffffff
); );
if(MouseUtils.isInside((int) mouseX, (int) mouseY, rx, ry, 11, 11) && Mouse.isButtonDown(0)) { if(MouseUtils.isInside((int) mouseX, (int) mouseY, rx, ry, 11, 11) && rmb) {
grid.getCells()[row][col] = true; grid.getCells()[row][col] = true;
} }
if(MouseUtils.isInside((int) mouseX, (int) mouseY, rx, ry, 11, 11) && Mouse.isButtonDown(1)) { if(MouseUtils.isInside((int) mouseX, (int) mouseY, rx, ry, 11, 11) && lmb) {
grid.getCells()[row][col] = false; grid.getCells()[row][col] = false;
} }
trashBtn.xPosition = (int)x;
trashBtn.yPosition = (int)y + 125;
trashBtn.drawButton(Minecraft.getMinecraft(), (int)mouseX, (int)mouseY);
} }
} }
} }
public static void click(float mouseX, float mouseY, int btn, Setting setting) {
if(trashBtn.isMouseOver() && btn == 0) {
setting.setCells(new boolean[11][11]);
} else {
if(btn == 1) {
lmb = true;
} else if (btn == 0) {
rmb = true;
}
}
}
public static void release() {
lmb = false;
rmb = false;
}
} }

View File

@ -7,6 +7,7 @@ import net.silentclient.client.Client;
import net.silentclient.client.gui.SilentScreen; import net.silentclient.client.gui.SilentScreen;
import net.silentclient.client.gui.elements.Button; import net.silentclient.client.gui.elements.Button;
import net.silentclient.client.gui.elements.Checkbox; import net.silentclient.client.gui.elements.Checkbox;
import net.silentclient.client.gui.elements.HSBPicker;
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
import net.silentclient.client.gui.theme.button.DefaultButtonTheme; import net.silentclient.client.gui.theme.button.DefaultButtonTheme;
import net.silentclient.client.gui.theme.button.SelectedButtonTheme; import net.silentclient.client.gui.theme.button.SelectedButtonTheme;
@ -14,6 +15,7 @@ import net.silentclient.client.gui.util.RenderUtil;
import net.silentclient.client.mods.Mod; import net.silentclient.client.mods.Mod;
import net.silentclient.client.mods.ModCategory; import net.silentclient.client.mods.ModCategory;
import net.silentclient.client.mods.Setting; import net.silentclient.client.mods.Setting;
import net.silentclient.client.mods.SettingsManager;
import net.silentclient.client.utils.MenuBlurUtils; import net.silentclient.client.utils.MenuBlurUtils;
import net.silentclient.client.utils.MouseCursorHandler; import net.silentclient.client.utils.MouseCursorHandler;
@ -27,6 +29,7 @@ public class ColorPicker extends SilentScreen {
private final GuiScreen parentScreen; private final GuiScreen parentScreen;
private ArrayList<Color> colors = new ArrayList<Color>(); private ArrayList<Color> colors = new ArrayList<Color>();
private final String value; private final String value;
private HSBPicker hsb;
public ColorPicker(Mod mod, String value, GuiScreen parentScreen) { public ColorPicker(Mod mod, String value, GuiScreen parentScreen) {
if (mod == null) throw new IllegalArgumentException("Mod is null"); if (mod == null) throw new IllegalArgumentException("Mod is null");
@ -34,6 +37,10 @@ public class ColorPicker extends SilentScreen {
this.mod = mod; this.mod = mod;
this.parentScreen = parentScreen; this.parentScreen = parentScreen;
this.value = value; this.value = value;
float colorY = 80;
int colorX = 3;
hsb = new HSBPicker((int)colorX, (int)colorY, 120, 70, true, value);
hsb.init();
} }
@Override @Override
@ -52,23 +59,6 @@ public class ColorPicker extends SilentScreen {
if(mod.getCategory() == ModCategory.MODS) { if(mod.getCategory() == ModCategory.MODS) {
this.buttonList.add(new Button(3, 76, this.height - 18, 70, 15, mod.isEnabled() ? "Enabled" : "Disabled", false, mod.isEnabled() ? new SelectedButtonTheme() : new DefaultButtonTheme())); this.buttonList.add(new Button(3, 76, this.height - 18, 70, 15, mod.isEnabled() ? "Enabled" : "Disabled", false, mod.isEnabled() ? new SelectedButtonTheme() : new DefaultButtonTheme()));
} }
colors.clear();
colors.add(new Color(255, 255, 255));
colors.add(new Color(156, 157, 151));
colors.add(new Color(71,79,82));
colors.add(new Color(0, 0, 0));
colors.add(new Color(255,216,61));
colors.add(new Color(249,128,29));
colors.add(new Color(176,46,38));
colors.add(new Color(130,84,50));
colors.add(new Color(128,199,31));
colors.add(new Color(58,179,218));
colors.add(new Color(22,156,157));
colors.add(new Color(60,68,169));
colors.add(new Color(243,140,170));
colors.add(new Color(198,79,189));
colors.add(new Color(137,50,183));
} }
@Override @Override
@ -80,39 +70,11 @@ public class ColorPicker extends SilentScreen {
ModMenu.drawOverlayListBase(height, "Choose a color"); ModMenu.drawOverlayListBase(height, "Choose a color");
ModMenu.trimContentStart(width, height); ModMenu.trimContentStart(width, height);
float colorY = 66; float colorY = 66;
int colorX = 3; hsb.render(mouseX, mouseY);
int colorIndex = 0;
for(Color color : colors) {
RenderUtil.drawRoundedRect(colorX, colorY, 20, 20, 3, new Color(color.getRed(), color.getGreen(), color.getBlue(), setting.getOpacity()).getRGB());
RenderUtil.drawRoundedOutline(colorX, colorY, 20, 20, 3, 2, new Color(0, 0, 0).getRGB());
if(MouseUtils.isInside(mouseX, mouseY, colorX, colorY, 20, 20)) {
cursorType = MouseCursorHandler.CursorType.POINTER;
}
colorX += 25;
colorIndex += 1;
if(colorIndex == 6) {
colorIndex = 0;
colorX = 3;
colorY += 25;
}
}
int settingHeight = 15; Client.getInstance().getSettingsManager().getSettingByName(mod, this.value).setValColor(hsb.getSelectedColorFinal());
colorY += settingHeight;
if(setting.isCanChangeOpacity()) {
colorY += settingHeight;
RegularSlider.render(3, colorY, 144, "Opacity", 255, setting.getOpacity());
if (RegularSlider.isDrag(mouseX, mouseY, 3, colorY, 144) && (System.currentTimeMillis() - initTime) > 500) {
double diff = 255 - 0;
double mouse = MathHelper.clamp_double((mouseX - 3) / 100D, 0, 1);
double newVal = 0 + mouse * diff;
setting.setOpacity((int) newVal);
}
colorY += settingHeight;
}
colorY += settingHeight;
Checkbox.render(mouseX, mouseY, 3, colorY, "Chroma", setting.isChroma()); Checkbox.render(mouseX, mouseY, 3, colorY, "Chroma", setting.isChroma());
if(Checkbox.isHovered(mouseX, mouseY, 3, colorY)) { if(Checkbox.isHovered(mouseX, mouseY, 3, colorY)) {
@ -153,21 +115,8 @@ public class ColorPicker extends SilentScreen {
super.mouseClicked(mouseX, mouseY, mouseButton); super.mouseClicked(mouseX, mouseY, mouseButton);
Setting setting = Client.getInstance().getSettingsManager().getSettingByName(mod, this.value); Setting setting = Client.getInstance().getSettingsManager().getSettingByName(mod, this.value);
float colorY = 66; float colorY = 66;
int colorX = 3;
int colorIndex = 0; hsb.mouseClicked(mouseX, mouseY, mouseButton);
for(Color color : colors) {
if(MouseUtils.isInside(mouseX, mouseY, colorX, colorY, 20, 20)) {
setting.setValColor(color);
mc.displayGuiScreen(parentScreen);
}
colorX += 25;
colorIndex += 1;
if(colorIndex == 6) {
colorIndex = 0;
colorX = 3;
colorY += 25;
}
}
int settingHeight = 15; int settingHeight = 15;
colorY += settingHeight; colorY += settingHeight;
@ -183,6 +132,12 @@ public class ColorPicker extends SilentScreen {
} }
} }
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
hsb.mouseReleased(mouseX, mouseY, state);
super.mouseReleased(mouseX, mouseY, state);
}
@Override @Override
public void onGuiClosed() { public void onGuiClosed() {
super.onGuiClosed(); super.onGuiClosed();

View File

@ -137,7 +137,7 @@ public class ModSettings extends SilentScreen {
} }
if(setting.isCellGrid()) { if(setting.isCellGrid()) {
CellGrid.render(mouseX, mouseY, 3, settingY, setting); CellGrid.render(mouseX, mouseY, 3, settingY, setting);
settingY += 120; settingY += 135;
} }
if(setting.isSlider()) { if(setting.isSlider()) {
RegularSlider.render(3, settingY, 144, setting.getName(), setting.getMax(), setting.getValDouble()); RegularSlider.render(3, settingY, 144, setting.getName(), setting.getMax(), setting.getValDouble());
@ -267,6 +267,10 @@ public class ModSettings extends SilentScreen {
} }
} }
if(setting.isCellGrid()) {
CellGrid.click(mouseX, mouseY, mouseButton, setting);
}
if(setting.isSlider()) { if(setting.isSlider()) {
settingY += 15; settingY += 15;
} }
@ -384,6 +388,17 @@ public class ModSettings extends SilentScreen {
MenuBlurUtils.unloadBlur(); MenuBlurUtils.unloadBlur();
} }
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
for (Setting setting : Client.getInstance().getSettingsManager().getSettingByMod(mod)) {
if(setting.isCellGrid()) {
CellGrid.release();
}
}
}
@Override @Override
public boolean doesGuiPauseGame() { public boolean doesGuiPauseGame() {
return !(this.mod instanceof TimeChangerMod); return !(this.mod instanceof TimeChangerMod);

View File

@ -4,6 +4,7 @@ import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraft.launchwrapper.LaunchClassLoader;
import net.silentclient.client.Client; import net.silentclient.client.Client;
import net.silentclient.client.mixin.transformer.NVGClassTransformer;
import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.Mixins; import org.spongepowered.asm.mixin.Mixins;
@ -66,6 +67,19 @@ public class SilentClientTweaker implements ITweaker {
} }
environment.setSide(MixinEnvironment.Side.CLIENT); environment.setSide(MixinEnvironment.Side.CLIENT);
classLoader.registerTransformer("net.silentclient.client.mixin.SilentClientTransformer"); classLoader.registerTransformer("net.silentclient.client.mixin.SilentClientTransformer");
classLoader.registerTransformer(NVGClassTransformer.class.getName());
unlockLwjgl();
}
private void unlockLwjgl() {
try {
Field transformerExceptions = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions");
transformerExceptions.setAccessible(true);
Object o = transformerExceptions.get(Launch.classLoader);
((Set<String>) o).remove("org.lwjgl.");
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
} }
@Override @Override

View File

@ -0,0 +1,51 @@
package net.silentclient.client.mixin.transformer;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
public class NVGClassTransformer implements IClassTransformer {
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if (name.equals("org.lwjgl.nanovg.NanoVGGLConfig")) {
ClassReader reader = new ClassReader(basicClass);
ClassNode node = new ClassNode();
reader.accept(node, ClassReader.EXPAND_FRAMES);
for (MethodNode method : node.methods) {
if (method.name.equals("configGL")) {
InsnList list = new InsnList();
list.add(new VarInsnNode(Opcodes.LLOAD, 0));
list.add(new TypeInsnNode(Opcodes.NEW, "me/djtheredstoner/lwjgl/Lwjgl2FunctionProvider"));
list.add(new InsnNode(Opcodes.DUP));
list.add(new MethodInsnNode(
Opcodes.INVOKESPECIAL,
"me/djtheredstoner/lwjgl/Lwjgl2FunctionProvider",
"<init>",
"()V",
false
));
list.add(new MethodInsnNode(
Opcodes.INVOKESTATIC,
"org/lwjgl/nanovg/NanoVGGLConfig",
"config",
"(JLorg/lwjgl/system/FunctionProvider;)V",
false
));
list.add(new InsnNode(Opcodes.RETURN));
method.instructions.clear();
method.instructions.insert(list);
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
node.accept(cw);
return cw.toByteArray();
}
return basicClass;
}
}

View File

@ -0,0 +1,68 @@
package net.silentclient.client.nanovg;
import net.minecraft.util.ResourceLocation;
import net.silentclient.client.Client;
import net.silentclient.client.utils.io.BufferUtil;
import net.silentclient.client.utils.io.LinkedStorage;
import org.lwjgl.nanovg.NVGColor;
import java.awt.*;
import java.io.IOException;
import java.nio.ByteBuffer;
public class NVGHelper {
public static int DRAW_STROKE = 0;
public static int DRAW_FILL = 1;
public static NVGColor nvgcolor(Color color) {
return NVGColor.calloc().r(color.getRed()/255f).g(color.getGreen()/255f).b(color.getBlue()/255f).a(color.getAlpha()/255f);
}
public static int[] int_to_rgba(int color) {
int[] rgba = new int[4];
rgba[0] = color >> 24 & 0xFF;
rgba[1] = color >> 16 & 0xFF;
rgba[2] = color >> 8 & 0xFF;
rgba[3] = color & 0xFF;
return rgba;
}
public static void path(Runnable r, int mode) {
NVGWrapper.beginPath();
r.run();
if(mode == 0) NVGWrapper.stroke();
if(mode == 1) NVGWrapper.fill();
NVGWrapper.closePath();
}
public static void path(float x, float y, Runnable r, int mode) {
NVGWrapper.beginPath();
NVGWrapper.moveTo(x,y);
r.run();
if(mode == 0) NVGWrapper.stroke();
if(mode == 1) NVGWrapper.fill();
NVGWrapper.closePath();
}
public static void initFont(String fontName, String fileName) {
try {
ByteBuffer data = BufferUtil.get().getResourceBytes(new ResourceLocation("silentclient/fonts/"+fileName), 1024);
Client.logger.info(" LOADING > ui > font > " + fontName);
LinkedStorage.put(data);
NVGWrapper.createFontMem(fontName, data, 0);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void initImage(String imgName, String fileName) {
try {
ByteBuffer data = BufferUtil.get().getResourceBytes(new ResourceLocation("silentclient/images/"+fileName), 1024);
LinkedStorage.put(data);
Client.logger.info("LOADING > ui > image > " + imgName);
int img = NVGWrapper.createImageMem(0, data);
UI.imagesmap.put(imgName,img);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,404 @@
package net.silentclient.client.nanovg;
import org.lwjgl.nanovg.*;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
public class NVGWrapper {
public static long cx;
public static void beginFrame(float width, float height, float dpi) {
NanoVG.nvgBeginFrame(cx, width, height, dpi);
}
public static void cancelFrame() {
NanoVG.nvgCancelFrame(cx);
}
public static void endFrame() {
NanoVG.nvgEndFrame(cx);
}
public static void globalCompositeOperation(int op) {
NanoVG.nvgGlobalCompositeOperation(cx, op);
}
public static void globalCompositeBlendFunc(int sfactor, int dfactor) {
NanoVG.nvgGlobalCompositeBlendFunc(cx, sfactor, dfactor);
}
public static void globalCompositeBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
NanoVG.nvgGlobalCompositeBlendFuncSeparate(cx, srcRGB, dstRGB, srcAlpha, dstAlpha);
}
public static NVGColor RGB(byte r, byte g, byte b, NVGColor __result) {
return NanoVG.nvgRGB(r, g, b, __result);
}
public static NVGColor RGBf(float r, float g, float b, NVGColor __result) {
return NanoVG.nvgRGBf(r, g, b, __result);
}
public static NVGColor RGBA(byte r, byte g, byte b, byte a, NVGColor __result) {
return NanoVG.nvgRGBA(r, g, b, a, __result);
}
public static NVGColor RGBAf(float r, float g, float b, float a, NVGColor __result) {
return NanoVG.nvgRGBAf(r, g, b, a, __result);
}
public static NVGColor lerpRGBA(NVGColor c0, NVGColor c1, float u, NVGColor __result) {
return NanoVG.nvgLerpRGBA(c0, c1, u, __result);
}
public static NVGColor transRGBA(NVGColor c0, byte a, NVGColor __result) {
return NanoVG.nvgTransRGBA(c0, a, __result);
}
public static NVGColor transRGBAf(NVGColor c0, float a, NVGColor __result) {
return NanoVG.nvgTransRGBAf(c0, a, __result);
}
public static NVGColor HSL(float h, float s, float l, NVGColor __result) {
return NanoVG.nvgHSL(h, s, l, __result);
}
public static NVGColor HSLA(float h, float s, float l, byte a, NVGColor __result) {
return NanoVG.nvgHSLA(h, s, l, a, __result);
}
public static void save() {
NanoVG.nvgSave(cx);
}
public static void restore() {
NanoVG.nvgRestore(cx);
}
public static void reset() {
NanoVG.nvgReset(cx);
}
public static void shapeAntiAlias(boolean enabled) {
NanoVG.nvgShapeAntiAlias(cx, enabled);
}
public static void strokeColor(NVGColor color) {
NanoVG.nvgStrokeColor(cx, color);
}
public static void strokePaint(NVGPaint paint) {
NanoVG.nvgStrokePaint(cx, paint);
}
public static void fillColor(NVGColor color) {
NanoVG.nvgFillColor(cx, color);
}
public static void fillPaint(NVGPaint paint) {
NanoVG.nvgFillPaint(cx, paint);
}
public static void miterLimit(float limit) {
NanoVG.nvgMiterLimit(cx, limit);
}
public static void strokeWidth(float width) {
NanoVG.nvgStrokeWidth(cx, width);
}
public static void lineCap(int cap) {
NanoVG.nvgLineCap(cx, cap);
}
public static void lineJoin(int join) {
NanoVG.nvgLineJoin(cx, join);
}
public static void globalAlpha(float alpha) {
NanoVG.nvgGlobalAlpha(cx, alpha);
}
public void resetTransformation() {
NanoVG.nvgResetTransform(cx);
}
public static void transform(float a, float b, float c, float d, float e, float f) {
NanoVG.nvgTransform(cx, a, b, c, d, e, f);
}
public static void translate(float x, float y) {
NanoVG.nvgTranslate(cx, x, y);
}
public static void rotate(float angle) {
NanoVG.nvgRotate(cx, angle);
}
public static void skewX(float angle) {
NanoVG.nvgSkewX(cx,angle);
}
public static void skewY(float angle) {
NanoVG.nvgSkewY(cx,angle);
}
public static void scale(float x, float y) {
NanoVG.nvgScale(cx,x,y);
}
public static void currentTransform(FloatBuffer xFrom) {
NanoVG.nvgCurrentTransform(cx,xFrom);
}
public static void transformIdentity(FloatBuffer dst) {
NanoVG.nvgTransformIdentity(dst);
}
public static void transformTranslate(FloatBuffer dst, float x, float y) {
NanoVG.nvgTransformTranslate(dst,x,y);
}
public static void transformScale(FloatBuffer dst, float x, float y) {
NanoVG.nvgTransformScale(dst,x,y);
}
public static void transformRotate(FloatBuffer dst, float angle) {
NanoVG.nvgTransformRotate(dst,angle);
}
public static void transformSkewX(FloatBuffer dst, float angle) {
NanoVG.nvgTransformSkewX(dst,angle);
}
public static void transformSkewY(FloatBuffer dst, float angle) {
NanoVG.nvgTransformSkewY(dst,angle);
}
public static void transformMultiply(FloatBuffer dst, FloatBuffer src) {
NanoVG.nvgTransformMultiply(dst,src);
}
public static void transfromPremultiply(FloatBuffer dst, FloatBuffer src) {
NanoVG.nvgTransformPremultiply(dst,src);
}
public static void transfromInverse(FloatBuffer dst, FloatBuffer src) {
NanoVG.nvgTransformInverse(dst,src);
}
public static void transfromPoint(FloatBuffer dstx, FloatBuffer dsty, FloatBuffer xfrom, float srcX, float srcY) {
NanoVG.nvgTransformPoint(dstx, dsty, xfrom, srcX, srcY);
}
public static float deg_rad(float val) {
return NanoVG.nvgDegToRad(val);
}
public static float rad_deg(float val) {
return NanoVG.nvgDegToRad(val);
}
public static int createImage(CharSequence filename, int imageFlags) {
return NanoVG.nvgCreateImage(cx,filename,imageFlags);
}
public static int createImageMem(int imageFlags, ByteBuffer data) {
return NanoVG.nvgCreateImageMem(cx,imageFlags,data);
}
public static int createImageRGBA(int w, int h, int imageFlags, ByteBuffer data) {
return NanoVG.nvgCreateImageRGBA(cx,w, h, imageFlags, data);
}
public static void updateImage(int image,ByteBuffer data) {
NanoVG.nvgUpdateImage(cx,image,data);
}
public static void imageSize(int image, IntBuffer w, IntBuffer h) {
NanoVG.nvgImageSize(cx,image,w,h);
}
public static void deleteImage(int image) {
NanoVG.nvgDeleteImage(cx,image);
}
public static NVGPaint linearGradient(float sx, float sy, float ex, float ey, NVGColor from, NVGColor to, NVGPaint __result) {
return NanoVG.nvgLinearGradient(cx,sx,sy,ex,ey,from,to,__result);
}
public static NVGPaint boxGradient(float x, float y, float w, float h, float r, float f, NVGColor from, NVGColor to, NVGPaint __result) {
return NanoVG.nvgBoxGradient(cx,x,y,w,h,r,f,from,to, __result);
}
public static NVGPaint imagePattern(float ox, float oy, float ex, float ey, float angle, int image, float alpha, NVGPaint __result) {
return NanoVG.nvgImagePattern(cx,ox,oy,ex,ey,angle,image,alpha,__result);
}
public static void scissor(float x, float y, float w, float h) {
NanoVG.nvgScissor(cx,x,y,w,h);
}
public static void intersectScissor(float x, float y, float w, float h) {
NanoVG.nvgIntersectScissor(cx,x,y,w,h);
}
public static void resetScissor() {
NanoVG.nvgResetScissor(cx);
}
public static void beginPath() {
NanoVG.nvgBeginPath(cx);
}
public static void moveTo(float x, float y) {
NanoVG.nvgMoveTo(cx,x,y);
}
public static void lineTo(float x, float y) {
NanoVG.nvgLineTo(cx,x,y);
}
public static void bezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
NanoVG.nvgBezierTo(cx,cx1,cy1,cx2,cy2, x,y);
}
public static void guadTo(float cx, float cy, float x, float y) {
NanoVG.nvgQuadTo(NVGWrapper.cx,cx,cy,x,y);
}
public static void arcTo(float x1, float y1, float x2, float y2, float radius) {
NanoVG.nvgArcTo(cx,x1,y1,x2,y2,radius);
}
public static void closePath() {
NanoVG.nvgClosePath(cx);
}
public static void pathWinding(int op) {
NanoVG.nvgPathWinding(cx,op);
}
public static void rect(float x, float y, float w, float h) {
NanoVG.nvgRect(cx,x,y,w,h);
}
public static void rrect(float x, float y, float w, float h, float rad) {
NanoVG.nvgRoundedRect(cx,x,y,w,h,rad);
}
public static void rrect(float x, float y, float w, float h, float rTL, float rTR, float rBL, float rBR) {
NanoVG.nvgRoundedRectVarying(cx,x,y,w,h,rTL,rTR,rBL,rBR);
}
public static void ellipse(float cx, float cy, float rx, float ry) {
NanoVG.nvgEllipse(NVGWrapper.cx,cx,cy,rx,ry);
}
public static void circle(float x, float y, float r) {
NanoVG.nvgCircle(cx,x,y,r);
}
public static void fill() {
NanoVG.nvgFill(cx);
}
public static void stroke() {
NanoVG.nvgStroke(cx);
}
public static int createFont(CharSequence name, CharSequence filename) {
return NanoVG.nvgCreateFont(cx,name,filename);
}
public static int createFontAtIndex(CharSequence name, CharSequence filename, int index) {
return NanoVG.nvgCreateFontAtIndex(cx,name,filename,index);
}
public static int createFontMem(CharSequence name, ByteBuffer data, int freeData) {
return NanoVG.nvgCreateFontMem(cx,name,data,freeData);
}
public static int createFontMemAtIndex(CharSequence name, ByteBuffer data, int freeData, int index) {
return NanoVG.nvgCreateFontMemAtIndex(cx,name,data,freeData,index);
}
public static int findFont(CharSequence name) {
return NanoVG.nvgFindFont(cx, name);
}
public static int addFallbackFontID(int baseFont, int fallbackFont) {
return NanoVG.nvgAddFallbackFontId(cx,baseFont,fallbackFont);
}
public static int addFallbackFont(CharSequence baseFont, CharSequence fallbackFont) {
return NanoVG.nvgAddFallbackFont(cx,baseFont, fallbackFont);
}
public static void resetFallbackFontsID(int baseFont) {
NanoVG.nvgResetFallbackFontsId(cx,baseFont);
}
public static void resetFallbackFonts(CharSequence baseFont) {
NanoVG.nvgResetFallbackFonts(cx,baseFont);
}
public static void fontSize(float size) {
NanoVG.nvgFontSize(cx,size);
}
public static void fontBlur(float blur) {
NanoVG.nvgFontBlur(cx,blur);
}
public static void textLetterSpacing(float spacing) {
NanoVG.nvgTextLetterSpacing(cx,spacing);
}
public static void textLineHeight(float lineHeight) {
NanoVG.nvgTextLineHeight(cx,lineHeight);
}
public static void textAlign(int align) {
NanoVG.nvgTextAlign(cx, align);
}
public static void fontFaceID(int font) {
NanoVG.nvgFontFaceId(cx, font);
}
public static void fontFace(CharSequence font) {
NanoVG.nvgFontFace(cx, font);
}
public static void text(CharSequence text, float x, float y) {
NanoVG.nvgText(cx,x,y,text);
}
public static void textBox(float x, float y, float breakLine, CharSequence text) {
NanoVG.nvgTextBox(cx,x,y,breakLine,text);
}
public static float textBounds(float x, float y, CharSequence text, FloatBuffer bounds) {
return NanoVG.nvgTextBounds(cx,x,y,text,bounds);
}
public static void textBoxBounds(float x, float y, float breakRowWidth, CharSequence text, FloatBuffer bounds) {
NanoVG.nvgTextBoxBounds(cx,x,y,breakRowWidth,text,bounds);
}
public static int textGlyphPositions(float x, float y, CharSequence text, NVGGlyphPosition.Buffer positions) {
return NanoVG.nvgTextGlyphPositions(cx,x,y,text,positions);
}
public static void textMetrics(FloatBuffer ascend, FloatBuffer descend, FloatBuffer lineh) {
NanoVG.nvgTextMetrics(cx,ascend,descend,lineh);
}
public static int textBreakLines(CharSequence text, float breakRowWidth, NVGTextRow.Buffer rows) {
return NanoVG.nvgTextBreakLines(cx,text,breakRowWidth,rows);
}
}

View File

@ -0,0 +1,248 @@
package net.silentclient.client.nanovg;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.nanovg.NVGColor;
import org.lwjgl.nanovg.NVGPaint;
import org.lwjgl.nanovg.NanoVG;
import org.lwjgl.nanovg.NanoVGGL2;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.EXTFramebufferObject;
import org.lwjgl.opengl.EXTPackedDepthStencil;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.HashMap;
import java.util.function.Consumer;
import static net.silentclient.client.nanovg.NVGWrapper.*;
import static net.silentclient.client.nanovg.NVGHelper.*;
public class UI {
private static UI instancce;
private static boolean initialized = false;
public static HashMap<String, Integer> imagesmap = new HashMap<>();
private long context = -1;
ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft());
public static void init() {
if(!initialized) {
new UI();
initialized = true;
}
}
public static UI get() {
return instancce;
}
private UI() {
instancce = this;
context = NanoVGGL2.nvgCreate(NanoVGGL2.NVG_ANTIALIAS | NanoVGGL2.NVG_STENCIL_STROKES);
NVGWrapper.cx = context;
initFont("icon", "icon.ttf");
}
public void render(Consumer<UI> renderer, float width, float height, float dpi) {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GlStateManager.disableAlpha();
fixDepthStencil();
NVGWrapper.beginFrame(width,height,dpi);
renderer.accept(this);
NVGWrapper.endFrame();
GlStateManager.enableAlpha();
GL11.glPopAttrib();
}
private void fixDepthStencil() {
if(Minecraft.getMinecraft().getFramebuffer().depthBuffer > -1) {
EXTFramebufferObject.glDeleteRenderbuffersEXT(Minecraft.getMinecraft().getFramebuffer().depthBuffer);
int id = EXTFramebufferObject.glGenRenderbuffersEXT();
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, id);
EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, EXTPackedDepthStencil.GL_DEPTH_STENCIL_EXT, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, id);
EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_STENCIL_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, id);
Minecraft.getMinecraft().getFramebuffer().depthBuffer = -1;
}
}
public void rect(float x, float y, float width, float height, Color color) {
NVGColor col = nvgcolor(color);
path(() -> {
NVGWrapper.rect(x, y, width, height);
fillColor(col);
}, DRAW_FILL);
col.free();
}
public void rrect(float x, float y, float width, float height, float radius, Color color) {
NVGColor col = nvgcolor(color);
path(() -> {
NVGWrapper.rrect(x, y, width, height, radius);
fillColor(col);
}, DRAW_FILL);
col.free();
}
public void rrect(float x, float y, float width, float height, float rTL, float rTR, float rBL, float rBR, Color color) {
NVGColor col = nvgcolor(color);
path(() -> {
NVGWrapper.rrect(x, y, width, height, rTL,rTR,rBL,rBR);
fillColor(col);
}, DRAW_FILL);
col.free();
}
public void text(float x, float y, float size, String font, String string, Color color, float blur, Alignment alignment) {
render((vg) -> {
NVGColor col = nvgcolor(color);
path(() -> {
fontBlur(blur);
fontFace(font);
fontSize(size*res.getScaleFactor());
textAlign(alignment.alignment);
fillColor(col);
NVGWrapper.text(string,x*res.getScaleFactor(),y*res.getScaleFactor());
}, -1);
col.free();
}, Display.getWidth(), Display.getHeight(), 1f);
}
public void text(float x, float y, float size, String font, String string, Color color, Alignment alignment) {
text(x,y,size,font,string,color,0,alignment);
}
public void text(float x, float y, float size, String font, String string, Color color) {
text(x,y,size,font,string,color,0,Alignment.LEFT_TOP);
}
public void image(float x, float y, float w, float h, String id, float alpha, float rad) {
render((vg) -> {
NVGPaint paint = NVGPaint.calloc();
NanoVG.nvgImageSize(context, imagesmap.get(id), new int[]{(int)w},new int[]{(int)h});
path(() -> {
imagePattern(x,y,w,h,0,imagesmap.get(id), alpha, paint);
NVGWrapper.rrect(x,y,w,h,rad);
fillPaint(paint);
}, DRAW_FILL);
paint.free();
}, res.getScaledWidth(), res.getScaledHeight(), res.getScaleFactor());
}
public void line(float sx, float sy, float ex, float ey, float w, Color c1, Color c2) {
NVGColor nc1 = nvgcolor(c1);
NVGColor nc2 = nvgcolor(c2);
NVGPaint paint = NVGPaint.create();
linearGradient(sx,sy,ex,ey,nc1,nc2,paint);
path(sx,sy, ()->{
strokeWidth(w);
strokePaint(paint);
lineTo(ex,ey);
}, DRAW_STROKE);
nc1.free();
nc2.free();
}
public void line(float sx, float sy, float ex, float ey, float w, Color color) {
NVGColor nc1 = nvgcolor(color);
path(sx,sy, ()->{
strokeWidth(w);
strokeColor(nc1);
lineTo(ex,ey);
}, DRAW_STROKE);
nc1.free();
}
public void dropShadow(float x, float y, float w, float h, float radius, float spread, Color color) {
NVGColor nvg_color = nvgcolor(color);
NVGColor nvg_transparent = nvgcolor(new Color(0, 0, 0, 0));
NVGPaint shadowPaint = NVGPaint.calloc();
boxGradient(x,y,w,h,radius, spread, nvg_color,nvg_transparent,shadowPaint);
path(() -> {
NVGWrapper.rrect(x-spread,y-spread,w+spread*2,h+spread*2,radius*2);
NVGWrapper.rrect(x,y,w,h,radius);
NVGWrapper.pathWinding(2);
fillPaint(shadowPaint);
}, DRAW_FILL);
shadowPaint.free();
nvg_color.free();
nvg_transparent.free();
}
public void horizontalGrad(float x, float y, float w, float h, float radius, Color from, Color to) {
gradient(x,y,w,h,x,y,x+w,y,radius,from,to);
}
public void verticalGrad(float x, float y, float w, float h, float radius, Color from, Color to) {
gradient(x,y,w,h,x,y,x,y+h,radius,from,to);
}
public void gradient(float x, float y, float w, float h, float startX, float startY, float endX, float endY, float radius, Color from, Color to) {
NVGColor nc1 = nvgcolor(from);
NVGColor nc2 = nvgcolor(to);
NVGPaint paint = NVGPaint.calloc();
linearGradient(startX, startY, endX, endY, nc1, nc2, paint);
path(() -> {
NVGWrapper.rrect(x,y,w,h,radius);
fillPaint(paint);
}, DRAW_FILL);
nc1.free();
nc2.free();
paint.free();
}
public float textWidth(String text, String face, float size) {
float[] bounds = new float[4];
float f = 0;
save();
fontFace(face);
fontSize(size);
f = NanoVG.nvgTextBounds(cx, 0, 0, text, bounds);
restore();
return f;
}
public float textHeight(String face, float size) {
float[] ascender = new float[1];
float[] descender = new float[1];
float[] lineh = new float[1];
fontFace(face);
fontSize(size);
NanoVG.nvgTextMetrics(cx, ascender, descender, lineh);
return lineh[0];
}
public enum Alignment {
LEFT_TOP(NanoVG.NVG_ALIGN_LEFT | NanoVG.NVG_ALIGN_TOP),
CENTER_TOP(NanoVG.NVG_ALIGN_CENTER | NanoVG.NVG_ALIGN_TOP),
RIGHT_TOP(NanoVG.NVG_ALIGN_RIGHT | NanoVG.NVG_ALIGN_TOP),
LEFT_MIDDLE(NanoVG.NVG_ALIGN_LEFT | NanoVG.NVG_ALIGN_MIDDLE),
CENTER_MIDDLE(NanoVG.NVG_ALIGN_CENTER | NanoVG.NVG_ALIGN_MIDDLE),
RIGHT_MIDDLE(NanoVG.NVG_ALIGN_RIGHT | NanoVG.NVG_ALIGN_MIDDLE),
LEFT_BOTTOM(NanoVG.NVG_ALIGN_LEFT | NanoVG.NVG_ALIGN_BOTTOM),
CENTER_BOTTOM(NanoVG.NVG_ALIGN_CENTER | NanoVG.NVG_ALIGN_BOTTOM),
RIGHT_BOTTOM(NanoVG.NVG_ALIGN_RIGHT | NanoVG.NVG_ALIGN_BOTTOM);
private final int alignment;
Alignment(int alignment) {
this.alignment = alignment;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
package net.silentclient.client.utils.io;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import static org.lwjgl.BufferUtils.createByteBuffer;
import static org.lwjgl.system.MemoryUtil.memSlice;
public class BufferUtil {
private static BufferUtil instance = new BufferUtil();
public static BufferUtil get() {
return instance;
}
public ByteBuffer getResourceBytes(ResourceLocation resource, int bufferSize) throws IOException {
ByteBuffer buffer;
InputStream source = Minecraft.getMinecraft().getResourceManager().getResource(resource).getInputStream();
ReadableByteChannel rbc = Channels.newChannel(source);
buffer = createByteBuffer(bufferSize);
while (true) {
int bytes = rbc.read(buffer);
if (bytes == -1) {
break;
}
if (buffer.remaining() == 0) {
ByteBuffer newBuffer = createByteBuffer(buffer.capacity() * 3 / 2);
buffer.flip();
newBuffer.put(buffer);
buffer = newBuffer;
}
}
buffer.flip();
return memSlice(buffer);
}
}

View File

@ -0,0 +1,42 @@
package net.silentclient.client.utils.io;
import org.lwjgl.system.MemoryUtil;
import java.nio.Buffer;
public class LinkedStorage {
private static OBJ head;
public static void put(Object val) {
OBJ newObj = new OBJ(val);
OBJ it = tail(head);
if(it == null) head = newObj;
else it.next = newObj;
}
private static OBJ tail(OBJ head) {
OBJ it;
for (it = head; it != null && it.next != null; it = it.next);
return it;
}
public static void free() {
if(head != null) {
OBJ it;
for (it = head; it.next != null; it = it.next) {
if(it.value instanceof Buffer) {
MemoryUtil.memFree((Buffer) it.value);
}
}
head = null;
}
}
private static class OBJ {
OBJ next;
Object value;
OBJ(Object v) {
value = v;
}
}
}