summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/Display.java31
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/PuzzleApplication.java36
-rw-r--r--src/com/fourisland/fourpuzzle/window/MessageWindow.java2
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;
12import com.fourisland.fourpuzzle.transition.TransitionDirection; 12import com.fourisland.fourpuzzle.transition.TransitionDirection;
13import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; 13import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException;
14import com.fourisland.fourpuzzle.util.Renderable; 14import com.fourisland.fourpuzzle.util.Renderable;
15import java.awt.Color;
15import java.awt.Component; 16import java.awt.Component;
16import java.awt.Font; 17import java.awt.Font;
17import java.awt.FontFormatException; 18import java.awt.FontFormatException;
18import java.awt.FontMetrics; 19import java.awt.FontMetrics;
19import java.awt.Graphics2D; 20import java.awt.Graphics2D;
20import java.awt.Image; 21import java.awt.Image;
22import java.awt.Rectangle;
21import java.awt.Toolkit; 23import java.awt.Toolkit;
22import java.awt.image.BufferedImage; 24import java.awt.image.BufferedImage;
23import java.awt.image.VolatileImage; 25import 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;
9import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; 9import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState;
10import com.fourisland.fourpuzzle.util.Interval; 10import com.fourisland.fourpuzzle.util.Interval;
11import com.fourisland.fourpuzzle.window.SystemGraphic; 11import com.fourisland.fourpuzzle.window.SystemGraphic;
12import java.awt.Container;
12import java.awt.GraphicsEnvironment; 13import java.awt.GraphicsEnvironment;
13import java.awt.event.KeyAdapter; 14import java.awt.event.KeyAdapter;
14import java.awt.event.KeyEvent; 15import java.awt.event.KeyEvent;
15import java.awt.event.WindowAdapter; 16import java.awt.event.WindowAdapter;
16import java.awt.event.WindowEvent; 17import java.awt.event.WindowEvent;
18import java.util.concurrent.Semaphore;
17import javax.swing.JDialog; 19import javax.swing.JDialog;
18import javax.swing.JFrame; 20import javax.swing.JFrame;
19import javax.swing.JLabel; 21import 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);