org.jrabbit.base.managers.window.controllers
Class WindowController

java.lang.Object
  extended by org.jrabbit.base.managers.window.controllers.WindowController
All Implemented Interfaces:
Createable, DataController, Destroyable, Dimensioned, Viewer, VectorTransform
Direct Known Subclasses:
BaseWindowController

public abstract class WindowController
extends java.lang.Object
implements DataController, VectorTransform, Viewer, Dimensioned

WindowController is an abstract class meant to provide a unified, extensible API for managing the LWJGL Display and making it interface with jRabbit. There are two general ways of setting the base Display: Making it fullscreen and placing it in a window. Windowed mode is fairly straightforward, but fullscreen mode is more complicated, as it allows various resolutions. When fullscreen, the visible resolution may be different than the desired scene to render (for example, we may want to show a 1024x768 scene at 640x400 resolution). After the display has been set, it's also possible to "embed" the view, where only a portion of the screen is rendered to. This is possible in both fullscreen and windowed modes. This has several potential uses, such as enforcing a strict viewing area for all games. Additionally, the screen outside of the embedded view can be rendered to, allowing decoration around the active game. Also, WindowController's responsibility goes beyond just changing settings on the Display. It's also used to transform the Mouse location into screen coordinates useful to the engine. Finally, it can be used to determine if a screen object is viewed, permitting fast culling. WindowControllers are supposed to manage alerting WindowListeners that a change has occurred; when they make changes they must call WindowManager.alertWindowChange(int) indicating the change that has been enacted. NOTE: When indicating dimensions, supplying 0 in any value will cause that value to default to the appropriate desktop dimension. So, if you say setFullscreen(0, 0) and the computer monitor is 1024x768, the resulting fullscreen display will be 1024x768.


Field Summary
protected  int sceneHeight
          The height of the "scene" viewed in the window.
protected  int sceneWidth
          The width of the "scene" viewed in the window.
 
Constructor Summary
WindowController()
           
 
Method Summary
protected  int adjustHeight(int height)
          Handles adjusting the indicated height.
protected  int adjustWidth(int width)
          Handles adjusting the indicated width.
 void beginRender()
          Begins a render sequence.
 void embed(int sceneWidth, int sceneHeight)
          Embeds the view, rendering only the section of the screen that represents a scene of the indicated dimensions.
 void embed(int sceneWidth, int sceneHeight, int offsetX, int offsetY)
          Embeds the view, rendering only the section of the screen that represents a scene of the indicated dimensions.
abstract  boolean embedded()
          Checks the state of the view.
 void endRender()
          Finishes a render and updates the jRabbit Display.
 float height()
          Accesses information about the scene being rendered.
protected  boolean isDisplaySetTo(int width, int height, boolean fullscreen)
          Determines whether or not the current DisplayMode is equivalent to the one required by the indicated settings.
protected abstract  void resolveEmbedRequest(int sceneWidth, int sceneHeight, int offsetX, int offsetY)
          "Embeds" the active rendering area on the Display.
protected abstract  void resolveFullscreenRequest(int sceneWidth, int sceneHeight, int resolutionWidth, int resolutionHeight)
          Sets the Display to have the indicated fullscreen settings.
protected abstract  void resolveWindowRequest(int width, int height)
          Sets the Display into a window with the indicated dimensions.
 void setFullscreen()
          Makes the Display enter fullscreen mode with the resolution and scene dimensions of the desktop.
 void setFullscreen(int resolutionWidth, int resolutionHeight)
          Makes the Display enter fullscreen mode at the indicated resolution.
 void setFullscreen(int sceneWidth, int sceneHeight, int resolutionWidth, int resolutionHeight)
          Makes the Display enter fullscreen mode at the indicated resolution, and sets the scene dimensions.
abstract  void setView(int sceneWidth, int sceneHeight, int viewportWidth, int viewportHeight, int viewportX, int viewportY)
          Sets the viewport and scene size, and updates all appropriate settings (mouse transforming, orthogonal view).
 void setWindowed(int width, int height)
          Places the Display into a window of the indicated dimensions.
