com.golden.gamedev.engine.graphics
Class HybridMode

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--com.golden.gamedev.engine.graphics.HybridMode
All Implemented Interfaces:
Accessible, BaseGraphics, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
Game

public class HybridMode
extends Applet
implements BaseGraphics

Graphics frame work supports Applet, Window, and Fullscreen Environment, parent class of Game.

See Also:
Serialized Form

Field Summary
static int APPLET_MODE
           
static int FULLSCREEN_MODE
           
static GraphicsConfiguration gc
           
static int WINDOW_MODE
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
HybridMode()
          Creates new instance of HybridMode, please see note below.
 
Method Summary
 void cleanup()
          Releases all graphics resources and do finalization.
protected  void createEnvironment(boolean fullscreen, boolean bufferstrategy)
           
 boolean flip()
          Flips backbuffer to screen (primary surface).
 Graphics2D getBackBuffer()
          Returns backbuffer where the rendering perform.
 Component getComponent()
          Returns the component where the rendering perform.
 int getEnvironment()
           
 String getEnvironmentString()
           
 Frame getFrame()
           
 Dimension getSize()
          Returns the dimension of this graphics component.
 void setup(Dimension d, boolean fullscreen)
           
 void setup(Dimension d, boolean fullscreen, boolean bufferstrategy)
           
 void start()
           
 
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

APPLET_MODE

public static final int APPLET_MODE
See Also:
Constant Field Values

WINDOW_MODE

public static final int WINDOW_MODE
See Also:
Constant Field Values

FULLSCREEN_MODE

public static final int FULLSCREEN_MODE
See Also:
Constant Field Values

gc

public static final GraphicsConfiguration gc
Constructor Detail

HybridMode

public HybridMode()
Creates new instance of HybridMode, please see note below.

Note:
Do not make any overloading constructors for this class.

Setup should be the first to call after object creation,
setup(Dimension, fullscreen) and setup(Dimension, fullscreen, bufferstrategy).
(for Window and FullScreen mode only)

For example:

   public class TestMode extends HybridMode {
       // writes only empty constructor,
       // or simply don't write any constructor
       public TestMode() { }

       // do not use both of these
   //  public TestMode(boolean fullscreen) {
   //      setup(new Dimension(640,480), fullscreen);
   //  }
   //  public TestMode() {
   //      setup(new Dimension(640,480), true);
   //  }

       public static void main(String[] args) {
           HybridMode frame = new TestMode();

           // sets fullscreen mode, with 640 x 480 display mode
           frame.setup(new Dimension(640,480), true);
       }
   }
 

See Also:
setup(Dimension, boolean), setup(Dimension, boolean, boolean)
Method Detail

createEnvironment

protected void createEnvironment(boolean fullscreen,
                                 boolean bufferstrategy)

setup

public void setup(Dimension d,
                  boolean fullscreen,
                  boolean bufferstrategy)

setup

public final void setup(Dimension d,
                        boolean fullscreen)

start

public void start()
Overrides:
start in class Applet

getEnvironment

public int getEnvironment()

getEnvironmentString

public String getEnvironmentString()

cleanup

public void cleanup()
Description copied from interface: BaseGraphics
Releases all graphics resources and do finalization.

Specified by:
cleanup in interface BaseGraphics

getBackBuffer

public Graphics2D getBackBuffer()
Description copied from interface: BaseGraphics
Returns backbuffer where the rendering perform.

Specified by:
getBackBuffer in interface BaseGraphics
Returns:
backbuffer graphics.

flip

public boolean flip()
Description copied from interface: BaseGraphics
Flips backbuffer to screen (primary surface). Since the backbuffer is VolatileImage type, the flipping data could be lost and need to be restored. Therefore, if this method return false, backbuffer needs to be rerendered.

For Example:

    do {
        Graphics2D g = BaseGraphics.getBackBuffer();
        //.... do graphics operation
    } while (BaseGraphics.flip() == false);
 
See VolatileImage for detail information.

Specified by:
flip in interface BaseGraphics
Returns:
true, if the flipping is successfully proceed
See Also:
BaseGraphics.getBackBuffer(), VolatileImage

getSize

public Dimension getSize()
Description copied from interface: BaseGraphics
Returns the dimension of this graphics component.

Specified by:
getSize in interface BaseGraphics
Overrides:
getSize in class Component
Returns:
graphics dimension.

getComponent

public Component getComponent()
Description copied from interface: BaseGraphics
Returns the component where the rendering perform.

Specified by:
getComponent in interface BaseGraphics
Returns:
graphics component.

getFrame

public Frame getFrame()