diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-02-16 11:37:48 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-02-16 11:37:48 -0500 |
commit | 8b77b7ac364b579053476f9d6541ddc24904e0c1 (patch) | |
tree | 0f68648d4d5715070c9b14459b70a730a02c76db /src | |
parent | 8828c24afa7c11e1c24299f0a445231260cfa508 (diff) | |
download | fourpuzzle-8b77b7ac364b579053476f9d6541ddc24904e0c1.tar.gz fourpuzzle-8b77b7ac364b579053476f9d6541ddc24904e0c1.tar.bz2 fourpuzzle-8b77b7ac364b579053476f9d6541ddc24904e0c1.zip |
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
Diffstat (limited to 'src')
-rwxr-xr-x | src/com/fourisland/fourpuzzle/Display.java | 31 | ||||
-rwxr-xr-x | src/com/fourisland/fourpuzzle/PuzzleApplication.java | 36 | ||||
-rw-r--r-- | src/com/fourisland/fourpuzzle/window/MessageWindow.java | 2 |
3 files changed, 59 insertions, 10 deletions
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; | |||
12 | import com.fourisland.fourpuzzle.transition.TransitionDirection; | 12 | import com.fourisland.fourpuzzle.transition.TransitionDirection; |
13 | import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; | 13 | import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; |
14 | import com.fourisland.fourpuzzle.util.Renderable; | 14 | import com.fourisland.fourpuzzle.util.Renderable; |
15 | import java.awt.Color; | ||
15 | import java.awt.Component; | 16 | import java.awt.Component; |
16 | import java.awt.Font; | 17 | import java.awt.Font; |
17 | import java.awt.FontFormatException; | 18 | import java.awt.FontFormatException; |
18 | import java.awt.FontMetrics; | 19 | import java.awt.FontMetrics; |
19 | import java.awt.Graphics2D; | 20 | import java.awt.Graphics2D; |
20 | import java.awt.Image; | 21 | import java.awt.Image; |
22 | import java.awt.Rectangle; | ||
21 | import java.awt.Toolkit; | 23 | import java.awt.Toolkit; |
22 | import java.awt.image.BufferedImage; | 24 | import java.awt.image.BufferedImage; |
23 | import java.awt.image.VolatileImage; | 25 | import java.awt.image.VolatileImage; |
@@ -61,7 +63,13 @@ public class Display { | |||
61 | img = vImg; | 63 | img = vImg; |
62 | } while (vImg.contentsLost()); | 64 | } while (vImg.contentsLost()); |
63 | 65 | ||
64 | gameFrame.getGraphics().drawImage(img, 0, 0, gameFrame.getWidth(), gameFrame.getHeight(), gameFrame); | 66 | Rectangle renderArea = getRenderArea(gameFrame); |
67 | gameFrame.getGraphics().setColor(Color.BLACK); | ||
68 | gameFrame.getGraphics().fillRect(0, 0, renderArea.x, gameFrame.getHeight()); | ||
69 | gameFrame.getGraphics().fillRect(0, 0, gameFrame.getWidth(), renderArea.y); | ||
70 | gameFrame.getGraphics().fillRect(renderArea.x+renderArea.width, 0, gameFrame.getWidth()-(renderArea.x+renderArea.width), gameFrame.getHeight()); | ||
71 | gameFrame.getGraphics().fillRect(0, renderArea.y+renderArea.height, gameFrame.getWidth(), gameFrame.getHeight()-(renderArea.y+renderArea.height)); | ||
72 | gameFrame.getGraphics().drawImage(img, renderArea.x, renderArea.y, renderArea.width, renderArea.height, gameFrame); | ||
65 | img.flush(); | 73 | img.flush(); |
66 | Toolkit.getDefaultToolkit().sync(); | 74 | Toolkit.getDefaultToolkit().sync(); |
67 | 75 | ||
@@ -256,4 +264,25 @@ public class Display { | |||
256 | return fontMetrics; | 264 | return fontMetrics; |
257 | } | 265 | } |
258 | 266 | ||
267 | private static Component cacheFrame = null; | ||
268 | private static Rectangle cachePoint = null; | ||
269 | private static Rectangle getRenderArea(Component gameFrame) | ||
270 | { | ||
271 | if ((cacheFrame != null) && (cacheFrame == gameFrame.getParent())) | ||
272 | { | ||
273 | return cachePoint; | ||
274 | } | ||
275 | |||
276 | float wt = gameFrame.getWidth() / (float) Game.WIDTH; | ||
277 | float ht = gameFrame.getHeight() / (float) Game.HEIGHT; | ||
278 | int width = Math.round(Math.min(wt, ht) * Game.WIDTH); | ||
279 | int height = Math.round(Math.min(wt, ht) * Game.HEIGHT); | ||
280 | int x = (gameFrame.getWidth()/2)-(width/2); | ||
281 | int y = (gameFrame.getHeight()/2)-(height/2); | ||
282 | cacheFrame = gameFrame.getParent(); | ||
283 | cachePoint = new Rectangle(x, y, width, height); | ||
284 | |||
285 | return cachePoint; | ||
286 | } | ||
287 | |||
259 | } | 288 | } |
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; | |||
9 | import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; | 9 | import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; |
10 | import com.fourisland.fourpuzzle.util.Interval; | 10 | import com.fourisland.fourpuzzle.util.Interval; |
11 | import com.fourisland.fourpuzzle.window.SystemGraphic; | 11 | import com.fourisland.fourpuzzle.window.SystemGraphic; |
12 | import java.awt.Container; | ||
12 | import java.awt.GraphicsEnvironment; | 13 | import java.awt.GraphicsEnvironment; |
13 | import java.awt.event.KeyAdapter; | 14 | import java.awt.event.KeyAdapter; |
14 | import java.awt.event.KeyEvent; | 15 | import java.awt.event.KeyEvent; |
15 | import java.awt.event.WindowAdapter; | 16 | import java.awt.event.WindowAdapter; |
16 | import java.awt.event.WindowEvent; | 17 | import java.awt.event.WindowEvent; |
18 | import java.util.concurrent.Semaphore; | ||
17 | import javax.swing.JDialog; | 19 | import javax.swing.JDialog; |
18 | import javax.swing.JFrame; | 20 | import javax.swing.JFrame; |
19 | import javax.swing.JLabel; | 21 | import javax.swing.JLabel; |
@@ -29,6 +31,8 @@ public class PuzzleApplication extends Application { | |||
29 | public static boolean debugSpeed = false; | 31 | public static boolean debugSpeed = false; |
30 | public static boolean stretchScreen = true; | 32 | public static boolean stretchScreen = true; |
31 | public static boolean gameSleep = false; | 33 | public static boolean gameSleep = false; |
34 | private static JDialog gameDialog = new JDialog(new JFrame(), false); | ||
35 | private static Semaphore gameDialogHandler = new Semaphore(1); | ||
32 | 36 | ||
33 | /** | 37 | /** |
34 | * @param args the command line arguments | 38 | * @param args the command line arguments |
@@ -36,16 +40,19 @@ public class PuzzleApplication extends Application { | |||
36 | public static void main(String[] args) { | 40 | public static void main(String[] args) { |
37 | launch(PuzzleApplication.class, args); | 41 | launch(PuzzleApplication.class, args); |
38 | } | 42 | } |
39 | 43 | ||
40 | @Override | 44 | private void initGameDialog(boolean undecorated) |
41 | protected void startup() { | 45 | { |
42 | INSTANCE = this; | 46 | gameDialogHandler.acquireUninterruptibly(); |
43 | 47 | ||
44 | final JDialog gameDialog = new JDialog(new JFrame(), false); | 48 | gameDialog.setVisible(false); |
49 | Container contentPane = gameDialog.getContentPane(); | ||
50 | gameDialog = new JDialog(new JFrame(), false); | ||
51 | gameDialog.setContentPane(contentPane); | ||
45 | gameDialog.setTitle(Database.getVocab(Vocabulary.Title)); | 52 | gameDialog.setTitle(Database.getVocab(Vocabulary.Title)); |
46 | gameDialog.setSize(Game.WIDTH * 2, Game.HEIGHT * 2); | 53 | gameDialog.setSize(Game.WIDTH * 2, Game.HEIGHT * 2); |
47 | gameDialog.setResizable(false); | 54 | gameDialog.setResizable(false); |
48 | gameDialog.setUndecorated(true); | 55 | gameDialog.setUndecorated(undecorated); |
49 | gameDialog.setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-Game.WIDTH, GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-Game.HEIGHT); | 56 | gameDialog.setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-Game.WIDTH, GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-Game.HEIGHT); |
50 | gameDialog.addWindowListener(new WindowAdapter() { | 57 | gameDialog.addWindowListener(new WindowAdapter() { |
51 | @Override | 58 | @Override |
@@ -73,8 +80,10 @@ public class PuzzleApplication extends Application { | |||
73 | 80 | ||
74 | if (stretchScreen) | 81 | if (stretchScreen) |
75 | { | 82 | { |
83 | initGameDialog(true); | ||
76 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(gameDialog); | 84 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(gameDialog); |
77 | } else { | 85 | } else { |
86 | initGameDialog(false); | ||
78 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null); | 87 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null); |
79 | } | 88 | } |
80 | } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) | 89 | } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) |
@@ -87,7 +96,7 @@ public class PuzzleApplication extends Application { | |||
87 | KeyboardInput.getKey().keyInput(e); | 96 | KeyboardInput.getKey().keyInput(e); |
88 | } | 97 | } |
89 | } | 98 | } |
90 | 99 | ||
91 | @Override | 100 | @Override |
92 | public void keyReleased(KeyEvent e) | 101 | public void keyReleased(KeyEvent e) |
93 | { | 102 | { |
@@ -101,6 +110,15 @@ public class PuzzleApplication extends Application { | |||
101 | }); | 110 | }); |
102 | gameDialog.setVisible(true); | 111 | gameDialog.setVisible(true); |
103 | 112 | ||
113 | gameDialogHandler.release(); | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | protected void startup() { | ||
118 | INSTANCE = this; | ||
119 | |||
120 | initGameDialog(true); | ||
121 | |||
104 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(gameDialog); | 122 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(gameDialog); |
105 | 123 | ||
106 | new Thread(new Runnable() { | 124 | new Thread(new Runnable() { |
@@ -122,8 +140,10 @@ public class PuzzleApplication extends Application { | |||
122 | 140 | ||
123 | Game.getGameState().doGameCycle(); | 141 | Game.getGameState().doGameCycle(); |
124 | } | 142 | } |
125 | 143 | ||
144 | gameDialogHandler.acquireUninterruptibly(); | ||
126 | Display.render(gameDialog.getContentPane()); | 145 | Display.render(gameDialog.getContentPane()); |
146 | gameDialogHandler.release(); | ||
127 | } | 147 | } |
128 | } | 148 | } |
129 | } catch (RuntimeException ex) { | 149 | } 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 { | |||
161 | 161 | ||
162 | g2.drawImage(cacheBase, 0, y, null); | 162 | g2.drawImage(cacheBase, 0, y, null); |
163 | 163 | ||
164 | int fw = g2.getFontMetrics().stringWidth(message); | ||
165 | int fh = g2.getFontMetrics().getHeight(); | 164 | int fh = g2.getFontMetrics().getHeight(); |
166 | int tx = Window.Default.getLeftX(); | 165 | int tx = Window.Default.getLeftX(); |
167 | int ty = Window.Default.getTopY()+fh-(SPACER/2)+y; | 166 | int ty = Window.Default.getTopY()+fh-(SPACER/2)+y; |
@@ -178,6 +177,7 @@ public class MessageWindow implements Renderable { | |||
178 | for (int i=0;i<msgs;i++) | 177 | for (int i=0;i<msgs;i++) |
179 | { | 178 | { |
180 | String message = messages.get(i); | 179 | String message = messages.get(i); |
180 | int fw = g2.getFontMetrics().stringWidth(message); | ||
181 | 181 | ||
182 | g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); | 182 | g2.setPaint(new TexturePaint(SystemGraphic.getTextColor(), new Rectangle(tx, ty, fw, fh))); |
183 | g2.drawString(message.substring(0, Math.min(toPrint, message.length())), tx, ty); | 183 | g2.drawString(message.substring(0, Math.min(toPrint, message.length())), tx, ty); |