abstract  void unembed()
          Resets embedding settings, making the view take up all of the available screen.
 boolean valid()
          Determines whether the LWJGL Display and the current window settings are valid.
 boolean views(float x, float y, float radius)
          Determines whether or not an object with the indicated location and radius is visible in the scene.
 float width()
          Accesses information about the scene being rendered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jrabbit.base.data.Createable
create
 
Methods inherited from interface org.jrabbit.base.data.Destroyable
destroy
 
Methods inherited from interface org.jrabbit.base.math.vector.VectorTransform
transform
 

Field Detail

sceneWidth

protected int sceneWidth
The width of the "scene" viewed in the window. This does not have to be the same as the current DisplayMode's width.


sceneHeight

protected int sceneHeight
The height of the "scene" viewed in the window. This does not have to be the same as the current DisplayMode's height.

Constructor Detail

WindowController

public WindowController()
Method Detail

valid

public boolean valid()
Determines whether the LWJGL Display and the current window settings are valid.

Specified by:
valid in interface DataController
Returns:
Whether or not the window has been created and the LWJGL context is usable.

adjustWidth

protected int adjustWidth(int width)
Handles adjusting the indicated width.

Parameters:
width - The desired width to use.
Returns:
If the supplied width was 0, returns the width of the desktop. Otherwise, this returns the same width as it was supplied.

adjustHeight

protected int adjustHeight(int height)
Handles adjusting the indicated height.

Parameters:
height - The desired height to use.
Returns:
If the supplied height was 0, returns the height of the desktop. Otherwise, this returns the same height as it was supplied.

isDisplaySetTo

protected boolean isDisplaySetTo(int width,
                                 int height,
                                 boolean fullscreen)
Determines whether or not the current DisplayMode is equivalent to the one required by the indicated settings.

Parameters:
width - The width to check against.
height - The height to check against.
fullscreen - Whether or not the Display needs to be fullscreen.
Returns:
True if the Display is set to the indicated settings, false if not.

resolveFullscreenRequest

protected abstract void resolveFullscreenRequest(int sceneWidth,
                                                 int sceneHeight,
                                                 int resolutionWidth,
                                                 int resolutionHeight)
Sets the Display to have the indicated fullscreen settings.

Parameters:
sceneWidth - The width of the scene to render.
sceneHeight - The height of the scene to render.
resolutionWidth - The width of the DisplayMode to use.
resolutionHeight - The height of the DisplayMode to use.

resolveWindowRequest

protected abstract void resolveWindowRequest(int width,
                                             int height)
Sets the Display into a window with the indicated dimensions.

Parameters:
width - The width of the desired window.
height - The height of the desired window.

resolveEmbedRequest

protected abstract void resolveEmbedRequest(int sceneWidth,
                                            int sceneHeight,
                                            int offsetX,
                                            int offsetY)
"Embeds" the active rendering area on the Display. The size of the scene is calculated from "scene" size; the current resolution is immaterial. Therefore, if you have a fullscreen mode rendering a scene, embedding a 600x400 area will result in the same section of the scene being chosen at any resolution. The offset values are from the middle of the screen; supplied 0 to either value will cause the scene to center on that axis. As usual, +X is to the right and +Y is down. NOTE: You shouldn't use this method with a Windowed Display, as its double buffering can cause unfortunate behavior.

Parameters:
sceneWidth - The width of the sub-scene to render.
sceneHeight - The height of the sub-scene to render.
offsetX - The X offset of the subscene to render; this is based on scene size.
offsetY - The Y offset of the subscene to render; this is based on scene size.

setView

public abstract void setView(int sceneWidth,
                             int sceneHeight,
                             int viewportWidth,
                             int viewportHeight,
                             int viewportX,
                             int viewportY)
Sets the viewport and scene size, and updates all appropriate settings (mouse transforming, orthogonal view). NOTE: Unlike most other methods, the coordinates for the viewport settings are in OpenGL format. Thus, +Y is up the screen (like cartesian coordinates), the origin is the bottom left, and the size of the viewport is based on the dimensions of the current DisplayMode (not the scene being rendered).

