com.hdcookbook.grinxlet
Class DebugDirectDrawEngine

java.lang.Object
  extended by com.hdcookbook.grin.animator.AnimationEngine
      extended by com.hdcookbook.grin.animator.ClockBasedEngine
          extended by com.hdcookbook.grin.animator.DirectDrawEngine
              extended by com.hdcookbook.grinxlet.DebugDirectDrawEngine
All Implemented Interfaces:
java.lang.Runnable

public class DebugDirectDrawEngine
extends DirectDrawEngine

A double-buffered animation engine that uses direct draw, and can be set in "debug draw" mode.

See Also:
DirectDrawEngine

Field Summary
 
Fields inherited from class com.hdcookbook.grin.animator.AnimationEngine
modelTimeSkipped, renderContext, repaintBounds, targetsCanOverlap, transparent
 
Constructor Summary
DebugDirectDrawEngine()
          Create a new DebugDirectDrawEngine.
 
Method Summary
protected  void callPaintTargets()
          Paint the current frame into the right graphics buffer.
 void initContainer(java.awt.Container container, java.awt.Rectangle bounds)
          Initialize this engine with its parent container and the position and size of the engine within the container.
 void setDebugDraw(boolean debugDraw)
          Tell us if we should step through each frame showing erase, paint areas, then painted result
 void setFps(int fps)
          Set the frame rate of the animation, in 1001sts of a second.
 
Methods inherited from class com.hdcookbook.grin.animator.DirectDrawEngine
clearArea, finishedFrame, getComponent, getHeight, getWidth, needsFullRedrawInAnimationLoop, terminatingEraseScreen, toString
 
Methods inherited from class com.hdcookbook.grin.animator.ClockBasedEngine
getFps, pause, runAnimationLoop, skipFrames, start
 
Methods inherited from class com.hdcookbook.grin.animator.AnimationEngine
advanceModel, checkDestroy, checkNewClients, destroy, destroyRequested, getAnimationClients, getDrawTargets, getEraseTargets, getModelTimeSkipped, getNumDrawTargets, getNumEraseTargets, initClients, initialize, paintFrame, paintNextFrameFully, paintTargets, repaintFrame, resetAnimationClients, run, setAllowOverlappingTargets, setDrawTargetCollapseThreshold, setThreadPriority, showFrame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DebugDirectDrawEngine

public DebugDirectDrawEngine()
Create a new DebugDirectDrawEngine.

Method Detail

initContainer

public void initContainer(java.awt.Container container,
                          java.awt.Rectangle bounds)
Initialize this engine with its parent container and the position and size of the engine within the container. This should be called exactly once, before start() is called. A good time to call this would be in the animationInitialize() call within the context code passed to initialize().

The Component will be set to the specified bounds, and an internal double buffer may be created to these bounds. The container is expected to have a null layout; if it doesn't, this might change the widget's size to be different than the bounds passed in (and therefore the double buffer). The container must be visible when this is called.

Overrides:
initContainer in class DirectDrawEngine
See Also:
AnimationEngine.initialize(com.hdcookbook.grin.animator.AnimationContext), AnimationContext.animationInitialize()

setDebugDraw

public void setDebugDraw(boolean debugDraw)
Tell us if we should step through each frame showing erase, paint areas, then painted result


callPaintTargets

protected void callPaintTargets()
                         throws java.lang.InterruptedException
Paint the current frame into the right graphics buffer. The subclass implementation of this method should call paintTargets(Graphics2D).

Overrides:
callPaintTargets in class DirectDrawEngine
Throws:
java.lang.InterruptedException
See Also:
AnimationEngine.paintFrame(java.awt.Graphics2D)

setFps

public void setFps(int fps)
Set the frame rate of the animation, in 1001sts of a second. In other words, the following table applies:

     Desired framerate    fps value
     =================    =========
           23.976                 24,000
           24.000           24,024
           29.970                 30,000
           30.000                 30,030
           59.940           60,000
           60.000           60,060
 
 
If you find yourself asking "why 1001," read the HD Handbook starting from page 2-2 (ISBN 978-0-07-149585-1). Long story short: NTSC video's frame rate is 30*1000/1001 frames/second, due to issues around the transition from B&W to color. Fun fact: 1001 isn't prime, it's 7*11*13

The frame rate must be greater than 0 fps. To stop the animation, call pause().

If the animation is paused when this method is called, it will stay paused.

Overrides:
setFps in class ClockBasedEngine
See Also:
ClockBasedEngine.skipFrames(int)