PulpCore

pulpcore.sprite
Class Button

java.lang.Object
  extended by pulpcore.sprite.Sprite
      extended by pulpcore.sprite.ImageSprite
          extended by pulpcore.sprite.Button
All Implemented Interfaces:
PropertyListener

public class Button
extends ImageSprite

The Button is a Sprite that behaves like a common UI push button. A Button has three visual states: normal, hover, and pressed. Call isClicked() to check if the user clicked the button. By default, a Button's cursor is Input.CURSOR_HAND.

By default, Buttons use pixel level checking for intersection tests. Use ImageSprite.setPixelLevelChecks(boolean) to disable this feature.


Field Summary
 
Fields inherited from class pulpcore.sprite.ImageSprite
antiAlias
 
Fields inherited from class pulpcore.sprite.Sprite
alpha, anchorX, anchorY, angle, CENTER, DEFAULT, EAST, enabled, height, NORTH, NORTH_EAST, NORTH_WEST, pixelSnapping, SOUTH, SOUTH_EAST, SOUTH_WEST, visible, WEST, width, x, y
 
Constructor Summary
Button(CoreImage[] images, double x, double y)
           
Button(CoreImage[] images, double x, double y, boolean isToggleButton)
           
Button(CoreImage[] images, int x, int y)
           
Button(CoreImage[] images, int x, int y, boolean isToggleButton)
           
 
Method Summary
 void clearKeyBinding()
          Clears the key binding for this button.
static Button createLabeledButton(CoreImage[] images, CoreFont font, String text, int x, int y)
           
static Button createLabeledButton(CoreImage[] images, CoreFont font, String text, int x, int y, int textX, int textY, double textAnchorX, double textAnchorY, boolean offsetPressedText)
           
static Button createLabeledButton(CoreImage[] images, CoreFont font, String text, int x, int y, int textX, int textY, double textAnchorX, double textAnchorY, boolean isToggleButton, boolean offsetPressedText)
           
static Button createLabeledButton(CoreImage[] images, CoreFont font, String text, int x, int y, int textX, int textY, int textAnchor, boolean offsetPressedText)
          Deprecated.  
static Button createLabeledButton(CoreImage[] images, CoreFont font, String text, int x, int y, int textX, int textY, int textAnchor, boolean isToggleButton, boolean offsetPressedText)
          Deprecated.  
static Button createLabeledButton(String text, int x, int y)
           
static Button createLabeledToggleButton(CoreImage[] images, CoreFont font, String text, int x, int y)
           
static Button createLabeledToggleButton(CoreImage[] images, CoreFont font, String text, int x, int y, int textX, int textY, double textAnchorX, double textAnchorY, boolean offsetPressedText)
           
static Button createLabeledToggleButton(CoreImage[] images, CoreFont font, String text, int x, int y, int textX, int textY, int textAnchor, boolean offsetPressedText)
          Deprecated.  
static Button createLabeledToggleButton(String text, int x, int y)
           
 int[] getKeyBinding()
          Gets a copy of the key bindings for this button.
 boolean isClicked()
          Determines if this button was clicked since the last frame.
 boolean isPressedDown()
          Determines if this button was pressed and the mouse is still held down over the button.
 boolean isSelected()
          Determines if this button is selected.
 boolean isToggleButton()
           
 void setKeyBinding(int keyCode)
          Sets the key binding for this button to the specified key code.
 void setKeyBinding(int[] keyCodes)
          Sets the key binding for this button to the specified key codes.
 void setSelected(boolean isSelected)
          Sets whether this button is selected.
 void update(int elapsedTime)
          Updates all of this Sprite's properties.
 
Methods inherited from class pulpcore.sprite.ImageSprite
drawSprite, getImage, getNaturalHeight, getNaturalWidth, getPixelLevelChecks, isOpaque, isTransparent, propertyChange, setAnchor, setAnchorToHotSpot, setImage, setImage, setPixelLevelChecks
 
Methods inherited from class pulpcore.sprite.Sprite
bindLocationTo, bindSizeTo, clearCursor, clearDirtyRect, contains, draw, getBlendMode, getCursor, getDirtyRect, getFilter, getLocalX, getLocalY, getParent, getRoot, getScene2D, getTag, getViewX, getViewX, getViewY, getViewY, intersects, isDirty, isEnabled, isEnabledAndVisible, isMouseDoubleClicked, isMouseDown, isMouseHover, isMouseOver, isMousePressed, isMouseReleased, isMouseTripleClicked, isMouseWheelRotated, isPick, isPickEnabledAndVisible, move, move, move, move, move, move, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, removeFromParent, scale, scale, scale, scale, scale, scale, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, setAnchor, setBlendMode, setCursor, setDirty, setFilter, setLocation, setLocation, setSize, setSize, setTag, translate, translate, updateDirtyRect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Button

public Button(CoreImage[] images,
              int x,
              int y)
Parameters:
images - an array of three images: normal, hover, and pressed.

Button

public Button(CoreImage[] images,
              int x,
              int y,
              boolean isToggleButton)
