Class 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 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.
      • View

        public View​(Container wrappedContainer,
                    Zorder z,
                    be.yildizgames.module.window.ScreenSize screenSize)
    • 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:
        true if the point is inside the view, false otherwise.
      • contains

        public boolean contains​(int x,
                                int y)
      • show

        public final void show()
        Set the view visible.
        Specified by:
        show in interface Visible
      • hide

        public final void hide()
        Set the view invisible.
        Specified by:
        hide in interface Visible
      • 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:
        true if the view is currently visible.
      • setVisible

        public final void setVisible​(boolean visibleState)
        Set the View visible or not.
        Parameters:
        visibleState - true to set the View visible, false to hide it.
      • compareTo

        public final int compareTo​(View otherView)
        Compare 2 View by their z order.
        Specified by:
        compareTo in interface Comparable<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 - true if the view is set to visible, false if it is hidden.
      • setActive

        public final void setActive​(boolean active)
        Called when the mouse is in the view.
        Parameters:
        active - true if 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:
        hashCode in class be.yildizgames.common.util.BaseRegisterable
      • equals

        public final boolean equals​(Object obj)
        Overrides:
        equals in class be.yildizgames.common.util.BaseRegisterable
      • toString

        public final String toString()
        Overrides:
        toString in class be.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)