fixed rounded rectangle
This commit is contained in:
@@ -73,21 +73,19 @@ public class RenderScope {
|
|||||||
public void drawRoundedCorner(int width, int height, int radius, int color) {
|
public void drawRoundedCorner(int width, int height, int radius, int color) {
|
||||||
int w = width * 20;
|
int w = width * 20;
|
||||||
int h = height * 20;
|
int h = height * 20;
|
||||||
|
|
||||||
for (int y = 0; y < h; y++) {
|
for (int y = 0; y < h; y++) {
|
||||||
int startX;
|
int startX = 0;
|
||||||
|
|
||||||
if (y < radius) {
|
if (y < radius) {
|
||||||
double dy = y - radius;
|
double dy = radius - y - 0.5;
|
||||||
double dx = radius - Math.sqrt(radius * radius - dy * dy);
|
double dx = Math.sqrt(Math.max(0, radius * radius - dy * dy));
|
||||||
startX = (int) Math.ceil(dx);
|
startX = radius - (int) dx;
|
||||||
} else {
|
|
||||||
startX = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.drawRect(startX, y, w - startX, 1, color);
|
this.drawRect(startX, y, w - startX, 1, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawRoundedSide(int cornerWidth, int cornerHeight, int radius, int color) {
|
private void drawRoundedSide(int cornerWidth, int cornerHeight, int radius, int color) {
|
||||||
// Top
|
// Top
|
||||||
@@ -95,7 +93,7 @@ public class RenderScope {
|
|||||||
|
|
||||||
this.matrices.scale(0.05f, 0.05f, 1.0f);
|
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();
|
this.matrices.pop();
|
||||||
|
|
||||||
@@ -108,9 +106,9 @@ public class RenderScope {
|
|||||||
|
|
||||||
this.matrices.translate(0, -cornerWidth, 0);
|
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();
|
this.matrices.pop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,6 @@ public class Button extends Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderScope renderScope) {
|
public void render(RenderScope renderScope) {
|
||||||
int w = 300;
|
renderScope.drawRoundedRectangle(0, 0, width, height, 10, color);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user