Parameters:
images - an array of three images: normal, hover, and pressed. Use six images for toggle buttons (unselected and selected).

Button

public Button(CoreImage[] images,
              double x,
              double y)
Parameters:
images - an array of three images: normal, hover, and pressed.

Button

public Button(CoreImage[] images,
              double x,
              double y,
              boolean isToggleButton)
Parameters:
images - an array of three images: normal, hover, and pressed. Use six images for toggle buttons (unselected and selected).
Method Detail

isToggleButton

public boolean isToggleButton()
Returns:
true if this button is a toggle button, false otherwise

getKeyBinding

public int[] getKeyBinding()
Gets a copy of the key bindings for this button. A button has no key bindings by default.

Returns:
the key bindings for this button, or null if there are no key bindings.
See Also:
setKeyBinding(int), setKeyBinding(int[]), clearKeyBinding()

clearKeyBinding

public void clearKeyBinding()
Clears the key binding for this button.

See Also:
getKeyBinding(), setKeyBinding(int), setKeyBinding(int[])

setKeyBinding

public void setKeyBinding(int keyCode)
Sets the key binding for this button to the specified key code. The button is considered "clicked" if that key is pressed and released.

See Also:
getKeyBinding(), setKeyBinding(int[]), clearKeyBinding()

setKeyBinding

public void setKeyBinding(int[] keyCodes)
Sets the key binding for this button to the specified key codes. The button is considered "clicked" if any of those keys are pressed and released.

See Also:
getKeyBinding(), setKeyBinding(int), clearKeyBinding()

setSelected

public void setSelected(boolean isSelected)
Sets whether this button is selected. For toggle buttons only.


isSelected

public boolean isSelected()
Determines if this button is selected. For toggle buttons only.


update

public void update(int elapsedTime)
Description copied from class: Sprite
Updates all of this Sprite's properties. Subclasses that override this method should call super.update().

Overrides:
update in class ImageSprite

isClicked

public boolean isClicked()
Determines if this button was clicked since the last frame.

Returns:
true if this button was clicked since the last frame.

isPressedDown

public boolean isPressedDown()
Determines if this button was pressed and the mouse is still held down over the button. This method continues to returns true as long as the mouse is pressed and still over the button.

To detect a click, use isClicked().


createLabeledButton

public static Button createLabeledButton(String text,
                                         int x,
                                         int y)

createLabeledToggleButton

public static Button createLabeledToggleButton(String text,
                                               int x,
                                               int y)

createLabeledButton

public static Button createLabeledButton(CoreImage[] images,
                                         CoreFont font,
                                         String text,
                                         int x,
                                         int y)

createLabeledButton

public static Button createLabeledButton(CoreImage[] images,
                                         CoreFont font,
                                         String text,
                                         int x,
                                         int y,
                                         int textX,
                                         int textY,
                                         int textAnchor,
                                         boolean offsetPressedText)
Deprecated. 


createLabeledButton

public static Button createLabeledButton(CoreImage[] images,
                                         CoreFont font,
                                         String text,
                                         int x,
                                         int y,
                                         int textX,
                                         int textY,
                                         double textAnchorX,
                                         double textAnchorY,
                                         boolean offsetPressedText)

createLabeledToggleButton

public static Button createLabeledToggleButton(CoreImage[] images,
                                               CoreFont font,
                                               String text,
                                               int x,
                                               int y)

createLabeledToggleButton

public static Button createLabeledToggleButton(CoreImage[] images,
                                               CoreFont font,
                                               String text,
                                               int x,
                                               int y,
                                               int textX,
                                               int textY,
                                               int textAnchor,
                                               boolean offsetPressedText)
Deprecated. 


createLabeledToggleButton

public static Button createLabeledToggleButton(CoreImage[] images,
                                               CoreFont font,
                                               String text,
                                               int x,
                                               int y,
                                               int textX,
                                               int textY,
                                               double textAnchorX,
                                               double textAnchorY,
                                               boolean offsetPressedText)

createLabeledButton

public static Button createLabeledButton(CoreImage[] images,
                                         CoreFont font,
                                         String text,
                                         int x,
                                         int y,
                                         int textX,
                                         int textY,
                                         int textAnchor,
                                         boolean isToggleButton,
                                         boolean offsetPressedText)
Deprecated. 

Parameters:
images - the images to use. If null, simple gray images are created to fit the text
font - the font to use for rendering the text label. If null, the system font is used.
offsetPressedText - Set to true to offset the button's text when the button is pressed.

createLabeledButton

public static Button createLabeledButton(CoreImage[] images,
                                         CoreFont font,
                                         String text,
                                         int x,
                                         int y,
                                         int textX,
                                         int textY,
                                         double textAnchorX,
                                         double textAnchorY,
                                         boolean isToggleButton,
                                         boolean offsetPressedText)
Parameters:
images - the images to use. If null, simple gray images are created to fit the text
font - the font to use for rendering the text label. If null, the system font is used.
offsetPressedText - Set to true to offset the button's text when the button is pressed.

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.