mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Support relaying touch events to display objects
This commit is contained in:
@@ -31,7 +31,6 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
//import forge.gui.home.variant.VSubmenuVanguard;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
@@ -14,7 +15,6 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
import com.badlogic.gdx.input.GestureDetector;
|
||||
import com.badlogic.gdx.input.GestureDetector.GestureListener;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
|
||||
@@ -47,7 +47,7 @@ public class Forge implements ApplicationListener {
|
||||
batch = new SpriteBatch();
|
||||
shapeRenderer = new ShapeRenderer();
|
||||
Gdx.graphics.setContinuousRendering(false); //save power consumption by disabling continuous rendering
|
||||
Gdx.input.setInputProcessor(new GestureDetector(new FGestureListener()));
|
||||
Gdx.input.setInputProcessor(new FGestureDetector());
|
||||
|
||||
FSkin.loadLight("journeyman", true);
|
||||
FSkin.loadFull(true);
|
||||
@@ -108,55 +108,107 @@ public class Forge implements ApplicationListener {
|
||||
shapeRenderer.dispose();
|
||||
}
|
||||
|
||||
private class FGestureListener implements GestureListener {
|
||||
private static class FGestureDetector extends GestureDetector {
|
||||
private static final ArrayList<FDisplayObject> potentialListeners = new ArrayList<FDisplayObject>();
|
||||
|
||||
@Override
|
||||
public boolean touchUp(float x, float y, int pointer, int button) {
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.touchUp(x, y)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.touchUp(x, y, pointer, button);
|
||||
}
|
||||
|
||||
private FGestureDetector() {
|
||||
super(new GestureListener() {
|
||||
@Override
|
||||
public boolean touchDown(float x, float y, int pointer, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
potentialListeners.clear();
|
||||
if (currentScreen != null) { //base potential listeners on object containing touch down point
|
||||
currentScreen.buildObjectsContainingPoint(x, y, potentialListeners);
|
||||
}
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.touchDown(x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.tap(x, y, count)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean longPress(float x, float y) {
|
||||
// TODO Auto-generated method stub
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.longPress(x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fling(float velocityX, float velocityY, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.fling(velocityX, velocityY)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
// TODO Auto-generated method stub
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.pan(x, y, deltaX, deltaY)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean panStop(float x, float y, int pointer, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.panStop(x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoom(float initialDistance, float distance) {
|
||||
// TODO Auto-generated method stub
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.zoom(initialDistance, distance)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||
// TODO Auto-generated method stub
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.pinch(initialPointer1, initialPointer2, pointer1, pointer2)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static class Graphics {
|
||||
private Rectangle bounds;
|
||||
|
||||
@@ -80,6 +80,30 @@ public class FButton extends FDisplayObject {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(float x, float y) {
|
||||
if (isToggled() || !isEnabled()) { return true; }
|
||||
imgL = FSkinImage.BTN_DOWN_LEFT;
|
||||
imgM = FSkinImage.BTN_DOWN_CENTER;
|
||||
imgR = FSkinImage.BTN_DOWN_RIGHT;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp(float x, float y) {
|
||||
if (isToggled() || !isEnabled()) { return true; }
|
||||
resetImg();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
if (count == 1) {
|
||||
//TODO: Run command
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
float w = getWidth();
|
||||
|
||||
@@ -2,8 +2,6 @@ package forge.toolbox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
|
||||
public abstract class FContainer extends FDisplayObject {
|
||||
@@ -48,52 +46,12 @@ public abstract class FContainer extends FDisplayObject {
|
||||
|
||||
protected abstract void doLayout(float width, float height);
|
||||
|
||||
@Override
|
||||
public boolean touchDown(float x, float y, int pointer, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public final void buildObjectsContainingPoint(float x, float y, ArrayList<FDisplayObject> objs) {
|
||||
if (contains(x, y)) {
|
||||
for (FDisplayObject child : children) {
|
||||
child.buildObjectsContainingPoint(x, y, objs);
|
||||
}
|
||||
objs.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean longPress(float x, float y) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fling(float velocityX, float velocityY, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean panStop(float x, float y, int pointer, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoom(float initialDistance, float distance) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2,
|
||||
Vector2 pointer1, Vector2 pointer2) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package forge.toolbox;
|
||||
|
||||
import com.badlogic.gdx.input.GestureDetector.GestureListener;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
|
||||
public abstract class FDisplayObject implements GestureListener {
|
||||
public abstract class FDisplayObject {
|
||||
private final Rectangle bounds = new Rectangle();
|
||||
|
||||
public void setPosition(float x, float y) {
|
||||
@@ -36,45 +37,50 @@ public abstract class FDisplayObject implements GestureListener {
|
||||
public float getHeight() {
|
||||
return bounds.height;
|
||||
}
|
||||
public boolean contains(float x, float y) {
|
||||
return bounds.contains(x, y);
|
||||
}
|
||||
|
||||
public abstract void draw(Graphics g);
|
||||
|
||||
@Override
|
||||
public boolean touchDown(float x, float y, int pointer, int button) {
|
||||
public void buildObjectsContainingPoint(float x, float y, ArrayList<FDisplayObject> objs) {
|
||||
if (contains(x, y)) {
|
||||
objs.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean touchDown(float x, float y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count, int button) {
|
||||
public boolean touchUp(float x, float y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tap(float x, float y, int count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean longPress(float x, float y) {
|
||||
return tap(x, y, 1); //treat longPress the same as a tap by default
|
||||
}
|
||||
|
||||
public boolean fling(float velocityX, float velocityY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fling(float velocityX, float velocityY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean panStop(float x, float y, int pointer, int button) {
|
||||
public boolean panStop(float x, float y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoom(float initialDistance, float distance) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user