Skip to content

Commit

Permalink
Visual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Apr 13, 2024
1 parent 0c53557 commit 9e4091c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
public class ContextMenu {
private final List<Option<?>> options = new ArrayList<>(); // The list of options in the context menu
public int x, y;
public int width = 0;
public int width = 0, finalWidth = 0;
public int height = 0;
public int backgroundColor = new Color(107, 112, 126, 124).getRGB();// Semi-transparent light greyish - blue color
public Color backgroundColor = new Color(107, 112, 126, 124);// Semi-transparent light greyish - blue color
public int padding = 5; // The amount of padding around the rectangle
public int heightOffset = 4; // Height offset from the widget
public boolean shouldDisplay = false;
public static boolean drawBorder = true;
protected float scale = 0.0f;

public ContextMenu(int x, int y) {
Expand All @@ -27,35 +28,40 @@ public void addOption(Option<?> option) {
options.add(option);
}

public void render(DrawContext drawContext, int x, int y, int height) {
public void render(DrawContext drawContext, int x, int y, int height, int mouseX, int mouseY) {
this.x = x;
this.y = y + heightOffset + height;
if (!shouldDisplay) return;

update();
DrawHelper.scaleAndPosition(drawContext.getMatrices(), x, y, scale);

int x1 = this.x - 1;
int y1 = this.y;
int x2 = this.x + width;
int y2 = this.y + this.height;

// Draw the background
DrawHelper.drawCutRectangle(drawContext, x1, y1, x2, y2, 0, backgroundColor, 1);
DrawHelper.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), this.x - 1, this.y, this.width, this.height, 2,backgroundColor.getRGB());
if(drawBorder){
DrawHelper.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), this.x - 1,this.y,width + 1,this.height,2,0.7f,backgroundColor.darker().darker().darker().darker().darker().getRGB());
}

int yOffset = y1 + 3;
int yOffset = this.y + 3;
this.width = 10;
for (Option<?> option : options) {
if (!option.shouldRender()) continue;
option.render(drawContext, x + 2, yOffset);
if(isMouseOver(mouseX,mouseY, this.x +1,yOffset-1,this.finalWidth - 2,option.height)){
DrawHelper.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), this.x,yOffset - 1.24f,this.finalWidth - 2,option.height + 0.48f,2,backgroundColor.darker().darker().getRGB());
}
option.render(drawContext, x + 2, yOffset,mouseX,mouseY);
this.width = Math.max(this.width, option.width + padding);
yOffset += option.height + 1;
}
this.width = this.width + 3;
this.height = (yOffset - y1);
this.finalWidth = this.width;
this.height = (yOffset - this.y);

DrawHelper.stopScaling(drawContext.getMatrices());
}
public boolean isMouseOver(int mouseX, int mouseY, int x, int y, int width, int height){
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
}

public void update() {
// Update the scale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public void render(DrawContext drawContext, int x, int y) {
this.x = x;
this.y = y;
}
public void render(DrawContext drawContext, int x, int y,int mouseX, int mouseY) {
this.render(drawContext, x, y);
}

public boolean mouseClicked(double mouseX, double mouseY, int button) {
return isMouseOver(mouseX, mouseY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public void render(DrawContext drawContext, int x, int y) {
this.height = mc.textRenderer.fontHeight;
this.width = mc.textRenderer.getWidth(name) + 12;
drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false);

int shadowOpacity = Math.min(value.getAlpha(),90);
DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
x + width - 8,
y,
8,
8,
2,
value.getRGB(),
90,
shadowOpacity,
1,
1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public SubMenuOption(String name, @NotNull ContextMenu parentMenu, Supplier<Bool
}

@Override
public void render(DrawContext drawContext, int x, int y) {
super.render(drawContext, x, y);
public void render(DrawContext drawContext, int x, int y,int mouseX,int mouseY) {
this.x = x;
this.y = y;

int color = value ? Color.GREEN.getRGB() : Color.RED.getRGB();
drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false);

subMenu.render(drawContext, this.x + parentMenu.width, this.y, 0);
subMenu.render(drawContext, this.x + parentMenu.width, this.y, 0,mouseX, mouseY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onRelease(double mouseX, double mouseY, int button) {
}

public void onDrag(double mouseX, double mouseY, int button) {
if (isDragging && isMouseOver(mouseX, mouseY)) {
if (isDragging) {
alphaHandleY = (int) mouseY - y;
alpha = 1.0f - (alphaHandleY / (float) height);
if (alpha < 0.0f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void render(DrawContext drawContext, int x, int y) {
float handleX = x + hue * width - handleWidth / 2.0f;
float handleY = y - (handleHeight - height) / 2.0f;

DrawHelper.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), handleX, handleY, handleWidth, handleHeight, 2, -1);
DrawHelper.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), handleX, handleY, handleWidth, handleHeight, -1);
drawContext.getMatrices().pop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void renderWidget(DrawContext drawContext, int mouseX, int mouseY) {
drawContext.drawText(mc.textRenderer, text, getX() + 2, getY() + 2, color, shadow);
widgetBox.setSizeAndPosition(getX(), getY(), mc.textRenderer.getWidth(text) + 3, mc.textRenderer.fontHeight + 2, this.shouldScale, GlobalConfig.get().scale);
}
menu.render(drawContext, getX(), getY(), (int) Math.ceil(getHeight()));
menu.render(drawContext, getX(), getY(), (int) Math.ceil(getHeight()),mouseX,mouseY);
}

@Override
Expand Down

0 comments on commit 9e4091c

Please sign in to comment.