From 62ab06b1884a608431d641570d544d61c02734c9 Mon Sep 17 00:00:00 2001 From: drdev Date: Thu, 25 Sep 2014 12:52:11 +0000 Subject: [PATCH] Support drawing prompt rotated 180 degrees --- forge-gui-mobile/src/forge/Graphics.java | 28 +++++++++++++++++-- .../src/forge/screens/match/MatchScreen.java | 1 + .../src/forge/toolbox/FDisplayObject.java | 8 ++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/forge-gui-mobile/src/forge/Graphics.java b/forge-gui-mobile/src/forge/Graphics.java index 82c32469f16..b5f74929e42 100644 --- a/forge-gui-mobile/src/forge/Graphics.java +++ b/forge-gui-mobile/src/forge/Graphics.java @@ -28,6 +28,7 @@ public class Graphics { private final SpriteBatch batch = new SpriteBatch(); private final ShapeRenderer shapeRenderer = new ShapeRenderer(); + private final Vector3 tmp = new Vector3(); private float regionHeight; private Rectangle bounds; private Rectangle visibleBounds; @@ -63,7 +64,15 @@ public class Graphics { } public boolean startClip(float x, float y, float w, float h) { batch.flush(); //must flush batch to prevent other things not rendering - if (!ScissorStack.pushScissors(new Rectangle(adjustX(x), adjustY(y, h), w, h))) { + + Rectangle clip = new Rectangle(adjustX(x), adjustY(y, h), w, h); + if (isTransformed) { //transform position if needed + tmp.set(clip.x + clip.width / 2, clip.y + clip.height / 2, 0); + tmp.mul(batch.getTransformMatrix()); + clip.x = tmp.x - clip.width / 2; + clip.y = tmp.y - clip.height / 2; + } + if (!ScissorStack.pushScissors(clip)) { failedClipCount++; //tracked failed clips to prevent calling popScissors on endClip return false; } @@ -86,15 +95,30 @@ public class Graphics { final Rectangle parentBounds = bounds; bounds = new Rectangle(parentBounds.x + displayObj.getLeft(), parentBounds.y + displayObj.getTop(), displayObj.getWidth(), displayObj.getHeight()); - displayObj.setScreenPosition(bounds.x, bounds.y); + if (isTransformed) { //transform screen position if needed + tmp.set(bounds.x + bounds.width / 2, regionHeight - bounds.y - bounds.height / 2, 0); + tmp.mul(batch.getTransformMatrix()); + displayObj.setScreenPosition(tmp.x - bounds.width / 2, regionHeight - tmp.y - bounds.height / 2); + } + else { + displayObj.setScreenPosition(bounds.x, bounds.y); + } Rectangle intersection = Utils.getIntersection(bounds, visibleBounds); if (intersection != null) { //avoid drawing object if it's not within visible region final Rectangle backup = visibleBounds; visibleBounds = intersection; + if (displayObj.getRotate180()) { + setRotateTransform(displayObj.getWidth() / 2, displayObj.getHeight() / 2, 180); + } + displayObj.draw(this); + if (displayObj.getRotate180()) { + clearTransform(); + } + visibleBounds = backup; } diff --git a/forge-gui-mobile/src/forge/screens/match/MatchScreen.java b/forge-gui-mobile/src/forge/screens/match/MatchScreen.java index 37d16783a7b..da34c8d7716 100644 --- a/forge-gui-mobile/src/forge/screens/match/MatchScreen.java +++ b/forge-gui-mobile/src/forge/screens/match/MatchScreen.java @@ -100,6 +100,7 @@ public class MatchScreen extends FScreen { MatchUtil.getGameView().selectButtonCancel(); } })); + topPlayerPrompt.setRotate180(true); } else { topPlayerPrompt = null; diff --git a/forge-gui-mobile/src/forge/toolbox/FDisplayObject.java b/forge-gui-mobile/src/forge/toolbox/FDisplayObject.java index 3488d1170e8..302aff024bb 100644 --- a/forge-gui-mobile/src/forge/toolbox/FDisplayObject.java +++ b/forge-gui-mobile/src/forge/toolbox/FDisplayObject.java @@ -12,6 +12,7 @@ public abstract class FDisplayObject { private boolean visible = true; private boolean enabled = true; + private boolean rotate180 = false; private final Rectangle bounds = new Rectangle(); private final Vector2 screenPosition = new Vector2(); @@ -92,6 +93,13 @@ public abstract class FDisplayObject { visible = b0; } + public boolean getRotate180() { + return rotate180; + } + public void setRotate180(boolean b0) { + rotate180 = b0; + } + //override to return true if drawOverlay should be called on container before drawing this object protected boolean drawAboveOverlay() { return false;