From 111527736873162443651d0bdc1ec86c5c6e03bb Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Wed, 5 Sep 2018 12:06:49 +0200 Subject: [PATCH] Add TOP_CENTER snap corner to snap center viewport Closes #5310 Signed-off-by: Tomas Slusny --- .../runelite/client/ui/overlay/OverlayBounds.java | 13 +++++++++++-- .../runelite/client/ui/overlay/OverlayPosition.java | 4 ++++ .../runelite/client/ui/overlay/OverlayRenderer.java | 8 +++++++- .../net/runelite/client/ui/overlay/OverlayUtil.java | 4 ++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayBounds.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayBounds.java index b29966bf5d..cb5cc39557 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayBounds.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayBounds.java @@ -33,6 +33,7 @@ import static net.runelite.client.ui.overlay.OverlayPosition.ABOVE_CHATBOX_RIGHT import static net.runelite.client.ui.overlay.OverlayPosition.BOTTOM_LEFT; import static net.runelite.client.ui.overlay.OverlayPosition.BOTTOM_RIGHT; import static net.runelite.client.ui.overlay.OverlayPosition.CANVAS_TOP_RIGHT; +import static net.runelite.client.ui.overlay.OverlayPosition.TOP_CENTER; import static net.runelite.client.ui.overlay.OverlayPosition.TOP_LEFT; import static net.runelite.client.ui.overlay.OverlayPosition.TOP_RIGHT; @@ -40,11 +41,12 @@ import static net.runelite.client.ui.overlay.OverlayPosition.TOP_RIGHT; @Value class OverlayBounds { - private final Rectangle topLeft, topRight, bottomLeft, bottomRight, aboveChatboxRight, canvasTopRight; + private final Rectangle topLeft, topCenter, topRight, bottomLeft, bottomRight, aboveChatboxRight, canvasTopRight; OverlayBounds(OverlayBounds other) { topLeft = new Rectangle(other.topLeft); + topCenter = new Rectangle(other.topCenter); topRight = new Rectangle(other.topRight); bottomLeft = new Rectangle(other.bottomLeft); bottomRight = new Rectangle(other.bottomRight); @@ -56,6 +58,7 @@ class OverlayBounds { final OverlayBounds translated = new OverlayBounds(this); translated.getTopRight().translate(x, 0); + translated.getTopCenter().translate(x / 2, 0); translated.getBottomLeft().translate(0, y); translated.getBottomRight().translate(x, y); translated.getAboveChatboxRight().translate(x, y); @@ -69,6 +72,8 @@ class OverlayBounds { case TOP_LEFT: return topLeft; + case TOP_CENTER: + return topCenter; case TOP_RIGHT: return topRight; case BOTTOM_LEFT: @@ -90,6 +95,10 @@ class OverlayBounds { return TOP_LEFT; } + else if (bounds == topCenter) + { + return TOP_CENTER; + } else if (bounds == topRight) { return TOP_RIGHT; @@ -118,6 +127,6 @@ class OverlayBounds Collection getBounds() { - return Arrays.asList(topLeft, topRight, bottomLeft, bottomRight, aboveChatboxRight, canvasTopRight); + return Arrays.asList(topLeft, topCenter, topRight, bottomLeft, bottomRight, aboveChatboxRight, canvasTopRight); } } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayPosition.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayPosition.java index dc489cf7e2..14edc0dd05 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayPosition.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayPosition.java @@ -38,6 +38,10 @@ public enum OverlayPosition * Place overlay in the top left viewport area */ TOP_LEFT, + /** + * Place overlay in the top center viewport area + */ + TOP_CENTER, /** * Place overlay in the top right viewport area */ diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java index 876268d97c..33d1bf1731 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java @@ -443,9 +443,14 @@ public class OverlayRenderer extends MouseListener implements KeyListener viewportOffset + BORDER, viewportOffset + BORDER_TOP); + final Point topCenterPoint = new Point( + viewportOffset + viewportBounds.width / 2, + viewportOffset + BORDER + ); + final Point topRightPoint = new Point( viewportOffset + viewportBounds.width - BORDER, - viewportOffset + BORDER); + topCenterPoint.y); final Point bottomLeftPoint = new Point( topLeftPoint.x, @@ -471,6 +476,7 @@ public class OverlayRenderer extends MouseListener implements KeyListener return new OverlayBounds( new Rectangle(topLeftPoint, SNAP_CORNER_SIZE), + new Rectangle(topCenterPoint, SNAP_CORNER_SIZE), new Rectangle(topRightPoint, SNAP_CORNER_SIZE), new Rectangle(bottomLeftPoint, SNAP_CORNER_SIZE), new Rectangle(bottomRightPoint, SNAP_CORNER_SIZE), diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayUtil.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayUtil.java index b22e20108f..39c7cfb37b 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayUtil.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayUtil.java @@ -202,6 +202,7 @@ public class OverlayUtil result.x -= dimension.width + (dimension.width == 0 ? 0 : padding); break; case TOP_LEFT: + case TOP_CENTER: result.y += dimension.height + (dimension.height == 0 ? 0 : padding); break; case CANVAS_TOP_RIGHT: @@ -226,6 +227,9 @@ public class OverlayUtil case TOOLTIP: case TOP_LEFT: break; + case TOP_CENTER: + result.x = result.x - dimension.width / 2; + break; case BOTTOM_LEFT: result.y = result.y - dimension.height; break;