summaryrefslogtreecommitdiff
path: root/NET/worlds/console/Overlay.java
blob: 237c506d5fb9699b9d1a7fcebf75cbb690d6d9aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package NET.worlds.console;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

class Overlay {
   private String name;
   private int x;
   private int y;
   private Image image;
   private Dimension dim;

   public Overlay(String name, int x, int y) {
      this.name = name;
      this.x = x;
      this.y = y;
      this.image = null;
   }

   public void paint(Graphics g, Component c) {
      if (this.image != null) {
         g.drawImage(this.image, this.x, this.y, c);
      }
   }

   public Dimension imageSize(Component c) {
      if (this.image == null) {
         this.image = SplashCanvas.getEarlyImage(this.name, c);
         if (this.image != null) {
            int width = this.image.getWidth(c);
            int height = this.image.getHeight(c);
            if (width != -1 && height != -1) {
               return this.dim = new Dimension(width, height);
            }
         }

         this.dim = new Dimension(0, 0);
      }

      return this.dim;
   }

   public boolean matches(String name, int x, int y) {
      return x == this.x && y == this.y && name.equals(this.name);
   }

   public void flush() {
      this.image.flush();
      this.image = null;
   }
}