From 8b77b7ac364b579053476f9d6541ddc24904e0c1 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 16 Feb 2009 11:37:48 -0500 Subject: Engine: Tuned Full Screen Mode Now, in full screen mode, the image is no longer stretched strangely, it's simply zoomed to the highest possible value. Plus, when returning to non-full-screen mode, decoration is returned so the X button is available. Refs #14 --- src/com/fourisland/fourpuzzle/Display.java | 31 ++++++++++++++++++- .../fourisland/fourpuzzle/PuzzleApplication.java | 36 +++++++++++++++++----- .../fourpuzzle/window/MessageWindow.java | 2 +- 3 files changed, 59 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index 686bd8e..b29ab01 100755 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java @@ -12,12 +12,14 @@ import com.fourisland.fourpuzzle.transition.Transition; import com.fourisland.fourpuzzle.transition.TransitionDirection; import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; import com.fourisland.fourpuzzle.util.Renderable; +import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.FontFormatException; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Image; +import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.awt.image.VolatileImage; @@ -61,7 +63,13 @@ public class Display { img = vImg; } while (vImg.contentsLost()); - gameFrame.getGraphics().drawImage(img, 0, 0, gameFrame.getWidth(), gameFrame.getHeight(), gameFrame); + Rectangle renderArea = getRenderArea(gameFrame); + gameFrame.getGraphics().setColor(Color.BLACK); + gameFrame.getGraphics().fillRect(0, 0, renderArea.x, gameFrame.getHeight()); + gameFrame.getGraphics().fillRect(0, 0, gameFrame.getWidth(), renderArea.y); + gameFrame.getGraphics().fillRect(renderArea.x+renderArea.width, 0, gameFrame.getWidth()-(renderArea.x+renderArea.width), gameFrame.getHeight()); + gameFrame.getGraphics().fillRect(0, renderArea.y+renderArea.height, gameFrame.getWidth(), gameFrame.getHeight()-(renderArea.y+renderArea.height)); + gameFrame.getGraphics().drawImage(img, renderArea.x, renderArea.y, renderArea.width, renderArea.height, gameFrame); img.flush(); Toolkit.getDefaultToolkit().sync(); @@ -256,4 +264,25 @@ public class Display { return fontMetrics; } + private static Component cacheFrame = null; + private static Rectangle cachePoint = null; + private static Rectangle getRenderArea(Component gameFrame) + { + if ((cacheFrame != null) && (cacheFrame == gameFrame.getParent())) + { + return cachePoint; + } + + float wt = gameFrame.getWidth() / (float) Game.WIDTH; + float ht = gameFrame.getHeight() / (float) Game.HEIGHT; + int width = Math.round(Math.min(wt, ht) * Game.WIDTH); + int height = Math.round(Math.min(wt, ht) * Game.HEIGHT); + int x = (gameFrame.getWidth()/2)-(width/2); + int y = (gameFrame.getHeight()/2)-(height/2); + cacheFrame = gameFrame.getParent(); + cachePoint = new Rectangle(x, y, width, height); + + return cachePoint; + } + } diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java index 8d5e638..13758cb 100755 --- a/src/com/fourisland/fourpuzzle/PuzzleApplication.java +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java @@ -9,11 +9,13 @@ import com.fourisland.fourpuzzle.database.Vocabulary; import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; import com.fourisland.fourpuzzle.util.Interval; import com.fourisland.fourpuzzle.window.SystemGraphic; +import java.awt.Container; import java.awt.GraphicsEnvironment; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.concurrent.Semaphore; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; @@ -29,6 +31,8 @@ public class PuzzleApplication extends Application { public static boolean debugSpeed = false; public static boolean stretchScreen = true; public static boolean gameSleep = false; + private static JDialog gameDialog = new JDialog(new JFrame(), false); + private static Semaphore gameDialogHandler = new Semaphore(1); /** * @param args the command line arguments @@ -36,16 +40,19 @@ public class PuzzleApplication extends Application { public static void main(String[] args) { launch(PuzzleApplication.class, args); } - - @Override - protected void startup() { - INSTANCE = this; + + private void initGameDialog(boolean undecorated) + { + gameDialogHandler.acquireUninterruptibly(); - final JDialog gameDialog = new JDialog(new JFrame(), false); + gameDialog.setVisible(false); + Container contentPane = gameDialog.getContentPane(); + gameDialog = new JDialog(new JFrame(), false); + gameDialog.setContentPane(contentPane); gameDialog.setTitle(Database.getVocab(Vocabulary.Title)); gameDialog.setSize(Game.WIDTH * 2, Game.HEIGHT * 2); gameDialog.setResizable(false); - gameDialog.setUndecorated(true); + gameDialog.setUndecorated(undecorated); gameDialog.setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-Game.WIDTH, GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-Game.HEIGHT); gameDialog.addWindowListener(new WindowAdapter() { @Override @@ -73,8 +80,10 @@ public class PuzzleApplication extends Application { if (stretchScreen) { + initGameDialog(true); GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(gameDialog); } else { + initGameDialog(false); GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null); } } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) @@ -87,7 +96,7 @@ public class PuzzleApplication extends Application { KeyboardInput.getKey().keyInput(e); } } - + @Override public void keyReleased(KeyEvent e) { @@ -101,6 +110,15 @@ public class PuzzleApplication extends Application { }); gameDialog.setVisible(true); + gameDialogHandler.release(); + } + + @Override + protected void startup() { + INSTANCE = this; + + initGameDialog(true); + GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(gameDialog); new Thread(new Runnable() { @@ -122,8 +140,10 @@ public class PuzzleApplication extends Application { Game.getGameState().doGameCycle(); } - + + gameDialogHandler.acquireUninterruptibly(); Display.render(gameDialog.getContentPane()); + gameDialogHandler.release(); } } } catch (RuntimeException ex) { diff --git a/src/com/fourisland/fourpuzzle/window/MessageWindow.java b/src/com/fourisland/fourpuzzle/window/MessageWindow.java index 9ddd379..172ba0d 100644 --- a/src/com/fourisland/fourpuzzle/window/MessageWindow.java +++ b/src/com/fourisland/fourpuzzle/window/MessageWindow.java @@ -161,7 +161,6 @@ public class MessageWindow implements Renderable { g2.drawImage(cacheBase, 0, y, null); - int fw = g2.getFontMetrics().stringWidth(message); int fh = g2.getFontMetrics().getHeight(); int tx = Window.Default.getLeftX(); int ty = Window.Default.getTopY()+fh-(SPACER/2)+y; @@ -178,6 +177,7 @@ public class MessageWindow implements Renderable { for (int i=0;i