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')
-rw-r--r--src/com/fourisland/fourpuzzle/window/ChoiceWindow.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java new file mode 100644 index 0000000..ed20ab0 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java
@@ -0,0 +1,109 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.window;
7
8import com.fourisland.fourpuzzle.util.TransparentPixelFilter;
9import java.awt.Font;
10import java.awt.Toolkit;
11import java.awt.Graphics2D;
12import java.awt.Rectangle;
13import java.awt.TexturePaint;
14import java.awt.image.BufferedImage;
15import java.awt.image.FilteredImageSource;
16import 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
21/**
22 *
23 * @author hatkirby
24 */
25public class ChoiceWindow {
26
27 private final int SPACER = 4;
28
29 private List<String> choices;
30 int numChoices;
31 public ChoiceWindow(List<String> choices)
32 {
33 this.choices = choices;
34 numChoices = choices.size();
35
36 createGraphic(new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB).createGraphics());
37 }
38
39 private int width;
40 private int height;
41 BufferedImage cacheBase;
42 private void createGraphic(Graphics2D g3)
43 {
44 for (String choice : choices)
45 {
46 int l = g3.getFontMetrics().stringWidth(choice);
47 if (l > getWidth())
48 {
49 width = l;
50 }
51
52 height += g3.getFontMetrics().getHeight() + SPACER;
53 }
54
55 width += SPACER*2;
56 height -= SPACER;
57
58 BufferedImage temp = new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB);
59 Graphics2D g = temp.createGraphics();
60
61 g.drawImage(SystemGraphic.getChoiceArea(TopLeft), 0, 0, null);
62 g.drawImage(SystemGraphic.getChoiceArea(Top), TopLeft.getWidth(), 0, getWidth(),Top.getHeight(), null);
63 g.drawImage(SystemGraphic.getChoiceArea(TopRight), TopLeft.getWidth()+getWidth(), 0, null);
64 g.drawImage(SystemGraphic.getChoiceArea(Left), 0, TopLeft.getHeight(), Left.getWidth(),getHeight(), null);
65 g.drawImage(SystemGraphic.getChoiceArea(BottomLeft), 0, TopLeft.getHeight()+getHeight(), null);
66 g.drawImage(SystemGraphic.getChoiceArea(Bottom), BottomLeft.getWidth(), (getHeight()+TopLeft.getHeight()+BottomLeft.getHeight())-Bottom.getHeight(), getWidth(),Bottom.getHeight(), null);
67 g.drawImage(SystemGraphic.getChoiceArea(BottomRight), BottomRight.getWidth()+getWidth(), TopRight.getHeight()+getHeight(), null);
68 g.drawImage(SystemGraphic.getChoiceArea(Right), (getWidth()+TopLeft.getWidth()+TopRight.getWidth())-Right.getWidth(), TopRight.getHeight(), Right.getWidth(),getHeight(), null);
69
70 cacheBase = new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB);
71 Graphics2D g2 = cacheBase.createGraphics();
72
73 g2.drawImage(SystemGraphic.getMessageBackground(), 1, 1, TopLeft.getWidth()+getWidth()+TopRight.getWidth()-2, TopLeft.getHeight()+getHeight()+BottomLeft.getHeight()-2, null);
74 g2.drawImage(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(-25600))), 0, 0, null);
75 g2.setFont(g2.getFont().deriveFont(Font.BOLD));
76
77 int tx = TopLeft.getWidth();
78 int ty = TopLeft.getHeight()+g2.getFontMetrics().getHeight()-SPACER;
79 for (String choice : choices)
80 {
81 /* TODO The following code paints the text onto the window. However,
82 * when it paints the lowercase 'y', the tail is white, not the
83 * correct gradient. */
84
85 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, g2.getFontMetrics().stringWidth(choice),g2.getFontMetrics().getHeight())));
86 g2.drawString(choice, tx, ty);
87
88 ty+=(SPACER+g2.getFontMetrics().getHeight());
89 }
90
91 g2.setFont(g2.getFont().deriveFont(Font.PLAIN));
92 }
93
94 public void render(Graphics2D g2, int x, int y)
95 {
96 g2.drawImage(cacheBase, x, y, null);
97 }
98
99 public int getWidth()
100 {
101 return width;
102 }
103
104 public int getHeight()
105 {
106 return height;
107 }
108
109}