toolbar block icons centred in their 16px box (test for all icons), tutorials say where the objects tab is

This commit is contained in:
MineTec committed 2026-11-07 19:09:39 +01:00
1 parent 52c70e817d
commit 322e36c0f3
7 files changed
+60 -8

No files matched your search

@@ -19,8 +19,8 @@ final class GeoIcons {
private static final Color RED = new Color(0xD93F3F);
static void register() {
Icons.register("prim-box", (g, fg) -> block(g, 2, 5, 12, 8, TOP, SIDE));
Icons.register("prim-platform", (g, fg) -> block(g, 1, 4, 14, 4, TOP, SIDE));
Icons.register("prim-box", (g, fg) -> block(g, 2, 1, 12, 8, TOP, SIDE));
Icons.register("prim-platform", (g, fg) -> block(g, 1, 2.5, 14, 4, TOP, SIDE));
Icons.register("prim-floor", (g, fg) -> {
Path2D p = poly(1, 10, 8, 6.5, 15, 10, 8, 13.5);
g.setColor(TOP);
@@ -47,7 +47,7 @@ final class GeoIcons {
g.setColor(fg);
g.draw(p);
});
Icons.register("prim-pillar", (g, fg) -> block(g, 5, 2, 6, 12, STONE, STONE.darker()));
Icons.register("prim-pillar", (g, fg) -> block(g, 5, 0.5, 6, 12, STONE, STONE.darker()));
Icons.register("prim-cylinder", (g, fg) -> {
g.setColor(STONE.darker());
g.fill(new java.awt.geom.Rectangle2D.Double(2, 6, 12, 5));
@@ -122,7 +122,7 @@ final class GeoIcons {
Icons.register("prim-invbox", (g, fg) -> {
g.setStroke(
new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] {2, 1.5f}, 0));
outlineBlock(g, 2, 5, 12, 8, new Color(255, 60, 60, 60), RED);
outlineBlock(g, 2, 1, 12, 8, new Color(255, 60, 60, 60), RED);
});
Icons.register("geo-collision", (g, fg) -> {
Path2D p = poly(1, 10, 8, 6.5, 15, 10, 8, 13.5);
@@ -221,6 +221,7 @@ final class GeoIcons {
}
/** Isometric block: x, y of the top-left, width w, side height h. */
/** An isometric block filling y .. y + w / 2 + h; keep that within the 16 × 16 icon box. */
private static void block(Graphics2D g, double x, double y, double w, double h, Color top, Color side) {
Color fg = g.getColor();
double d = w / 4;
@@ -40,6 +40,11 @@ public final class Icons {
private Icons() {}
/** Names of all registered icons (sorted). */
public static java.util.List<String> names() {
return PAINTERS.keySet().stream().sorted().toList();
}
public static void register(String name, Painter p) {
PAINTERS.put(name, p);
CACHE.keySet().removeIf(k -> k.startsWith(name + "@"));
@@ -0,0 +1,40 @@
package com.eliasmueller.llamamod.editor.tools.geometry;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.eliasmueller.llamamod.editor.ui.Icons;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
/** Every vector icon stays inside its 16 × 16 box, so toolbar icons line up. */
class IconBoundsTest {
@Test
void iconsStayInsideTheirBox() {
GeoIcons.register();
List<String> outside = new ArrayList<>();
for (String name : Icons.names()) {
BufferedImage img = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = img.createGraphics();
Icons.get(name, 16).paintIcon(null, g, 8, 8);
g.dispose();
int minY = 32, maxY = -1, minX = 32, maxX = -1;
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; x++) {
if ((img.getRGB(x, y) >>> 24) > 40) {
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
minX = Math.min(minX, x);
maxX = Math.max(maxX, x);
}
}
}
if (maxY >= 0 && (minY < 7 || maxY > 24 || minX < 7 || maxX > 24)) {
outside.add(name + " x " + (minX - 8) + ".." + (maxX - 8) + " y " + (minY - 8) + ".." + (maxY - 8));
}
}
assertTrue(outside.isEmpty(), "icons drawn outside their 16x16 box: " + outside);
}
}