OSDN Git Service

Stage, if no keyboard/scroll focus, fire event on the root.
authorNathanSweet <nathan.sweet@gmail.com>
Fri, 21 Sep 2012 04:45:14 +0000 (21:45 -0700)
committerNathanSweet <nathan.sweet@gmail.com>
Fri, 21 Sep 2012 04:45:14 +0000 (21:45 -0700)
gdx/src/com/badlogic/gdx/scenes/scene2d/Stage.java

index 6c827fb..240208f 100644 (file)
@@ -347,7 +347,7 @@ public class Stage extends InputAdapter implements Disposable {
        /** Applies a mouse scroll event to the stage and returns true if an actor in the scene {@link Event#handle() handled} the\r
         * event. This event only occurs on the desktop. */\r
        public boolean scrolled (int amount) {\r
-               if (scrollFocus == null) return false;\r
+               Actor target = scrollFocus == null ? root : scrollFocus;\r
 \r
                screenToStageCoordinates(stageCoords.set(mouseScreenX, mouseScreenY));\r
 \r
@@ -357,7 +357,7 @@ public class Stage extends InputAdapter implements Disposable {
                event.setScrollAmount(amount);\r
                event.setStageX(stageCoords.x);\r
                event.setStageY(stageCoords.y);\r
-               scrollFocus.fire(event);\r
+               target.fire(event);\r
                boolean handled = event.isHandled();\r
                Pools.free(event);\r
                return handled;\r
@@ -366,12 +366,12 @@ public class Stage extends InputAdapter implements Disposable {
        /** Applies a key down event to the actor that has {@link Stage#setKeyboardFocus(Actor) keyboard focus}, if any, and returns\r
         * true if the event was {@link Event#handle() handled}. */\r
        public boolean keyDown (int keyCode) {\r
-               if (keyboardFocus == null) return false;\r
+               Actor target = keyboardFocus == null ? root : keyboardFocus;\r
                InputEvent event = Pools.obtain(InputEvent.class);\r
                event.setStage(this);\r
                event.setType(InputEvent.Type.keyDown);\r
                event.setKeyCode(keyCode);\r
-               keyboardFocus.fire(event);\r
+               target.fire(event);\r
                boolean handled = event.isHandled();\r
                Pools.free(event);\r
                return handled;\r
@@ -380,12 +380,12 @@ public class Stage extends InputAdapter implements Disposable {
        /** Applies a key up event to the actor that has {@link Stage#setKeyboardFocus(Actor) keyboard focus}, if any, and returns true\r
         * if the event was {@link Event#handle() handled}. */\r
        public boolean keyUp (int keyCode) {\r
-               if (keyboardFocus == null) return false;\r
+               Actor target = keyboardFocus == null ? root : keyboardFocus;\r
                InputEvent event = Pools.obtain(InputEvent.class);\r
                event.setStage(this);\r
                event.setType(InputEvent.Type.keyUp);\r
                event.setKeyCode(keyCode);\r
-               keyboardFocus.fire(event);\r
+               target.fire(event);\r
                boolean handled = event.isHandled();\r
                Pools.free(event);\r
                return handled;\r
@@ -394,12 +394,12 @@ public class Stage extends InputAdapter implements Disposable {
        /** Applies a key typed event to the actor that has {@link Stage#setKeyboardFocus(Actor) keyboard focus}, if any, and returns\r
         * true if the event was {@link Event#handle() handled}. */\r
        public boolean keyTyped (char character) {\r
-               if (keyboardFocus == null) return false;\r
+               Actor target = keyboardFocus == null ? root : keyboardFocus;\r
                InputEvent event = Pools.obtain(InputEvent.class);\r
                event.setStage(this);\r
                event.setType(InputEvent.Type.keyTyped);\r
                event.setCharacter(character);\r
-               keyboardFocus.fire(event);\r
+               target.fire(event);\r
                boolean handled = event.isHandled();\r
                Pools.free(event);\r
                return handled;\r