diff --git a/src/main/java/de/oshgnacknak/gruphi/Canvas.java b/src/main/java/de/oshgnacknak/gruphi/Canvas.java index 634b5f6..2c08aa8 100644 --- a/src/main/java/de/oshgnacknak/gruphi/Canvas.java +++ b/src/main/java/de/oshgnacknak/gruphi/Canvas.java @@ -75,6 +75,19 @@ public class Canvas extends JPanel { r.run(); 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)); + } }); } diff --git a/src/main/java/de/oshgnacknak/gruphi/Drawable.java b/src/main/java/de/oshgnacknak/gruphi/Drawable.java index 628e793..64a3aa7 100644 --- a/src/main/java/de/oshgnacknak/gruphi/Drawable.java +++ b/src/main/java/de/oshgnacknak/gruphi/Drawable.java @@ -23,4 +23,8 @@ public interface Drawable { void translated(double x, double y, Runnable r); void scaled(double scale, Runnable r); + + void text(double x, double y, String text); + + void textSize(int size); }