world map overlay: make icons display fully on the map when edge snapped

This commit is contained in:
Hydrox6
2021-02-25 10:56:27 +00:00
committed by Adam
parent d69a5ddd8b
commit c09c96cd78

View File

@@ -131,7 +131,24 @@ public class WorldMapOverlay extends Overlay
if (worldPoint.isSnapToEdge()) if (worldPoint.isSnapToEdge())
{ {
if (worldMapRectangle.contains(drawPoint.getX(), drawPoint.getY())) // Get a smaller rect for edge-snapped icons so they display correctly at the edge
final Rectangle snappedRect = widget.getBounds();
snappedRect.grow(-image.getWidth() / 2, -image.getHeight() / 2);
final Rectangle unsnappedRect = new Rectangle(snappedRect);
if (worldPoint.getImagePoint() != null)
{
int dx = worldPoint.getImagePoint().getX() - (image.getWidth() / 2);
int dy = worldPoint.getImagePoint().getY() - (image.getHeight() / 2);
unsnappedRect.translate(dx, dy);
}
// Make the unsnap rect slightly smaller so a smaller snapped image doesn't cause a freak out
if (worldPoint.isCurrentlyEdgeSnapped())
{
unsnappedRect.grow(-image.getWidth(), -image.getHeight());
}
if (unsnappedRect.contains(drawPoint.getX(), drawPoint.getY()))
{ {
if (worldPoint.isCurrentlyEdgeSnapped()) if (worldPoint.isCurrentlyEdgeSnapped())
{ {
@@ -141,7 +158,7 @@ public class WorldMapOverlay extends Overlay
} }
else else
{ {
drawPoint = clipToRectangle(drawPoint, worldMapRectangle); drawPoint = clipToRectangle(drawPoint, snappedRect);
if (!worldPoint.isCurrentlyEdgeSnapped()) if (!worldPoint.isCurrentlyEdgeSnapped())
{ {
worldPoint.setCurrentlyEdgeSnapped(true); worldPoint.setCurrentlyEdgeSnapped(true);