v1.4.0: several text input improvements for Steam Deck

This commit is contained in:
Evan Debenham
2022-08-12 11:05:28 -04:00
parent dcc84e4e7e
commit 4ae3bf9336
7 changed files with 45 additions and 27 deletions

View File

@@ -78,6 +78,20 @@ public class InputHandler extends InputAdapter {
public void removeInputProcessor(InputProcessor processor){ public void removeInputProcessor(InputProcessor processor){
multiplexer.removeProcessor(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(){ public void processAllEvents(){
PointerEvent.processPointerEvents(); PointerEvent.processPointerEvents();
@@ -91,8 +105,10 @@ public class InputHandler extends InputAdapter {
@Override @Override
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) { public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
ControllerHandler.setControllerPointer(false); if (pointer < 10) {
ControllerHandler.controllerActive = false; ControllerHandler.setControllerPointer(false);
ControllerHandler.controllerActive = false;
}
if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) { if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) {
KeyEvent.addKeyEvent( new KeyEvent( button + 1000, true ) ); KeyEvent.addKeyEvent( new KeyEvent( button + 1000, true ) );

View File

@@ -21,6 +21,7 @@
package com.watabou.input; package com.watabou.input;
import com.watabou.noosa.Game;
import com.watabou.utils.Signal; import com.watabou.utils.Signal;
import java.util.ArrayList; import java.util.ArrayList;
@@ -63,13 +64,13 @@ public class KeyEvent {
public static synchronized void processKeyEvents(){ public static synchronized void processKeyEvents(){
for (KeyEvent k : keyEvents){ for (KeyEvent k : keyEvents){
if (KeyBindings.getActionForKey(k) == GameAction.LEFT_CLICK){ 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); if (KeyBindings.bindingKey) keySignal.dispatch(k);
} else if (KeyBindings.getActionForKey(k) == GameAction.RIGHT_CLICK){ } 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); if (KeyBindings.bindingKey) keySignal.dispatch(k);
} else if (KeyBindings.getActionForKey(k) == GameAction.MIDDLE_CLICK){ } 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); if (KeyBindings.bindingKey) keySignal.dispatch(k);
} else { } else {
keySignal.dispatch(k); keySignal.dispatch(k);

View File

@@ -121,14 +121,6 @@ public class PointerEvent {
} }
return lastHoverPos.clone(); 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 ){ public static synchronized void addPointerEvent( PointerEvent event ){
pointerEvents.add( event ); pointerEvents.add( event );
@@ -155,10 +147,9 @@ public class PointerEvent {
//add drag events for any emulated presses //add drag events for any emulated presses
if (hovered){ if (hovered){
for (int i = 1000+LEFT; i <= 1000+FORWARD; i++){ for (int i = 10+LEFT; i <= 10+FORWARD; i++){
if (activePointers.containsKey(i)){ if (activePointers.containsKey(i)){
//add to front in case pointer is also being released this frame Game.inputHandler.emulateDrag(i-10);
pointerEvents.add(0, new PointerEvent((int)lastHoverPos.x, (int)lastHoverPos.y, i, Type.DOWN, i));
} }
} }
} }
@@ -187,7 +178,7 @@ public class PointerEvent {
} }
if (clearKeyboardThisPress){ if (clearKeyboardThisPress){
//most press events should clear the keyboard //most press events should clear the keyboard
Gdx.input.setOnscreenKeyboardVisible(false); Game.platform.setOnscreenKeyboardVisible(false);
} }
} }
pointerEvents.clear(); pointerEvents.clear();

View File

@@ -101,12 +101,20 @@ public class TextInput extends Component {
enterPressed(); enterPressed();
} }
} }
}); });
} }
textField.setOnscreenKeyboard(new TextField.OnscreenKeyboard() {
@Override
public void show(boolean visible) {
Game.platform.setOnscreenKeyboardVisible(visible);
}
});
container.setActor(textField); container.setActor(textField);
stage.setKeyboardFocus(textField); stage.setKeyboardFocus(textField);
Gdx.input.setOnscreenKeyboardVisible(true); Game.platform.setOnscreenKeyboardVisible(true);
} }
public void enterPressed(){ public void enterPressed(){
@@ -209,7 +217,7 @@ public class TextInput extends Component {
stage.dispose(); stage.dispose();
skin.dispose(); skin.dispose();
Game.inputHandler.removeInputProcessor(stage); Game.inputHandler.removeInputProcessor(stage);
Gdx.input.setOnscreenKeyboardVisible(false); Game.platform.setOnscreenKeyboardVisible(false);
if (!DeviceCompat.isDesktop()) Game.platform.updateSystemUI(); if (!DeviceCompat.isDesktop()) Game.platform.updateSystemUI();
} }
} }

View File

@@ -51,6 +51,10 @@ public abstract class PlatformSupport {
return Gdx.net.openURI( uri ); 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 //TODO should consider spinning this into its own class, rather than platform support getting ever bigger
protected static HashMap<FreeTypeFontGenerator, HashMap<Integer, BitmapFont>> fonts; protected static HashMap<FreeTypeFontGenerator, HashMap<Integer, BitmapFont>> fonts;

View File

@@ -1097,8 +1097,8 @@ public class GameScene extends PixelScene {
for (Gizmo g : scene.members){ for (Gizmo g : scene.members){
if (g instanceof Window) offsetToInherit = ((Window) g).getOffset(); if (g instanceof Window) offsetToInherit = ((Window) g).getOffset();
} }
if (scene.lastOffset != null && offsetToInherit == null) { if (lastOffset != null) {
offsetToInherit = scene.lastOffset; offsetToInherit = lastOffset;
} }
if (offsetToInherit != null) { if (offsetToInherit != null) {
wnd.offset(offsetToInherit); wnd.offset(offsetToInherit);

View File

@@ -49,12 +49,10 @@ public class WndTextInput extends Window {
super(); super();
//need to offset to give space for the soft keyboard //need to offset to give space for the soft keyboard
if (!DeviceCompat.isDesktop()) { if (PixelScene.landscape()) {
if (PixelScene.landscape()) { offset(0, -45);
offset(0, -45); } else {
} else { offset(0, multiLine ? -60 : -45);
offset(0, multiLine ? -60 : -45);
}
} }
final int width; final int width;