OSDN Git Service

[fixed] TWL event consumption.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 19 Dec 2010 10:12:47 +0000 (10:12 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 19 Dec 2010 10:12:47 +0000 (10:12 +0000)
[added] Iterable to utils collections.

extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/TWL.java
gdx/src/com/badlogic/gdx/utils/ArrayPool.java
gdx/src/com/badlogic/gdx/utils/Bag.java
gdx/src/com/badlogic/gdx/utils/BagPool.java

index 71d5685..6adf32c 100644 (file)
@@ -56,6 +56,8 @@ public class TWL implements InputProcessor {
        private final GdxRenderer renderer = new GdxRenderer();\r
        private final GUI gui;\r
 \r
+       private boolean mouseDown, ignoreMouse, lastPressConsumed;\r
+\r
        /**\r
         * Creates a new TWL instance with the specified theme file. The specified widget is added to the root pane.\r
         */\r
@@ -142,24 +144,36 @@ public class TWL implements InputProcessor {
        }\r
 \r
        public boolean keyTyped (char character) {\r
-               boolean handled = gui.handleKey(0, character, true);\r
-               return gui.handleKey(0, character, false) || handled;\r
+               return gui.handleKey(0, character, true);\r
        }\r
 \r
        public boolean touchDown (int x, int y, int pointer) {\r
-               return gui.handleMouse(x, y, pointer, true);\r
+               if (!mouseDown) lastPressConsumed = false; // Only the first button down counts.\r
+               mouseDown = true;\r
+               if (ignoreMouse) return false;\r
+               boolean handled = gui.handleMouse(x, y, pointer, true);\r
+               if (handled) lastPressConsumed = true;\r
+               return handled;\r
        }\r
 \r
        public boolean touchUp (int x, int y, int pointer) {\r
+               mouseDown = false;\r
+               if (ignoreMouse) {\r
+                       ignoreMouse = false;\r
+                       return false;\r
+               }\r
                boolean handled = gui.handleMouse(x, y, pointer, false);\r
-               gui.handleMouse(-9999, -9999, -1, true);\r
+               gui.handleMouse(-9999, -9999, -1, false);\r
                return handled;\r
        }\r
 \r
        public boolean touchDragged (int x, int y, int pointer) {\r
-               boolean handled = gui.handleMouse(x, y, -1, true);\r
-               System.out.println(handled);\r
-               return handled;\r
+               if (mouseDown && !lastPressConsumed) {\r
+                       ignoreMouse = true;\r
+                       gui.clearMouseState();\r
+                       return false;\r
+               }\r
+               return gui.handleMouse(x, y, -1, true);\r
        }\r
 \r
        public void dispose () {\r
@@ -281,15 +295,14 @@ public class TWL implements InputProcessor {
                        return Event.KEY_SPACE;\r
                case Keys.KEYCODE_TAB:\r
                        return Event.KEY_TAB;\r
-               default:\r
-                       return Event.KEY_NONE;\r
                }\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
+        * {@link GUI#applyTheme(ThemeManager)}. This is only needed if not using the {@link TWL} class to make use of TWL.\r
         */\r
        static public URL getThemeURL (String themeFile, final FileType fileType) throws MalformedURLException {\r
                File file = new File(themeFile);\r
index 9d91a55..a6f5b60 100644 (file)
@@ -35,7 +35,7 @@ import java.util.NoSuchElementException;
  * @author Nathan Sweet\r
  * @author Matthias Mann\r
  */\r
-abstract public class ArrayPool<T> {\r
+abstract public class ArrayPool<T> implements Iterable<T> {\r
        public T[] items;\r
        public int size;\r
 \r
index 19f593c..800c71c 100644 (file)
@@ -24,7 +24,7 @@ import java.util.NoSuchElementException;
  * @author Riven\r
  * @author Nathan Sweet\r
  */\r
-public class Bag<T> {\r
+public class Bag<T> implements Iterable<T> {\r
        public T[] items;\r
        public int size;\r
 \r
index 9058911..b17a1b5 100644 (file)
@@ -24,7 +24,7 @@ import java.util.NoSuchElementException;
  * @author Riven\r
  * @author Nathan Sweet\r
  */\r
-abstract public class BagPool<T> {\r
+abstract public class BagPool<T> implements Iterable<T> {\r
        public T[] items;\r
        public int size;\r
 \r