From 325f6291557ff38d3992a0fb38a4efbc70aefa58 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 11 Feb 2009 21:49:49 -0500 Subject: Engine: Added global font Converted RM2K's RMG2000.fon to a TrueType font using some long and difficult processes (involving first converting to a .bdf, then to a .ttf). With this standard font included in the package, there will be no worry of strange fonts, as TrueType is a standard. Also, probably because of the size of the new font, the white-tail bug has disappeared. This seems rickety, but because this is the only font that should be used, it should be ok. And if the problem ever arises again, the ticket can be reopened. Fixes #6 and #1. --- src/com/fourisland/fourpuzzle/Display.java | 49 +++++++++++++++++++-- .../fourpuzzle/gamestate/mapview/Map.java | 4 +- .../gamestate/mapview/MapViewGameState.java | 3 +- .../fourisland/fourpuzzle/resources/RMG2000.ttf | Bin 0 -> 70260 bytes .../fourisland/fourpuzzle/window/ChoiceWindow.java | 28 +++++------- .../fourpuzzle/window/MessageWindow.java | 33 +++----------- .../fourpuzzle/window/SystemGraphic.java | 4 +- src/com/fourisland/fourpuzzle/window/Window.java | 3 +- 8 files changed, 71 insertions(+), 53 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/resources/RMG2000.ttf (limited to 'src/com') diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index 5f5a891..85acaf4 100755 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java @@ -11,13 +11,20 @@ import com.fourisland.fourpuzzle.transition.OutTransition; import com.fourisland.fourpuzzle.transition.Transition; import com.fourisland.fourpuzzle.transition.TransitionDirection; import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; +import java.awt.Font; +import java.awt.FontFormatException; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.awt.image.VolatileImage; +import java.io.IOException; +import java.io.InputStream; import java.util.concurrent.CountDownLatch; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.JDialog; +import org.jdesktop.application.ResourceMap; /** * @@ -118,11 +125,11 @@ public class Display { { temp.setPreTransition(midTransition); - postTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + postTransition = Display.createCanvas(Game.WIDTH, Game.HEIGHT); Game.getGameState().render(postTransition.createGraphics()); temp.setPostTransition(postTransition); } else { - BufferedImage preTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + BufferedImage preTransition = Display.createCanvas(Game.WIDTH, Game.HEIGHT); Game.getGameState().render(preTransition.createGraphics()); temp.setPreTransition(preTransition); } @@ -139,11 +146,11 @@ public class Display { { transition.setPreTransition(midTransition); - postTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + postTransition = Display.createCanvas(Game.WIDTH, Game.HEIGHT); Game.getGameState().render(postTransition.createGraphics()); ((InTransition) transition).setPostTransition(postTransition); } else { - BufferedImage preTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + BufferedImage preTransition = Display.createCanvas(Game.WIDTH, Game.HEIGHT); Game.getGameState().render(preTransition.createGraphics()); transition.setPreTransition(preTransition); } @@ -169,4 +176,38 @@ public class Display { return transitionRunning; } + private static Font theFont = null; + private static void initalizeFont() + { + ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceMap(); + InputStream file = rm.getClassLoader().getResourceAsStream("com/fourisland/fourpuzzle/resources/RMG2000.ttf"); + + try { + theFont = Font.createFont(Font.TRUETYPE_FONT, file); + } catch (FontFormatException ex) { + Logger.getLogger(Display.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(Display.class.getName()).log(Level.SEVERE, null, ex); + } + + theFont = theFont.deriveFont(Font.PLAIN, 10); + } + + public static void setFont(Graphics2D g) + { + if (theFont == null) + { + initalizeFont(); + } + + g.setFont(theFont); + } + + public static BufferedImage createCanvas(int width, int height) + { + BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + + return temp; + } + } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index bb40b39..124ea95 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java @@ -214,7 +214,7 @@ public abstract class Map { { if (lowerLayer == null) { - lowerLayer = new BufferedImage(size.width*16, size.height*16, BufferedImage.TYPE_INT_ARGB); + lowerLayer = Display.createCanvas(size.width*16, size.height*16); Graphics2D g = lowerLayer.createGraphics(); ChipSet chipSetObj = ChipSet.getChipSet(chipSet); int i,x,y; @@ -243,7 +243,7 @@ public abstract class Map { { if (upperLayer == null) { - upperLayer = new BufferedImage(size.width*16, size.height*16, BufferedImage.TYPE_INT_ARGB); + upperLayer = Display.createCanvas(size.width*16, size.height*16); Graphics2D g = upperLayer.createGraphics(); ChipSet chipSetObj = ChipSet.getChipSet(chipSet); int i,x,y; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 52a56c4..8f411af 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -8,6 +8,7 @@ package com.fourisland.fourpuzzle.gamestate.mapview; import com.fourisland.fourpuzzle.Audio; import com.fourisland.fourpuzzle.gamestate.*; import com.fourisland.fourpuzzle.Direction; +import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; import com.fourisland.fourpuzzle.Game; import com.fourisland.fourpuzzle.Layer; @@ -206,7 +207,7 @@ public class MapViewGameState implements GameState { g.drawImage(currentMap.renderLower(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); - BufferedImage eventLayer = new BufferedImage(currentMap.getSize().width*16, currentMap.getSize().height*16, BufferedImage.TYPE_INT_ARGB); + BufferedImage eventLayer = Display.createCanvas(currentMap.getSize().width*16, currentMap.getSize().height*16); Graphics2D g2 = eventLayer.createGraphics(); EventList events = currentMap.getEvents(); diff --git a/src/com/fourisland/fourpuzzle/resources/RMG2000.ttf b/src/com/fourisland/fourpuzzle/resources/RMG2000.ttf new file mode 100644 index 0000000..5012ff1 Binary files /dev/null and b/src/com/fourisland/fourpuzzle/resources/RMG2000.ttf differ diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index bf193c1..ca84383 100755 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java @@ -6,9 +6,9 @@ package com.fourisland.fourpuzzle.window; import com.fourisland.fourpuzzle.Audio; +import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.database.Database; import com.fourisland.fourpuzzle.database.Sound; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.TexturePaint; @@ -26,20 +26,18 @@ public class ChoiceWindow { private List choices; int numChoices; boolean center; + private int width; + private int height; + BufferedImage cacheBase; public ChoiceWindow(List choices, boolean center) { this.choices = choices; numChoices = choices.size(); this.center = center; - createGraphic(new BufferedImage(Window.Default.getFullWidth(width), Window.Default.getFullHeight(height), BufferedImage.TYPE_INT_ARGB).createGraphics()); - } - - private int width; - private int height; - BufferedImage cacheBase; - private void createGraphic(Graphics2D g3) - { + Graphics2D g3 = Display.createCanvas(1, 1).createGraphics(); + Display.setFont(g3); + for (String choice : choices) { int l = g3.getFontMetrics().stringWidth(choice); @@ -58,12 +56,12 @@ public class ChoiceWindow { public void render(Graphics2D g2, int x, int y) { - g2.drawImage(cacheBase, x, y, null); + Display.setFont(g2); - g2.setFont(g2.getFont().deriveFont(Font.BOLD)); + g2.drawImage(cacheBase, x, y, null); int fh = g2.getFontMetrics().getHeight(); - int ty = Window.Default.getTopY()+fh-(SPACER/2)+y; + int ty = Window.Default.getTopY()+fh+y; for (String choice : choices) { int fw = g2.getFontMetrics().stringWidth(choice); @@ -76,7 +74,7 @@ public class ChoiceWindow { if (getSelected().equals(choice)) { - g2.drawImage(Window.Selector.getImage(fw-Window.Selector.getLeftX(), fh-Window.Selector.getTopY()), tx-SPACER, ty-fh, null); + g2.drawImage(Window.Selector.getImage(fw-Window.Selector.getLeftX(), fh-Window.Selector.getTopY()), tx-SPACER, ty-fh-SPACER, null); } g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); @@ -84,8 +82,6 @@ public class ChoiceWindow { ty+=(SPACER+g2.getFontMetrics().getHeight()); } - - g2.setFont(g2.getFont().deriveFont(Font.PLAIN)); } public int getWidth() @@ -124,4 +120,4 @@ public class ChoiceWindow { return choices.get(selected); } -} +} \ No newline at end of file diff --git a/src/com/fourisland/fourpuzzle/window/MessageWindow.java b/src/com/fourisland/fourpuzzle/window/MessageWindow.java index ea34ab9..deab252 100644 --- a/src/com/fourisland/fourpuzzle/window/MessageWindow.java +++ b/src/com/fourisland/fourpuzzle/window/MessageWindow.java @@ -5,19 +5,14 @@ package com.fourisland.fourpuzzle.window; +import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.Game; -import java.awt.Font; -import java.awt.FontFormatException; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.TexturePaint; import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; /** * @@ -26,7 +21,7 @@ import java.util.logging.Logger; public class MessageWindow { private static final int SPACER = 4; - private static final int HEIGHT = 4*(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics().getFontMetrics().getHeight()+SPACER); + private static final int HEIGHT = 4*(Display.createCanvas(1, 1).createGraphics().getFontMetrics().getHeight()+SPACER); private List messages; int width; @@ -36,14 +31,14 @@ public class MessageWindow { width = Game.WIDTH - Window.Default.getFullWidth(0); messages = new ArrayList(); - initalizeMessages(message, new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics()); + initalizeMessages(message, Display.createCanvas(1, 1).createGraphics()); cacheBase = Window.Default.getImage(width, HEIGHT); } private void initalizeMessages(String message, Graphics2D g) { - setFont(g); + Display.setFont(g); String temp = message; int len = 0; @@ -79,9 +74,9 @@ public class MessageWindow { { int y = MessageWindowLocation.Bottom.getY(); + Display.setFont(g2); + g2.drawImage(cacheBase, 0, y, null); - - setFont(g2); int fh = g2.getFontMetrics().getHeight(); int ty = Window.Default.getTopY()+fh-(SPACER/2)+y; @@ -97,8 +92,6 @@ public class MessageWindow { ty+=(SPACER+g2.getFontMetrics().getHeight()); } - - g2.setFont(g2.getFont().deriveFont(Font.PLAIN)); } public static enum MessageWindowLocation @@ -118,18 +111,4 @@ public class MessageWindow { return y; } } - - public static void setFont(Graphics2D g) - { - try { - g.setFont(Font.createFont(Font.TRUETYPE_FONT, new File("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf"))); - } catch (FontFormatException ex) { - Logger.getLogger(MessageWindow.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(MessageWindow.class.getName()).log(Level.SEVERE, null, ex); - } - - g.setFont(g.getFont().deriveFont(Font.PLAIN, 10)); - } - } diff --git a/src/com/fourisland/fourpuzzle/window/SystemGraphic.java b/src/com/fourisland/fourpuzzle/window/SystemGraphic.java index a17a83f..75e2b45 100755 --- a/src/com/fourisland/fourpuzzle/window/SystemGraphic.java +++ b/src/com/fourisland/fourpuzzle/window/SystemGraphic.java @@ -5,9 +5,9 @@ package com.fourisland.fourpuzzle.window; +import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.util.ObjectLoader; import com.fourisland.fourpuzzle.util.TransparentPixelFilter; -import com.fourisland.fourpuzzle.window.Window.SystemArea; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.image.BufferedImage; @@ -29,7 +29,7 @@ public class SystemGraphic { public static void initalize() { BufferedImage temp = ObjectLoader.getImage("Picture", filename); - systemGraphic = new BufferedImage(160, 80, BufferedImage.TYPE_INT_ARGB); + systemGraphic = Display.createCanvas(160, 80); systemGraphic.createGraphics().drawImage(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(temp.getRGB(159, 0)))),0,0,null); } diff --git a/src/com/fourisland/fourpuzzle/window/Window.java b/src/com/fourisland/fourpuzzle/window/Window.java index f970b68..db1bfab 100644 --- a/src/com/fourisland/fourpuzzle/window/Window.java +++ b/src/com/fourisland/fourpuzzle/window/Window.java @@ -5,6 +5,7 @@ package com.fourisland.fourpuzzle.window; +import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.util.Interval; import java.awt.Graphics2D; import java.awt.Rectangle; @@ -134,7 +135,7 @@ public enum Window public BufferedImage getImage(int width, int height) { - BufferedImage temp = new BufferedImage(getFullWidth(width), getFullHeight(height), BufferedImage.TYPE_INT_ARGB); + BufferedImage temp = Display.createCanvas(getFullWidth(width), getFullHeight(height)); Graphics2D g = temp.createGraphics(); g.drawImage(getBackground(), 3, 3, getFullWidth(width)-6, getFullHeight(height)-6, null); -- cgit 1.4.1