Create translated copy of OverlayBounds

- Add new method to OverlayBounds for translating them that will return
translated copy of the bounds
- Use this new method in OverlayRenderer to prevent mutations of
OverlayBounds, what are not desired
- Use stored overlay bounds in mouse events and translate them by making
new copy

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-03-23 12:06:46 +01:00
parent 553fee70c4
commit 4a8af3d049
2 changed files with 15 additions and 18 deletions

View File

@@ -50,6 +50,16 @@ class OverlayBounds
aboveChatboxRight = new Rectangle(other.aboveChatboxRight);
}
OverlayBounds translated(final int x, final int y)
{
final OverlayBounds translated = new OverlayBounds(this);
translated.getTopRight().translate(x, 0);
translated.getBottomLeft().translate(0, y);
translated.getBottomRight().translate(x, y);
translated.getAboveChatboxRight().translate(x, y);
return translated;
}
Rectangle forPosition(OverlayPosition overlayPosition)
{
switch (overlayPosition)

View File

@@ -283,7 +283,10 @@ public class OverlayRenderer extends MouseListener implements KeyListener
// Draw snap corners
if (layer == OverlayLayer.UNDER_WIDGETS && movedOverlay != null)
{
final OverlayBounds translatedSnapCorners = translateSnapCorners(snapCorners);
final OverlayBounds translatedSnapCorners = snapCorners.translated(
-SNAP_CORNER_SIZE.width,
-SNAP_CORNER_SIZE.height);
final Color previous = graphics.getColor();
for (final Rectangle corner : translatedSnapCorners.getBounds())
@@ -432,7 +435,7 @@ public class OverlayRenderer extends MouseListener implements KeyListener
if (movedOverlay != null)
{
mousePosition.setLocation(-1, -1);
final OverlayBounds snapCorners = translateSnapCorners(buildSnapCorners());
final OverlayBounds snapCorners = this.snapCorners.translated(-SNAP_CORNER_SIZE.width, -SNAP_CORNER_SIZE.height);
for (Rectangle snapCorner : snapCorners.getBounds())
{
@@ -558,22 +561,6 @@ public class OverlayRenderer extends MouseListener implements KeyListener
new Rectangle(rightChatboxPoint, SNAP_CORNER_SIZE));
}
private OverlayBounds translateSnapCorners(OverlayBounds snapCorners)
{
return new OverlayBounds(
snapCorners.getTopLeft(),
translate(snapCorners.getTopRight(), -SNAP_CORNER_SIZE.width, 0),
translate(snapCorners.getBottomLeft(), 0, -SNAP_CORNER_SIZE.height),
translate(snapCorners.getBottomRight(), -SNAP_CORNER_SIZE.width, -SNAP_CORNER_SIZE.height),
translate(snapCorners.getAboveChatboxRight(), -SNAP_CORNER_SIZE.width, -SNAP_CORNER_SIZE.height));
}
private static Rectangle translate(Rectangle rectangle, int dx, int dy)
{
rectangle.translate(dx, dy);
return rectangle;
}
private void saveOverlayLocation(final Overlay overlay)
{
final String key = overlay.getClass().getSimpleName() + OVERLAY_CONFIG_PREFERRED_LOCATION;