summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/Display.java
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-01-17 10:36:37 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-01-17 10:36:37 -0500
commit69b495c392bffe96dab97306a42466edd4b2474e (patch)
tree2adccc01f4027bcb76bbefee03bb6a9622ce3e00 /src/com/fourisland/fourpuzzle/Display.java
parent4c768483aecd687529b9abb48ed42950fabc886f (diff)
downloadfourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.tar.gz
fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.tar.bz2
fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.zip
Imported sources
Diffstat (limited to 'src/com/fourisland/fourpuzzle/Display.java')
-rw-r--r--src/com/fourisland/fourpuzzle/Display.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java new file mode 100644 index 0000000..45e6c22 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/Display.java
@@ -0,0 +1,105 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8import com.fourisland.fourpuzzle.transition.Transition;
9import com.fourisland.fourpuzzle.transition.TransitionCallbackThread;
10import java.awt.Graphics2D;
11import java.awt.Image;
12import java.awt.Toolkit;
13import java.awt.image.VolatileImage;
14import javax.swing.JDialog;
15
16/**
17 *
18 * @author hatkirby
19 */
20public class Display {
21
22 public static int tileAnimationFrame = 0;
23
24 public static void render(JDialog gameFrame) throws Exception
25 {
26 if (enabled)
27 {
28 VolatileImage vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
29 render(gameFrame, vImg);
30
31 Image img = null;
32 do
33 {
34 int returnCode = vImg.validate(gameFrame.getGraphicsConfiguration());
35 if (returnCode == VolatileImage.IMAGE_RESTORED)
36 {
37 render(gameFrame, vImg);
38 } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE)
39 {
40 vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
41 render(gameFrame, vImg);
42 }
43
44 img = vImg;
45 } while (vImg.contentsLost());
46
47 gameFrame.getContentPane().getGraphics().drawImage(img, 0, 0, gameFrame.getContentPane().getWidth(), gameFrame.getContentPane().getHeight(), gameFrame);
48 img.flush();
49 Toolkit.getDefaultToolkit().sync();
50
51 if (tileAnimationFrame == 15)
52 {
53 tileAnimationFrame = 0;
54 } else {
55 tileAnimationFrame++;
56 }
57 }
58 }
59
60 private static void render(JDialog gameFrame, VolatileImage vImg) throws Exception
61 {
62 if (vImg.validate(gameFrame.getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE)
63 {
64 vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
65 }
66
67 Graphics2D g = vImg.createGraphics();
68
69 if (transition != null)
70 {
71 transition.render(g);
72 }
73
74 Game.getGameState().render(g);
75 g.dispose();
76 }
77
78 public static void transition(Transition transition, Runnable callback)
79 {
80 setTransition(transition);
81
82 new Thread(new TransitionCallbackThread(callback)).start();
83 }
84
85 private static Transition transition;
86 public static Transition getTransition()
87 {
88 return transition;
89 }
90 public static void setTransition(Transition transition)
91 {
92 Display.transition = transition;
93 }
94
95 private static boolean enabled = true;
96 public static boolean isEnabled()
97 {
98 return enabled;
99 }
100 public static void setEnabled(boolean aEnabled)
101 {
102 enabled = aEnabled;
103 }
104
105}