Package squidpony.squidgrid.gui.gdx
Class ColorChangeLabel
java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.badlogic.gdx.scenes.scene2d.ui.Label
squidpony.squidgrid.gui.gdx.ColorChangeLabel
- All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Layout
public class ColorChangeLabel extends com.badlogic.gdx.scenes.scene2d.ui.Label
A Label that changes its color automatically, taking its current color from a list such as a gradient. Useful for
implementing a "blink" effect where a creature alternates being visible and invisible, for a magical object that has
all the colors of the rainbow, or for all sorts of similar uses. The color pattern loops, by default one loop per two
seconds (but this can be changed), so longer lists of colors will display each color for a shorter time.
Created by Tommy Ettinger on 3/23/2016.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protected
ColorChangeLabel()
ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, float loopTime, boolean doubleWidth, com.badlogic.gdx.graphics.Color... colors)
Constructs a ColorChangeLabel.ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, float loopTime, boolean doubleWidth, Collection<com.badlogic.gdx.graphics.Color> colors)
Constructs a ColorChangeLabel.ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, float loopTime, com.badlogic.gdx.graphics.Color... colors)
Constructs a ColorChangeLabel.ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, float loopTime, Collection<com.badlogic.gdx.graphics.Color> colors)
Constructs a ColorChangeLabel.ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, com.badlogic.gdx.graphics.Color... colors)
Constructs a ColorChangeLabel.ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, Collection<com.badlogic.gdx.graphics.Color> colors)
Constructs a ColorChangeLabel. -
Method Summary
Modifier and Type Method Description void
act(float delta)
Updates the actor based on time.com.badlogic.gdx.graphics.Color
getColor()
Returns the color the actor will be tinted when drawn.void
resetLoopTime(float loopTime)
Changes the amount of time this takes to loop through all colors, and also resets the current loop to its start.void
setColors(com.badlogic.gdx.graphics.Color... colors)
Sets the list of colors this uses to choose what color it draws with.void
setColors(Collection<com.badlogic.gdx.graphics.Color> colors)
Sets the list of colors this uses to choose what color it draws with.Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Label
draw, getBitmapFontCache, getFontScaleX, getFontScaleY, getGlyphLayout, getLabelAlign, getLineAlign, getPrefHeight, getPrefWidth, getStyle, getText, getWrap, invalidate, layout, setAlignment, setAlignment, setEllipsis, setEllipsis, setFontScale, setFontScale, setFontScaleX, setFontScaleY, setStyle, setText, setText, setWrap, textEquals, toString
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, drawDebugBounds, fire, firstAscendant, getActions, getCaptureListeners, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, hit, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
Field Details
-
Constructor Details
-
ColorChangeLabel
protected ColorChangeLabel() -
ColorChangeLabel
public ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, Collection<com.badlogic.gdx.graphics.Color> colors)Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.- Parameters:
text
- the text to display in this ColorChangeLabelstyle
- the LabelStyle to use for this; typically TextCellFactory handles thiscolors
- a Collection (usually a List) of Color, such as one returned by SquidColorCenter's gradient method
-
ColorChangeLabel
public ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, float loopTime, Collection<com.badlogic.gdx.graphics.Color> colors)Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.- Parameters:
text
- the text to display in this ColorChangeLabelstyle
- the LabelStyle to use for this; typically TextCellFactory handles thisloopTime
- the amount of time, in seconds, it takes to loop through all the colors in the listcolors
- a Collection (usually a List) of Color, such as one returned by SquidColorCenter's gradient method
-
ColorChangeLabel
public ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, float loopTime, boolean doubleWidth, Collection<com.badlogic.gdx.graphics.Color> colors)Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.- Parameters:
text
- the text to display in this ColorChangeLabelstyle
- the LabelStyle to use for this; typically TextCellFactory handles thisloopTime
- the amount of time, in seconds, it takes to loop through all the colors in the listdoubleWidth
- true if this takes up two grid cells; only matters if you useAnimatedEntity.setDirection(Direction)
colors
- a Collection (usually a List) of Color, such as one returned by SquidColorCenter's gradient method
-
ColorChangeLabel
public ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, com.badlogic.gdx.graphics.Color... colors)Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.- Parameters:
text
- the text to display in this ColorChangeLabelstyle
- the LabelStyle to use for this; typically TextCellFactory handles thiscolors
- an array or vararg of Color
-
ColorChangeLabel
public ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, float loopTime, com.badlogic.gdx.graphics.Color... colors)Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.- Parameters:
text
- the text to display in this ColorChangeLabelstyle
- the LabelStyle to use for this; typically TextCellFactory handles thisloopTime
- the amount of time, in seconds, it takes to loop through all the colors in the listcolors
- an array or vararg of Color
-
ColorChangeLabel
public ColorChangeLabel(CharSequence text, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle style, float loopTime, boolean doubleWidth, com.badlogic.gdx.graphics.Color... colors)Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.- Parameters:
text
- the text to display in this ColorChangeLabelstyle
- the LabelStyle to use for this; typically TextCellFactory handles thisloopTime
- the amount of time, in seconds, it takes to loop through all the colors in the listdoubleWidth
- true if this takes up two grid cells; only matters if you useAnimatedEntity.setDirection(Direction)
colors
- an array or vararg of Color
-
-
Method Details
-
getColor
Returns the color the actor will be tinted when drawn. Takes the Color from the List of Color this was constructed with or assigned with setColors, not the normal Actor color assigned with setColor.- Overrides:
getColor
in classcom.badlogic.gdx.scenes.scene2d.Actor
- Returns:
- the Color this will be drawn with
-
setColors
Sets the list of colors this uses to choose what color it draws with.- Parameters:
colors
- a Collection (usually a List) of Color, such as one returned by SquidColorCenter's gradient method
-
setColors
Sets the list of colors this uses to choose what color it draws with.- Parameters:
colors
- an array or vararg of Color
-
act
Updates the actor based on time. Typically this is called each frame byStage.act(float)
.The default implementation calls
Action.act(float)
on each action and removes actions that are complete.- Overrides:
act
in classcom.badlogic.gdx.scenes.scene2d.Actor
- Parameters:
delta
- Time in seconds since the last frame.
-
resetLoopTime
Changes the amount of time this takes to loop through all colors, and also resets the current loop to its start.- Parameters:
loopTime
- the amount of time, in seconds, it takes to loop through all the colors in the list
-