From 78f9af78f7966163791737741b0004568f8fdf50 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 8 Feb 2009 12:12:57 -0500 Subject: Added text centering to ChoiceWindow --- .../fourpuzzle/gamestate/TitleScreenGameState.java | 3 +-- src/com/fourisland/fourpuzzle/window/ChoiceWindow.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index 621ec0d..2f5dc97 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -28,8 +28,7 @@ public class TitleScreenGameState implements GameState { { Audio.playMusic(Database.getMusic("Title")); - choices = new ChoiceWindow(Arrays.asList(Database.getVocab("NewGame"), Database.getVocab("LoadGame"), Database.getVocab("EndGame"))); - + choices = new ChoiceWindow(Arrays.asList(Database.getVocab("NewGame"), Database.getVocab("LoadGame"), Database.getVocab("EndGame")), true); wx = (Game.WIDTH/2)-(choices.getWidth()/2); wy = (Game.HEIGHT/4*3)-(choices.getHeight()/2); } diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index ed20ab0..bf7391e 100644 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java @@ -28,10 +28,12 @@ public class ChoiceWindow { private List choices; int numChoices; - public ChoiceWindow(List choices) + boolean center; + public ChoiceWindow(List choices, boolean center) { this.choices = choices; numChoices = choices.size(); + this.center = center; createGraphic(new BufferedImage(TopLeft.getWidth()+getWidth()+TopRight.getWidth(), TopLeft.getHeight()+getHeight()+BottomLeft.getHeight(), BufferedImage.TYPE_INT_ARGB).createGraphics()); } @@ -74,10 +76,16 @@ public class ChoiceWindow { g2.drawImage(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(-25600))), 0, 0, null); g2.setFont(g2.getFont().deriveFont(Font.BOLD)); - int tx = TopLeft.getWidth(); int ty = TopLeft.getHeight()+g2.getFontMetrics().getHeight()-SPACER; for (String choice : choices) { + int tx = TopLeft.getWidth(); + + if (center) + { + tx += ((width/2)-(g2.getFontMetrics().stringWidth(choice)/2)); + } + /* TODO The following code paints the text onto the window. However, * when it paints the lowercase 'y', the tail is white, not the * correct gradient. */ -- cgit 1.4.1