Class BaseElement

  • All Implemented Interfaces:
    be.yildizgames.common.util.Registerable, Element
    Direct Known Subclasses:
    AbstractIconElement, AbstractTextElement, BaseWidget

    public abstract class BaseElement
    extends be.yildizgames.common.util.BaseRegisterable
    implements Element
    Base for GUI elements.
    Author:
    Grégory Van Den Borre
    • Field Detail

      • MAX_OPACITY

        public static final int MAX_OPACITY
        Value for maximum opacity.
        See Also:
        Constant Field Values
      • virtualHeight

        protected int virtualHeight
    • Constructor Detail

      • BaseElement

        protected BaseElement​(String name,
                              be.yildizgames.module.coordinate.BaseCoordinate coordinates)
        Full constructor.
        Parameters:
        name - Element name, must be unique.
        coordinates - Element size and position.
    • Method Detail

      • setLeft

        public final BaseElement setLeft​(Element other,
                                         PositionRelativeLeft relative,
                                         int diff)
        Set the element left position relative to an other element with a position difference.
        Specified by:
        setLeft in interface Element
        Parameters:
        other - Element to use as reference position.
        relative - PositionRelative to use.
        diff - Difference to set, in pixel.
        Returns:
        This.
      • setLeft

        public final BaseElement setLeft​(Element other,
                                         PositionRelativeLeft left,
                                         be.yildizgames.module.coordinate.Relative relativeDiff)
        Set the element left position relative to an other element with a position difference relative to the width of the parent.
        Specified by:
        setLeft in interface Element
        Parameters:
        other - Element to use as reference position.
        left - PositionRelative to use.
        relativeDiff - Difference to set, relative to the width of the parent.
        Returns:
        This.
      • setVisible

        public final Element setVisible​(boolean visible)
        Show or hide the element.
        Specified by:
        setVisible in interface Element
        Parameters:
        visible - true will set the element visible, false will hide it.
        Returns:
        This object for chaining.
      • setLeft

        public final BaseElement setLeft​(Element other,
                                         PositionRelativeLeft relative)
        Set the element left position relative to an other widget.
        Specified by:
        setLeft in interface Element
        Parameters:
        other - Element to use as reference position.
        relative - PositionRelative to use.
        Returns:
        This.
      • updateAddPositionValue

        public final void updateAddPositionValue​(int left,
                                                 int top)
        Update position value without updating the widget.
        Parameters:
        left - Value to add to left value.
        top - Value to add to top value.
      • setTop

        public final BaseElement setTop​(Element other,
                                        PositionRelativeTop relative,
                                        int diff)
        Set the element top position relative to an other element with a position difference.
        Specified by:
        setTop in interface Element
        Parameters:
        other - Element to use as reference position.
        relative - PositionRelative to use.
        diff - Difference to set, in pixel.
        Returns:
        This.
      • setTop

        public final BaseElement setTop​(Element other,
                                        PositionRelativeTop top,
                                        be.yildizgames.module.coordinate.Relative relativeDiff)
        Set the element top position relative to an other element with a position difference relative to the height of the parent.
        Specified by:
        setTop in interface Element
        Parameters:
        other - Element to use as reference position.
        top - PositionRelative to use.
        relativeDiff - Difference to set, relative to the height of the parent.
        Returns:
        This.
      • setTop

        public final BaseElement setTop​(Element other,
                                        PositionRelativeTop relative)
        Set the element top position relative to an other widget.
        Specified by:
        setTop in interface Element
        Parameters:
        other - Element to use as reference position.
        relative - PositionRelative to use.
        Returns:
        This.
      • setPosition

        public final BaseElement setPosition​(Element other)
        Set at the same position as the other element.
        Specified by:
        setPosition in interface Element
        Parameters:
        other - Other element to get the position.
        Returns:
        This.
      • show

        public final Element show()
        Description copied from interface: Element
        Set the element visible on screen.
        Specified by:
        show in interface Element
        Returns:
        This.
      • hide

        public final Element hide()
        Description copied from interface: Element
        Set the element invisible on screen.
        Specified by:
        hide in interface Element
        Returns:
        This.
      • addToPosition

        public final void addToPosition​(int xValue,
                                        int yValue)
        Move the widget.
        Specified by:
        addToPosition in interface Element
        Parameters:
        xValue - Add this value to the container current X position.
        yValue - Add this value to the container current Y position.
      • addToLeft

        public final void addToLeft​(int value)
        Move the element left or right by adding a value to its current x value.
        Specified by:
        addToLeft in interface Element
        Parameters:
        value - Value to add to the current x position.
      • addToTop

        public final void addToTop​(int value)
        Move the element up or down by adding a value to its current y value.
        Specified by:
        addToTop in interface Element
        Parameters:
        value - Value to add to the current y position.
      • multiplySize

        public final void multiplySize​(float factor)
        Multiply the size of the element.
        Parameters:
        factor - Multiplication factor.
      • delete

        public abstract void delete()
        Delete the widget.
      • showImpl

        protected abstract void showImpl()
        Implementation to set the widget visible.
      • hideImpl

        protected abstract void hideImpl()
        Implementation to set the widget invisible.
      • setPosition

        public final Element setPosition​(int leftPosition,
                                         int topPosition)
        Set the left and top element position.
        Specified by:
        setPosition in interface Element
        Parameters:
        leftPosition - Left position.
        topPosition - Top position.
        Returns:
        This object for chaining.
      • setTop

        public final Element setTop​(int topValue)
        Description copied from interface: Element
        Set the element top position.
        Specified by:
        setTop in interface Element
        Parameters:
        topValue - New widget top position in pixels.
        Returns:
        This.
      • setLeft

        public final Element setLeft​(int leftValue)
        Description copied from interface: Element
        Set the element left position.
        Specified by:
        setLeft in interface Element
        Parameters:
        leftValue - New widget left position in pixels.
        Returns:
        This.
      • getBottom

        public final int getBottom()
        Specified by:
        getBottom in interface Element
        Returns:
        Widget bottom border position.
      • setSize

        public final void setSize​(be.yildizgames.module.coordinate.Size size)
        Update the widget size.
        Specified by:
        setSize in interface Element
        Parameters:
        size - New width and height, in pixels.
      • setHeight

        public final void setHeight​(int value)
        Set the widget height.
        Specified by:
        setHeight in interface Element
        Parameters:
        value - New widget height value in pixels.
      • setWidth

        public final void setWidth​(int value)
        Set the widget width.
        Specified by:
        setWidth in interface Element
        Parameters:
        value - New widget width value in pixels.
      • getCoordinates

        public final be.yildizgames.module.coordinate.BaseCoordinate getCoordinates()
        Specified by:
        getCoordinates in interface Element
        Returns:
        An object containing this widget coordinates.
      • setCoordinates

        public final void setCoordinates​(be.yildizgames.module.coordinate.BaseCoordinate coordinates)
        Set the position and size coordinates.
        Specified by:
        setCoordinates in interface Element
        Parameters:
        coordinates - Coordinates to set.
      • setSize

        public final void setSize​(int newWidth,
                                  int newHeight)
        Update the widget size.
        Specified by:
        setSize in interface Element
        Parameters:
        newWidth - New width, in pixels.
        newHeight - New height, in pixels.
      • isVisible

        public final boolean isVisible()
        Specified by:
        isVisible in interface Element
      • getWidth

        public final int getWidth()
        Specified by:
        getWidth in interface Element
        Returns:
        The element width.
      • getHeight

        public final int getHeight()
        Specified by:
        getHeight in interface Element
        Returns:
        The element height.
      • getLeft

        public final int getLeft()
        Specified by:
        getLeft in interface Element
        Returns:
        The element left position.
      • getTop

        public final int getTop()
        Specified by:
        getTop in interface Element
        Returns:
        The element top position.
      • getOpacity

        public final int getOpacity()
      • getRight

        public final int getRight()
        Specified by:
        getRight in interface Element
        Returns:
        Widget right border position.
      • setVirtualHeight

        public final void setVirtualHeight​(int height)
        Specified by:
        setVirtualHeight in interface Element
      • setSizeImpl

        protected abstract void setSizeImpl​(int newWidth,
                                            int newHeight)
        Implementation to set the widget size.
        Parameters:
        newWidth - New width.
        newHeight - New height.
      • setPositionImpl

        protected abstract Element setPositionImpl​(int newLeft,
                                                   int newTop)
        Implementation to update the widget position.
        Parameters:
        newLeft - New widget x position.
        newTop - New widget y position.
        Returns:
        This object for chaining.