Add text capabilities to Drawable

This commit is contained in:
2021-09-05 21:47:45 +02:00
parent bb7b48e6e6
commit da5b0fd5b3
2 changed files with 17 additions and 0 deletions

View File

@ -75,6 +75,19 @@ public class Canvas extends JPanel {
r.run(); r.run();
g.scale(1/scale, 1/scale); g.scale(1/scale, 1/scale);
} }
@Override
public void text(double x, double y, String text) {
FontMetrics metrics = g.getFontMetrics(g.getFont());
int d = metrics.getAscent();
g.drawString(text, round(x), round(y) + d);
}
@Override
public void textSize(int size) {
var f = g.getFont();
g.setFont(new Font(f.getName(), Font.PLAIN, size));
}
}); });
} }

View File

@ -23,4 +23,8 @@ public interface Drawable {
void translated(double x, double y, Runnable r); void translated(double x, double y, Runnable r);
void scaled(double scale, Runnable r); void scaled(double scale, Runnable r);
void text(double x, double y, String text);
void textSize(int size);
} }