Swipeable buttons are a bit faster now

This commit is contained in:
SerpentSpirale 2021-08-13 20:47:06 +02:00
parent 1929143337
commit 17f78bed03
2 changed files with 10 additions and 14 deletions

View File

@ -260,7 +260,7 @@ public class ControlLayout extends FrameLayout
//Check if the action is cancelling, reset the lastControl button associated to the view
if(ev.getActionMasked() == MotionEvent.ACTION_UP || ev.getActionMasked() == MotionEvent.ACTION_CANCEL){
if(lastControlButton != null) lastControlButton.onTouchEvent(ev);
if(lastControlButton != null) lastControlButton.sendKeyPresses(false);
mapTable.put(v, null);
return true;
}
@ -275,9 +275,8 @@ public class ControlLayout extends FrameLayout
}
}
//Release the last key
ev.setAction(MotionEvent.ACTION_POINTER_UP);
if (lastControlButton != null) lastControlButton.onTouchEvent(ev);
//Release last keys
if (lastControlButton != null) lastControlButton.sendKeyPresses(false);
mapTable.put(v, null);
//Look for another SWIPEABLE button
@ -289,8 +288,7 @@ public class ControlLayout extends FrameLayout
//Press the new key
if(!button.equals(lastControlButton)){
ev.setAction(MotionEvent.ACTION_POINTER_DOWN);
button.onTouchEvent(ev);
button.sendKeyPresses(true);
mapTable.put(v, button);
}

View File

@ -269,7 +269,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
if(mProperties.isSwipeable && !isPointerOutOfBounds){
//Remove keys
if(!triggerToggle(event)) {
sendKeyPresses(event, false);
sendKeyPresses(false);
}
}
isPointerOutOfBounds = true;
@ -282,7 +282,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
((ControlLayout) getParent()).onTouch(this, event);
//RE-press the button
if(mProperties.isSwipeable && !mProperties.isToggle){
sendKeyPresses(event, true);
sendKeyPresses(true);
}
}
isPointerOutOfBounds = false;
@ -291,7 +291,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
case MotionEvent.ACTION_DOWN: // 0
case MotionEvent.ACTION_POINTER_DOWN: // 5
if(!mProperties.isToggle){
sendKeyPresses(event, true);
sendKeyPresses(true);
}
break;
@ -306,7 +306,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
isPointerOutOfBounds = false;
if(!triggerToggle(event)) {
sendKeyPresses(event, false);
sendKeyPresses(false);
}
break;
@ -465,19 +465,17 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
if(mProperties.isToggle){
isToggled = !isToggled;
invalidate();
sendKeyPresses(event, isToggled);
sendKeyPresses(isToggled);
return true;
}
return false;
}
public void sendKeyPresses(MotionEvent event, boolean isDown){
public void sendKeyPresses(boolean isDown){
for(int keycode : mProperties.keycodes){
if(keycode >= GLFW_KEY_UNKNOWN){
MainActivity.sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
CallbackBridge.setModifiers(keycode, isDown);
}else {
super.onTouchEvent(event);
}
}
}