From ef268ebc7f63866b26ff538f0969f530b44d0046 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Jun 2022 16:37:01 -0400 Subject: [PATCH] tooltip: don't set overlay bounds when rendering The overlay was storing the previous frames tooltip width and height in the overlay bounds, to use for the next frame to position the overlay correctly so that it did not get pushed off canvas. This requires the tooltip overlay to have a non-empty bounds, which is not something dynamic/tooltip overlays usually support. The overlay renderer translates the g2d to the given bounds prior to rendering. The reason this worked was it always kept x/y=0, causing the translation to not happen. However this incorrectly caused the overlay to be picked when testing overlay bounds against the mouse position when up near the corner of the screen. This would then cause the player to pick the tooltip overlay, despite the overlay not being rendered there. --- .../ui/overlay/tooltip/TooltipOverlay.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltip/TooltipOverlay.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltip/TooltipOverlay.java index 81a1142e08..24c1ef704b 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltip/TooltipOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/tooltip/TooltipOverlay.java @@ -27,7 +27,6 @@ package net.runelite.client.ui.overlay.tooltip; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; -import java.awt.Rectangle; import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; @@ -52,6 +51,8 @@ public class TooltipOverlay extends Overlay private final Client client; private final RuneLiteConfig runeLiteConfig; + private int prevWidth, prevHeight; + @Inject private TooltipOverlay(Client client, TooltipManager tooltipManager, final RuneLiteConfig runeLiteConfig) { @@ -91,15 +92,13 @@ public class TooltipOverlay extends Overlay final int canvasWidth = client.getCanvasWidth(); final int canvasHeight = client.getCanvasHeight(); final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition(); - final Rectangle prevBounds = getBounds(); - final int tooltipX = Math.min(canvasWidth - prevBounds.width, mouseCanvasPosition.getX()); + final int tooltipX = Math.min(canvasWidth - prevWidth, mouseCanvasPosition.getX()); final int tooltipY = runeLiteConfig.tooltipPosition() == TooltipPositionType.ABOVE_CURSOR - ? Math.max(0, mouseCanvasPosition.getY() - prevBounds.height) - : Math.min(canvasHeight - prevBounds.height, mouseCanvasPosition.getY() + UNDER_OFFSET); - - final Rectangle newBounds = new Rectangle(tooltipX, tooltipY, 0, 0); + ? Math.max(0, mouseCanvasPosition.getY() - prevHeight) + : Math.min(canvasHeight - prevHeight, mouseCanvasPosition.getY() + UNDER_OFFSET); + int width = 0, height = 0; for (Tooltip tooltip : tooltips) { final LayoutableRenderableEntity entity; @@ -121,14 +120,16 @@ public class TooltipOverlay extends Overlay entity = tooltipComponent; } - entity.setPreferredLocation(new Point(tooltipX, tooltipY + newBounds.height)); + entity.setPreferredLocation(new Point(tooltipX, tooltipY + height)); final Dimension dimension = entity.render(graphics); // Create incremental tooltip newBounds - newBounds.height += dimension.height + PADDING; - newBounds.width = Math.max(newBounds.width, dimension.width); + height += dimension.height + PADDING; + width = Math.max(width, dimension.width); } - return newBounds.getSize(); + prevWidth = width; + prevHeight = height; + return null; } }