- java.lang.Object
-
- be.yildizgames.common.util.BaseRegisterable
-
- be.yildizgames.module.graphic.gui.View
-
- All Implemented Interfaces:
be.yildizgames.common.util.Registerable,Visible,Comparable<View>
- Direct Known Subclasses:
SimpleView,Window
public abstract class View extends be.yildizgames.common.util.BaseRegisterable implements Comparable<View>, Visible
A View is an abstract game component, it can be the game window, or a map, or a gui window. It contains a Z value to help the EventDispatcher to correctly dispatch the inputs: the higher the value, the higher the priority to check if the mouse is in this view. So if a view is on top of another, it has to use a greater Z value.- Author:
- Grégory Van den Borre
-
-
Constructor Summary
Constructors Constructor Description View(Container wrappedContainer, Zorder z, GuiEventManager eventManager, be.yildizgames.module.window.ScreenSize size)Full constructor, initialize the visibility to true, add the view to the event dispatcher.View(Container wrappedContainer, Zorder z, be.yildizgames.module.window.ScreenSize screenSize)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddKeyboardListener(be.yildizgames.module.window.input.KeyboardListener listener)Add a keyboard listener to this view.voidaddMouseDragListener(be.yildizgames.module.window.input.MouseDragListener listener)Add a mouse drag listener to this view.voidaddMouseLeftClickListener(be.yildizgames.module.window.input.MouseLeftClickListener listener)Add a mouse click listener to this view.voidaddMouseMoveListener(be.yildizgames.module.window.input.MouseMoveListener listener)Add a mouse listener to this view.voidaddMouseReleaseListener(be.yildizgames.module.window.input.MouseReleaseListener listener)Add a mouse release listener to this view.voidaddMouseRightClickListener(be.yildizgames.module.window.input.MouseRightClickListener listener)voidaddMouseWheelListener(be.yildizgames.module.window.input.MouseWheelListener listener)Add a mouse wheel listener to this view.intcompareTo(View otherView)Compare 2 View by their z order.booleancontains(int x, int y)booleancontains(be.yildizgames.module.window.input.MousePosition position)Compute if the point is in the view.voiddelete()Delete the view.voiddisableHighlight()booleanequals(Object obj)static Viewget(String name)Get a view from its name.ContainergetContainer()WidgetgetFocus()inthashCode()voidhide()Set the view invisible.booleanisActive()booleanisVisible()voidsetActive(boolean active)Called when the mouse is in the view.protected abstract voidsetActiveImpl(boolean active)Implementation specific set active.voidsetBackground(Material background)Set the background material.protected voidsetFocus(BaseWidget focus)voidsetPosition(int left, int top)Set the view position.protected voidsetPosition(PositionRelative position)voidsetVisible(boolean visibleState)Set the View visible or not.protected abstract voidsetVisibleImpl(boolean show)Set specific implementation when setVisible is called.voidshow()Set the view visible.StringtoString()
-
-
-
Constructor Detail
-
View
public View(Container wrappedContainer, Zorder z, GuiEventManager eventManager, be.yildizgames.module.window.ScreenSize size)
Full constructor, initialize the visibility to true, add the view to the event dispatcher.- Parameters:
wrappedContainer- Wrapped container.z- Z order.eventManager- Event manager to notify.
-
-
Method Detail
-
get
public static View get(String name)
Get a view from its name.- Parameters:
name- View name to retrieve.- Returns:
- The view associated with the name.
-
contains
public boolean contains(be.yildizgames.module.window.input.MousePosition position)
Compute if the point is in the view. i.e. if the view is at (100,100) and its size is (150,100), a point with x between 100 and 250 and y between 100 and 200 will return true.- Parameters:
position- Point to test.- Returns:
trueif the point is inside the view,falseotherwise.
-
contains
public boolean contains(int x, int y)
-
delete
public final void delete()
Delete the view.
-
addMouseMoveListener
public final void addMouseMoveListener(be.yildizgames.module.window.input.MouseMoveListener listener)
Add a mouse listener to this view.- Parameters:
listener- Listener to use when the mouse is moved in the view.
-
addMouseLeftClickListener
public final void addMouseLeftClickListener(be.yildizgames.module.window.input.MouseLeftClickListener listener)
Add a mouse click listener to this view.- Parameters:
listener- Listener to use when the mouse button is pressed in the view.
-
addMouseRightClickListener
public final void addMouseRightClickListener(be.yildizgames.module.window.input.MouseRightClickListener listener)
-
addMouseReleaseListener
public final void addMouseReleaseListener(be.yildizgames.module.window.input.MouseReleaseListener listener)
Add a mouse release listener to this view.- Parameters:
listener- Listener to use when the mouse button is released in the view.
-
addKeyboardListener
public final void addKeyboardListener(be.yildizgames.module.window.input.KeyboardListener listener)
Add a keyboard listener to this view.- Parameters:
listener- Listener to use when the keyboard is used in the view.
-
addMouseDragListener
public final void addMouseDragListener(be.yildizgames.module.window.input.MouseDragListener listener)
Add a mouse drag listener to this view.- Parameters:
listener- Listener to use when the mouse is dragged in this view.
-
addMouseWheelListener
public final void addMouseWheelListener(be.yildizgames.module.window.input.MouseWheelListener listener)
Add a mouse wheel listener to this view.- Parameters:
listener- Listener to use when the mouse is scrolled in this view.
-
isVisible
public final boolean isVisible()
- Returns:
trueif the view is currently visible.
-
setVisible
public final void setVisible(boolean visibleState)
Set the View visible or not.- Parameters:
visibleState-trueto set the View visible,falseto hide it.
-
compareTo
public final int compareTo(View otherView)
Compare 2 View by their z order.- Specified by:
compareToin interfaceComparable<View>- Parameters:
otherView- Other View to compare with this one.- Returns:
- 0 if equals, 1 if the other view is greater, -1 otherwise.
-
setPosition
public final void setPosition(int left, int top)Set the view position.- Parameters:
left- View left position value.top- View top position value.
-
setBackground
public final void setBackground(Material background)
Set the background material.- Parameters:
background- New background material.
-
setVisibleImpl
protected abstract void setVisibleImpl(boolean show)
Set specific implementation when setVisible is called.- Parameters:
show-trueif the view is set to visible,falseif it is hidden.
-
setActive
public final void setActive(boolean active)
Called when the mouse is in the view.- Parameters:
active-trueif the mouse is in the view, false otherwise.
-
setActiveImpl
protected abstract void setActiveImpl(boolean active)
Implementation specific set active.- Parameters:
active- Active state.
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classbe.yildizgames.common.util.BaseRegisterable
-
equals
public final boolean equals(Object obj)
- Overrides:
equalsin classbe.yildizgames.common.util.BaseRegisterable
-
toString
public final String toString()
- Overrides:
toStringin classbe.yildizgames.common.util.BaseRegisterable- Returns:
- The class name and the z order.
-
disableHighlight
public void disableHighlight()
-
getContainer
public Container getContainer()
-
isActive
public boolean isActive()
-
getFocus
public Widget getFocus()
-
setFocus
protected void setFocus(BaseWidget focus)
-
setPosition
protected void setPosition(PositionRelative position)
-
-