Package org.xjge.core

Class Widget

java.lang.Object
org.xjge.core.Widget

public abstract class Widget
extends java.lang.Object
An abstract class which can be used to define subclasses that will comprise individual elements of a user interface.
Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected static Font defaultFont  
    protected int height  
    org.joml.Vector3i position  
    boolean resolveEvent
    Used to resolve a special event that occurs when a gamepad is disconnected.
    protected int width  
  • Constructor Summary

    Constructors
    Constructor Description
    Widget​(org.joml.Vector3i position, int width, int height)
    Creates a new widget object that can be used to organize individual elements of a user interface.
  • Method Summary

    Modifier and Type Method Description
    abstract void destroy()
    Used to free resources used by the widget when its removed from a viewport.
    protected void drawString​(Font font, java.lang.String text, org.joml.Vector2i position, Color color)
    Draws a string of text to the screen.
    abstract void processKeyInput​(int key, int action, int mods)
    Processes input from the keyboard captured by the game window.
    abstract void render​(java.util.Map<java.lang.String,​GLProgram> glPrograms)
    Organizes calls to the OpenGL API made by this widget.
    abstract void setSplitPosition​(Split split, int viewportWidth, int viewportHeight)
    Called automatically anytime a change to the applications viewports occurs.Using this method, widgets can update the positions of their elements to better suit the size of the viewport.
    abstract void update()
    Updates the internal logic of the widget.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • width

      protected int width
    • height

      protected int height
    • resolveEvent

      public boolean resolveEvent
      Used to resolve a special event that occurs when a gamepad is disconnected. You should set its value to be the result of some kind of test like Input.getDevicePresent(int) if the implementing class will be used as the games Input.missingGamepad widget.
    • defaultFont

      protected static Font defaultFont
    • position

      public org.joml.Vector3i position
  • Constructor Details

    • Widget

      public Widget​(org.joml.Vector3i position, int width, int height)
      Creates a new widget object that can be used to organize individual elements of a user interface.
      Parameters:
      position - the position of the widget on the screen
      width - the width of the widget
      height - the height of the widget
  • Method Details

    • update

      public abstract void update()
      Updates the internal logic of the widget.
    • render

      public abstract void render​(java.util.Map<java.lang.String,​GLProgram> glPrograms)
      Organizes calls to the OpenGL API made by this widget.
      Parameters:
      glPrograms - an immutable collection containing the shader programs compiled during startup
    • setSplitPosition

      public abstract void setSplitPosition​(Split split, int viewportWidth, int viewportHeight)
      Called automatically anytime a change to the applications viewports occurs.Using this method, widgets can update the positions of their elements to better suit the size of the viewport.

      The arguments found here are provided out of convenience and can be accessed statically though the XJGE class if the implementation prefers.

      Parameters:
      split - the current split value used to divide the screen
      viewportWidth - the width (in internal resolution pixels) of the viewport rendering this widget
      viewportHeight - the height (in internal resolution pixels) of the viewport rendering this widget
    • processKeyInput

      public abstract void processKeyInput​(int key, int action, int mods)
      Processes input from the keyboard captured by the game window.

      NOTE: Only the first viewport (ID: 0) will receive input from the keyboard.

      Parameters:
      key - the value supplied by GLFW of a single key on the keyboard
      action - an action supplied by GLFW that describes the nature of the key press
      mods - a value supplied by GLFW denoting whether any mod keys where held (such as shift or control)
      See Also:
      Input.getKeyChar(int, int)
    • destroy

      public abstract void destroy()
      Used to free resources used by the widget when its removed from a viewport.
    • drawString

      protected void drawString​(Font font, java.lang.String text, org.joml.Vector2i position, Color color)
      Draws a string of text to the screen.
      Parameters:
      font - the font the text will be drawn in
      text - the string of text to display
      position - the position in the window at which the text string will be rendered
      color - the color the text will be rendered in