summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2019-12-18 23:06:14 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2019-12-18 23:06:14 +0100
commit797c4defd7bf0b6807a796278180bb01a8a96805 (patch)
tree4684fced4c178888394216981076950de32f6c24
parent888f704e5a6809d2b42b3c08ef143525a6f2780a (diff)
downloadgdx-boardgame-797c4defd7bf0b6807a796278180bb01a8a96805.zip
gdx-boardgame-797c4defd7bf0b6807a796278180bb01a8a96805.tar.gz
UI : add drag(...) to Touchable, Element and Assembly
-rw-r--r--core/src/ch/asynk/gdx/boardgame/Touchable.java1
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Assembly.java14
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Element.java6
3 files changed, 20 insertions, 1 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/Touchable.java b/core/src/ch/asynk/gdx/boardgame/Touchable.java
index 0fd99d0..fab7ab9 100644
--- a/core/src/ch/asynk/gdx/boardgame/Touchable.java
+++ b/core/src/ch/asynk/gdx/boardgame/Touchable.java
@@ -3,4 +3,5 @@ package ch.asynk.gdx.boardgame;
public interface Touchable
{
public boolean touch(float x, float y);
+ public boolean drag(float x, float y, int dx, int dy);
}
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java b/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
index 6754518..866c3dd 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
@@ -41,15 +41,27 @@ public abstract class Assembly extends Element
@Override public boolean touch(float x, float y)
{
- for (Element e : children)
+ for (Element e : children) {
if (e.touch(x, y)) {
touched = e;
return true;
}
+
+ }
touched = null;
return false;
}
+ @Override public boolean drag(float x, float y, int dx, int dy)
+ {
+ if (touched != null) {
+ if (touched.drag(x, y, dx, dy))
+ return true;
+ touched = null;
+ }
+ return false;
+ }
+
@Override public void draw(Batch batch)
{
if (tainted) computeGeometry();
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Element.java b/core/src/ch/asynk/gdx/boardgame/ui/Element.java
index 3368f3c..dec0cc7 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Element.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Element.java
@@ -83,6 +83,12 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
return rect.contains(x, y);
}
+ @Override public boolean drag(float x, float y, int dx, int dy)
+ {
+ if (blocked || !visible) return false;
+ return rect.contains(x, y);
+ }
+
public void taint()
{
this.tainted = true;