public abstract class GuiComponent extends java.lang.Object implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, IRenderable
Modifier and Type | Field and Description |
---|---|
protected static java.awt.Font |
ICON_FONT |
Modifier | Constructor and Description |
---|---|
protected |
GuiComponent(double x,
double y)
Instantiates a new gui component with the dimension (0,0) at the given location.
|
protected |
GuiComponent(double x,
double y,
double width,
double height)
Instantiates a new gui component at the point (x,y) with the dimension (width,height).
|
Modifier and Type | Method and Description |
---|---|
boolean |
drawTextShadow()
Draw text shadow.
|
Appearance |
getAppearance()
Gets the default appearance object for this GuiComponent.
|
Appearance |
getAppearanceDisabled()
Gets the appearance object for this GuiComponent while disabled.
|
Appearance |
getAppearanceHovered()
Gets the appearance object for this GuiComponent while hovered.
|
java.awt.geom.Rectangle2D |
getBoundingBox()
Gets the bounding box of this GuiComponent.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> |
getClickConsumer()
Gets the click consumer list.
|
int |
getComponentId()
Gets the component id of this GuiComponent.
|
java.util.List<GuiComponent> |
getComponents()
Gets the child components of this GuiComponent.
|
protected Appearance |
getCurrentAppearance() |
java.awt.Font |
getFont()
Gets the font of this GuiComponent's text.
|
double |
getHeight()
Gets the height of this GuiComponent.
|
double |
getHorizontalTextMargin()
Gets the margin size between the GuiComponent's left and right border and the Text bounds.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> |
getHoverConsumer()
Gets the hover consumer list.
|
Sound |
getHoverSound()
Gets the sound that is played when hovering the GuiComponent.
|
java.awt.geom.Point2D |
getLocation()
Gets the screen location of this GuiComponent.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> |
getMouseDraggedConsumer()
Gets the mouse dragged consumer list.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> |
getMouseEnterConsumer()
Gets the mouse enter consumer list.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> |
getMouseLeaveConsumer()
Gets the mouse leave consumer list.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> |
getMouseMovedConsumer()
Gets the mouse moved consumer list.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> |
getMousePressedConsumer()
Gets the mouse pressed consumer list.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> |
getMouseReleasedConsumer()
Gets the mouse released consumer list.
|
protected java.util.List<java.util.function.Consumer<ComponentMouseWheelEvent>> |
getMouseWheelConsumer()
Gets the mouse wheel consumer list.
|
java.lang.String |
getName()
Gets the name of this GuiComponent.
|
java.awt.geom.RectangularShape |
getShape() |
java.lang.Object |
getTag()
Gets the tag.
|
java.lang.String |
getText()
Gets the entire Text associated with this GuiComponent.
|
Align |
getTextAlign()
Gets the horizontal text alignment.
|
int |
getTextAngle()
Gets the text angle.
|
java.awt.Color |
getTextShadowColor()
Gets the text shadow color.
|
java.lang.String |
getTextToRender(java.awt.Graphics2D g)
Gets only the non-cropped bits of Text visible on this GuiComponent.m
To retrieve only the entire text associated with this GuiComponent, use
GuiComponent.getText() . |
double |
getTextX()
Gets the text X coordinate.
|
double |
getTextY()
Gets the text Y coordinate.
|
double |
getWidth()
Gets the width of this GuiComponent.
|
double |
getX()
Gets the x coordinate of this GuiComponent.
|
double |
getY()
Gets the y coordinate of this GuiComponent.
|
protected void |
initializeComponents()
Initialize child components.
|
boolean |
isEnabled()
Checks if the GuiComponent is enabled.
|
boolean |
isForwardMouseEvents()
Checks if mouse events are being forwarded by this GuiComponent.
|
boolean |
isHovered()
Checks if the cursor bounding box intersects with this GuiCOmponent's bounding box.
|
boolean |
isPressed()
Checks if the mouse button is currently being pressed on this GuiComponent.
|
boolean |
isSelected()
Checks if the GuiComponent is currently selected.
|
boolean |
isSuspended()
Checks if the GuiComponent is currently suspended.
|
boolean |
isVisible()
Checks if the GuiComponent is currently visible.
|
void |
mouseClicked(java.awt.event.MouseEvent e) |
void |
mouseDragged(java.awt.event.MouseEvent e) |
void |
mouseEntered(java.awt.event.MouseEvent e) |
protected boolean |
mouseEventShouldBeForwarded(java.awt.event.MouseEvent e)
Check if a Mouse event should be forwarded.
|
void |
mouseExited(java.awt.event.MouseEvent e) |
void |
mouseMoved(java.awt.event.MouseEvent e) |
void |
mousePressed(java.awt.event.MouseEvent e) |
void |
mouseReleased(java.awt.event.MouseEvent e) |
void |
mouseWheelMoved(java.awt.event.MouseWheelEvent e) |
void |
onClicked(java.util.function.Consumer<ComponentMouseEvent> callback)
Add a callback that is being executed if this GuiComponent is clicked once.
|
void |
onHovered(java.util.function.Consumer<ComponentMouseEvent> callback)
Add a callback that is being executed if this GuiComponent is hovered with the mouse.
|
void |
onMouseDragged(java.util.function.Consumer<ComponentMouseEvent> callback)
Add a callback that is being executed if the mouse is pressed and moving around while within the bounds of this GuiComponent.
|
void |
onMouseEnter(java.util.function.Consumer<ComponentMouseEvent> callback)
Add a callback that is being executed if the mouse enters the bounds of this GuiComponent.
|
void |
onMouseLeave(java.util.function.Consumer<ComponentMouseEvent> callback)
Add a callback that is being executed if the mouse leaves the bounds of this GuiComponent.
|
void |
onMouseMoved(java.util.function.Consumer<ComponentMouseEvent> callback)
Add a callback that is being executed if the mouse is moving around while within the bounds of this GuiComponent.
|
void |
onMousePressed(java.util.function.Consumer<ComponentMouseEvent> callback)
Add a callback that is being executed if the mouse is continually pressed while within the bounds of this GuiComponent.
|
void |
onMouseReleased(java.util.function.Consumer<ComponentMouseEvent> callback)
Add a callback that is being executed if the mouse button is released while within the bounds of this GuiComponent.
|
void |
onMouseWheelScrolled(java.util.function.Consumer<ComponentMouseWheelEvent> callback)
Add a callback that is being executed if the mouse wheel is scrolled while within the bounds of this GuiComponent.
|
void |
onTextChanged(java.util.function.Consumer<java.lang.String> cons)
Add a callback that is being executed if the text on this GuiComponent changes.
|
void |
prepare()
Prepare the GuiComponent and all its child Components (Makes the GuiComponent visible and adds mouse listeners.).
|
void |
render(java.awt.Graphics2D g)
Renders the visual contents of this instance onto the provided graphics context.
|
void |
setDimension(double width,
double height)
Sets the width and height of this GuiComponent.
|
void |
setEnabled(boolean enabled)
Sets the "enabled" property on this GuiComponent and its child components.
|
void |
setFont(java.awt.Font font)
Sets the font for this GuiComponent's text.
|
void |
setFontSize(float size)
Sets the font size for this GuiComponent's text.
|
void |
setForwardMouseEvents(boolean forwardMouseEvents)
Enable or disable forwarding mouse events by this GuiComponent.
|
void |
setHeight(double height)
Sets the GuiComponent's height.
|
void |
setHorizontalTextMargin(double xMargin)
Sets the margin size between the GuiComponent's left and right border and the Text bounds.
|
void |
setHovered(boolean hovered)
Sets the "enabled" property on this GuiComponent.
|
void |
setHoverSound(Sound hoverSound)
Sets the hover sound.
|
void |
setLocation(double x,
double y)
Sets this GuiComponent's location.
|
void |
setLocation(java.awt.geom.Point2D location)
Sets this GuiComponent's location.
|
void |
setName(java.lang.String name)
Sets this GuiComponent's name.
|
void |
setSelected(boolean bool)
Sets the "selected" property on this GuiComponent.
|
void |
setTag(java.lang.Object tag)
Sets the tag.
|
void |
setText(java.lang.String text)
Sets the text.
|
void |
setTextAlign(Align textAlignment)
Sets the horizontal text alignment.
|
void |
setTextAngle(int textAngle)
Sets the text angle in degrees.
|
void |
setTextShadow(boolean drawTextShadow)
Enable or disable the shadow being drawn below the text
|
void |
setTextShadowColor(java.awt.Color textShadowColor)
Sets the text shadow color.
|
void |
setTextX(double x)
Sets the text X coordinate.
|
void |
setTextY(double y)
Sets the text Y coordinate.
|
void |
setVisible(boolean visible)
Sets the "visible" property on this GuiComponent.
|
void |
setWidth(double width)
Sets the GuiComponent's width.
|
void |
setX(double x)
Sets the GuiComponent's x coordinate.
|
void |
setY(double y)
Sets the GuiComponent's y coordinate.
|
void |
suspend()
Suspend the GuiComponent and all its child Components (Makes the GuiComponent invisible and removes mouse listeners.).
|
void |
toggleSelection()
Toggle this GuiComponent's selection.
|
void |
toggleSuspension()
Toggle this GuiComponent's suspension state.
|
protected GuiComponent(double x, double y)
x
- the xy
- the yprotected GuiComponent(double x, double y, double width, double height)
x
- the xy
- the ywidth
- the widthheight
- the heightpublic boolean drawTextShadow()
public Appearance getAppearance()
public Appearance getAppearanceDisabled()
public Appearance getAppearanceHovered()
public java.awt.geom.Rectangle2D getBoundingBox()
public int getComponentId()
public java.util.List<GuiComponent> getComponents()
public java.awt.Font getFont()
public double getHeight()
public double getHorizontalTextMargin()
public Sound getHoverSound()
public java.awt.geom.Point2D getLocation()
public java.lang.String getName()
public java.lang.Object getTag()
public java.lang.String getText()
GuiComponent.getTextToRender(Graphics2D g)
.public Align getTextAlign()
public int getTextAngle()
public java.awt.Color getTextShadowColor()
public java.lang.String getTextToRender(java.awt.Graphics2D g)
GuiComponent.getText()
.g
- The graphics object to render on.public double getTextX()
public double getTextY()
public double getWidth()
public double getX()
public double getY()
public boolean isEnabled()
public boolean isForwardMouseEvents()
public boolean isHovered()
public boolean isPressed()
public boolean isSelected()
public boolean isSuspended()
public boolean isVisible()
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged
in interface java.awt.event.MouseMotionListener
public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
mouseWheelMoved
in interface java.awt.event.MouseWheelListener
public void onClicked(java.util.function.Consumer<ComponentMouseEvent> callback)
callback
- the callbackpublic void onHovered(java.util.function.Consumer<ComponentMouseEvent> callback)
callback
- the callbackpublic void onMouseDragged(java.util.function.Consumer<ComponentMouseEvent> callback)
callback
- the callbackpublic void onMouseEnter(java.util.function.Consumer<ComponentMouseEvent> callback)
callback
- the callbackpublic void onMouseLeave(java.util.function.Consumer<ComponentMouseEvent> callback)
callback
- the callbackpublic void onMouseMoved(java.util.function.Consumer<ComponentMouseEvent> callback)
callback
- the callbackpublic void onMousePressed(java.util.function.Consumer<ComponentMouseEvent> callback)
callback
- the callbackpublic void onMouseReleased(java.util.function.Consumer<ComponentMouseEvent> callback)
callback
- the callbackpublic void onMouseWheelScrolled(java.util.function.Consumer<ComponentMouseWheelEvent> callback)
callback
- the callbackpublic void onTextChanged(java.util.function.Consumer<java.lang.String> cons)
cons
- the conspublic void prepare()
public void render(java.awt.Graphics2D g)
IRenderable
If an Entity
implements this interface, this method will be called right after the entity was rendered from the environment.
Allowing for a custom rendering mechanism.
This interface can be implemented in general by anything that should be rendered to the game's screen.
render
in interface IRenderable
g
- The current graphics object onto which this instance will render its visual contents.RenderEngine.renderEntity(Graphics2D, de.gurkenlabs.litiengine.entities.IEntity)
public java.awt.geom.RectangularShape getShape()
public void setDimension(double width, double height)
width
- the widthheight
- the heightpublic void setEnabled(boolean enabled)
enabled
- the new enabled propertypublic void setFont(java.awt.Font font)
font
- the new fontpublic void setFontSize(float size)
size
- the new font sizepublic void setForwardMouseEvents(boolean forwardMouseEvents)
forwardMouseEvents
- the new forward mouse eventspublic void setHeight(double height)
height
- the new heightpublic void setHorizontalTextMargin(double xMargin)
xMargin
- the new text X marginpublic void setHovered(boolean hovered)
hovered
- the new hoveredpublic void setHoverSound(Sound hoverSound)
hoverSound
- the new hover soundpublic void setLocation(double x, double y)
x
- the new x coordinatey
- the new y coordinatepublic void setLocation(java.awt.geom.Point2D location)
location
- the new locationpublic void setName(java.lang.String name)
name
- the new namepublic void setSelected(boolean bool)
bool
- the new selectedpublic void setTag(java.lang.Object tag)
tag
- the new tagpublic void setText(java.lang.String text)
text
- the new textpublic void setTextAlign(Align textAlignment)
textAlignment
- the new text alignpublic void setTextAngle(int textAngle)
textAngle
- the new text angle in degreespublic void setTextShadow(boolean drawTextShadow)
drawTextShadow
- the boolean determining if a text shadow should be drawnpublic void setTextShadowColor(java.awt.Color textShadowColor)
textShadowColor
- the new text shadow colorpublic void setTextX(double x)
x
- the new text Xpublic void setTextY(double y)
y
- the new text Ypublic void setVisible(boolean visible)
visible
- the new visiblepublic void setWidth(double width)
width
- the new widthpublic void setX(double x)
x
- the new x coordinatepublic void setY(double y)
y
- the new y coordinatepublic void suspend()
public void toggleSelection()
public void toggleSuspension()
protected Appearance getCurrentAppearance()
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> getClickConsumer()
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> getHoverConsumer()
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> getMouseDraggedConsumer()
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> getMouseEnterConsumer()
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> getMouseLeaveConsumer()
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> getMouseMovedConsumer()
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> getMousePressedConsumer()
protected java.util.List<java.util.function.Consumer<ComponentMouseEvent>> getMouseReleasedConsumer()
protected java.util.List<java.util.function.Consumer<ComponentMouseWheelEvent>> getMouseWheelConsumer()
protected void initializeComponents()
protected boolean mouseEventShouldBeForwarded(java.awt.event.MouseEvent e)
e
- the mouse event