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 resolveEventUsed 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 likeInput.getDevicePresent(int)
if the implementing class will be used as the gamesInput.missingGamepad
widget. -
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 screenwidth
- the width of the widgetheight
- the height of the widget
-
-
Method Details
-
update
public abstract void update()Updates the internal logic of the widget. -
render
Organizes calls to the OpenGL API made by this widget.- Parameters:
glPrograms
- an immutable collection containing the shader programs compiled during startup
-
setSplitPosition
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 screenviewportWidth
- the width (in internal resolution pixels) of the viewport rendering this widgetviewportHeight
- 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 keyboardaction
- an action supplied by GLFW that describes the nature of the key pressmods
- 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 intext
- the string of text to displayposition
- the position in the window at which the text string will be renderedcolor
- the color the text will be rendered in
-