Merge pull request #5312 from deathbeam/snap-center

Add TOP_CENTER snap corner to snap center viewport
This commit is contained in:
Tomas Slusny
2018-09-05 12:15:15 +02:00
committed by GitHub
4 changed files with 26 additions and 3 deletions

View File

@@ -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<Rectangle> getBounds()
{
return Arrays.asList(topLeft, topRight, bottomLeft, bottomRight, aboveChatboxRight, canvasTopRight);
return Arrays.asList(topLeft, topCenter, topRight, bottomLeft, bottomRight, aboveChatboxRight, canvasTopRight);
}
}

View File

@@ -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
*/

View File

@@ -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),

View File

@@ -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;