Class BaseWidget
- java.lang.Object
-
- be.yildizgames.common.util.BaseRegisterable
-
- be.yildizgames.module.graphic.gui.internal.BaseElement
-
- be.yildizgames.module.graphic.gui.internal.BaseWidget
-
- Direct Known Subclasses:
BaseContainerChild,SimpleContainer
public abstract class BaseWidget extends BaseElement implements Widget
This is the parent of all components of the gui.- Author:
- Grégory Van Den Borre
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface be.yildizgames.module.graphic.gui.internal.Element
Element.Alignment
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<be.yildizgames.common.geometry.Rectangle>emptyZonesList of zones to ignore to check if a point is inside the container.-
Fields inherited from class be.yildizgames.module.graphic.gui.internal.BaseElement
MAX_OPACITY, virtualHeight
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseWidget(String name, be.yildizgames.module.coordinate.BaseCoordinate coordinates)Full constructor.protectedBaseWidget(String name, be.yildizgames.module.coordinate.BaseCoordinate coordinates, Container parent)Full constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddEmptyZone(be.yildizgames.common.geometry.Rectangle zone)Add a zone to ignore when checking if the container contains the mouse, if the mouse position is inside this zone, it will be considered as outside of the container.protected abstract voidaddEmptyZoneImpl(be.yildizgames.common.geometry.Rectangle zone)voidaddKeyboardListener(be.yildizgames.module.window.input.KeyboardListener listener)Add a new KeyboardListener on this widget and set the widget focusable.voidaddMouseDoubleLeftClickListener(be.yildizgames.module.window.input.MouseDoubleLeftClickListener listener)Add a new MouseDoubleClickListener on this widget.voidaddMouseDragListener(be.yildizgames.module.window.input.MouseDragListener listener)Add a new MouseDragListener on this widget.voidaddMouseLeftClickListener(be.yildizgames.module.window.input.MouseLeftClickListener listener)Add a new MouseClickListener on this widget.voidaddMouseMoveListener(be.yildizgames.module.window.input.MouseMoveListener listener)Add a new MouseMoveListener on this widget.voidaddMouseReleaseListener(be.yildizgames.module.window.input.MouseReleaseListener listener)Add a new MouseReleaseClickListener on this widget.voidaddMouseRightClickListener(be.yildizgames.module.window.input.MouseRightClickListener listener)voidaddMouseWheelListener(be.yildizgames.module.window.input.MouseWheelListener listener)Add a new MouseWheelListener on this widget.voidaddOnMouseOverListener(OnMouseOverListener listener)Add a new OnMouseOverListener on this widget.voidalign(Element.Alignment alignment)Align the widgetbooleancontains(int x, int y)booleancontains(be.yildizgames.module.window.input.MousePosition position)Check if a point in contained in this container.voiddisableEmptyZone()voidenableEmptyZone()Optional<Container>findParent()voidfocus(boolean over)Called when the focus status must be updated.voidforceContainsFalse()Force the contains method to always return false, in order to ignore inputs.intgetAbsoluteLeft()Give the absolute left position instead of relative from parent.be.yildizgames.common.geometry.Point2DgetAbsolutePosition()intgetAbsoluteTop()Give the absolute top position instead of relative from parent.voidhighlight(boolean over)Called when the highlight status must be updated.protected abstract voidhighlightImpl(boolean highlightState)Implementation to set the widget highlight.booleanisContainer()booleanisFocusable()protected booleanisMouseOver()voidkeyPressed(char key)Called when a key is pressed on the keyboard.voidmouseLeftClick(be.yildizgames.module.window.input.MousePosition position)Called when the mouse left button is pressed.voidplayAnimation(String name)voidregisterAnimation(BaseAnimationGui anim)voidremoveAllClickListeners()Clear the list of all click listeners.voidsetFocusable(boolean focusable)Set the widget to be considered as focusable or not.protected voidsetHighlightable(boolean value)Set the widget to be considered as hightligthable or not.protected voidsetMouseClickActive(boolean active)Activate or disable the mouse button action on this widget.ElementsetMouseOver(boolean over, be.yildizgames.module.window.input.MousePosition position)Called when the mouse enter or get out of a widget.voidspecialKeyPressed(be.yildizgames.module.window.input.Key keyCode)Called when a special key is pressed on the keyboard.voidstopAnimation(String name)StringtoString()-
Methods inherited from class be.yildizgames.module.graphic.gui.internal.BaseElement
addToLeft, addToPosition, addToTop, delete, getBottom, getCoordinates, getHeight, getLeft, getOpacity, getRight, getTop, getWidth, hide, hideImpl, isVisible, multiplySize, resetVirtualHeight, setCoordinates, setHeight, setLeft, setLeft, setLeft, setLeft, setPosition, setPosition, setPositionImpl, setSize, setSize, setSizeImpl, setTop, setTop, setTop, setTop, setVirtualHeight, setVisible, setWidth, show, showImpl, updateAddPositionValue
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface be.yildizgames.module.graphic.gui.internal.Element
addToLeft, addToPosition, addToTop, getBottom, getCoordinates, getHeight, getLeft, getRight, getTop, getWidth, hide, isVisible, resetVirtualHeight, setCoordinates, setHeight, setLeft, setLeft, setLeft, setLeft, setPosition, setPosition, setSize, setSize, setTop, setTop, setTop, setTop, setVirtualHeight, setVisible, setWidth, show
-
-
-
-
Field Detail
-
emptyZones
protected final Set<be.yildizgames.common.geometry.Rectangle> emptyZones
List of zones to ignore to check if a point is inside the container.
-
-
Constructor Detail
-
BaseWidget
protected BaseWidget(String name, be.yildizgames.module.coordinate.BaseCoordinate coordinates)
Full constructor.- Parameters:
name- Widget unique name.coordinates- Widget initial size and position.
-
-
Method Detail
-
addMouseLeftClickListener
public final void addMouseLeftClickListener(be.yildizgames.module.window.input.MouseLeftClickListener listener)
Description copied from interface:WidgetAdd a new MouseClickListener on this widget.- Specified by:
addMouseLeftClickListenerin interfaceWidget- Parameters:
listener- Listener to add.
-
addMouseRightClickListener
public final void addMouseRightClickListener(be.yildizgames.module.window.input.MouseRightClickListener listener)
- Specified by:
addMouseRightClickListenerin interfaceWidget
-
addMouseDoubleLeftClickListener
public final void addMouseDoubleLeftClickListener(be.yildizgames.module.window.input.MouseDoubleLeftClickListener listener)
Description copied from interface:WidgetAdd a new MouseDoubleClickListener on this widget.- Specified by:
addMouseDoubleLeftClickListenerin interfaceWidget- Parameters:
listener- Listener to add.
-
addMouseReleaseListener
public final void addMouseReleaseListener(be.yildizgames.module.window.input.MouseReleaseListener listener)
Description copied from interface:WidgetAdd a new MouseReleaseClickListener on this widget.- Specified by:
addMouseReleaseListenerin interfaceWidget- Parameters:
listener- Listener to add.
-
removeAllClickListeners
public final void removeAllClickListeners()
Description copied from interface:WidgetClear the list of all click listeners.- Specified by:
removeAllClickListenersin interfaceWidget
-
addKeyboardListener
public final void addKeyboardListener(be.yildizgames.module.window.input.KeyboardListener listener)
Description copied from interface:WidgetAdd a new KeyboardListener on this widget and set the widget focusable.- Specified by:
addKeyboardListenerin interfaceWidget- Parameters:
listener- Listener to add.
-
addMouseMoveListener
public final void addMouseMoveListener(be.yildizgames.module.window.input.MouseMoveListener listener)
Description copied from interface:WidgetAdd a new MouseMoveListener on this widget.- Specified by:
addMouseMoveListenerin interfaceWidget- Parameters:
listener- Listener to add.
-
addMouseWheelListener
public final void addMouseWheelListener(be.yildizgames.module.window.input.MouseWheelListener listener)
Description copied from interface:WidgetAdd a new MouseWheelListener on this widget.- Specified by:
addMouseWheelListenerin interfaceWidget- Parameters:
listener- Listener to add.
-
addMouseDragListener
public final void addMouseDragListener(be.yildizgames.module.window.input.MouseDragListener listener)
Description copied from interface:WidgetAdd a new MouseDragListener on this widget.- Specified by:
addMouseDragListenerin interfaceWidget- Parameters:
listener- Listener to add.
-
addOnMouseOverListener
public final void addOnMouseOverListener(OnMouseOverListener listener)
Description copied from interface:WidgetAdd a new OnMouseOverListener on this widget.- Specified by:
addOnMouseOverListenerin interfaceWidget- Parameters:
listener- Listener to add.
-
registerAnimation
public final void registerAnimation(BaseAnimationGui anim)
- Specified by:
registerAnimationin interfaceWidget
-
playAnimation
public final void playAnimation(String name)
- Specified by:
playAnimationin interfaceWidget
-
stopAnimation
public final void stopAnimation(String name)
- Specified by:
stopAnimationin interfaceWidget
-
highlightImpl
protected abstract void highlightImpl(boolean highlightState)
Implementation to set the widget highlight.- Parameters:
highlightState- Highlight state.
-
contains
public final boolean contains(be.yildizgames.module.window.input.MousePosition position)
Description copied from interface:WidgetCheck if a point in contained in this container.
-
addEmptyZone
public final void addEmptyZone(be.yildizgames.common.geometry.Rectangle zone)
Description copied from interface:WidgetAdd a zone to ignore when checking if the container contains the mouse, if the mouse position is inside this zone, it will be considered as outside of the container.- Specified by:
addEmptyZonein interfaceWidget- Parameters:
zone- Empty zone.
-
addEmptyZoneImpl
protected abstract void addEmptyZoneImpl(be.yildizgames.common.geometry.Rectangle zone)
-
mouseLeftClick
public final void mouseLeftClick(be.yildizgames.module.window.input.MousePosition position)
Called when the mouse left button is pressed. Only to be used from the EventDispatcher.- Parameters:
position- Mouse position.
-
getAbsolutePosition
public final be.yildizgames.common.geometry.Point2D getAbsolutePosition()
-
keyPressed
public final void keyPressed(char key)
Called when a key is pressed on the keyboard. Only to be used from the EventDispatcher.- Parameters:
key- Character pressed.
-
specialKeyPressed
public final void specialKeyPressed(be.yildizgames.module.window.input.Key keyCode)
Called when a special key is pressed on the keyboard. Only to be used from the EventDispatcher.- Parameters:
keyCode- Key pressed value.
-
highlight
public final void highlight(boolean over)
Called when the highlight status must be updated.
-
focus
public final void focus(boolean over)
Called when the focus status must be updated.
-
align
public final void align(Element.Alignment alignment)
Description copied from interface:WidgetAlign the widget
-
setMouseClickActive
protected final void setMouseClickActive(boolean active)
Activate or disable the mouse button action on this widget.- Parameters:
active-truewill set the mouse button active,falsewill deactivate them.
-
isFocusable
public final boolean isFocusable()
- Specified by:
isFocusablein interfaceWidget- Returns:
trueif the widget can be focused, false otherwise.
-
setFocusable
public final void setFocusable(boolean focusable)
Set the widget to be considered as focusable or not.- Parameters:
focusable-trueto set the widget focusable.
-
setHighlightable
protected final void setHighlightable(boolean value)
Set the widget to be considered as hightligthable or not.- Parameters:
value-trueto make the widget highlitable.
-
setMouseOver
public final Element setMouseOver(boolean over, be.yildizgames.module.window.input.MousePosition position)
Called when the mouse enter or get out of a widget.- Parameters:
over- New mouse over status.position- Current mouse position.- Returns:
- This object for chaining.
-
isMouseOver
protected final boolean isMouseOver()
- Returns:
trueif the mouse is over this widget.
-
forceContainsFalse
public final void forceContainsFalse()
Force the contains method to always return false, in order to ignore inputs.
-
toString
public String toString()
- Overrides:
toStringin classbe.yildizgames.common.util.BaseRegisterable- Returns:
- The class name.
-
getAbsoluteLeft
public final int getAbsoluteLeft()
Description copied from interface:WidgetGive the absolute left position instead of relative from parent.- Specified by:
getAbsoluteLeftin interfaceWidget- Returns:
- The parent left position + the widget left position.
-
getAbsoluteTop
public final int getAbsoluteTop()
Description copied from interface:WidgetGive the absolute top position instead of relative from parent.- Specified by:
getAbsoluteTopin interfaceWidget- Returns:
- The parent top position + the widget top position.
-
isContainer
public boolean isContainer()
-
disableEmptyZone
public final void disableEmptyZone()
-
enableEmptyZone
public final void enableEmptyZone()
-
-