-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11441ea
commit 4eb6360
Showing
12 changed files
with
1,466 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
847 changes: 847 additions & 0 deletions
847
src/main/java/com/tanishisherewith/dynamichud/newTrial/helpers/DrawHelper.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
.../java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/options/ColorOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options; | ||
|
||
import com.tanishisherewith.dynamichud.newTrial.helpers.DrawHelper; | ||
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option; | ||
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.coloroption.ColorGradientPicker; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.text.Text; | ||
|
||
import java.awt.*; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
public class ColorOption extends Option<Color> { | ||
public String name = "Empty"; | ||
public boolean isVisible = false; | ||
private ColorGradientPicker colorPicker = null; | ||
public ColorOption(String name, Supplier<Color> getter, Consumer<Color> setter) { | ||
super(getter, setter); | ||
this.name = name; | ||
colorPicker = new ColorGradientPicker(x + this.width + 50,y,value,color-> set(new Color(color)),50,100 ); | ||
} | ||
|
||
@Override | ||
public void render(DrawContext drawContext, int x, int y) { | ||
super.render(drawContext, x, y); | ||
value = get(); | ||
|
||
int color = isVisible ? Color.GREEN.getRGB() : Color.RED.getRGB(); | ||
this.height = mc.textRenderer.fontHeight; | ||
this.width = mc.textRenderer.getWidth(name) + 12; | ||
drawContext.drawText(mc.textRenderer, Text.of(name),x,y, color,false); | ||
DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), | ||
x + width - 8, | ||
y, | ||
8, | ||
8, | ||
2, | ||
value.getRGB(), | ||
90, | ||
1, | ||
1 ); | ||
|
||
colorPicker.render(drawContext,x + this.width + 50,y); | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
if(isMouseOver(mouseX, mouseY)) { | ||
isVisible = !isVisible; | ||
if(isVisible) | ||
{ | ||
colorPicker.setPos(x + this.width + 50,y); | ||
colorPicker.display(); | ||
}else{ | ||
colorPicker.close(); | ||
} | ||
} | ||
colorPicker.mouseClicked(mouseX,mouseY,button); | ||
return super.mouseClicked(mouseX, mouseY, button); | ||
} | ||
|
||
@Override | ||
public boolean mouseReleased(double mouseX, double mouseY, int button) { | ||
colorPicker.mouseReleased(mouseX, mouseY, button); | ||
return super.mouseReleased(mouseX, mouseY, button); | ||
} | ||
|
||
@Override | ||
public boolean mouseDragged(double mouseX, double mouseY, int button) { | ||
colorPicker.mouseDragged(mouseX, mouseY, button); | ||
return super.mouseDragged(mouseX, mouseY, button); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
...rewith/dynamichud/newTrial/utils/contextmenu/options/coloroption/ColorGradientPicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.coloroption; | ||
|
||
import com.tanishisherewith.dynamichud.widget.Widget; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gl.Framebuffer; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.util.GlAllocationUtils; | ||
import org.lwjgl.opengl.GL11; | ||
|
||
import java.awt.*; | ||
import java.nio.ByteBuffer; | ||
import java.util.Arrays; | ||
import java.util.function.Consumer; | ||
|
||
public class ColorGradientPicker { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
private final Consumer<Integer> onColorSelected; // The callback to call when a color is selected | ||
private final GradientSlider gradientSlider; | ||
private final GradientBox gradientBox; | ||
private final ColorPickerButton colorPickerButton; | ||
private int x,y; | ||
private final int boxSize; | ||
private boolean display = false; | ||
|
||
public ColorGradientPicker(int x, int y, Color initialColor, Consumer<Integer> onColorSelected, int boxSize, int colors) { | ||
this.x = x; | ||
this.y = y; | ||
this.onColorSelected = onColorSelected; | ||
float[] hsv = new float[3]; | ||
Color.RGBtoHSB(initialColor.getRed(), initialColor.getGreen(), initialColor.getBlue(), hsv); | ||
this.boxSize = boxSize; | ||
this.gradientSlider = new GradientSlider(x, y, colors, 10); | ||
this.gradientSlider.setHue(hsv[0]); | ||
|
||
this.gradientBox = new GradientBox(x, y + 20, boxSize); | ||
this.gradientBox.setHue(hsv[0]); | ||
this.gradientBox.setSaturation(hsv[1]); | ||
this.gradientBox.setValue(hsv[2]); | ||
this.colorPickerButton = new ColorPickerButton(x + boxSize + 8, y + 20, 35, 20); | ||
} | ||
public void setPos(int x, int y){ | ||
this.x = x; | ||
this.y = y; | ||
} | ||
public void display() { | ||
display = true; | ||
} | ||
public void close() { | ||
display = false; | ||
} | ||
public void tick() { | ||
gradientSlider.tick(); | ||
gradientBox.tick(); | ||
} | ||
public void defaultValues(){ | ||
gradientSlider.defaultValues(); | ||
gradientBox.defaultValues(); | ||
} | ||
|
||
public void render(DrawContext drawContext, int x1, int y1) { | ||
setPos(x1,y1); | ||
if(!display){ | ||
defaultValues(); | ||
return; | ||
} | ||
tick(); | ||
gradientSlider.render(drawContext,x + 30, y +client.textRenderer.fontHeight + 4); | ||
gradientBox.render(drawContext,x + 30, y + client.textRenderer.fontHeight + gradientSlider.getHeight() + 10); | ||
colorPickerButton.render(drawContext,x+ 40 + boxSize,y + client.textRenderer.fontHeight + gradientSlider.getHeight() + 7); | ||
|
||
if (colorPickerButton.isPicking()) { | ||
// Draw the cursor | ||
double mouseX = client.mouse.getX() * client.getWindow().getScaledWidth() / (double) client.getWindow().getWidth(); | ||
double mouseY = client.mouse.getY() * client.getWindow().getScaledHeight() / (double) client.getWindow().getHeight(); | ||
|
||
Framebuffer framebuffer = client.getFramebuffer(); | ||
int x = (int) (mouseX * framebuffer.textureWidth / client.getWindow().getScaledWidth()); | ||
int y = (int) ((client.getWindow().getScaledHeight() - mouseY) * framebuffer.textureHeight / client.getWindow().getScaledHeight()); | ||
|
||
ByteBuffer buffer = GlAllocationUtils.allocateByteBuffer(4); | ||
GL11.glReadPixels(x, y, 1, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); | ||
int red = buffer.get(0) & 0xFF; | ||
int green = buffer.get(1) & 0xFF; | ||
int blue = buffer.get(2) & 0xFF; | ||
|
||
drawContext.fill((int) mouseX + 10, (int) mouseY, (int) mouseX + 26, (int) mouseY + 16, -1); | ||
drawContext.fill((int) mouseX + 11, (int) mouseY + 1, (int) mouseX + 25, (int) mouseY + 15, (red << 16) | (green << 8) | blue | 0xFF000000); | ||
} | ||
} | ||
|
||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
if(!display){ | ||
return false; | ||
} | ||
if (colorPickerButton.onClick(mouseX, mouseY, button)) { | ||
return true; | ||
} else if (gradientSlider.isMouseOver(mouseX, mouseY)) { | ||
gradientSlider.onClick(mouseX, mouseY, button); | ||
gradientBox.setHue(gradientSlider.getHue()); | ||
} else if (gradientBox.isMouseOver(mouseX, mouseY)) { | ||
gradientBox.onClick(mouseX, mouseY, button); | ||
} else if (colorPickerButton.isPicking()) { | ||
Framebuffer framebuffer = client.getFramebuffer(); | ||
int x = (int) (mouseX * framebuffer.textureWidth / client.getWindow().getScaledWidth()); | ||
int y = (int) ((client.getWindow().getScaledHeight() - mouseY) * framebuffer.textureHeight / client.getWindow().getScaledHeight()); | ||
|
||
ByteBuffer buffer = GlAllocationUtils.allocateByteBuffer(4); | ||
GL11.glReadPixels(x, y, 1, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); | ||
int red = buffer.get(0) & 0xFF; | ||
int green = buffer.get(1) & 0xFF; | ||
int blue = buffer.get(2) & 0xFF; | ||
|
||
float[] hsv = Color.RGBtoHSB(red, green, blue, null); | ||
gradientSlider.setHue(hsv[0]); | ||
gradientBox.setHue(hsv[0]); | ||
gradientBox.setSaturation(hsv[1]); | ||
gradientBox.setValue(hsv[2]); | ||
|
||
colorPickerButton.setPicking(false); | ||
} | ||
onColorSelected.accept(gradientBox.getColor()); | ||
return true; | ||
} | ||
|
||
public void mouseReleased(double mouseX, double mouseY, int button) { | ||
gradientSlider.onRelease(mouseX, mouseY, button); | ||
gradientBox.onRelease(mouseX, mouseY, button); | ||
} | ||
|
||
public void mouseDragged(double mouseX, double mouseY, int button) { | ||
if(!display){ | ||
return; | ||
} | ||
gradientSlider.onDrag(mouseX, mouseY, button); | ||
gradientBox.setHue(gradientSlider.getHue()); | ||
gradientBox.onDrag(mouseX, mouseY, button); | ||
onColorSelected.accept(gradientBox.getColor()); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...herewith/dynamichud/newTrial/utils/contextmenu/options/coloroption/ColorPickerButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.coloroption; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
|
||
public class ColorPickerButton { | ||
private int x; | ||
private int y; | ||
private final int width; | ||
private final int height; | ||
private boolean isPicking = false; | ||
|
||
public ColorPickerButton(int x, int y, int width, int height) { | ||
this.x = x; | ||
this.y = y; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public void render(DrawContext drawContext, int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
drawContext.getMatrices().push(); | ||
drawContext.getMatrices().translate(0,0,404); | ||
// Draw the button | ||
drawContext.fill(x + 2, y + 2, x + width - 2, y + height - 2, 0xFFAAAAAA); | ||
drawContext.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer, "Pick", x + width / 2, y + (height - 8) / 2, 0xFFFFFFFF); | ||
drawContext.getMatrices().pop(); | ||
} | ||
|
||
public int getHeight() { | ||
return height; | ||
} | ||
|
||
public boolean onClick(double mouseX, double mouseY, int button) { | ||
if (button == 0) { | ||
if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height) { | ||
isPicking = true; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean isPicking() { | ||
return isPicking; | ||
} | ||
|
||
public void setPicking(boolean picking) { | ||
isPicking = picking; | ||
} | ||
} |
Oops, something went wrong.