summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-02-14 13:19:09 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-02-14 13:19:09 -0500
commit41bc398cfb530ab790f1f7f2e5f3a2c3f0e350c2 (patch)
treece37aa2fd97458c88e702282675c794a5dada6ea /src
parent67890906cf4c4aa2967bdc50cd947335e6fafb5c (diff)
downloadfourpuzzle-41bc398cfb530ab790f1f7f2e5f3a2c3f0e350c2.tar.gz
fourpuzzle-41bc398cfb530ab790f1f7f2e5f3a2c3f0e350c2.tar.bz2
fourpuzzle-41bc398cfb530ab790f1f7f2e5f3a2c3f0e350c2.zip
Engine: Refactored retieval of FontMetrics
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/Display.java22
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/window/ChoiceWindow.java9
-rw-r--r--src/com/fourisland/fourpuzzle/window/MessageWindow.java12
3 files changed, 27 insertions, 16 deletions
diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index 0a9bfe1..a265806 100755 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java
@@ -14,6 +14,7 @@ import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException;
14import com.fourisland.fourpuzzle.util.Renderable; 14import com.fourisland.fourpuzzle.util.Renderable;
15import java.awt.Font; 15import java.awt.Font;
16import java.awt.FontFormatException; 16import java.awt.FontFormatException;
17import java.awt.FontMetrics;
17import java.awt.Graphics2D; 18import java.awt.Graphics2D;
18import java.awt.Image; 19import java.awt.Image;
19import java.awt.Toolkit; 20import java.awt.Toolkit;
@@ -227,6 +228,16 @@ public class Display {
227 g.setFont(theFont); 228 g.setFont(theFont);
228 } 229 }
229 230
231 public static Font getFont()
232 {
233 if (theFont == null)
234 {
235 initalizeFont();
236 }
237
238 return theFont;
239 }
240
230 public static BufferedImage createCanvas(int width, int height) 241 public static BufferedImage createCanvas(int width, int height)
231 { 242 {
232 BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 243 BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
@@ -234,4 +245,15 @@ public class Display {
234 return temp; 245 return temp;
235 } 246 }
236 247
248 private static FontMetrics fontMetrics = null;
249 public static FontMetrics getFontMetrics()
250 {
251 if (fontMetrics == null)
252 {
253 fontMetrics = createCanvas(1, 1).createGraphics().getFontMetrics(getFont());
254 }
255
256 return fontMetrics;
257 }
258
237} 259}
diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index b2a0af7..ef57226 100755 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java
@@ -39,18 +39,15 @@ public class ChoiceWindow implements Renderable {
39 numChoices = choices.size(); 39 numChoices = choices.size();
40 this.center = center; 40 this.center = center;
41 41
42 Graphics2D g3 = Display.createCanvas(1, 1).createGraphics();
43 Display.setFont(g3);
44
45 for (String choice : choices) 42 for (String choice : choices)
46 { 43 {
47 int l = g3.getFontMetrics().stringWidth(choice); 44 int l = Display.getFontMetrics().stringWidth(choice);
48 if (l > getWidth()) 45 if (l > getWidth())
49 { 46 {
50 width = l; 47 width = l;
51 } 48 }
52 49
53 height += g3.getFontMetrics().getHeight() + SPACER; 50 height += Display.getFontMetrics().getHeight() + SPACER;
54 } 51 }
55 52
56 cacheBase = Window.Default.getImage(width, height); 53 cacheBase = Window.Default.getImage(width, height);
@@ -85,7 +82,7 @@ public class ChoiceWindow implements Renderable {
85 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); 82 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh)));
86 g2.drawString(choice, tx, ty); 83 g2.drawString(choice, tx, ty);
87 84
88 ty+=(SPACER+g2.getFontMetrics().getHeight()); 85 ty+=(SPACER+fh);
89 } 86 }
90 } 87 }
91 88
diff --git a/src/com/fourisland/fourpuzzle/window/MessageWindow.java b/src/com/fourisland/fourpuzzle/window/MessageWindow.java index 595fb55..fb90f04 100644 --- a/src/com/fourisland/fourpuzzle/window/MessageWindow.java +++ b/src/com/fourisland/fourpuzzle/window/MessageWindow.java
@@ -28,15 +28,7 @@ import java.util.concurrent.CountDownLatch;
28public class MessageWindow implements Renderable { 28public class MessageWindow implements Renderable {
29 29
30 private static final int SPACER = 4; 30 private static final int SPACER = 4;
31 private static final int HEIGHT; 31 private static final int HEIGHT = (4*(Display.getFontMetrics().getHeight()+SPACER));
32
33 static
34 {
35 BufferedImage d = Display.createCanvas(1, 1);
36 Display.setFont(d.createGraphics());
37
38 HEIGHT = 3*(d.createGraphics().getFontMetrics().getHeight()+SPACER);
39 }
40 32
41 String message; 33 String message;
42 private volatile List<String> messages; 34 private volatile List<String> messages;
@@ -191,7 +183,7 @@ public class MessageWindow implements Renderable {
191 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); 183 g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh)));
192 g2.drawString(message.substring(0, Math.min(toPrint, message.length())), tx, ty); 184 g2.drawString(message.substring(0, Math.min(toPrint, message.length())), tx, ty);
193 185
194 ty+=(SPACER+g2.getFontMetrics().getHeight()); 186 ty+=(SPACER+fh);
195 187
196 toPrint -= Math.min(toPrint, message.length()); 188 toPrint -= Math.min(toPrint, message.length());
197 } 189 }