mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 23:59:21 -04:00
Feat[input]: use the grab listener instead of deciding the state on each event
This commit is contained in:
parent
13cad686ec
commit
fdd0570084
@ -75,6 +75,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
|
||||
private final InGameEventProcessor mIngameProcessor = new InGameEventProcessor(mSensitivityFactor);
|
||||
private final InGUIEventProcessor mInGUIProcessor = new InGUIEventProcessor(mScaleFactor);
|
||||
private TouchEventProcessor mCurrentTouchProcessor = mInGUIProcessor;
|
||||
private boolean mLastGrabState = false;
|
||||
|
||||
public MinecraftGLSurface(Context context) {
|
||||
@ -181,18 +182,8 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
CallbackBridge.sendCursorPos( e.getX(i) * mScaleFactor, e.getY(i) * mScaleFactor);
|
||||
return true; //mouse event handled successfully
|
||||
}
|
||||
|
||||
if(mIngameProcessor == null || mInGUIProcessor == null) return true;
|
||||
boolean isGrabbing = CallbackBridge.isGrabbing();
|
||||
if(mLastGrabState != isGrabbing) {
|
||||
pickEventProcessor(mLastGrabState).cancelPendingActions();
|
||||
mLastGrabState = isGrabbing;
|
||||
}
|
||||
return pickEventProcessor(isGrabbing).processTouchEvent(e);
|
||||
}
|
||||
|
||||
private TouchEventProcessor pickEventProcessor(boolean isGrabbing) {
|
||||
return isGrabbing ? mIngameProcessor : mInGUIProcessor;
|
||||
if (mIngameProcessor == null || mInGUIProcessor == null) return true;
|
||||
return mCurrentTouchProcessor.processTouchEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -403,7 +394,16 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
post(()->updateGrabState(isGrabbing));
|
||||
}
|
||||
|
||||
private TouchEventProcessor pickEventProcessor(boolean isGrabbing) {
|
||||
return isGrabbing ? mIngameProcessor : mInGUIProcessor;
|
||||
}
|
||||
|
||||
private void updateGrabState(boolean isGrabbing) {
|
||||
if(mLastGrabState != isGrabbing) {
|
||||
mCurrentTouchProcessor.cancelPendingActions();
|
||||
mCurrentTouchProcessor = pickEventProcessor(isGrabbing);
|
||||
mLastGrabState = isGrabbing;
|
||||
}
|
||||
if(!MainActivity.isAndroid8OrHigher()) return;
|
||||
|
||||
boolean hasPointerCapture = hasPointerCapture();
|
||||
|
Loading…
x
Reference in New Issue
Block a user