summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/ChangeAvatarImageButtons.java
blob: 56bd29e5326856f63119bbbfa34e96b0a04cff5a (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
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.console.ImageButtons;
import NET.worlds.console.ImageButtonsCallback;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;

class ChangeAvatarImageButtons extends ImageButtons {
   private static final int textBoxX = 0;
   private static final int textBoxY = 0;
   private static final int textBoxW = 177;
   private static final int textBoxH = 23;
   private static Font font = new Font(Console.message("AvatarFont"), 0, 12);
   private static int textWidth;
   private static int textX;
   private static int textY;
   private String text;

   public ChangeAvatarImageButtons(String texture, Rectangle[] rects, ImageButtonsCallback cb, String text) {
      super(texture, rects, cb);
      this.text = text;
   }

   @Override
   public void paint(Graphics g) {
      super.paint(g);
      g.setFont(font);
      g.setColor(Color.white);
      if (textWidth == 0) {
         FontMetrics fm = g.getFontMetrics();
         textWidth = fm.stringWidth(this.text);
         textX = (177 - textWidth) / 2;
         textY = 23 - (23 - fm.getAscent()) / 2;
      }

      g.drawString(this.text, textX, textY);
   }
}