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

java.lang.Object
  extended by org.jrabbit.base.managers.window.controllers.WindowController
      extended by org.jrabbit.base.managers.window.controllers.BaseWindowController
          extended by org.jrabbit.base.managers.window.controllers.CanvasWindowController
All Implemented Interfaces:
java.awt.event.ComponentListener, java.util.EventListener, Createable, DataController, Destroyable, Dimensioned, Viewer, VectorTransform

public class CanvasWindowController
extends BaseWindowController
implements java.awt.event.ComponentListener

A CanvasWindowController is a bit more specialized than the DesktopWindowController - it handles an LWJGL Display that is set onto an AWT Canvas instead of being a standalone application. This, it turns out, can be quite useful. Using this WindowController, a jRabbit game can be placed in any Swing or AWT application (or applet). This allows browser-based games, editors, you name it! This WindowController automatically listens to its Canvas for size changes; when the canvas is resized, the viewport and scene settings are automatically adjusted accordingly. NOTE: This WindowController does not allow multiple LWJGL views. To do so, one needs to use an AWTGLCanvas, instead of Display.setParent().

Author:
Chris Molini

Field Summary
protected  boolean needResize
          A flag that determines whether or not the view needs to adjust for a resized Canvas.
protected  boolean onCanvas
          A flag that determines whether or not the Display is currently set to a canvas.
protected  java.awt.Canvas parent
          A reference to the Canvas the Display has as a parent.
 
Fields inherited from class org.jrabbit.base.managers.window.controllers.BaseWindowController
displayHeight, displayWidth, embedded, embedOffsetX, embedOffsetY, fullSceneHeight, fullSceneWidth, sceneMultX, sceneMultY, sceneOffsetX, sceneOffsetY
 
Fields inherited from class org.jrabbit.base.managers.window.controllers.WindowController
sceneHeight, sceneWidth
 
Constructor Summary
CanvasWindowController(java.awt.Canvas canvas)
          Creates a CanvasWindowController that will plant the Display on the indicated Canvas.
 
Method Summary
 void beginRender()
          At the start of every render cycle, this checks to see if the CanvasWindowController needs to resize the view.
 void componentHidden(java.awt.event.ComponentEvent e)
          This ComponentListener method is not needed by CanvasWindowController; it's implementation is empty.
 void componentMoved(java.awt.event.ComponentEvent e)
          This ComponentListener method is not needed by CanvasWindowController; it's implementation is empty.
 void componentResized(java.awt.event.ComponentEvent e)
          Flags the CanvasWindowController that it should adjust its view on the next render.
 void componentShown(java.awt.event.ComponentEvent e)
          This ComponentListener method is not needed by CanvasWindowController; it's implementation is empty.
 void create()
          Initializes the WindowController on the initial Canvas.
 void resize()
          Adjusts the CanvasWindowController's size and view to accommodate a differently sized parent Canvas.
 void resolveFullscreenRequest(int sceneWidth, int sceneHeight, int resolutionWidth, int resolutionHeight)
          Requesting a fullscreen mode will pop the Display off of the parent canvas and into its own fullscreen view.
 void resolveWindowRequest(int width, int height)
          Any and all requests to enter a windowed state simply pop the Display back onto its parent canvas.
 
Methods inherited from class org.jrabbit.base.managers.window.controllers.BaseWindowController
destroy, embedded, resolveEmbedRequest, setView, transform, unembed
 
Methods inherited from class org.jrabbit.base.managers.window.controllers.WindowController
adjustHeight, adjustWidth, embed, embed, endRender, height, isDisplaySetTo, setFullscreen, setFullscreen, setFullscreen, setWindowed, valid, views, width
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

onCanvas

protected boolean onCanvas
A flag that determines whether or not the Display is currently set to a canvas.


needResize

protected boolean needResize
A flag that determines whether or not the view needs to adjust for a resized Canvas.


parent

protected java.awt.Canvas parent
A reference to the Canvas the Display has as a parent.

Constructor Detail

CanvasWindowController

public CanvasWindowController(java.awt.Canvas canvas)
Creates a CanvasWindowController that will plant the Display on the indicated Canvas.

Parameters:
canvas - The canvas to use as the parent of the Display.
Method Detail

create

public void create()
Initializes the WindowController on the initial Canvas.

Specified by:
create in interface Createable

resolveFullscreenRequest

public void resolveFullscreenRequest(int sceneWidth,
                                     int sceneHeight,
                                     int resolutionWidth,
                                     int resolutionHeight)
Requesting a fullscreen mode will pop the Display off of the parent canvas and into its own fullscreen view. Otherwise, this functions in the same way as the fullscreen request in BaseWindowController.

Overrides:
resolveFullscreenRequest in class BaseWindowController
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

public void resolveWindowRequest(int width,
                                 int height)
Any and all requests to enter a windowed state simply pop the Display back onto its parent canvas. The indicated dimensions are immaterial.

Overrides:
resolveWindowRequest in class BaseWindowController
Parameters:
width - The desired width of the window (ignored).
height - The desired height of the window (ignored).

beginRender

public void beginRender()
At the start of every render cycle, this checks to see if the CanvasWindowController needs to resize the view.

Overrides:
beginRender in class WindowController

resize

public void resize()
Adjusts the CanvasWindowController's size and view to accommodate a differently sized parent Canvas.


componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
This ComponentListener method is not needed by CanvasWindowController; it's implementation is empty.

Specified by:
componentHidden in interface java.awt.event.ComponentListener
Parameters:
e - The ComponentEvent to process.

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
This ComponentListener method is not needed by CanvasWindowController; it's implementation is empty.

Specified by:
componentMoved in interface java.awt.event.ComponentListener
Parameters:
e - The ComponentEvent to process.

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Flags the CanvasWindowController that it should adjust its view on the next render.

Specified by:
componentResized in interface java.awt.event.ComponentListener
Parameters:
e - The ComponentEvent to process.

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
This ComponentListener method is not needed by CanvasWindowController; it's implementation is empty.

Specified by:
componentShown in interface java.awt.event.ComponentListener
Parameters:
e - The ComponentEvent to process.