v1.4.0: several text input improvements for Steam Deck
This commit is contained in:
@@ -78,6 +78,20 @@ public class InputHandler extends InputAdapter {
|
||||
public void removeInputProcessor(InputProcessor processor){
|
||||
multiplexer.removeProcessor(processor);
|
||||
}
|
||||
|
||||
public void emulateTouch(int button, boolean down){
|
||||
PointF hoverPos = PointerEvent.currentHoverPos();
|
||||
if (down){
|
||||
multiplexer.touchDown((int)hoverPos.x, (int)hoverPos.y, 10+button, button);
|
||||
} else {
|
||||
multiplexer.touchUp((int)hoverPos.x, (int)hoverPos.y, 10+button, button);
|
||||
}
|
||||
}
|
||||
|
||||
public void emulateDrag(int button){
|
||||
PointF hoverPos = PointerEvent.currentHoverPos();
|
||||
multiplexer.touchDragged((int)hoverPos.x, (int)hoverPos.y, 10+button);
|
||||
}
|
||||
|
||||
public void processAllEvents(){
|
||||
PointerEvent.processPointerEvents();
|
||||
@@ -91,8 +105,10 @@ public class InputHandler extends InputAdapter {
|
||||
|
||||
@Override
|
||||
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||
ControllerHandler.setControllerPointer(false);
|
||||
ControllerHandler.controllerActive = false;
|
||||
if (pointer < 10) {
|
||||
ControllerHandler.setControllerPointer(false);
|
||||
ControllerHandler.controllerActive = false;
|
||||
}
|
||||
|
||||
if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) {
|
||||
KeyEvent.addKeyEvent( new KeyEvent( button + 1000, true ) );
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
package com.watabou.input;
|
||||
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.utils.Signal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -63,13 +64,13 @@ public class KeyEvent {
|
||||
public static synchronized void processKeyEvents(){
|
||||
for (KeyEvent k : keyEvents){
|
||||
if (KeyBindings.getActionForKey(k) == GameAction.LEFT_CLICK){
|
||||
PointerEvent.emulateMouseButton(PointerEvent.LEFT, k.pressed);
|
||||
Game.inputHandler.emulateTouch(PointerEvent.LEFT, k.pressed);
|
||||
if (KeyBindings.bindingKey) keySignal.dispatch(k);
|
||||
} else if (KeyBindings.getActionForKey(k) == GameAction.RIGHT_CLICK){
|
||||
PointerEvent.emulateMouseButton(PointerEvent.RIGHT, k.pressed);
|
||||
Game.inputHandler.emulateTouch(PointerEvent.RIGHT, k.pressed);
|
||||
if (KeyBindings.bindingKey) keySignal.dispatch(k);
|
||||
} else if (KeyBindings.getActionForKey(k) == GameAction.MIDDLE_CLICK){
|
||||
PointerEvent.emulateMouseButton(PointerEvent.MIDDLE, k.pressed);
|
||||
Game.inputHandler.emulateTouch(PointerEvent.MIDDLE, k.pressed);
|
||||
if (KeyBindings.bindingKey) keySignal.dispatch(k);
|
||||
} else {
|
||||
keySignal.dispatch(k);
|
||||
|
||||
@@ -121,14 +121,6 @@ public class PointerEvent {
|
||||
}
|
||||
return lastHoverPos.clone();
|
||||
}
|
||||
|
||||
public static synchronized void emulateMouseButton( int button, boolean down ){
|
||||
if (down){
|
||||
addPointerEvent(new PointerEvent((int)lastHoverPos.x, (int)lastHoverPos.y, 1000+button, Type.DOWN, button));
|
||||
} else {
|
||||
addPointerEvent(new PointerEvent((int)lastHoverPos.x, (int)lastHoverPos.y, 1000+button, Type.UP, button));
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void addPointerEvent( PointerEvent event ){
|
||||
pointerEvents.add( event );
|
||||
@@ -155,10 +147,9 @@ public class PointerEvent {
|
||||
|
||||
//add drag events for any emulated presses
|
||||
if (hovered){
|
||||
for (int i = 1000+LEFT; i <= 1000+FORWARD; i++){
|
||||
for (int i = 10+LEFT; i <= 10+FORWARD; i++){
|
||||
if (activePointers.containsKey(i)){
|
||||
//add to front in case pointer is also being released this frame
|
||||
pointerEvents.add(0, new PointerEvent((int)lastHoverPos.x, (int)lastHoverPos.y, i, Type.DOWN, i));
|
||||
Game.inputHandler.emulateDrag(i-10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,7 +178,7 @@ public class PointerEvent {
|
||||
}
|
||||
if (clearKeyboardThisPress){
|
||||
//most press events should clear the keyboard
|
||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||
Game.platform.setOnscreenKeyboardVisible(false);
|
||||
}
|
||||
}
|
||||
pointerEvents.clear();
|
||||
|
||||
@@ -101,12 +101,20 @@ public class TextInput extends Component {
|
||||
enterPressed();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
textField.setOnscreenKeyboard(new TextField.OnscreenKeyboard() {
|
||||
@Override
|
||||
public void show(boolean visible) {
|
||||
Game.platform.setOnscreenKeyboardVisible(visible);
|
||||
}
|
||||
});
|
||||
|
||||
container.setActor(textField);
|
||||
stage.setKeyboardFocus(textField);
|
||||
Gdx.input.setOnscreenKeyboardVisible(true);
|
||||
Game.platform.setOnscreenKeyboardVisible(true);
|
||||
}
|
||||
|
||||
public void enterPressed(){
|
||||
@@ -209,7 +217,7 @@ public class TextInput extends Component {
|
||||
stage.dispose();
|
||||
skin.dispose();
|
||||
Game.inputHandler.removeInputProcessor(stage);
|
||||
Gdx.input.setOnscreenKeyboardVisible(false);
|
||||
Game.platform.setOnscreenKeyboardVisible(false);
|
||||
if (!DeviceCompat.isDesktop()) Game.platform.updateSystemUI();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,10 @@ public abstract class PlatformSupport {
|
||||
return Gdx.net.openURI( uri );
|
||||
}
|
||||
|
||||
public void setOnscreenKeyboardVisible(boolean value){
|
||||
Gdx.input.setOnscreenKeyboardVisible(value);
|
||||
}
|
||||
|
||||
//TODO should consider spinning this into its own class, rather than platform support getting ever bigger
|
||||
protected static HashMap<FreeTypeFontGenerator, HashMap<Integer, BitmapFont>> fonts;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user