Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding in UIs #619

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2cef7d6
First attempt at rounding, not quite perfect
JFronny May 1, 2021
e8600bc
Custom drawing for background outline (fix transparency)
JFronny May 1, 2021
14eba34
Round top bar
JFronny May 1, 2021
2aac4aa
Make TopBarButton with edges default case
JFronny May 1, 2021
b74f5bb
Round Combat and PlayerModel HUD element backgrounds
JFronny May 1, 2021
a218d20
Round flat inventory HUD
JFronny May 11, 2021
9f5540c
Merge branch 'MeteorDevelopment:master' into rounded-ui
JFronny May 11, 2021
f5e847f
Merge branch 'MeteorDevelopment:master' into rounded-ui
JFronny May 20, 2021
186a89d
Expose logic for drawing partial circles
May 20, 2021
db8a9db
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jun 1, 2021
ad58388
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jun 7, 2021
0c4f1aa
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jun 10, 2021
d07e057
Fix
JFronny Jun 10, 2021
543c97f
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jun 11, 2021
c5f98a4
Optimize circlePartOutline
JFronny Jun 11, 2021
fb7c593
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jun 14, 2021
cb0ca2d
Fix
JFronny Jun 14, 2021
b65c5e7
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jun 17, 2021
0a0ec41
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jun 19, 2021
dfc9230
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jul 19, 2021
37cc259
Fix Mesh addition
JFronny Jul 19, 2021
9281345
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Jul 24, 2021
f3fdb37
Remove seams in MeteorWidget.renderBackground
JFronny Jul 24, 2021
8093f10
Merge branch 'master' into rounded-ui
JFronny Jul 26, 2021
9c1cfd3
Merge remote-tracking branch 'origin/master' into rounded-ui
JFronny Aug 21, 2021
1c42070
Update mesh patch for DMA
JFronny Aug 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/minegame159/meteorclient/gui/GuiTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ public WidgetScreen proxiesScreen() {
public abstract boolean categoryIcons();

public abstract boolean blur();

public abstract int roundAmount();

public double textWidth(String text, int length, boolean title) {
return scale(textRenderer().getWidth(text, length) * (title ? TITLE_TEXT_SCALE : 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ public void quad(double x, double y, double width, double height, GuiTexture tex
mbTex.texQuad(x, y, width, height, texture.get(width, height), color);
}

public void quadRounded(double x, double y, double width, double height, Color color, int round, boolean roundTop) {
mb.quadRounded(x, y, width, height, color, round, roundTop);
}
public void quadRounded(double x, double y, double width, double height, Color color, int round) {
quadRounded(x, y, width, height, color, round, true);
}
public void quadRounded(WWidget widget, Color color, int round) {
quadRounded(widget.x, widget.y, widget.width, widget.height, color, round);
}
public void quadOutlineRounded(double x, double y, double width, double height, Color color, int round, double s) {
mb.quadRoundedOutline(x, y, width, height, color, round, s);
}
public void quadOutlineRounded(WWidget widget, Color color, int round, double s) {
quadOutlineRounded(widget.x, widget.y, widget.width, widget.height, color, round, s);
}
public void quadRoundedSide(double x, double y, double width, double height, Color color, int r, boolean right) {
mb.quadRoundedSide(x, y, width, height, color, r, right);
}
public void quadRoundedSide(WWidget widget, Color color, int round, boolean right) {
quadRoundedSide(widget.x, widget.y, widget.width, widget.height, color, round, right);
}

public void rotatedQuad(double x, double y, double width, double height, double rotation, GuiTexture texture, Color color) {
TextureRegion region = texture.get(width, height);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public class MeteorGuiTheme extends GuiTheme {
.build()
);

public final Setting<Integer> round = sgGeneral.add(new IntSetting.Builder()
.name("round")
.description("How much windows should be rounded")
.defaultValue(0)
.min(0)
.max(20)
.sliderMin(0)
.sliderMax(15)
.build()
);

// Colors

public final Setting<SettingColor> accentColor = color("accent", "Main color of the GUI.", new SettingColor(135, 0, 255));
Expand Down Expand Up @@ -294,6 +305,11 @@ public boolean blur() {
return blur.get();
}

@Override
public int roundAmount() {
return round.get();
}

public class ThreeStateColorSetting {
private final Setting<SettingColor> normal, hovered, pressed;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ default MeteorGuiTheme theme() {

default void renderBackground(GuiRenderer renderer, WWidget widget, boolean pressed, boolean mouseOver) {
MeteorGuiTheme theme = theme();
double s = theme.scale(2);

renderer.quad(widget.x + s, widget.y + s, widget.width - s * 2, widget.height - s * 2, theme.backgroundColor.get(pressed, mouseOver));

int r = theme.roundAmount();
Color outlineColor = theme.outlineColor.get(pressed, mouseOver);
renderer.quad(widget.x, widget.y, widget.width, s, outlineColor);
renderer.quad(widget.x, widget.y + widget.height - s, widget.width, s, outlineColor);
renderer.quad(widget.x, widget.y + s, s, widget.height - s * 2, outlineColor);
renderer.quad(widget.x + widget.width - s, widget.y + s, s, widget.height - s * 2, outlineColor);
renderer.quadRounded(widget, theme.backgroundColor.get(pressed, mouseOver), r);
renderer.quadOutlineRounded(widget, outlineColor, r, theme.scale(2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package minegame159.meteorclient.gui.themes.meteor.widgets;

import minegame159.meteorclient.gui.renderer.GuiRenderer;
import minegame159.meteorclient.gui.themes.meteor.MeteorWidget;
import minegame159.meteorclient.gui.widgets.WQuad;
import minegame159.meteorclient.utils.render.color.Color;

Expand All @@ -16,6 +17,6 @@ public WMeteorQuad(Color color) {

@Override
protected void onRender(GuiRenderer renderer, double mouseX, double mouseY, double delta) {
renderer.quad(x, y, width, height, color);
renderer.quadRounded(x, y, width, height, color, theme.roundAmount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ protected WHeader header() {
@Override
protected void onRender(GuiRenderer renderer, double mouseX, double mouseY, double delta) {
if (expanded || animProgress > 0) {
renderer.quad(x, y + header.height, width, height - header.height, theme().backgroundColor.get());
renderer.quadRounded(x, y + header.height / 2, width, height - header.height / 2, theme().backgroundColor.get(), theme.roundAmount(), false);
}
}

private class WMeteorHeader extends WHeader {
@Override
protected void onRender(GuiRenderer renderer, double mouseX, double mouseY, double delta) {
renderer.quad(this, theme().accentColor.get());
renderer.quadRounded(this, theme().accentColor.get(), theme.roundAmount());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected void onRender(GuiRenderer renderer, double mouseX, double mouseY, doub

if (animProgress > 0) {
double cs = (width - theme.scale(2)) / 1.75 * animProgress;
renderer.quad(x + (width - cs) / 2, y + (height - cs) / 2, cs, cs, theme.checkboxColor.get());
renderer.quadRounded(x + (width - cs) / 2, y + (height - cs) / 2, cs, cs, theme.checkboxColor.get(), theme.roundAmount());
}
}
}
25 changes: 24 additions & 1 deletion src/main/java/minegame159/meteorclient/gui/widgets/WTopBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public void init() {
}
}

protected int getState(WTopBarButton btn) {
int a = 0;
if (btn.equals(cells.get(0).widget()))
a |= 1;
if (btn.equals(cells.get(cells.size() - 1).widget()))
a |= 2;
return a;
}

protected class WTopBarButton extends WPressable {
private final Tab tab;

Expand Down Expand Up @@ -66,7 +75,21 @@ protected void onRender(GuiRenderer renderer, double mouseX, double mouseY, doub
double pad = pad();
Color color = getButtonColor(pressed || (mc.currentScreen instanceof TabScreen && ((TabScreen) mc.currentScreen).tab == tab), mouseOver);

renderer.quad(x, y, width, height, color);
//renderer.quad(x, y, width, height, color);
switch (getState(this)) {
case 1:
renderer.quadRoundedSide(this, color, theme.roundAmount(), false);
break;
case 2:
renderer.quadRoundedSide(this, color, theme.roundAmount(), true);
break;
case 3:
renderer.quadRounded(this, color, theme.roundAmount());
break;
default:
renderer.quad(this, color);
break;
}
renderer.text(tab.name, x + pad, y + pad, getNameColor(), false);
}
}
Expand Down
127 changes: 127 additions & 0 deletions src/main/java/minegame159/meteorclient/rendering/MeshBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,133 @@ public void boxSides(double x1, double y1, double z1, double x2, double y2, doub
if (Dir.is(excludeDir, Dir.EAST)) quad(x2, y1, z1, x2, y2, z1, x2, y2, z2, x2, y1, z2, color); // Right
}

// Rounded quad

public void quadRoundedOutline(double x, double y, double width, double height, Color color, int r, double s) {
r = getR(r, width, height);
if (r == 0) {
quad(x, y, width, s, color);
quad(x, y + height - s, width, s, color);
quad(x, y + s, s, height - s * 2, color);
quad(x + width - s, y + s, s, height - s * 2, color);
}
else {
int cirDepth = getCir(r);
//top
quarterCircleOutline(x + r, y + r, r, 3, cirDepth, color, s);
quad(x + r, y, width - r * 2, s, color);
quarterCircleOutline(x + width - r, y + r, r, 0, cirDepth, color, s);
//middle
quad(x, y + r, s, height - r * 2, color);
quad(x + width - s, y + r, s, height - r * 2, color);
//bottom
quarterCircleOutline(x + width - r, y + height - r, r, 1, cirDepth, color, s);
quad(x + r, y + height - s, width - r * 2, s, color);
quarterCircleOutline(x + r, y + height - r, r, 2, cirDepth, color, s);
}
}

public void quadRounded(double x, double y, double width, double height, Color color, int r, boolean roundTop) {
r = getR(r, width, height);
if (r == 0)
quad(x, y, width, height, color);
else {
int cirDepth = getCir(r);
if (roundTop) {
//top
quarterCircle(x + r, y + r, r, 3, cirDepth, color);
quad(x + r, y, width - 2 * r, r, color);
quarterCircle(x + width - r, y + r, r, 0, cirDepth, color);
//middle
quad(x, y + r, width, height - 2 * r, color);
}
else {
//middle
quad(x, y, width, height - r, color);
}
//bottom
quarterCircle(x + width - r, y + height - r, r, 1, cirDepth, color);
quad(x + r, y + height - r, width - 2 * r, r, color);
quarterCircle(x + r, y + height - r, r, 2, cirDepth, color);
}
}

public void quadRoundedSide(double x, double y, double width, double height, Color color, int r, boolean right) {
r = getR(r, width, height);
if (r == 0)
quad(x, y, width, height, color);
else {
int cirDepth = getCir(r);
if (right) {
quarterCircle(x + width - r, y + r, r, 0, cirDepth, color);
quarterCircle(x + width - r, y + height - r, r, 1, cirDepth, color);
quad(x, y, width - r, height, color);
quad(x + width - r, y + r, r, height - r * 2, color);
}
else {
quarterCircle(x + r, y + r, r, 3, cirDepth, color);
quarterCircle(x + r, y + height - r, r, 2, cirDepth, color);
quad(x + r, y, width - r, height, color);
quad(x, y + r, r, height - r * 2, color);
}
}
}

private int getR(int r, double w, double h) {
if (r * 2 > h) {
r = (int)h / 2;
}
if (r * 2 > w) {
r = (int)w / 2;
}
return r;
}

private int getCir(int r) {
return Math.max(r / 2, 1);
}

private void quarterCircle(double x, double y, double r, double a, int cirDepth, Color color) {
a *= Math.PI / 2;
double cirPart = Math.PI / 2 / cirDepth;
vert2(x + Math.sin(a) * r, y - Math.cos(a) * r, color);
for (int i = 1; i < cirDepth + 1; i++) {
vert2(x, y, color);
double xV = x + Math.sin(a + cirPart * i) * r;
double yV = y - Math.cos(a + cirPart * i) * r;
vert2(xV, yV, color);
if (i != cirDepth)
vert2(xV, yV, color);
}
}

private void quarterCircleOutline(double x, double y, double r, double a, int cirDepth, Color color, double s) {
a *= Math.PI / 2;
double cirPart = Math.PI / 2 / cirDepth;
for (int i = 0; i < cirDepth; i++) {
double xOC = x + Math.sin(a + cirPart * i) * r;
double yOC = y - Math.cos(a + cirPart * i) * r;
double xIC = x + Math.sin(a + cirPart * i) * (r - s);
double yIC = y - Math.cos(a + cirPart * i) * (r - s);
double xON = x + Math.sin(a + cirPart * (i + 1)) * r;
double yON = y - Math.cos(a + cirPart * (i + 1)) * r;
double xIN = x + Math.sin(a + cirPart * (i + 1)) * (r - s);
double yIN = y - Math.cos(a + cirPart * (i + 1)) * (r - s);
//
vert2(xOC, yOC, color);
vert2(xON, yON, color);
vert2(xIC, yIC, color);
//
vert2(xIC, yIC, color);
vert2(xON, yON, color);
vert2(xIN, yIN, color);
}
}

public void vert2(double x, double y, Color c) {
pos(x, y, 0).color(c).endVertex();
}

// LINES

public void line(double x1, double y1, double z1, double x2, double y2, double z2, Color startColor, Color endColor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package minegame159.meteorclient.systems.modules.render.hud;

import minegame159.meteorclient.gui.GuiThemes;
import minegame159.meteorclient.rendering.text.TextRenderer;
import minegame159.meteorclient.utils.render.color.Color;

Expand Down Expand Up @@ -46,4 +47,8 @@ public double textHeight() {
public void addPostTask(Runnable runnable) {
postTasks.add(runnable);
}

public int roundAmount() {
return GuiThemes.get().roundAmount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void render(HudRenderer renderer) {

// Background
Renderer.NORMAL.begin(null, DrawMode.Triangles, VertexFormats.POSITION_COLOR);
Renderer.NORMAL.quad(x, y, box.width, box.height, backgroundColor.get());
Renderer.NORMAL.quadRounded(x, y, box.width, box.height, backgroundColor.get(), renderer.roundAmount(), true);
Renderer.NORMAL.end();

// Player Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package minegame159.meteorclient.systems.modules.render.hud.modules;

import com.mojang.blaze3d.systems.RenderSystem;
import minegame159.meteorclient.gui.GuiThemes;
import minegame159.meteorclient.rendering.DrawMode;
import minegame159.meteorclient.rendering.Matrices;
import minegame159.meteorclient.rendering.Renderer;
Expand Down Expand Up @@ -103,7 +104,7 @@ private void drawBackground(int x, int y) {
break;
case Flat:
Renderer.NORMAL.begin(null, DrawMode.Triangles, VertexFormats.POSITION_COLOR);
Renderer.NORMAL.quad(x, y, w, h, color.get());
Renderer.NORMAL.quadRounded(x, y, w, h, color.get(), GuiThemes.get().roundAmount(), true);
Renderer.NORMAL.end();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void render(HudRenderer renderer) {

if (background.get()) {
Renderer.NORMAL.begin(null, DrawMode.Triangles, VertexFormats.POSITION_COLOR);
Renderer.NORMAL.quad(x, y, box.width, box.height, backgroundColor.get());
Renderer.NORMAL.quadRounded(x, y, box.width, box.height, backgroundColor.get(), renderer.roundAmount(), true);
Renderer.NORMAL.end();
}

Expand Down