summaryrefslogtreecommitdiff
path: root/NET/worlds/console/SplashCanvas.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/SplashCanvas.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/SplashCanvas.java')
-rw-r--r--NET/worlds/console/SplashCanvas.java126
1 files changed, 126 insertions, 0 deletions
diff --git a/NET/worlds/console/SplashCanvas.java b/NET/worlds/console/SplashCanvas.java
new file mode 100644
index 0000000..9d7d499
--- /dev/null
+++ b/NET/worlds/console/SplashCanvas.java
@@ -0,0 +1,126 @@
+package NET.worlds.console;
+
+import java.awt.Canvas;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.MediaTracker;
+import java.awt.Toolkit;
+import java.util.Vector;
+
+class SplashCanvas extends Canvas {
+ private static final long serialVersionUID = 341168247494647821L;
+ protected String name;
+ protected Image image;
+ protected Dimension dim;
+ protected Vector<Overlay> overlays = new Vector<Overlay>();
+
+ SplashCanvas(String name) {
+ this.name = name;
+ }
+
+ public void flush() {
+ this.image.flush();
+ this.image = null;
+
+ for (int i = 0; i < this.overlays.size(); i++) {
+ Overlay over = this.overlays.elementAt(i);
+ over.flush();
+ }
+
+ this.overlays.removeAllElements();
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+ g.drawImage(this.image, 0, 0, this);
+
+ for (int i = 0; i < this.overlays.size(); i++) {
+ Overlay over = this.overlays.elementAt(i);
+ over.paint(g, this);
+ }
+ }
+
+ public void setImage(String name) {
+ this.name = name;
+ this.image = null;
+ this.imageSize();
+ }
+
+ public void addOverlay(String name, int x, int y) {
+ Overlay over = new Overlay(name, x, y);
+ Dimension dim = over.imageSize(this);
+ this.overlays.addElement(over);
+ this.repaint(x, y, dim.width, dim.height);
+ }
+
+ public void removeOverlay(String name, int x, int y) {
+ for (int i = 0; i < this.overlays.size(); i++) {
+ Overlay over = this.overlays.elementAt(i);
+ if (over.matches(name, x, y)) {
+ Dimension dim = over.imageSize(this);
+ this.overlays.removeElementAt(i);
+ this.repaint(x, y, dim.width, dim.height);
+ return;
+ }
+ }
+ }
+
+ private Dimension imageSize() {
+ if (this.image == null) {
+ this.image = getEarlyImage(this.name, this);
+ if (this.image != null) {
+ int width = this.image.getWidth(this);
+ int height = this.image.getHeight(this);
+ if (width != -1 && height != -1) {
+ return this.dim = new Dimension(width, height);
+ }
+ }
+
+ this.dim = new Dimension(0, 0);
+ }
+
+ for (int i = 0; i < this.overlays.size(); i++) {
+ Overlay over = this.overlays.elementAt(i);
+ over.imageSize(this);
+ }
+
+ return this.dim;
+ }
+
+ public static Image getEarlyImage(String name, Component comp) {
+ for (int pass = 0; pass < 2; pass++) {
+ String imagename = Gamma.earlyURLUnalias(name);
+ Image image = Toolkit.getDefaultToolkit().getImage(imagename);
+ MediaTracker tracker = new MediaTracker(comp);
+ tracker.addImage(image, 0);
+
+ try {
+ tracker.waitForAll();
+ } catch (InterruptedException var7) {
+ }
+
+ if (!tracker.isErrorAny()) {
+ return image;
+ }
+
+ if (pass == 0) {
+ name = "..\\" + name;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Dimension preferredSize() {
+ return this.imageSize();
+ }
+
+ @Override
+ public Dimension minimumSize() {
+ return this.imageSize();
+ }
+}