\r
import com.badlogic.gdx.ApplicationListener;\r
\r
+/**\r
+ * An OpenGL surface in an applet.\r
+ * @author Nathan Sweet <misc@n4te.com>\r
+ */\r
public class LwjglApplet extends Applet {\r
final Canvas canvas;\r
LwjglApplication app;\r
import com.badlogic.gdx.Input;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
+/**\r
+ * An OpenGL surface fullscreen or in a lightweight window.\r
+ */\r
public class LwjglApplication implements Application {\r
LwjglGraphics graphics;\r
LwjglAudio audio;\r
import com.badlogic.gdx.Input;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
+/**\r
+ * An OpenGL surface on an AWT Canvas, allowing OpenGL to be embedded in a Swing application. All OpenGL calls are done on the\r
+ * EDT. This is slightly less efficient then a dedicated thread, but greatly simplifies synchronization.\r
+ * @author Nathan Sweet <misc@n4te.com>\r
+ */\r
public class LwjglCanvas implements Application {\r
final LwjglGraphics graphics;\r
final LwjglAudio audio;\r
import de.matthiasmann.twl.DialogLayout;\r
import de.matthiasmann.twl.Widget;\r
\r
+/**\r
+ * Adds convenience methods to {@link DialogLayout}.\r
+ * @author Nathan Sweet <misc@n4te.com>\r
+ */\r
public class Layout extends DialogLayout {\r
public Layout () {\r
setTheme("");\r
this.horizontal = horizontal;\r
}\r
\r
+ /**\r
+ * @param widgets Either {@link Widget} or {@link Integer} objects. Integers are used to specify the gap size.\r
+ */\r
public Group sequence (Object... widgets) {\r
DialogLayout.Group dialogGroup = createSequentialGroup();\r
if (horizontal)\r
return new Group(null, dialogGroup).add(widgets);\r
}\r
\r
+ /**\r
+ * @param widgets Either {@link Widget} or {@link Integer} objects. Integers are used to specify the gap size.\r
+ */\r
public Group parallel (Object... widgets) {\r
DialogLayout.Group dialogGroup = createParallelGroup();\r
if (horizontal)\r
this.dialogGroup = dialogGroup;\r
}\r
\r
+ /**\r
+ * @param widgets Either {@link Widget} or {@link Integer} objects. Integers are used to specify the gap size.\r
+ */\r
public Group sequence (Object... widgets) {\r
DialogLayout.Group dialogGroup = createSequentialGroup();\r
this.dialogGroup.addGroup(dialogGroup);\r
return new Group(this, dialogGroup).add(widgets);\r
}\r
\r
+ /**\r
+ * @param widgets Either {@link Widget} or {@link Integer} objects. Integers are used to specify the gap size.\r
+ */\r
public Group parallel (Object... widgets) {\r
DialogLayout.Group dialogGroup = createParallelGroup();\r
this.dialogGroup.addGroup(dialogGroup);\r
return new Group(this, dialogGroup).add(widgets);\r
}\r
\r
+ /**\r
+ * @param widgets Either {@link Widget} or {@link Integer} objects. Integers are used to specify the gap size.\r
+ */\r
public Group add (Object... widgets) {\r
for (int i = 0, n = widgets.length; i < n; i++) {\r
Object object = widgets[i];\r
import com.badlogic.gdx.Files.FileType;\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.Input;\r
+import com.badlogic.gdx.InputMultiplexer;\r
import com.badlogic.gdx.InputProcessor;\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.twl.renderer.GdxRenderer;\r
import de.matthiasmann.twl.Widget;\r
import de.matthiasmann.twl.theme.ThemeManager;\r
\r
+/**\r
+ * Convenience class for using TWL. This provides all the basics sufficient for most UIs. TWL can be used without this class if\r
+ * more complex configurations are required (eg, multiple GUI instances).<br>\r
+ * <br>\r
+ * This class provides a single {@link GUI} instance with a root pane set to a widget that takes up the whole screen.\r
+ * {@link #setWidget(Widget)} puts a widget into the root pane, making it easy to layout your widgets using the whole screen.<br>\r
+ * <br>\r
+ * This class is relatively heavyweight because it loads a TWL theme. Generally only one instance should be created for an entire\r
+ * application. Use {@link #setWidget(Widget)} and {@link #clear()} to change the widgets displayed on various application\r
+ * screens.<br>\r
+ * <br>\r
+ * This class implements {@link InputProcessor} and the input methods return true if TWL handled an event. Generally you will want\r
+ * to use {@link InputMultiplexer} to avoid dispatching events that TWL handled to your application.<br>\r
+ * <br>\r
+ * If an instance of this call will no longer be used, {@link #dispose()} must be called to release resources.\r
+ * @author Nathan Sweet <misc@n4te.com>\r
+ */\r
public class TWL implements InputProcessor {\r
private final GdxRenderer renderer = new GdxRenderer();\r
private final GUI gui;\r
\r
+ /**\r
+ * Creates a new TWL instance with the specified theme file. The specified widget is added to the root pane.\r
+ */\r
public TWL (String themeFile, FileType fileType, Widget widget) {\r
this(themeFile, fileType);\r
setWidget(widget);\r
}\r
\r
+ /**\r
+ * Creates a new TWL instance with the specified theme file.\r
+ */\r
public TWL (String themeFile, FileType fileType) {\r
Widget root = new Widget() {\r
protected void layout () {\r
}\r
}\r
\r
- public GdxRenderer getRenderer () {\r
- return renderer;\r
- }\r
-\r
+ /**\r
+ * Returns the GUI instance, which is the root of the TWL UI hierachy and manages timing, inputs, etc.\r
+ */\r
public GUI getGUI () {\r
return gui;\r
}\r
\r
+ /**\r
+ * Sets the widget in the GUI's root pane. By default the root pane takes up the whole screen.\r
+ */\r
public void setWidget (Widget widget) {\r
Widget root = gui.getRootPane();\r
root.removeAllChildren();\r
root.add(widget);\r
}\r
\r
+ /**\r
+ * Removes all widgets from the GUI's root pane. This effectively means that no TWL UI will be drawn.\r
+ */\r
public void clear () {\r
gui.getRootPane().removeAllChildren();\r
}\r
\r
+ /**\r
+ * Draws the TWL UI.\r
+ */\r
public void render () {\r
GUI gui = this.gui;\r
int viewWidth = Gdx.graphics.getWidth();\r
return Event.KEY_NONE;\r
}\r
\r
+ /**\r
+ * Returns a URL to a theme file, which can be used with\r
+ * {@link ThemeManager#createThemeManager(URL, de.matthiasmann.twl.renderer.Renderer) ThemeManager} to create a theme for\r
+ * {@link GUI#applyTheme(ThemeManager)}. This is only needed if not using the TWL class make use of TWL.\r
+ */\r
static public URL getThemeURL (String themeFile, final FileType fileType) throws MalformedURLException {\r
File file = new File(themeFile);\r
final File themeRoot = file.getParentFile();\r
\r
package com.badlogic.gdx;\r
\r
+/**\r
+ * An {@link ApplicationListener} that delegates to a {@link Screen}. This allows an application to easily have multiple screens.<br>\r
+ * <br>\r
+ * Screens are not disposed automatically. You must handle whether you want to keep screens around or dispose of them when another\r
+ * screen is set.\r
+ */\r
public abstract class Game implements ApplicationListener {\r
Screen screen;\r
\r
if (screen != null) screen.resize(width, height);\r
}\r
\r
+ /**\r
+ * Sets the current screen. {@link Screen#hide()} is called on any old screen, and {@link Screen#show()} is called on the new\r
+ * screen.\r
+ */\r
public void setScreen (Screen screen) {\r
if (this.screen != null) this.screen.hide();\r
this.screen = screen;\r
screen.show();\r
}\r
+\r
+ public Screen getScreen () {\r
+ return screen;\r
+ }\r
}\r
\r
import java.util.ArrayList;\r
\r
+/**\r
+ * An {@link InputProcessor} that delegates to an ordered list of other InputProcessors. Delegation for an event stops if a\r
+ * processor returns true, which indicates that the event was handled.\r
+ * @author Nathan Sweet <misc@n4te.com>\r
+ */\r
public class InputMultiplexer implements InputProcessor {\r
private ArrayList<InputProcessor> processors = new ArrayList(4);\r
\r
processors.add(processor);\r
}\r
\r
+ public void removeProcessor (InputProcessor processor) {\r
+ processors.remove(processor);\r
+ }\r
+\r
public boolean keyDown (int keycode) {\r
for (int i = 0, n = processors.size(); i < n; i++)\r
if (processors.get(i).keyDown(keycode)) return true;\r
\r
package com.badlogic.gdx;\r
\r
+/**\r
+ * Represents one of many application screens.<br>\r
+ * <br>\r
+ * Note that {@link #dispose()} is not called automatically.\r
+ * @see Game\r
+ */\r
public abstract class Screen {\r
- public final Game game;\r
-\r
- public Screen (Game game) {\r
- this.game = game;\r
- }\r
-\r
+ /**\r
+ * Called when the screen should render itself.\r
+ * @param delta The time in seconds since the last render.\r
+ */\r
public abstract void render (float delta);\r
\r
+ /**\r
+ * @see ApplicationListener#resize(int, int)\r
+ */\r
public void resize (int width, int height) {\r
}\r
\r
+ /**\r
+ * Called when this screen becomes the current screen for a {@link Game}.\r
+ */\r
public void show () {\r
}\r
\r
+ /**\r
+ * Called when this screen is no longer the current screen for a {@link Game}.\r
+ */\r
public void hide () {\r
}\r
\r
+ /**\r
+ * @see ApplicationListener#pause()\r
+ */\r
public void pause () {\r
}\r
\r
+ /**\r
+ * @see ApplicationListener#resume()\r
+ */\r
public void resume () {\r
}\r
\r
+ /**\r
+ * Called when this screen should release all resources.\r
+ */\r
public void dispose () {\r
}\r
}\r