diff options
-rw-r--r-- | src/subconscious/graphics/Scene.java | 11 | ||||
-rw-r--r-- | src/subconscious/graphics/widget/Button.java | 19 | ||||
-rw-r--r-- | src/subconscious/graphics/widget/Clickable.java | 7 | ||||
-rw-r--r-- | src/subconscious/graphics/widget/Widget.java | 10 |
4 files changed, 44 insertions, 3 deletions
diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java index 60b9616..cfbdc87 100644 --- a/src/subconscious/graphics/Scene.java +++ b/src/subconscious/graphics/Scene.java @@ -3,6 +3,7 @@ package subconscious.graphics; import subconscious.Game; import subconscious.graphics.widget.Widget; +import subconscious.graphics.widget.Clickable; import java.util.ArrayList; @@ -264,7 +265,15 @@ public abstract class Scene extends JPanel @Override public void keyReleased(KeyEvent e) {} /* mouse listener */ - @Override public void mouseClicked(MouseEvent e) {} + @Override + public void mouseClicked(MouseEvent e) { + for (Widget w : this.widgets) { + if (w instanceof Clickable) { + ((Clickable) w).mouseClick(e.getPoint()); + } + } + } + @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseExited(MouseEvent e) {} @Override public void mousePressed(MouseEvent e) {} diff --git a/src/subconscious/graphics/widget/Button.java b/src/subconscious/graphics/widget/Button.java new file mode 100644 index 0000000..47ba810 --- /dev/null +++ b/src/subconscious/graphics/widget/Button.java @@ -0,0 +1,19 @@ +package subconscious.graphics.widget; + +import java.awt.Graphics2D; +import java.awt.Point; + +public class Button extends Widget implements Clickable { + + public Button(String uniqueName, int x, int y, int width, int height) { + super(uniqueName, x, y, width, height); + } + + public void render(Graphics2D g) { + g.drawRect(0, 0, this.width, this.height); + } + + public void mouseClick(Point mouse) { + + } +}
\ No newline at end of file diff --git a/src/subconscious/graphics/widget/Clickable.java b/src/subconscious/graphics/widget/Clickable.java new file mode 100644 index 0000000..f90c5a8 --- /dev/null +++ b/src/subconscious/graphics/widget/Clickable.java @@ -0,0 +1,7 @@ +package subconscious.graphics.widget; + +import java.awt.Point; + +public interface Clickable { + public void mouseClick(Point position); +}
\ No newline at end of file diff --git a/src/subconscious/graphics/widget/Widget.java b/src/subconscious/graphics/widget/Widget.java index b3bf4e2..31edc9a 100644 --- a/src/subconscious/graphics/widget/Widget.java +++ b/src/subconscious/graphics/widget/Widget.java @@ -1,11 +1,11 @@ package subconscious.graphics.widget; import java.awt.Graphics2D; - +import java.awt.Rectangle; public abstract class Widget { - protected final String UNIQUE_NAME; + public final String UNIQUE_NAME; protected int x, y; protected int width, height; @@ -18,9 +18,15 @@ public abstract class Widget { this.height = height; } + // This render function receives a graphics clipped + // at the widget's coordinates with the widget's size public abstract void render(Graphics2D g); /* accessors */ + public Rectangle getRect() { + return new Rectangle(this.x, this.y, this.width, this.height); + } + public int getX() { return this.x; } public int getY() { return this.y; } public int getWidth() { return this.width; } |