comparison game/IDMButton.java @ 134:4c0dec72e2f0

Whitespace cosmetic cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 Nov 2011 21:51:54 +0200
parents 881deac2daf8
children d6d92845d6a2
comparison
equal deleted inserted replaced
133:881deac2daf8 134:4c0dec72e2f0
19 static BufferedImage imgUp, imgPressed; 19 static BufferedImage imgUp, imgPressed;
20 Font font; 20 Font font;
21 FontMetrics metrics; 21 FontMetrics metrics;
22 String text; 22 String text;
23 boolean active; 23 boolean active;
24 24
25 public IDMButton(IDMPoint pos, int keyCode, Font font, String text) 25 public IDMButton(IDMPoint pos, int keyCode, Font font, String text)
26 { 26 {
27 super(pos); 27 super(pos);
28 loadImages(); 28 loadImages();
29 setSize(imgUp.getWidth(), imgUp.getHeight()); 29 setSize(imgUp.getWidth(), imgUp.getHeight());
33 this.text = text; 33 this.text = text;
34 34
35 state = State.NORMAL; 35 state = State.NORMAL;
36 active = false; 36 active = false;
37 } 37 }
38 38
39 public IDMButton(float x, float y, int keyCode, Font font, String text) 39 public IDMButton(float x, float y, int keyCode, Font font, String text)
40 { 40 {
41 this(new IDMPoint(x, y), keyCode, font, text); 41 this(new IDMPoint(x, y), keyCode, font, text);
42 } 42 }
43 43
44 private static void loadImages() 44 private static void loadImages()
45 { 45 {
46 if (imgUp != null && imgPressed != null) 46 if (imgUp != null && imgPressed != null)
47 return; 47 return;
48 48
61 } 61 }
62 62
63 public void scale() 63 public void scale()
64 { 64 {
65 } 65 }
66 66
67 public void paint(Graphics2D g) 67 public void paint(Graphics2D g)
68 { 68 {
69 BufferedImage img; 69 BufferedImage img;
70 int xoffs, yoffs; 70 int xoffs, yoffs;
71 71
80 img = imgUp; 80 img = imgUp;
81 } 81 }
82 82
83 if (metrics == null) 83 if (metrics == null)
84 metrics = g.getFontMetrics(font); 84 metrics = g.getFontMetrics(font);
85 85
86 int textWidth = metrics.stringWidth(text); 86 int textWidth = metrics.stringWidth(text);
87 g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null); 87 g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null);
88 88
89 g.setFont(font); 89 g.setFont(font);
90 g.setPaint(Color.black); 90 g.setPaint(Color.black);
91 g.drawString(text, 91 g.drawString(text,
92 getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2, 92 getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2,
93 getScaledY() + yoffs + getScaledHeight() / 2); 93 getScaledY() + yoffs + getScaledHeight() / 2);
94 } 94 }
95 95
96 96
97 public boolean mousePressed(MouseEvent e) 97 public boolean mousePressed(MouseEvent e)
98 { 98 {
99 state = State.PRESSED; 99 state = State.PRESSED;
100 active = true; 100 active = true;
101 return true; 101 return true;