Parameters:
sceneWidth - The new width of the scene.
sceneHeight - The new height of the scene.
viewportWidth - The width of the viewport.
viewportHeight - The height of the viewport.
viewportX - The X offset of the viewport, from the bottom left of the screen.
viewportY - The Y offset of the viewport, from the bottom left of the screen.

setFullscreen

public void setFullscreen()
Makes the Display enter fullscreen mode with the resolution and scene dimensions of the desktop. Basically, this is "high-res" fullscreen.


setFullscreen

public void setFullscreen(int resolutionWidth,
                          int resolutionHeight)
Makes the Display enter fullscreen mode at the indicated resolution. If the indicated resolution is not available as a fullscreen mode, the closest available DisplayMode is chosen and an error is printed to the console. NOTE: This method changes the resolution of the display, but the scene shown is considered to be the size of the desktop. That way, if the high-res fullscreen mode is used, and then this method is called, the game will be at a lower resolution but no change will occur to what is being rendered.

Parameters:
resolutionWidth - The width of the DisplayMode to use.
resolutionHeight - The width of the DisplayMode to use.

setFullscreen

public void setFullscreen(int sceneWidth,
                          int sceneHeight,
                          int resolutionWidth,
                          int resolutionHeight)
Makes the Display enter fullscreen mode at the indicated resolution, and sets the scene dimensions.

Parameters:
sceneWidth - The width of the scene to render.
sceneHeight - The height of the scene to render.
resolutionWidth - The width of the DisplayMode used to render the scene.
resolutionHeight - The height of the DisplayMode used to render the scene.

setWindowed

public void setWindowed(int width,
                        int height)
Places the Display into a window of the indicated dimensions. NOTE: It's not recommended to further embed the view once it's already in a window. It's double buffered, and that can cause problems, as jRabbit does not automatically clear the color buffer.

Parameters:
width - The width of the window.
height - The height of the window.

embed

public void embed(int sceneWidth,
                  int sceneHeight)
Embeds the view, rendering only the section of the screen that represents a scene of the indicated dimensions. The resulting viewport is centered. NOTE: Anything already rendered on the screen stays there. This can be useful if you want to "decorate" the area around the screen,

Parameters:
sceneWidth - The width of the scene to render.
sceneHeight - The height of the scene to render.

embed

public void embed(int sceneWidth,
                  int sceneHeight,
                  int offsetX,
                  int offsetY)
Embeds the view, rendering only the section of the screen that represents a scene of the indicated dimensions. The resulting viewport is offset from the center by the indicated amount.

Parameters:
sceneWidth - The width of the scene to render.
sceneHeight - The height of the scene to render.
offsetX - The X offset of the embedded view, in scene coordinates.
offsetY - The Y offset of the embedded view, in scene coordinates.

unembed

public abstract void unembed()
Resets embedding settings, making the view take up all of the available screen. Calling this should result in the same scene as before any embed() calls.


embedded

public abstract boolean embedded()
Checks the state of the view.

Returns:
Whether or not the Display view is currently embedded.

beginRender

public void beginRender()
Begins a render sequence. It's quite possible that nothing is required in this method.


endRender

public void endRender()
Finishes a render and updates the jRabbit Display.


width

public float width()
Accesses information about the scene being rendered.

Specified by:
width in interface Dimensioned
Returns:
The width of the scene being rendered. This does not have to be the same as the width of the Display.

height

public float height()
Accesses information about the scene being rendered.

Specified by:
height in interface Dimensioned
Returns:
The height of the scene being rendered. This does not have to be the same as the height of the Display.

views

public boolean views(float x,
                     float y,
                     float radius)
Determines whether or not an object with the indicated location and radius is visible in the scene.

Specified by:
views in interface Viewer
Parameters:
x - The central x coordinate.
y - The central y coordinate.
radius - The radius of the visible object.
Returns:
Whether or not the object is visible.