mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Prevent scrolling in opposite direction of main finger direction when dealing with multiple scroll panes
This commit is contained in:
@@ -424,10 +424,10 @@ public class Forge implements ApplicationListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY, boolean moreVertical) {
|
||||
try {
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.pan(listener.screenToLocalX(x), listener.screenToLocalY(y), deltaX, deltaY)) {
|
||||
if (listener.pan(listener.screenToLocalX(x), listener.screenToLocalY(y), deltaX, deltaY, moreVertical)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -491,10 +491,10 @@ public class Forge implements ApplicationListener {
|
||||
|
||||
boolean handled;
|
||||
if (KeyInputAdapter.isShiftKeyDown()) {
|
||||
handled = pan(mouseMovedX, mouseMovedY, -Utils.AVG_FINGER_WIDTH * amount, 0);
|
||||
handled = pan(mouseMovedX, mouseMovedY, -Utils.AVG_FINGER_WIDTH * amount, 0, false);
|
||||
}
|
||||
else {
|
||||
handled = pan(mouseMovedX, mouseMovedY, 0, -Utils.AVG_FINGER_HEIGHT * amount);
|
||||
handled = pan(mouseMovedX, mouseMovedY, 0, -Utils.AVG_FINGER_HEIGHT * amount, true);
|
||||
}
|
||||
if (panStop(mouseMovedX, mouseMovedY)) {
|
||||
handled = true;
|
||||
|
||||
@@ -226,11 +226,17 @@ public class MatchScreen extends FScreen {
|
||||
|
||||
@Override
|
||||
public boolean zoom(float x, float y, float amount) {
|
||||
y += getScrollTop();
|
||||
float yRatioBefore = (y + getScrollTop()) / getScrollHeight();
|
||||
|
||||
extraHeight += amount;
|
||||
if (extraHeight < 0) {
|
||||
extraHeight = 0;
|
||||
}
|
||||
revalidate();
|
||||
|
||||
float yRatioAfter = (y + getScrollTop()) / getScrollHeight();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public abstract class FDialog extends FOverlay {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY, boolean moreVertical) {
|
||||
for (FDisplayObject child : FDialog.this.getChildren()) {
|
||||
child.setLeft(child.getLeft() + deltaX);
|
||||
child.setTop(child.getTop() + deltaY);
|
||||
|
||||
@@ -121,7 +121,7 @@ public abstract class FDisplayObject {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY, boolean moreVertical) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class FGestureAdapter extends InputAdapter {
|
||||
public abstract boolean release(float x, float y);
|
||||
public abstract boolean tap(float x, float y, int count);
|
||||
public abstract boolean fling(float velocityX, float velocityY);
|
||||
public abstract boolean pan(float x, float y, float deltaX, float deltaY);
|
||||
public abstract boolean pan(float x, float y, float deltaX, float deltaY, boolean moreVertical);
|
||||
public abstract boolean panStop(float x, float y);
|
||||
public abstract boolean zoom(float x, float y, float amount);
|
||||
|
||||
@@ -166,7 +166,8 @@ public abstract class FGestureAdapter extends InputAdapter {
|
||||
// if we have left the tap square, we are panning
|
||||
if (!inTapSquare) {
|
||||
panning = true;
|
||||
return pan(x, y, tracker.deltaX, tracker.deltaY);
|
||||
boolean moreVertical = Math.abs(tracker.startY - y) > Math.abs(tracker.startX - x);
|
||||
return pan(x, y, tracker.deltaX, tracker.deltaY, moreVertical);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -279,6 +280,7 @@ public abstract class FGestureAdapter extends InputAdapter {
|
||||
|
||||
private static class VelocityTracker {
|
||||
int sampleSize = 10;
|
||||
float startX, startY;
|
||||
float lastX, lastY;
|
||||
float deltaX, deltaY;
|
||||
long lastTime;
|
||||
@@ -288,6 +290,8 @@ public abstract class FGestureAdapter extends InputAdapter {
|
||||
long[] meanTime = new long[sampleSize];
|
||||
|
||||
public void start(float x, float y, long timeStamp) {
|
||||
startX = x;
|
||||
startY = y;
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
deltaX = 0;
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract class FOverlay extends FContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY, boolean moreVertical) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -215,6 +215,15 @@ public abstract class FScrollPane extends FContainer {
|
||||
|
||||
@Override
|
||||
public boolean fling(float velocityX, float velocityY) {
|
||||
if (Math.abs(velocityY) > Math.abs(velocityX)) {
|
||||
if (getMaxScrollTop() == 0) {
|
||||
return false; //if fling is more vertical and can't scroll vertically, don't scroll at all
|
||||
}
|
||||
}
|
||||
else if (getMaxScrollLeft() == 0) {
|
||||
return false; //if fling is more horizontal and can't scroll horizontally, don't scroll at all
|
||||
}
|
||||
|
||||
velocityX = -velocityX; //reverse velocities to account for scroll moving in opposite direction
|
||||
velocityY = -velocityY;
|
||||
|
||||
@@ -226,7 +235,7 @@ public abstract class FScrollPane extends FContainer {
|
||||
activeFlingAnimation.physicsObj.getVelocity().set(velocityX, velocityY);
|
||||
activeFlingAnimation.physicsObj.setDecel(FLING_DECEL, FLING_DECEL);
|
||||
}
|
||||
return false; //don't prevent outer scroll panes from working
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -251,9 +260,19 @@ public abstract class FScrollPane extends FContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY, boolean moreVertical) {
|
||||
if (getMaxScrollTop() == 0 && (moreVertical || y < 0 || y >= getHeight() || Math.abs(deltaY) > Math.abs(deltaX))) {
|
||||
//if can't scroll vertically, don't scroll at all if pan is more vertical
|
||||
//or current position is above or below this scroll pane
|
||||
return false;
|
||||
}
|
||||
if (getMaxScrollLeft() == 0 && (!moreVertical || x < 0 || x >= getWidth() || Math.abs(deltaX) > Math.abs(deltaY))) {
|
||||
//if can't scroll horizontally, don't scroll at all if pan is more horizontal
|
||||
//or current position is left or right of this scroll pane
|
||||
return false;
|
||||
}
|
||||
setScrollPositions(scrollLeft - deltaX, scrollTop - deltaY);
|
||||
return false; //don't prevent outer scroll panes from working
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -95,7 +95,7 @@ public class FToggleSwitch extends FDisplayObject {
|
||||
|
||||
//support dragging finger left or right to toggle on/off
|
||||
@Override
|
||||
public final boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
public final boolean pan(float x, float y, float deltaX, float deltaY, boolean moreVertical) {
|
||||
if (contains(getLeft() + x, getTop() + y)) {
|
||||
if (x < getHeight()) {
|
||||
setToggled(false, true);
|
||||
|
||||
Reference in New Issue
Block a user