summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland/fourpuzzle/window/ChoiceWindow.java')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/window/ChoiceWindow.java68
1 files changed, 35 insertions, 33 deletions
diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index 40fff30..3b30acc 100755 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java
@@ -5,18 +5,13 @@
5 5
6package com.fourisland.fourpuzzle.window; 6package com.fourisland.fourpuzzle.window;
7 7
8import com.fourisland.fourpuzzle.util.TransparentPixelFilter; 8import com.fourisland.fourpuzzle.Audio;
9import java.awt.Font; 9import java.awt.Font;
10import java.awt.Toolkit;
11import java.awt.Graphics2D; 10import java.awt.Graphics2D;
12import java.awt.Rectangle; 11import java.awt.Rectangle;
13import java.awt.TexturePaint; 12import java.awt.TexturePaint;
14import java.awt.image.BufferedImage; 13import java.awt.image.BufferedImage;
15import java.awt.image.FilteredImageSource;
16import java.util.List; 14import java.util.List;
17import static com.fourisland.fourpuzzle.window.SystemChoiceArea.*;
18
19/* TODO Find a more elegant way to implement window, it looks terrible now */
20 15
21/** 16/**
22 * 17 *
@@ -35,7 +30,7 @@ public class ChoiceWindow {
35 numChoices = choices.size(); 30 numChoices = choices.size();
36 this.center = center; 31 this.center = center;
37 32
38 createGraphic(new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB).createGraphics()); 33 createGraphic(new BufferedImage(Window.Default.getFullWidth(width), Window.Default.getFullHeight(height), BufferedImage.TYPE_INT_ARGB).createGraphics());
39 } 34 }
40 35
41 private int width; 36 private int width;
@@ -57,36 +52,38 @@ public class ChoiceWindow {
57 width += SPACER*2; 52 width += SPACER*2;
58 height -= SPACER; 53 height -= SPACER;
59 54
60 BufferedImage temp = new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB); 55 cacheBase = new BufferedImage(Window.Default.getFullWidth(width), Window.Default.getFullHeight(height), BufferedImage.TYPE_INT_ARGB);
61 Graphics2D g = temp.createGraphics();
62
63 g.drawImage(SystemGraphic.getChoiceArea(TopLeft), 0, 0, null);
64 g.drawImage(SystemGraphic.getChoiceArea(Top), TopLeft.getWidth(), 0, getWidth(),Top.getHeight(), null);
65 g.drawImage(SystemGraphic.getChoiceArea(TopRight), TopLeft.getWidth()+getWidth(), 0, null);
66 g.drawImage(SystemGraphic.getChoiceArea(Left), 0, TopLeft.getHeight(), Left.getWidth(),getHeight(), null);
67 g.drawImage(SystemGraphic.getChoiceArea(BottomLeft), 0, TopLeft.getHeight()+getHeight(), null);
68 g.drawImage(SystemGraphic.getChoiceArea(Bottom), BottomLeft.getWidth(), (getHeight()+TopLeft.getHeight()+BottomLeft.getHeight())-Bottom.getHeight(), getWidth(),Bottom.getHeight(), null);
69 g.drawImage(SystemGraphic.getChoiceArea(BottomRight), BottomRight.getWidth()+getWidth(), TopRight.getHeight()+getHeight(), null);
70 g.drawImage(SystemGraphic.getChoiceArea(Right), (getWidth()+TopLeft.getWidth()+TopRight.getWidth())-Right.getWidth(), TopRight.getHeight(), Right.getWidth(),getHeight(), null);
71
72 cacheBase = new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB);
73 Graphics2D g2 = cacheBase.createGraphics(); 56 Graphics2D g2 = cacheBase.createGraphics();
74 57
75 g2.drawImage(SystemGraphic.getMessageBackground(), 1, 1, TopLeft.getWidth()+getWidth()+TopRight.getWidth()-2, TopLeft.getHeight()+getHeight()+BottomLeft.getHeight()-2, null); 58 g2.drawImage(SystemGraphic.getMessageBackground(), 1, 1, Window.Default.getFullWidth(width)-2, Window.Default.getFullHeight(height)-2, null);
76 g2.drawImage(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(SystemGraphic.getTransparentColor().getRGB()))), 0, 0, null); 59 g2.drawImage(Window.Default.getImage(width, height), 0, 0, null);
60 }
61
62 public void render(Graphics2D g2, int x, int y)
63 {
64 g2.drawImage(cacheBase, x, y, null);
65
77 g2.setFont(g2.getFont().deriveFont(Font.BOLD)); 66 g2.setFont(g2.getFont().deriveFont(Font.BOLD));
78 67
79 int ty = TopLeft.getHeight()+g2.getFontMetrics().getHeight()-SPACER; 68 int fh = g2.getFontMetrics().getHeight();
69 int ty = Window.Default.getTopY()+fh-SPACER+y;
80 for (String choice : choices) 70 for (String choice : choices)
81 { 71 {
82 int tx = TopLeft.getWidth(); 72 int fw = g2.getFontMetrics().stringWidth(choice);
73 int tx = Window.Default.getLeftX()+x;
83 74
84 if (center) 75 if (center)
85 { 76 {
86 tx += ((width/2)-(g2.getFontMetrics().stringWidth(choice)/2)); 77 tx += ((width/2)-(fw/2));
78 }
79
80 if (getSelected().equals(choice))
81 {
82 g2.drawImage(SystemGraphic.getSelectionBackground(), tx, ty-fh, fw+SPACER-2, fh+SPACER-2, null);
83 g2.drawImage(Window.Selector.getImage(fw-Window.Selector.getLeftX(), fh-Window.Selector.getTopY()), tx-SPACER, ty-fh, null);
87 } 84 }
88 85
89 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, g2.getFontMetrics().stringWidth(choice),g2.getFontMetrics().getHeight()))); 86 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh)));
90 g2.drawString(choice, tx, ty); 87 g2.drawString(choice, tx, ty);
91 88
92 ty+=(SPACER+g2.getFontMetrics().getHeight()); 89 ty+=(SPACER+g2.getFontMetrics().getHeight());
@@ -95,11 +92,6 @@ public class ChoiceWindow {
95 g2.setFont(g2.getFont().deriveFont(Font.PLAIN)); 92 g2.setFont(g2.getFont().deriveFont(Font.PLAIN));
96 } 93 }
97 94
98 public void render(Graphics2D g2, int x, int y)
99 {
100 g2.drawImage(cacheBase, x, y, null);
101 }
102
103 public int getWidth() 95 public int getWidth()
104 { 96 {
105 return width; 97 return width;
@@ -113,12 +105,22 @@ public class ChoiceWindow {
113 int selected = 0; 105 int selected = 0;
114 public void moveUp() 106 public void moveUp()
115 { 107 {
116 selected--; 108 if (selected > 0)
109 {
110 Audio.playSound("Cursor1");
111
112 selected--;
113 }
117 } 114 }
118 115
119 public void moveDown() 116 public void moveDown()
120 { 117 {
121 selected++; 118 if (selected < (choices.size()-1))
119 {
120 Audio.playSound("Cursor1");
121
122 selected++;
123 }
122 } 124 }
123 125
124 public String getSelected() 126 public String getSelected()