Package totalcross.game
Class AnimatedButton
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.game.Animation
-
- totalcross.game.AnimatedButton
-
public class AnimatedButton extends Animation
An animated button control.
This control displays an animated button which can take'S'different states and each state is fades in or out in'F'frames.'S'and'F'represent the two first constructor arguments. The frames of this special animation have to be ordered to be supported by this class. The states are numbered from0to'S'-1and the frames order is the following depending on the layoutType value:
FADE_OUT_LAYOUT : S0F0,S0F1,S0F2,S1F0,S1F1,S1F2,S2F0,S2F1,S2F2
where
FADE_IN_LAYOUT : S0F2,S0F1,S0F0,S1F2,S1F1,S1F0,S2F2,S2F1,S2F0
FADE_OUT_IN_LAYOUT : S0F0,S0F1,S1F1,S1F0,S1F1,S2F1,S2F0,S2F1,S0F1
Sstands for state,Ffor frame; and whereS0F0,S1F0, andS2F0are the full states and the others are transition frames. Open theonOff.bmpin the Scape game sample and you will understand ;-) .
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description static intFADE_IN_LAYOUTFrames fading in mode.static intFADE_OUT_IN_LAYOUTFrames fading out then fading in mode.static intFADE_OUT_LAYOUTDefines the frames animation order.protected intfadeInStateprotected intframesPerStateprotected intlayoutTypeprotected intmaxStatesprotected intstatecurrent animated button stateprotected int[]statesIndexes-
Fields inherited from class totalcross.game.Animation
background, curFrame, drawOp, eventFinish, eventFrame, eventLoop, eventNone, eventsMask, framePeriod, framesBuffer, isPaused, isPlaying, LOOPS_UNLIMITED, pauseIfNotVisible
-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Constructor Description AnimatedButton(Image frames, int states, int framesPerState, int layoutType, int framePeriod)Animated button constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetState()Gets the animated button state.protected voidinc(boolean up)Increases/decreases the animated button state.voidonEvent(Event event)Animated button event handler.voidsetState(int state)Sets the animated button state.-
Methods inherited from class totalcross.game.Animation
enableEvents, getPreferredHeight, getPreferredWidth, onPaint, pause, resume, setImage, size, start, start, stop
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, clear, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onBoundsChanged, onColorsChanged, onFontChanged, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setEnabled, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
FADE_OUT_LAYOUT
public static final int FADE_OUT_LAYOUT
Defines the frames animation order. In the case ofSstates button ofFframes per state,FADE_OUT_LAYOUTmeans that the frames are aSset ofFframes that are fading out the state, which means the first frame of each set is the full state image. In theFADE_IN_LAYOUTlayout, it's the opposite, namely the last frame of each set represents the state ending position. Finally theFADE_OUT_IN_LAYOUTis a mix of the two others, because inter-frames represent successively fading out from one state to fading in to next state.- See Also:
- Constant Field Values
-
FADE_IN_LAYOUT
public static final int FADE_IN_LAYOUT
Frames fading in mode.- See Also:
FADE_OUT_LAYOUT, Constant Field Values
-
FADE_OUT_IN_LAYOUT
public static final int FADE_OUT_IN_LAYOUT
Frames fading out then fading in mode.- See Also:
FADE_OUT_LAYOUT, Constant Field Values
-
state
protected int state
current animated button state
-
layoutType
protected int layoutType
-
fadeInState
protected int fadeInState
-
framesPerState
protected int framesPerState
-
maxStates
protected int maxStates
-
statesIndexes
protected int[] statesIndexes
-
-
Constructor Detail
-
AnimatedButton
public AnimatedButton(Image frames, int states, int framesPerState, int layoutType, int framePeriod) throws ImageException
Animated button constructor.- Parameters:
frames- Button different states frames in multi-frame BMP format.states- Number of states of the button.framesPerState- Number of frames for each state.layoutType-FADE_OUT_LAYOUT,FADE_IN_LAYOUT, orFADE_OUT_IN_LAYOUT.framePeriod- Delay in milliseconds between two frames.- Throws:
ImageException- If an internal method throws it.- See Also:
FADE_OUT_LAYOUT,FADE_IN_LAYOUT,FADE_OUT_IN_LAYOUT
-
-
Method Detail
-
setState
public void setState(int state)
Sets the animated button state.- Parameters:
state- Value between0andstates-1.
-
getState
public int getState()
Gets the animated button state.- Returns:
- Value between
0andstates-1.
-
onEvent
public void onEvent(Event event)
Animated button event handler.
-
inc
protected void inc(boolean up)
Increases/decreases the animated button state.- Parameters:
up- Boolean with atruevalue to increase the value; decrease otherwise.
-
-