world map overlay: Clip around widgets above map

This commit clips the overlay draw area to exclude the area taken by
widgets which draw above the world map, namely the overview map and
surface selector.

Fixes runelite/runelite#3264
Fixes runelite/runelite#3456
Closes runelite/runelite#3468
This commit is contained in:
Jordan Atwood
2018-09-13 16:18:35 -07:00
parent 1263e8a636
commit fba6b0122d

View File

@@ -24,12 +24,12 @@
*/
package net.runelite.client.ui.overlay.worldmap;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.awt.image.BufferedImage;
import java.util.List;
import javax.inject.Inject;
@@ -91,6 +91,8 @@ public class WorldMapOverlay extends Overlay
}
final Rectangle worldMapRectangle = widget.getBounds();
final Area mapViewArea = getWorldMapClipArea(worldMapRectangle);
final Area canvasViewArea = getWorldMapClipArea(client.getCanvas().getBounds());
WorldMapPoint tooltipPoint = null;
for (WorldMapPoint worldPoint : points)
@@ -110,8 +112,7 @@ public class WorldMapOverlay extends Overlay
if (worldPoint.isSnapToEdge())
{
Canvas canvas = client.getCanvas();
graphics.setClip(0, 0, canvas.getWidth(), canvas.getHeight());
graphics.setClip(canvasViewArea);
if (worldMapRectangle.contains(drawPoint.getX(), drawPoint.getY()))
{
@@ -133,7 +134,7 @@ public class WorldMapOverlay extends Overlay
}
else
{
graphics.setClip(worldMapRectangle);
graphics.setClip(mapViewArea);
}
int drawX = drawPoint.getX();
@@ -216,6 +217,33 @@ public class WorldMapOverlay extends Overlay
return null;
}
/**
* Gets a clip area which excludes the area of widgets which overlay the world map.
*
* @param baseRectangle The base area to clip from
* @return An {@link Area} representing <code>baseRectangle</code>, with the area
* of visible widgets overlaying the world map clipped from it.
*/
private Area getWorldMapClipArea(Rectangle baseRectangle)
{
final Widget overview = client.getWidget(WidgetInfo.WORLD_MAP_OVERVIEW_MAP);
final Widget surfaceSelector = client.getWidget(WidgetInfo.WORLD_MAP_SURFACE_SELECTOR);
Area clipArea = new Area(baseRectangle);
if (overview != null && !overview.isHidden())
{
clipArea.subtract(new Area(overview.getBounds()));
}
if (surfaceSelector != null && !surfaceSelector.isHidden())
{
clipArea.subtract(new Area(surfaceSelector.getBounds()));
}
return clipArea;
}
private void drawTooltip(Graphics2D graphics, WorldMapPoint worldPoint)
{
String tooltip = worldPoint.getTooltip();
@@ -227,7 +255,7 @@ public class WorldMapOverlay extends Overlay
drawPoint = new Point(drawPoint.getX() + TOOLTIP_OFFSET_WIDTH, drawPoint.getY() + TOOLTIP_OFFSET_HEIGHT);
graphics.setClip(0, 0, client.getCanvas().getWidth(), client.getCanvas().getHeight());
graphics.setClip(client.getCanvas().getBounds());
graphics.setColor(TOOLTIP_BACKGROUND);
graphics.setFont(FontManager.getRunescapeFont());
FontMetrics fm = graphics.getFontMetrics();