gamingtools
Class GraphicsSource

java.lang.Object
  |
  +--gamingtools.GraphicsSource

public final class GraphicsSource
extends Object

The GraphicsSource class provides methods for entering and exiting full-screen exclusive mode and for registering for animation frame rendering callbacks. All of the methods of this class are static.


Field Summary
static WindowAdapter DEFAULT_WINDOW_LISTENER
          Used when the application runs in a window instead of full-screen exclusive mode.
 
Method Summary
static void clearRenderListener()
          Unregisters the RenderListener if there is one.
static void enterDisplayMode(int width, int height)
          Attempts to enter full-screen exclusive mode with the specified screen dimensions.
static void exitDisplayMode()
          Restores the display mode back to normal and stops the animation.
static int getBufferHeight()
          Obtains the height of the buffers.
static int getBufferWidth()
          Obtains the width of the buffers.
static ExceptionHandler getExceptionHandler()
          Obtains the ExceptionHandler used when an exception is thrown in the animation loop thread.
static Frame getFrame()
          Obtains the Frame used as the full-screen window.
static boolean isPageFlipping()
          Returns whether or not page flipping is used as the double-buffer strategy.
static void setExceptionHandler(ExceptionHandler exceptionHandler)
          Sets the ExceptionHandler used when an exception is thrown in the animation loop thread.
static void setRenderListener(RenderListener renderListener)
          Sets the RenderListener used for generating animation frames.
static void startAnimation(int framesPerSecond)
          Starts the animation loop.
static void startAnimation(int framesPerSecond, int maxFrameSkips)
          Starts the animation loop.
static void stopAnimation()
          Stops the animation loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_WINDOW_LISTENER

public static final WindowAdapter DEFAULT_WINDOW_LISTENER
Used when the application runs in a window instead of full-screen exclusive mode. This listener exits the program.

Method Detail

setRenderListener

public static void setRenderListener(RenderListener renderListener)

Sets the RenderListener used for generating animation frames.

This method invokes init() on a different thread than the calling thread. This enables init() to perform blocking calls, such as loading images and sounds, while an animation continues to run. After init() completes, GraphicsSource switches over to the specified RenderListener.

Parameters:
renderListener - RenderListener used for generating animation frames. Or, null to switch back to the default RenderListener. The default RenderListener simply paints the buffers completely black.
See Also:
clearRenderListener()

clearRenderListener

public static void clearRenderListener()
Unregisters the RenderListener if there is one. This method is equivalent to passing null to setRenderListener().

See Also:
setRenderListener(RenderListener)

startAnimation

public static void startAnimation(int framesPerSecond)
Starts the animation loop.

Parameters:
framesPerSecond - The apparent frame rate in fps.

startAnimation

public static void startAnimation(int framesPerSecond,
                                  int maxFrameSkips)
Starts the animation loop.

Parameters:
framesPerSecond - The apparent frame rate in fps.
maxFrameSkips - Maximum number of frames to skip. Use 0 to indicate no frame skipping.

stopAnimation

public static void stopAnimation()
Stops the animation loop. This method does not return until the animation loop thread terminates.


enterDisplayMode

public static void enterDisplayMode(int width,
                                    int height)

Attempts to enter full-screen exclusive mode with the specified screen dimensions. Of all available display modes, it enters the one with the highest bit depth and refresh rate. Bit depth is considered a higher priority.

If full-screen exclusive mode is unobtainable, it generates a Frame with a visible drawing surface of the specified size and the program will run outside of full-screen exclusive mode.

Parameters:
width - Width of full screen size.
height - Height of full screen size.
See Also:
getFrame(), DEFAULT_WINDOW_LISTENER

exitDisplayMode

public static void exitDisplayMode()
Restores the display mode back to normal and stops the animation.


isPageFlipping

public static boolean isPageFlipping()
Returns whether or not page flipping is used as the double-buffer strategy. Reguardless of the strategy used, the RenderListener will always be passed a graphics context to the non-visible buffer. After the frame is drawn, it will be displayed in one of two ways. If page flipping is used, then the buffers are instantly swapped by adjusting the video pointer to the opposite buffer; so, even and odd frames are drawn to different buffers. If page flipping is not used, then the contents of the non-visible buffer is copied to the visible one; meaning that drawing always occurs on the same buffer. The value that this method returns is important because it determines how to clean up the buffer to draw the next animation frame.

Returns:
true if page flipping is used as the double-buffer strategy.

getFrame

public static Frame getFrame()
Obtains the Frame used as the full-screen window.

Returns:
The full screen window.

setExceptionHandler

public static void setExceptionHandler(ExceptionHandler exceptionHandler)
Sets the ExceptionHandler used when an exception is thrown in the animation loop thread. If you pass in null or if you never call this method, the default exception handler is used. The default exception handler prints the stack trace to standard out and shuts down the application.

Parameters:
exceptionHandler -
See Also:
getExceptionHandler()

getExceptionHandler

public static ExceptionHandler getExceptionHandler()
Obtains the ExceptionHandler used when an exception is thrown in the animation loop thread.

Returns:
Either the ExceptionHandler passed to setExceptionHandler() or the default ExceptionHandler if none was ever set.
See Also:
setExceptionHandler(ExceptionHandler)

getBufferWidth

public static int getBufferWidth()
Obtains the width of the buffers.

Returns:
The width of the buffers.

getBufferHeight

public static int getBufferHeight()
Obtains the height of the buffers.

Returns:
The height of the buffers.