ch.aplu.jgamegrid
Class GGButton

java.lang.Object
  extended by ch.aplu.jgamegrid.Actor
      extended by ch.aplu.jgamegrid.GGButtonBase
          extended by ch.aplu.jgamegrid.GGButton
All Implemented Interfaces:
GGActorCollisionListener, GGBorderListener, GGTileCollisionListener, java.util.EventListener

public class GGButton
extends GGButtonBase

Class that implements a button actor with standard behavior. Button events 'left entered', 'left exited', 'left pressed', 'left released' and 'left clicked' are reported by a registered GGButtonListener.

The button is centered in the middle of a cell. Use Actor.setLocationOffset() to fine tune the button location.

3 sprites are used: one for the released state, one for the pressed state and one for the rollover state.


Field Summary
 
Fields inherited from class ch.aplu.jgamegrid.Actor
gameGrid, nbCycles
 
Constructor Summary
GGButton(java.lang.String buttonImage)
          Same as GGButton(String buttonImage, false) (no rollover).
GGButton(java.lang.String buttonImage, boolean isRollover)
          Creates a button from the given sprite images.
 
Method Summary
 void addButtonListener(GGButtonListener listener)
          Registers a GGButtonListener to get notifications when the button is manipulated.
 void addButtonOverListener(GGButtonOverListener listener)
          Registers a GGOverButtonListener to get notifications when the mouse cursor enters the active mouse area.
 boolean isPressed()
          Returns the current state of the ButtonA.
 
Methods inherited from class ch.aplu.jgamegrid.GGButtonBase
isEnabled, setEnabled, setHotspotArea, setRefreshEnabled
 
Methods inherited from class ch.aplu.jgamegrid.Actor
act, addActorCollisionListener, addBorderListener, addCollisionActor, addCollisionActors, addCollisionActors, addCollisionTile, addCollisionTiles, addCollisionTiles, addMouseTouchListener, addMouseTouchListener, addTileCollisionListener, collide, collide, delay, displace, getBackground, getCollisionActors, getCollisionActorsInRange, getCollisionTiles, getCurrentImage, getDirection, getDirectionStart, getDisplacePosition, getHeight, getIdVisible, getImage, getImage, getIntDirection, getLocation, getLocationOffset, getLocationStart, getNbCycles, getNbHorzCells, getNbSprites, getNbVertCells, getNeighbours, getNeighbours, getNextMoveLocation, getPixelColor, getPixelLocation, getRotatedPosition, getRotationIndex, getScaledImage, getScaledImage, getScaledImage, getSlowDown, getWidth, getX, getXStart, getY, getYStart, hide, isActEnabled, isActorCollisionEnabled, isHorzMirror, isInGrid, isMoveValid, isNearBorder, isRemoved, isRotatable, isTileCollisionEnabled, isVertMirror, isVisible, move, move, nearBorder, removeSelf, reset, rotate, rotate, setActEnabled, setActorCollisionEnabled, setCollisionCircle, setCollisionCircle, setCollisionImage, setCollisionImage, setCollisionLine, setCollisionLine, setCollisionRectangle, setCollisionRectangle, setCollisionSpot, setCollisionSpot, setDirection, setDirection, setDisplacePosition, setHorzMirror, setLocation, setLocationOffset, setLocationOffset, setMouseTouchCircle, setMouseTouchCircle, setMouseTouchEnabled, setMouseTouchImage, setMouseTouchImage, setMouseTouchRectangle, setMouseTouchRectangle, setOnBottom, setOnTop, setPixelLocation, setSlowDown, setTileCollisionEnabled, setVertMirror, setX, setY, show, show, showNextSprite, showPreviousSprite, turn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GGButton

public GGButton(java.lang.String buttonImage,
                boolean isRollover)
Creates a button from the given sprite images. Multiple sprites are assumed, using the implicite underline convention. If isRollover is true, image_0.gif corresponds to the released state, image_1.gif to the pressed state and image_2.gif to the rollover state. If isRollover is false, only image_0.gif and image_1.gif are needed.

Parameters:
buttonImage - the filename or URL of the 2 or 3 button sprites
isRollover - if true, a rollover image is used

GGButton

public GGButton(java.lang.String buttonImage)
Same as GGButton(String buttonImage, false) (no rollover). Only image_0.gif and image_1.gif are needed.

Parameters:
buttonImage - the filename or URL of the 2 button sprites
Method Detail

isPressed

public boolean isPressed()
Returns the current state of the ButtonA.

Returns:
true, if the button is pressed; otherwise false

addButtonListener

public void addButtonListener(GGButtonListener listener)
Registers a GGButtonListener to get notifications when the button is manipulated. The default hotspot area is the button image bounding rectangle.

Parameters:
listener - the GGButtonListener to register

addButtonOverListener

public void addButtonOverListener(GGButtonOverListener listener)
Registers a GGOverButtonListener to get notifications when the mouse cursor enters the active mouse area.

Parameters:
listener - the GGButtonOverListener to register