libgdx API

com.badlogic.gdx.twl
Class TWL

java.lang.Object
  extended by com.badlogic.gdx.twl.TWL
All Implemented Interfaces:
InputProcessor

public class TWL
extends java.lang.Object
implements InputProcessor

Convenience class for using TWL. This provides all the basics sufficient for most UIs. TWL can be used without this class if more complex configurations are required (eg, multiple GUI instances).

This class provides a single GUI instance with a root pane set to a widget that takes up the whole screen. setWidget(Widget) puts a widget into the root pane, making it easy to layout your widgets using the whole screen.

This class is relatively heavyweight because it loads a TWL theme. Generally only one instance should be created for an entire application. Use setWidget(Widget) and clear() to change the widgets displayed on various application screens.

This class implements InputProcessor and the input methods return true if TWL handled an event. Generally you will want to use InputMultiplexer to avoid dispatching events that TWL handled to your application.

If an instance of this call will no longer be used, dispose() must be called to release resources.

Author:
Nathan Sweet

Field Summary
 Widget root
           
 
Constructor Summary
TWL(SpriteBatch batch, java.lang.String themeFile, Files.FileType fileType)
          Creates a new TWL instance with the specified theme file.
TWL(SpriteBatch batch, java.lang.String themeFile, Files.FileType fileType, Widget widget)
          Creates a new TWL instance with the specified theme file.
 
Method Summary
 void clear()
          Removes all widgets from the GUI's root pane.
 void dispose()
           
 GUI getGUI()
          Returns the GUI instance, which is the root of the TWL UI hierachy and manages timing, inputs, etc.
static java.net.URL getThemeURL(java.lang.String themeFile, Files.FileType fileType)
          Returns a URL to a theme file, which can be used with ThemeManager to create a theme for GUI#applyTheme(ThemeManager).
static int getTwlKeyCode(int gdxKeyCode)
           
 boolean keyDown(int keycode)
          Called when a key was pressed
 boolean keyTyped(char character)
          Called when a key was typed
 boolean keyUp(int keycode)
          Called when a key was released
 void render()
          Draws the TWL UI.
 boolean scrolled(int amount)
          Called when the mouse wheel was scrolled.
 void setWidget(Widget widget)
          Sets the widget in the GUI's root pane.
 boolean touchDown(int x, int y, int pointer, int button)
          Called when the screen was touched or a mouse button was pressed.
 boolean touchDragged(int x, int y, int pointer)
          Called when a finger or the mouse was dragged.
 boolean touchMoved(int x, int y)
          Called when the mouse was moved without any buttons being pressed.
 boolean touchUp(int x, int y, int pointer, int button)
          Called when a finger was lifted or a mouse button was released.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

public Widget root
Constructor Detail

TWL

public TWL(SpriteBatch batch,
           java.lang.String themeFile,
           Files.FileType fileType,
           Widget widget)
Creates a new TWL instance with the specified theme file. The specified widget is added to the root pane.


TWL

public TWL(SpriteBatch batch,
           java.lang.String themeFile,
           Files.FileType fileType)
Creates a new TWL instance with the specified theme file.

Method Detail

getGUI

public GUI getGUI()
Returns the GUI instance, which is the root of the TWL UI hierachy and manages timing, inputs, etc.


setWidget

public void setWidget(Widget widget)
Sets the widget in the GUI's root pane. By default the root pane takes up the whole screen.

Parameters:
widget - If null, this method is equivalent to clear().

clear

public void clear()
Removes all widgets from the GUI's root pane. This effectively means that no TWL UI will be drawn.


render

public void render()
Draws the TWL UI.


keyDown

public boolean keyDown(int keycode)
Description copied from interface: InputProcessor
Called when a key was pressed

Specified by:
keyDown in interface InputProcessor
Parameters:
keycode - one of the constants in Input.Keys
Returns:
whether the input was processed

keyUp

public boolean keyUp(int keycode)
Description copied from interface: InputProcessor
Called when a key was released

Specified by:
keyUp in interface InputProcessor
Parameters:
keycode - one of the constants in Input.Keys
Returns:
whether the input was processed

keyTyped

public boolean keyTyped(char character)
Description copied from interface: InputProcessor
Called when a key was typed

Specified by:
keyTyped in interface InputProcessor
Parameters:
character - The character
Returns:
whether the input was processed

touchDown

public boolean touchDown(int x,
                         int y,
                         int pointer,
                         int button)
Description copied from interface: InputProcessor
Called when the screen was touched or a mouse button was pressed. The button parameter will be Input.Buttons.LEFT on Android.

Specified by:
touchDown in interface InputProcessor
Parameters:
x - The x coordinate, origin is in the upper left corner
y - The y coordinate, origin is in the upper left corner
pointer - the pointer for the event.
button - the button
Returns:
whether the input was processed

touchUp

public boolean touchUp(int x,
                       int y,
                       int pointer,
                       int button)
Description copied from interface: InputProcessor
Called when a finger was lifted or a mouse button was released. The button parameter will be Input.Buttons.LEFT on Android.

Specified by:
touchUp in interface InputProcessor
Parameters:
x - The x coordinate
y - The y coordinate
pointer - the pointer for the event.
button - the button
Returns:
whether the input was processed

touchDragged

public boolean touchDragged(int x,
                            int y,
                            int pointer)
Description copied from interface: InputProcessor
Called when a finger or the mouse was dragged.

Specified by:
touchDragged in interface InputProcessor
Parameters:
x - The x coordinate
y - The y coordinate
pointer - the pointer for the event.
Returns:
whether the input was processed

touchMoved

public boolean touchMoved(int x,
                          int y)
Description copied from interface: InputProcessor
Called when the mouse was moved without any buttons being pressed. Will not be called on Android.

Specified by:
touchMoved in interface InputProcessor
Parameters:
x - The x coordinate
y - The y coordinate
Returns:
whether the input was processed

scrolled

public boolean scrolled(int amount)
Description copied from interface: InputProcessor
Called when the mouse wheel was scrolled. Will not be called on Android.

Specified by:
scrolled in interface InputProcessor
Parameters:
amount - the scroll amount, -1 or 1 depending on the direction the wheel was scrolled.
Returns:
whether the input was processed.

dispose

public void dispose()

getTwlKeyCode

public static int getTwlKeyCode(int gdxKeyCode)

getThemeURL

public static java.net.URL getThemeURL(java.lang.String themeFile,
                                       Files.FileType fileType)
                                throws java.net.MalformedURLException
Returns a URL to a theme file, which can be used with ThemeManager to create a theme for GUI#applyTheme(ThemeManager). This is only needed if not using the TWL class to make use of TWL.

Throws:
java.net.MalformedURLException

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)