diff options
Diffstat (limited to '')
-rw-r--r-- | src/subconscious/graphics/Scene.java | 20 | ||||
-rw-r--r-- | src/subconscious/graphics/widget/Widget.java | 28 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java index 9d11707..60b9616 100644 --- a/src/subconscious/graphics/Scene.java +++ b/src/subconscious/graphics/Scene.java @@ -2,6 +2,10 @@ package subconscious.graphics; import subconscious.Game; +import subconscious.graphics.widget.Widget; + +import java.util.ArrayList; + import java.awt.Canvas; import java.awt.Graphics2D; import java.awt.Dimension; @@ -43,7 +47,9 @@ public abstract class Scene extends JPanel protected final long DESIRED_FPS = 60; protected final long DESIRED_DELTA_LOOP = (1000*1000*1000)/DESIRED_FPS; - // Game is never be cached in the local thread + protected ArrayList<Widget> widgets = new ArrayList<>(); + + // Game is never cached in the local thread protected volatile Game game; // TODO: this could become a Queue of scenes to load @@ -97,6 +103,17 @@ public abstract class Scene extends JPanel protected abstract void update(long deltaNanoTime); protected abstract void render(Graphics2D g); + protected void renderWidgets(Graphics2D g) { + for (Widget w : this.widgets) { + Graphics2D widgetGraphics = (Graphics2D) g.create( + w.getX(), w.getY(), w.getWidth(), w.getHeight() + ); + + w.render(widgetGraphics); + widgetGraphics.dispose(); + } + } + /* request scenes */ protected synchronized void requestPrevScene() { this.requestedPrevScene = true; @@ -160,6 +177,7 @@ public abstract class Scene extends JPanel do { Graphics2D g = (Graphics2D) this.buffer.getDrawGraphics(); this.render(g); + this.renderWidgets(g); g.dispose(); // repeat if the rendering buffer contents were restored } while (this.buffer.contentsRestored() && running); diff --git a/src/subconscious/graphics/widget/Widget.java b/src/subconscious/graphics/widget/Widget.java new file mode 100644 index 0000000..b3bf4e2 --- /dev/null +++ b/src/subconscious/graphics/widget/Widget.java @@ -0,0 +1,28 @@ +package subconscious.graphics.widget; + +import java.awt.Graphics2D; + + +public abstract class Widget { + + protected final String UNIQUE_NAME; + + protected int x, y; + protected int width, height; + + public Widget(String uniqueName, int x, int y, int width, int height) { + this.UNIQUE_NAME = uniqueName; + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public abstract void render(Graphics2D g); + + /* accessors */ + public int getX() { return this.x; } + public int getY() { return this.y; } + public int getWidth() { return this.width; } + public int getHeight() { return this.height; } +}
\ No newline at end of file |