Class Element
- Direct Known Subclasses:
Bar
,GridImage
,Group
,Image
,Label
,LCanvas.JumpCurve
,MapView
,ProgressBar
,TextField
,Touchpad
,WarningBar
-
Field Summary
Modifier and TypeFieldDescriptionfinal Color
boolean
boolean
protected float
DO NOT modify without calling sizeChanged.float
float
protected float
Alpha value of the parent.float
float
float
boolean
protected float
DO NOT modify without calling sizeChanged.float
float
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
act
(float delta) Updates the actor based on time.void
void
boolean
addCaptureListener
(EventListener listener) Adds a listener that is only notified during the capture phase.boolean
addListener
(EventListener listener) Add a listener to receive events thathit
this actor.void
change()
Fires a change event on all listeners.void
Adds a click listener.void
clear()
Removes all actions and listeners on this actor.void
Removes all actions on this actor.void
Removes all listeners on this actor.clicked
(Cons<ClickListener> tweaker, Cons<ClickListener> runner) clicked
(Cons<ClickListener> tweaker, Runnable r) Adds a click listener.Adds a click listener.Adds a click listener.boolean
CallsclipBegin(float, float, float, float)
to clip this actor's bounds.boolean
clipBegin
(float x, float y, float width, float height) Clips the specified screen aligned rectangle, specified relative to the transform matrix of the stage's Batch.void
clipEnd()
Ends clipping begun byclipBegin(float, float, float, float)
.void
Adds a listener which listens for drag (touch down and move) events.void
draw()
Draws the element.void
Adds a hover/mouse exit listener.boolean
fire
(SceneEvent event) void
Fakes a click event on all ClickListeners.float
float
float
float
float
float
float
float
getRight()
Returns x plus width.float
getScene()
Returns the stage that this actor is currently in, or null if not in a stage.float
getTop()
Returns y plus height.float
getWidth()
float
getX
(int alignment) Returns the X position of the specifiedalignment
.float
getY
(int alignment) Returns the Y position of the specifiedalignment
.int
Returns the z-index of this actor.boolean
Returns true if the actor has one or more actions.boolean
boolean
hasMouse()
boolean
Returns true if the actor's parent is not null.boolean
hit
(float x, float y, boolean touchable) Returns the deepest actor that contains the specified point and istouchable
andvisible
, or null if no actor was hit.void
Adds a hover/mouse enter listener.void
Invalidates this actor's layout, causinglayout()
to happen the next timevalidate()
is called.void
Invalidates this actor and its ascendants, callinginvalidate()
on each.boolean
isAscendantOf
(Element actor) Returns true if this actor is the same as or is the ascendant of the specified actor.boolean
isDescendantOf
(Boolf<Element> actor) boolean
isDescendantOf
(Element actor) Returns true if this actor is the same as or is the descendant of the specified actor.boolean
Returns true if input events are processed by this actor.void
void
Adds a keydown input listener.void
void
layout()
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsinvalidate()
on any each child whose width or height has changed, and callsvalidate()
on each child.localToAscendantCoordinates
(Element ascendant, Vec2 localCoords) Converts coordinates for this actor to those of a parent actor.localToParentCoordinates
(Vec2 localCoords) Transforms the specified point in the actor's coordinates to be in the parent's coordinates.localToStageCoordinates
(Vec2 localCoords) Transforms the specified point in the actor's coordinates to be in the stage's coordinates.void
moveBy
(float x, float y) Add x and y to current positionboolean
Returns true if the widget's layout has beeninvalidated
.boolean
notify
(SceneEvent event, boolean capture) void
pack()
Sizes this actor to its preferred width and height, then callsvalidate()
.parentToLocalCoordinates
(Vec2 parentCoords) Converts the coordinates given in the parent's coordinate system to this actor's coordinate system.void
Adds a mouse up listener.boolean
remove()
Removes this actor from its parent, if it has a parent.void
removeAction
(Action action) boolean
removeCaptureListener
(EventListener listener) boolean
removeListener
(EventListener listener) void
void
void
rotateBy
(float amountInDegrees) Adds the specified rotation to the current rotation.protected void
Called when the actor's rotation has been changed.void
scaleBy
(float scale) Adds the specified scale to the current scale.void
scaleBy
(float scaleX, float scaleY) Adds the specified scale to the current scale.screenToLocalCoordinates
(Vec2 screenCoords) Transforms the specified point in screen coordinates to the actor's local coordinate system.void
void
setBounds
(float x, float y, float width, float height) Set bounds the x, y, width, and height.void
setColor
(float r, float g, float b, float a) void
void
setFillParent
(boolean fillParent) If true, this actor will be sized to the parent invalidate()
.void
setHeight
(float height) void
setLayoutEnabled
(boolean enabled) void
setOrigin
(float originX, float originY) Sets the origin position which is relative to the actor's bottom left corner.void
setOrigin
(int alignment) Sets the origin position to the specifiedalignment
.void
setPosition
(float x, float y) Sets the position of the actor's bottom left corner.void
setPosition
(float x, float y, int alignment) Sets the position using the specifiedalignment
.void
setRotation
(float degrees) void
setRotationOrigin
(float degrees, int align) void
setScale
(float scaleXY) Sets the scale for both X and Yvoid
setScale
(float scaleX, float scaleY) Sets the scale X and scale Y.protected void
Called by the framework when this actor or any parent is added to a group that is in the stage.void
setSize
(float size) void
setSize
(float width, float height) Sets the width and height.void
setTranslation
(float x, float y) void
setWidth
(float width) void
setZIndex
(int index) Sets the z-index of this actor.void
sizeBy
(float size) Adds the specified size to the current size.void
sizeBy
(float width, float height) Adds the specified size to the current size.protected void
Called when the actor's size has been changed.stageToLocalCoordinates
(Vec2 stageCoords) Transforms the specified point in the stage's coordinates to the actor's local coordinate system.Adds a touch listener.void
toBack()
Changes the z-order for this actor so it is in back of all siblings.void
toFront()
Changes the z-order for this actor so it is in front of all siblings.toString()
void
void
void
validate()
Ensures the actor has been laid out.
-
Field Details
-
color
-
originX
public float originX -
originY
public float originY -
scaleX
public float scaleX -
scaleY
public float scaleY -
rotation
public float rotation -
name
-
fillParent
public boolean fillParent -
translation
-
visible
public boolean visible -
userObject
-
touchable
-
parent
-
visibility
-
touchablility
-
cullable
public boolean cullable -
x
public float x -
y
public float y -
width
protected float widthDO NOT modify without calling sizeChanged. -
height
protected float heightDO NOT modify without calling sizeChanged. -
parentAlpha
protected float parentAlphaAlpha value of the parent. Should be multiplied with the actor's alpha, allowing a parent's alpha to affect all children.
-
-
Constructor Details
-
Element
public Element()
-
-
Method Details
-
draw
public void draw()Draws the element. Does nothing by default. -
act
public void act(float delta) Updates the actor based on time. Typically this is called each frame byScene.act(float)
.The default implementation calls
Action.act(float)
on each action and removes actions that are complete.- Parameters:
delta
- Time in seconds since the last frame.
-
updateVisibility
public void updateVisibility() -
hasMouse
public boolean hasMouse() -
hasKeyboard
public boolean hasKeyboard() -
hasScroll
public boolean hasScroll() -
requestKeyboard
public void requestKeyboard() -
requestScroll
public void requestScroll() -
fire
-
notify
-
hit
Returns the deepest actor that contains the specified point and istouchable
andvisible
, or null if no actor was hit. The point is specified in the actor's local coordinate system (0,0 is the bottom left of the actor and width,height is the upper right).This method is used to delegate touchDown, mouse, and enter/exit events. If this method returns null, those events will not occur on this Actor.
The default implementation returns this actor if the point is within this actor's bounds.
- Parameters:
touchable
- If true, the hit detection will respect thetouchability
.- See Also:
-
remove
public boolean remove()Removes this actor from its parent, if it has a parent.- See Also:
-
dragged
Adds a listener which listens for drag (touch down and move) events. Results are returned in positive deltas. -
scrolled
-
addListener
Add a listener to receive events thathit
this actor. Seefire(SceneEvent)
.- See Also:
-
removeListener
-
getListeners
-
addCaptureListener
Adds a listener that is only notified during the capture phase.- See Also:
-
removeCaptureListener
-
getCaptureListeners
-
addAction
-
actions
-
removeAction
-
getActions
-
hasActions
public boolean hasActions()Returns true if the actor has one or more actions. -
clearActions
public void clearActions()Removes all actions on this actor. -
clearListeners
public void clearListeners()Removes all listeners on this actor. -
clear
public void clear()Removes all actions and listeners on this actor. -
getScene
Returns the stage that this actor is currently in, or null if not in a stage. -
setScene
Called by the framework when this actor or any parent is added to a group that is in the stage.- Parameters:
stage
- May be null if the actor or any parent is no longer in a stage.
-
isDescendantOf
-
isDescendantOf
Returns true if this actor is the same as or is the descendant of the specified actor. -
isAscendantOf
Returns true if this actor is the same as or is the ascendant of the specified actor. -
hasParent
public boolean hasParent()Returns true if the actor's parent is not null. -
isTouchable
public boolean isTouchable()Returns true if input events are processed by this actor. -
getX
public float getX(int alignment) Returns the X position of the specifiedalignment
. -
getY
public float getY(int alignment) Returns the Y position of the specifiedalignment
. -
setPosition
public void setPosition(float x, float y) Sets the position of the actor's bottom left corner. -
setPosition
public void setPosition(float x, float y, int alignment) Sets the position using the specifiedalignment
. Note this may set the position to non-integer coordinates. -
moveBy
public void moveBy(float x, float y) Add x and y to current position -
getWidth
public float getWidth() -
setWidth
public void setWidth(float width) -
getHeight
public float getHeight() -
setHeight
public void setHeight(float height) -
getTop
public float getTop()Returns y plus height. -
getRight
public float getRight()Returns x plus width. -
sizeChanged
protected void sizeChanged()Called when the actor's size has been changed. -
rotationChanged
protected void rotationChanged()Called when the actor's rotation has been changed. -
setSize
public void setSize(float size) -
setSize
public void setSize(float width, float height) Sets the width and height. -
sizeBy
public void sizeBy(float size) Adds the specified size to the current size. -
sizeBy
public void sizeBy(float width, float height) Adds the specified size to the current size. -
setBounds
public void setBounds(float x, float y, float width, float height) Set bounds the x, y, width, and height. -
setOrigin
public void setOrigin(float originX, float originY) Sets the origin position which is relative to the actor's bottom left corner. -
setOrigin
public void setOrigin(int alignment) Sets the origin position to the specifiedalignment
. -
setScale
public void setScale(float scaleXY) Sets the scale for both X and Y -
setScale
public void setScale(float scaleX, float scaleY) Sets the scale X and scale Y. -
scaleBy
public void scaleBy(float scale) Adds the specified scale to the current scale. -
scaleBy
public void scaleBy(float scaleX, float scaleY) Adds the specified scale to the current scale. -
getRotation
public float getRotation() -
setRotation
public void setRotation(float degrees) -
setRotationOrigin
public void setRotationOrigin(float degrees, int align) -
rotateBy
public void rotateBy(float amountInDegrees) Adds the specified rotation to the current rotation. -
setColor
public void setColor(float r, float g, float b, float a) -
setColor
-
toFront
public void toFront()Changes the z-order for this actor so it is in front of all siblings. -
toBack
public void toBack()Changes the z-order for this actor so it is in back of all siblings. -
getZIndex
public int getZIndex()Returns the z-index of this actor.- See Also:
-
setZIndex
public void setZIndex(int index) Sets the z-index of this actor. The z-index is the index into the parent'schildren
, where a lower index is below a higher index. Setting a z-index higher than the number of children will move the child to the front. Setting a z-index less than zero is invalid. -
clipBegin
public boolean clipBegin()CallsclipBegin(float, float, float, float)
to clip this actor's bounds. -
clipBegin
public boolean clipBegin(float x, float y, float width, float height) Clips the specified screen aligned rectangle, specified relative to the transform matrix of the stage's Batch. The transform matrix and the stage's camera must not have rotational components. Calling this method must be followed by a call toclipEnd()
if true is returned.- Returns:
- false if the clipping area is zero and no drawing should occur.
- See Also:
-
clipEnd
public void clipEnd()Ends clipping begun byclipBegin(float, float, float, float)
. -
screenToLocalCoordinates
Transforms the specified point in screen coordinates to the actor's local coordinate system. -
stageToLocalCoordinates
Transforms the specified point in the stage's coordinates to the actor's local coordinate system. -
localToStageCoordinates
Transforms the specified point in the actor's coordinates to be in the stage's coordinates. -
localToParentCoordinates
Transforms the specified point in the actor's coordinates to be in the parent's coordinates. -
localToAscendantCoordinates
Converts coordinates for this actor to those of a parent actor. The ascendant does not need to be a direct parent. -
parentToLocalCoordinates
Converts the coordinates given in the parent's coordinate system to this actor's coordinate system. -
getMinWidth
public float getMinWidth() -
getMinHeight
public float getMinHeight() -
getPrefWidth
public float getPrefWidth() -
getPrefHeight
public float getPrefHeight() -
getMaxWidth
public float getMaxWidth() -
getMaxHeight
public float getMaxHeight() -
setLayoutEnabled
public void setLayoutEnabled(boolean enabled) -
validate
public void validate()Ensures the actor has been laid out. Callslayout()
ifinvalidate()
has been called since the last timevalidate()
was called, or if the actor otherwise needs to be laid out. This method is usually called indraw()
by the actor itself before drawing is performed. -
needsLayout
public boolean needsLayout()Returns true if the widget's layout has beeninvalidated
. -
invalidate
public void invalidate()Invalidates this actor's layout, causinglayout()
to happen the next timevalidate()
is called. This method should be called when state changes in the actor that requires a layout but does not change the minimum, preferred, maximum, or actual size of the actor (meaning it does not affect the parent actor's layout). -
invalidateHierarchy
public void invalidateHierarchy()Invalidates this actor and its ascendants, callinginvalidate()
on each. This method should be called when state changes in the actor that affects the minimum, preferred, maximum, or actual size of the actor (meaning it potentially affects the parent actor's layout). -
pack
public void pack()Sizes this actor to its preferred width and height, then callsvalidate()
.Generally this method should not be called in an actor's constructor because it calls
layout()
, which means a subclass would have layout() called before the subclass' constructor. Instead, in constructors simply set the actor's size togetPrefWidth()
andgetPrefHeight()
. This allows the actor to have a size at construction time for more convenient use with groups that do not layout their children. -
setFillParent
public void setFillParent(boolean fillParent) If true, this actor will be sized to the parent invalidate()
. If the parent is the stage, the actor will be sized to the stage. This method is for convenience only when the widget's parent does not set the size of its children (such as the stage). -
layout
public void layout()Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsinvalidate()
on any each child whose width or height has changed, and callsvalidate()
on each child. This method should almost never be called directly, insteadvalidate()
should be used. -
keepInStage
public void keepInStage() -
setTranslation
public void setTranslation(float x, float y) -
keyDown
-
keyDown
Adds a keydown input listener. -
fireClick
public void fireClick()Fakes a click event on all ClickListeners. -
clicked
Adds a click listener. -
clicked
Adds a click listener. -
clicked
Adds a click listener. -
clicked
-
tapped
Adds a touch listener. -
hovered
Adds a hover/mouse enter listener. -
exited
Adds a hover/mouse exit listener. -
released
Adds a mouse up listener. -
change
public void change()Fires a change event on all listeners. -
changed
Adds a click listener. -
update
-
visible
-
touchable
-
toString
-