Permalink
Browse files

Code formattings, added debug info option in Window

  • Loading branch information...
1 parent 01ff5a7 commit 66ff00157c5273d37c7e692e3be5bb2be0479bce @scravy scravy committed Jan 17, 2014
@@ -96,6 +96,8 @@ public static int randomInt() {
*
* This method will return zero if you pass it a value less than one.
*
+ * This method is thread-safe.
+ *
* @param upto
* The maximum number (exclusive).
* @return An integer value between 0 (inclusive) and <code>upto</code>
@@ -111,6 +113,14 @@ public static int randomInt(int upto) {
}
}
+ /**
+ *
+ * This method is thread-safe.
+ *
+ * @param from
+ * @param upto
+ * @return
+ */
public static int randomInt(int from, int upto) {
return randomInt(upto - from) + from;
}
@@ -171,6 +181,8 @@ public static void shuffle(double[] array) {
/**
* Displays a static picture in a single window.
*
+ * You can open multiple windows using this method.
+ *
* @param title
* The title of the displayed window.
* @param width
@@ -199,28 +211,68 @@ public void update(double time, double delta) {
});
}
+ /**
+ * @param title
+ * @param picture
+ * @return
+ */
public static Window displayFullscreen(String title, Picture picture) {
return display(title, 0, 0, picture);
}
- public static Window animate(final String title, int a, int b,
+ /**
+ * Displays an animation in a single window.
+ *
+ * You can open multiple windows using this method.
+ *
+ * @param title
+ * The title of the displayed window.
+ * @param width
+ * The width of the displayed window.
+ * @param height
+ * The height of the displayed window.
+ * @param animation
+ * The animation to be shown in the displayed window.
+ * @return A reference to the newly created window.
+ */
+ public static Window animate(final String title, int width, int height,
final Animation animation) {
- return play(title, a, b, animation);
+ return play(title, width, height, animation);
}
- public static <M> Window animate(final String title, int a, int b,
- final M w, final Renderer<M> r, final UpdateHandler<M> u) {
- return animate(title, a, b, new Animation() {
- M world = w;
+ /**
+ * Displays an animation in a single window.
+ *
+ * You can open multiple windows using this method.
+ *
+ * @see Renderer
+ * @param title
+ * The title of the displayed window.
+ * @param width
+ * The width of the displayed window.
+ * @param height
+ * The height of the displayed window.
+ * @param model
+ * The model (a data object that describes your world).
+ * @param renderer
+ * The renderer that derives a picture from the model.
+ * @param updateHandler
+ * The update handler that updates the model.
+ * @return A reference to the newly created window.
+ */
+ public static <M> Window animate(final String title, int width, int height,
+ final M model, final Renderer<M> renderer,
+ final UpdateHandler<M> updateHandler) {
+ return animate(title, width, height, new Animation() {
@Override
public void update(double time, double delta) {
- u.update(world, time, delta);
+ updateHandler.update(model, time, delta);
}
@Override
public Picture getPicture() {
- return r.render(world);
+ return renderer.render(model);
}
});
}
@@ -251,15 +303,21 @@ public static Window playFullscreen(String title, World world) {
}
/**
- * INTERNAL:
+ * INTERNAL:
*
* @param title
+ * The title of the window to be created.
* @param width
+ * The width of the canvas (not the window).
* @param height
+ * The height of the canvas (not the window).
* @param model
- * @return
+ * The model which is used for rendering (includes a renderer,
+ * update handler, and event handler).
+ * @return A reference to the newly created window.
*/
- static WindowImpl play(final String title, final int width, final int height,
+ static WindowImpl play(final String title, final int width,
+ final int height,
final Model model) {
final WindowImpl window = new WindowImpl();
@@ -272,7 +330,8 @@ public void run() {
final GraphicsDevice device = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
- if ((width <= 0 || height <= 0) && device.isFullScreenSupported()) {
+ if ((width <= 0 || height <= 0)
+ && device.isFullScreenSupported()) {
device.setFullScreenWindow(mainWindow);
} else {
mainWindow.setVisible(true);
@@ -1,48 +1,154 @@
package jazz;
+/**
+ * A Jazz Window - a drawing canvas with a window border, or a fullscreen
+ * canvas.
+ *
+ * The canvas in a Jazz window can be accessed via a coordinate system just like
+ * in mathematics.
+ *
+ * <pre>
+ * (+)
+ * y ^
+ * |
+ * |
+ * |
+ * (-) ------------+------------> x (+)
+ * |
+ * |
+ * |
+ * (-)
+ * </pre>
+ *
+ * @author Julian Fleischer
+ */
public interface Window {
- Window close();
-
- Window title(String title);
-
- Window onClose(Runnable runnable);
-
- Window onShow(Runnable runnable);
-
- Window onHide(Runnable runnable);
-
- Window onActivate(Runnable runnable);
-
- Window onDeactivate(Runnable runnable);
-
- int width();
-
- int height();
-
- int originX();
-
- int originY();
-
- Window originX(int originX);
-
- Window originY(int originY);
-
- Window antiAlias(boolean antialias);
-
- Window maxFps(int maxFps);
-
- Window speed(double acceleration);
-
- double speed();
-
- Window pause();
-
- Window resume();
-
- Window pauseOrUnpause();
-
- double scale();
-
- WindowImpl scale(double scale);
+ /**
+ * @return
+ */
+ Window close();
+
+ /**
+ * @param title
+ * @return
+ */
+ Window title(String title);
+
+ /**
+ * @param runnable
+ * @return
+ */
+ Window onClose(Runnable runnable);
+
+ /**
+ * @param runnable
+ * @return
+ */
+ Window onShow(Runnable runnable);
+
+ /**
+ * @param runnable
+ * @return
+ */
+ Window onHide(Runnable runnable);
+
+ /**
+ * @param runnable
+ * @return
+ */
+ Window onActivate(Runnable runnable);
+
+ /**
+ * @param runnable
+ * @return
+ */
+ Window onDeactivate(Runnable runnable);
+
+ /**
+ * @return
+ */
+ int width();
+
+ /**
+ * @return
+ */
+ int height();
+
+ /**
+ * @return
+ */
+ int originX();
+
+ /**
+ * @return
+ */
+ int originY();
+
+ /**
+ * @param originX
+ * @return this.
+ */
+ Window originX(int originX);
+
+ /**
+ * @param originY
+ * @return this.
+ */
+ Window originY(int originY);
+
+ /**
+ * @param antialias
+ * @return this.
+ */
+ Window antiAlias(boolean antialias);
+
+ /**
+ * @param maxFps
+ * @return this.
+ */
+ Window maxFps(int maxFps);
+
+ /**
+ * @param doShowDebugOutput
+ * @return this.
+ */
+ Window debugOutput(boolean doShowDebugOutput);
+
+ /**
+ * @param acceleration
+ * @return this.
+ */
+ Window speed(double acceleration);
+
+ /**
+ * @return
+ */
+ double speed();
+
+ /**
+ * @return this.
+ */
+ Window pause();
+
+ /**
+ * @return this.
+ */
+ Window resume();
+
+ /**
+ * @return this.
+ */
+ Window pauseOrUnpause();
+
+ /**
+ * @return
+ */
+ double scale();
+
+ /**
+ * @param scale
+ * @return this.
+ */
+ Window scale(double scale);
}
@@ -235,4 +235,14 @@ public WindowImpl resume() {
}
return this;
}
+
+@Override
+public Window debugOutput(boolean doShowDebugOutput) {
+ if (mainWindow != null) {
+ mainWindow.mainPanel.doShowDebugOutput = doShowDebugOutput;
+ }
+ return this;
+}
+
+
}
Oops, something went wrong.

0 comments on commit 66ff001

Please sign in to comment.