From 404838b70d54974e484e60bd3d85db2eab3b3eb7 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Mon, 21 Apr 2025 17:18:23 +0200 Subject: [PATCH] fixed rounded rectangle --- .../org/saturnclient/ui2/RenderScope.java | 24 +++++++++---------- .../org/saturnclient/ui2/elements/Button.java | 7 +----- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/saturnclient/ui2/RenderScope.java b/src/main/java/org/saturnclient/ui2/RenderScope.java index bd7ebe3..852704d 100644 --- a/src/main/java/org/saturnclient/ui2/RenderScope.java +++ b/src/main/java/org/saturnclient/ui2/RenderScope.java @@ -73,21 +73,19 @@ public class RenderScope { public void drawRoundedCorner(int width, int height, int radius, int color) { int w = width * 20; int h = height * 20; - + for (int y = 0; y < h; y++) { - int startX; - + int startX = 0; + if (y < radius) { - double dy = y - radius; - double dx = radius - Math.sqrt(radius * radius - dy * dy); - startX = (int) Math.ceil(dx); - } else { - startX = 0; + double dy = radius - y - 0.5; + double dx = Math.sqrt(Math.max(0, radius * radius - dy * dy)); + startX = radius - (int) dx; } - + this.drawRect(startX, y, w - startX, 1, color); } - } + } private void drawRoundedSide(int cornerWidth, int cornerHeight, int radius, int color) { // Top @@ -95,7 +93,7 @@ public class RenderScope { this.matrices.scale(0.05f, 0.05f, 1.0f); - this.drawRoundedCorner(cornerWidth, cornerHeight, radius * 3, color); + this.drawRoundedCorner(cornerWidth, cornerHeight, radius * 10, color); this.matrices.pop(); @@ -108,9 +106,9 @@ public class RenderScope { this.matrices.translate(0, -cornerWidth, 0); - this.matrices.scale(0.1f, 0.1f, 1.0f); + this.matrices.scale(0.05f, 0.05f, 1.0f); - this.drawRoundedCorner(cornerHeight, cornerWidth, radius * 3, color); + this.drawRoundedCorner(cornerHeight, cornerWidth, radius * 10, color); this.matrices.pop(); } diff --git a/src/main/java/org/saturnclient/ui2/elements/Button.java b/src/main/java/org/saturnclient/ui2/elements/Button.java index 26db6e6..0527445 100644 --- a/src/main/java/org/saturnclient/ui2/elements/Button.java +++ b/src/main/java/org/saturnclient/ui2/elements/Button.java @@ -19,11 +19,6 @@ public class Button extends Element { @Override public void render(RenderScope renderScope) { - int w = 300; - int h = 100; - - renderScope.drawRect(0, h, w, h, color); - renderScope.drawRect(w, 0, w, h, color); - renderScope.drawRoundedRectangle(0, 0, w, h, 80, 0xFF000000); + renderScope.drawRoundedRectangle(0, 0, width, height, 10, color); } }