Mercurial > hg > ristipolku
comparison game/IDMButton.java @ 178:981a8e20b363
Implement alternative button graphics support.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 16 Mar 2017 10:45:39 +0200 |
parents | 32b1c41e194a |
children | c9b743e32567 |
comparison
equal
deleted
inserted
replaced
177:9f04e8ab180a | 178:981a8e20b363 |
---|---|
14 | 14 |
15 public class IDMButton extends IDMWidget | 15 public class IDMButton extends IDMWidget |
16 { | 16 { |
17 enum State { FOCUSED, PRESSED, NORMAL } | 17 enum State { FOCUSED, PRESSED, NORMAL } |
18 State state; | 18 State state; |
19 static BufferedImage imgOrigUnpressed, imgOrigPressed; | 19 BufferedImage imgOrigUnpressed, imgOrigPressed; |
20 static BufferedImage imgUnpressed, imgPressed; | 20 BufferedImage imgUnpressed, imgPressed; |
21 Font font; | 21 Font font; |
22 FontMetrics metrics; | 22 FontMetrics metrics; |
23 String text; | 23 String text; |
24 boolean active; | 24 boolean active; |
25 | 25 |
26 public IDMButton(IDMPoint pos, int keyCode, Font font, String text) | 26 public IDMButton(IDMPoint pos, String prefix, int keyCode, Font font, String text) |
27 { | 27 { |
28 super(pos); | 28 super(pos); |
29 loadImages(); | 29 loadImages(prefix); |
30 setSize(imgOrigUnpressed.getWidth(), imgOrigUnpressed.getHeight()); | 30 setSize(imgOrigUnpressed.getWidth(), imgOrigUnpressed.getHeight()); |
31 setScale(1, 1); | 31 setScale(1, 1); |
32 | 32 |
33 this.font = font; | 33 this.font = font; |
34 this.keyCode = keyCode; | 34 this.keyCode = keyCode; |
36 | 36 |
37 state = State.NORMAL; | 37 state = State.NORMAL; |
38 active = false; | 38 active = false; |
39 } | 39 } |
40 | 40 |
41 public IDMButton(IDMPoint pos, int keyCode, Font font, String text) | |
42 { | |
43 this(pos, "button1", keyCode, font, text); | |
44 } | |
45 | |
46 public IDMButton(float x, float y, String prefix, int keyCode, Font font, String text) | |
47 { | |
48 this(new IDMPoint(x, y), prefix, keyCode, font, text); | |
49 } | |
50 | |
41 public IDMButton(float x, float y, int keyCode, Font font, String text) | 51 public IDMButton(float x, float y, int keyCode, Font font, String text) |
42 { | 52 { |
43 this(new IDMPoint(x, y), keyCode, font, text); | 53 this(new IDMPoint(x, y), keyCode, font, text); |
44 } | 54 } |
45 | 55 |
46 private static void loadImages() | 56 |
57 public void loadImages(String prefix) | |
47 { | 58 { |
48 if (imgUnpressed != null && imgPressed != null) | |
49 return; | |
50 | |
51 try | 59 try |
52 { | 60 { |
53 ResourceLoader res = new ResourceLoader("graphics/button1_up.png"); | 61 ResourceLoader res = new ResourceLoader("graphics/"+ prefix +"_up.png"); |
54 imgOrigUnpressed = ImageIO.read(res.getStream()); | 62 imgOrigUnpressed = ImageIO.read(res.getStream()); |
55 | 63 |
56 res = new ResourceLoader("graphics/button1_down.png"); | 64 res = new ResourceLoader("graphics/"+ prefix +"_down.png"); |
57 imgOrigPressed = ImageIO.read(res.getStream()); | 65 imgOrigPressed = ImageIO.read(res.getStream()); |
58 } | 66 } |
59 catch (IOException e) | 67 catch (IOException e) |
60 { | 68 { |
61 System.out.print(e.getMessage()); | 69 System.out.print(e.getMessage()); |