Skip to content

Commit

Permalink
Fix[input]: make scroll gesture and swap hand more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Apr 7, 2024
1 parent f9fb995 commit 540cdfb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public boolean onTouchEvent(MotionEvent event) {
case MotionEvent.ACTION_MOVE: // 2
//Scrolling feature
if (!LauncherPreferences.PREF_DISABLE_GESTURES && !CallbackBridge.isGrabbing() && event.getPointerCount() >= 2) {
int hScroll = ((int) (event.getX() - mScrollLastInitialX)) / FINGER_SCROLL_THRESHOLD;
int vScroll = ((int) (event.getY() - mScrollLastInitialY)) / FINGER_SCROLL_THRESHOLD;
int hScroll = (int) ((event.getX() - mScrollLastInitialX) / FINGER_SCROLL_THRESHOLD);
int vScroll = (int) ((event.getY() - mScrollLastInitialY) / FINGER_SCROLL_THRESHOLD);

if(vScroll != 0 || hScroll != 0){
CallbackBridge.sendScroll(hScroll, vScroll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ private void repositionView() {
@Override
public boolean onTouchEvent(MotionEvent event) {
if(!CallbackBridge.isGrabbing()) return false;
// Check if we are double-tapping to swap hands
boolean hasDoubleTapped = mDoubleTapDetector.onTouchEvent(event);
if(hasDoubleTapped && !LauncherPreferences.PREF_DISABLE_SWAP_HAND) CallbackBridge.sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_F);

// Check if we need to cancel the drop event
int actionMasked = event.getActionMasked();
Expand All @@ -100,12 +98,16 @@ public boolean onTouchEvent(MotionEvent event) {
if(x < 0 || x > mWidth) return true;
int hotbarIndex = (int)MathUtils.map(x, 0, mWidth, 0, HOTBAR_KEYS.length);
// Check if the slot changed and we need to make a key press
if(hotbarIndex == mLastIndex) return true;
if(hotbarIndex == mLastIndex) {
// Only check for doubletapping if the slot has not changed
if(hasDoubleTapped && !LauncherPreferences.PREF_DISABLE_SWAP_HAND) CallbackBridge.sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_F);
return true;
}
mLastIndex = hotbarIndex;
int hotbarKey = HOTBAR_KEYS[hotbarIndex];
CallbackBridge.sendKeyPress(hotbarKey);
// Cancel the event since we changed hotbar slots.
mDropGesture.cancel();
mDropGesture.cancel();
// Only resubmit the gesture only if it isn't the last event we will receive.
if(!isLastEventInGesture(actionMasked)) mDropGesture.submit();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class InGUIEventProcessor implements TouchEventProcessor {
private final PointerTracker mTracker = new PointerTracker();
private boolean mIsMouseDown = false;
private final float mScaleFactor;
public static final int FINGER_SCROLL_THRESHOLD = (int) Tools.dpToPx(6);
public static final float FINGER_SCROLL_THRESHOLD = Tools.dpToPx(6);
public InGUIEventProcessor(float scaleFactor) {
mScaleFactor = scaleFactor;
}
Expand All @@ -34,8 +34,8 @@ public boolean processTouchEvent(MotionEvent motionEvent) {
if(!mIsMouseDown) enableMouse();
} else {
float[] motionVector = mTracker.getMotionVector();
int hScroll = ((int) motionVector[0]) / FINGER_SCROLL_THRESHOLD;
int vScroll = ((int) motionVector[1]) / FINGER_SCROLL_THRESHOLD;
int hScroll = (int)(motionVector[0] / FINGER_SCROLL_THRESHOLD);
int vScroll = (int)(motionVector[1] / FINGER_SCROLL_THRESHOLD);
if(hScroll != 0 | vScroll != 0) CallbackBridge.sendScroll(hScroll, vScroll);
}
break;
Expand Down

0 comments on commit 540cdfb

Please sign in to comment.