mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 16:47:14 -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 InGameEventProcessor mIngameProcessor = new InGameEventProcessor(mSensitivityFactor);
|
||||||
private final InGUIEventProcessor mInGUIProcessor = new InGUIEventProcessor(mScaleFactor);
|
private final InGUIEventProcessor mInGUIProcessor = new InGUIEventProcessor(mScaleFactor);
|
||||||
|
private TouchEventProcessor mCurrentTouchProcessor = mInGUIProcessor;
|
||||||
private boolean mLastGrabState = false;
|
private boolean mLastGrabState = false;
|
||||||
|
|
||||||
public MinecraftGLSurface(Context context) {
|
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);
|
CallbackBridge.sendCursorPos( e.getX(i) * mScaleFactor, e.getY(i) * mScaleFactor);
|
||||||
return true; //mouse event handled successfully
|
return true; //mouse event handled successfully
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mIngameProcessor == null || mInGUIProcessor == null) return true;
|
if (mIngameProcessor == null || mInGUIProcessor == null) return true;
|
||||||
boolean isGrabbing = CallbackBridge.isGrabbing();
|
return mCurrentTouchProcessor.processTouchEvent(e);
|
||||||
if(mLastGrabState != isGrabbing) {
|
|
||||||
pickEventProcessor(mLastGrabState).cancelPendingActions();
|
|
||||||
mLastGrabState = isGrabbing;
|
|
||||||
}
|
|
||||||
return pickEventProcessor(isGrabbing).processTouchEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TouchEventProcessor pickEventProcessor(boolean isGrabbing) {
|
|
||||||
return isGrabbing ? mIngameProcessor : mInGUIProcessor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -403,7 +394,16 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
|||||||
post(()->updateGrabState(isGrabbing));
|
post(()->updateGrabState(isGrabbing));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TouchEventProcessor pickEventProcessor(boolean isGrabbing) {
|
||||||
|
return isGrabbing ? mIngameProcessor : mInGUIProcessor;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateGrabState(boolean isGrabbing) {
|
private void updateGrabState(boolean isGrabbing) {
|
||||||
|
if(mLastGrabState != isGrabbing) {
|
||||||
|
mCurrentTouchProcessor.cancelPendingActions();
|
||||||
|
mCurrentTouchProcessor = pickEventProcessor(isGrabbing);
|
||||||
|
mLastGrabState = isGrabbing;
|
||||||
|
}
|
||||||
if(!MainActivity.isAndroid8OrHigher()) return;
|
if(!MainActivity.isAndroid8OrHigher()) return;
|
||||||
|
|
||||||
boolean hasPointerCapture = hasPointerCapture();
|
boolean hasPointerCapture = hasPointerCapture();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user