diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2019-12-18 16:39:45 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2019-12-18 16:39:45 +0100 |
commit | 888f704e5a6809d2b42b3c08ef143525a6f2780a (patch) | |
tree | 3583e3cd11d699352ede96c7a053c1a8744757f2 /core/src | |
parent | 24b29457aa17c09c198464d1cb4e86b8b47aa9d5 (diff) | |
download | gdx-boardgame-888f704e5a6809d2b42b3c08ef143525a6f2780a.zip gdx-boardgame-888f704e5a6809d2b42b3c08ef143525a6f2780a.tar.gz |
UI : add Scissors
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Scissors.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Scissors.java b/core/src/ch/asynk/gdx/boardgame/ui/Scissors.java new file mode 100644 index 0000000..096b883 --- /dev/null +++ b/core/src/ch/asynk/gdx/boardgame/ui/Scissors.java @@ -0,0 +1,67 @@ +package ch.asynk.gdx.boardgame.ui; + +import com.badlogic.gdx.graphics.Camera; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack; + +import ch.asynk.gdx.boardgame.utils.IterableArray; + +public class Scissors +{ + private static IterableArray<Rectangle> array = new IterableArray<Rectangle>(5); + + private static Camera camera; + private static Batch batch; + + public static void clear() + { + array.clear(); + } + + public static void invalidate() + { + for (int i = 0; i < array.size(); i++) + array.replace(null, i); + } + + public static void register(Camera _camera, Batch _batch) + { + camera = _camera; + batch = _batch; + invalidate(); + } + + public static int compute(int idx, Rectangle area) + { + if (idx < 0) { + array.add(compute(area)); + return array.size() - 1; + } else { + array.replace(compute(area), idx); + return idx; + } + } + + public static Rectangle get(int idx, Rectangle area) + { + Rectangle r = array.get(idx); + if (r == null) { + array.replace(compute(area), idx); + r = array.get(idx); + } + return r; + } + + public static Rectangle compute(Rectangle area) + { + Rectangle scissor = new Rectangle(); + compute(area, scissor); + return scissor; + } + + public static void compute(Rectangle area, Rectangle scissor) + { + ScissorStack.calculateScissors(camera, batch.getTransformMatrix(), area, scissor); + } +} |