v0.9.4: added support for input multiplexing

This commit is contained in:
Evan Debenham 2021-07-08 12:19:15 -04:00
parent a492c565d0
commit bcdbf8ef43
2 changed files with 52 additions and 15 deletions

View File

@ -21,19 +21,63 @@
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();
KeyEvent.processKeyEvents();
@ -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;

View File

@ -79,7 +79,7 @@ public class Game implements ApplicationListener {
public static float timeTotal = 0f;
public static long realTime = 0;
protected static InputHandler inputHandler;
public static InputHandler inputHandler;
public static PlatformSupport platform;