diff --git a/src/main/java/de/oshgnacknak/gruphi/Canvas.java b/src/main/java/de/oshgnacknak/gruphi/Canvas.java index 482e958..634b5f6 100644 --- a/src/main/java/de/oshgnacknak/gruphi/Canvas.java +++ b/src/main/java/de/oshgnacknak/gruphi/Canvas.java @@ -50,6 +50,11 @@ public class Canvas extends JPanel { g.drawLine(round(x1), round(y1), round(x2), round(y2)); } + @Override + public void image(Image image, double x, double y, double w, double h) { + g.drawImage(image, round(x), round(y), round(w), round(h), null); + } + @Override public void rotated(double theta, double x, double y, Runnable r) { g.rotate(theta, x, y); diff --git a/src/main/java/de/oshgnacknak/gruphi/Drawable.java b/src/main/java/de/oshgnacknak/gruphi/Drawable.java index 47f0369..628e793 100644 --- a/src/main/java/de/oshgnacknak/gruphi/Drawable.java +++ b/src/main/java/de/oshgnacknak/gruphi/Drawable.java @@ -16,6 +16,8 @@ public interface Drawable { void line(double x1, double y1, double x2, double y2); + void image(Image image, double x, double y, double w, double h); + void rotated(double theta, double x, double y, Runnable r); void translated(double x, double y, Runnable r); diff --git a/src/main/java/de/oshgnacknak/gruphi/GruphiFrame.java b/src/main/java/de/oshgnacknak/gruphi/GruphiFrame.java index 420edb5..3946597 100644 --- a/src/main/java/de/oshgnacknak/gruphi/GruphiFrame.java +++ b/src/main/java/de/oshgnacknak/gruphi/GruphiFrame.java @@ -2,15 +2,29 @@ package de.oshgnacknak.gruphi; import h07.graph.DirectedGraph; +import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.io.IOException; import java.util.Optional; class GruphiFrame extends JFrame { + private static final Image NUGGET = loadNugget(); + + private static Image loadNugget() { + try { + return ImageIO.read(Gruphi.class.getResourceAsStream("/nugget.png")); + } catch (IOException e) { + e.printStackTrace(); + } + return new BufferedImage(0, 0, BufferedImage.TYPE_INT_RGB); + } + private final DirectedGraph graph; private final MazeGenerator mazeGenerator; @@ -23,6 +37,7 @@ class GruphiFrame extends JFrame { private Node selected = null; private boolean running = true; + private boolean nuggets = false; GruphiFrame(Gruphi gruphi) { super("Gruphi - The Graph GUI - By Osh"); @@ -109,6 +124,10 @@ class GruphiFrame extends JFrame { generateGrid(); } break; + case KeyEvent.VK_N: { + nuggets = !nuggets; + } break; + default: break; } } @@ -240,6 +259,11 @@ class GruphiFrame extends JFrame { for (var node : graph.getAllNodes()) { d.fill(node.color); d.ellipse(node.pos.x, node.pos.y, node.radius * 2, node.radius * 2); + + if (nuggets) { + var r = node.radius * 0.9; + d.image(NUGGET, node.pos.x - r, node.pos.y - r, r*2, r*2); + } } } diff --git a/src/main/resources/nugget.png b/src/main/resources/nugget.png new file mode 100644 index 0000000..b65aa7f Binary files /dev/null and b/src/main/resources/nugget.png differ