diff --git a/SPD-classes/src/main/java/com/watabou/input/InputHandler.java b/SPD-classes/src/main/java/com/watabou/input/InputHandler.java index ab62a4188..9f1824c5c 100644 --- a/SPD-classes/src/main/java/com/watabou/input/InputHandler.java +++ b/SPD-classes/src/main/java/com/watabou/input/InputHandler.java @@ -21,18 +21,62 @@ package com.watabou.input; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; +import com.badlogic.gdx.InputMultiplexer; +import com.badlogic.gdx.InputProcessor; import com.watabou.noosa.Game; import com.watabou.utils.PointF; public class InputHandler extends InputAdapter { - + + private InputMultiplexer multiplexer; + public InputHandler( Input input ){ - input.setInputProcessor( this ); + //An input multiplexer, with additional coord tweaks for power saver mode + multiplexer = new InputMultiplexer(){ + @Override + public boolean touchDown(int screenX, int screenY, int pointer, int button) { + screenX /= (Game.dispWidth / (float)Game.width); + screenY /= (Game.dispHeight / (float)Game.height); + return super.touchDown(screenX, screenY, pointer, button); + } + + @Override + public boolean touchDragged(int screenX, int screenY, int pointer) { + screenX /= (Game.dispWidth / (float)Game.width); + screenY /= (Game.dispHeight / (float)Game.height); + return super.touchDragged(screenX, screenY, pointer); + } + + @Override + public boolean touchUp(int screenX, int screenY, int pointer, int button) { + screenX /= (Game.dispWidth / (float)Game.width); + screenY /= (Game.dispHeight / (float)Game.height); + return super.touchUp(screenX, screenY, pointer, button); + } + + @Override + public boolean mouseMoved(int screenX, int screenY) { + screenX /= (Game.dispWidth / (float)Game.width); + screenY /= (Game.dispHeight / (float)Game.height); + return super.mouseMoved(screenX, screenY); + } + }; + input.setInputProcessor(multiplexer); + addInputProcessor(this); input.setCatchKey( Input.Keys.BACK, true); input.setCatchKey( Input.Keys.MENU, true); } + + public void addInputProcessor(InputProcessor processor){ + multiplexer.addProcessor(0, processor); + } + + public void removeInputProcessor(InputProcessor processor){ + multiplexer.removeProcessor(processor); + } public void processAllEvents(){ PointerEvent.processPointerEvents(); @@ -46,24 +90,19 @@ public class InputHandler extends InputAdapter { @Override public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) { - screenX /= (Game.dispWidth / (float)Game.width); - screenY /= (Game.dispHeight / (float)Game.height); + Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, true)); return true; } @Override public synchronized boolean touchUp(int screenX, int screenY, int pointer, int button) { - screenX /= (Game.dispWidth / (float)Game.width); - screenY /= (Game.dispHeight / (float)Game.height); PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, false)); return true; } @Override public synchronized boolean touchDragged(int screenX, int screenY, int pointer) { - screenX /= (Game.dispWidth / (float)Game.width); - screenY /= (Game.dispHeight / (float)Game.height); PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, true)); return true; } @@ -73,8 +112,6 @@ public class InputHandler extends InputAdapter { @Override public boolean mouseMoved(int screenX, int screenY) { - screenX /= (Game.dispWidth / (float)Game.width); - screenY /= (Game.dispHeight / (float)Game.height); pointerHoverPos.x = screenX; pointerHoverPos.y = screenY; return true; diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Game.java b/SPD-classes/src/main/java/com/watabou/noosa/Game.java index c02dc1b35..6785c41d9 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Game.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Game.java @@ -78,8 +78,8 @@ public class Game implements ApplicationListener { public static float elapsed = 0f; public static float timeTotal = 0f; public static long realTime = 0; - - protected static InputHandler inputHandler; + + public static InputHandler inputHandler; public static PlatformSupport platform; @@ -95,9 +95,9 @@ public class Game implements ApplicationListener { density = Gdx.graphics.getDensity(); dispHeight = Gdx.graphics.getDisplayMode().height; dispWidth = Gdx.graphics.getDisplayMode().width; - + inputHandler = new InputHandler( Gdx.input ); - + //refreshes texture and vertex data stored on the gpu versionContextRef = Gdx.graphics.getGLVersion(); Blending.useDefault(); @@ -123,7 +123,7 @@ public class Game implements ApplicationListener { } if (height != Game.height || width != Game.width) { - + Game.width = width; Game.height = height;