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.
This commit is contained in:
Adam
2022-06-22 16:37:01 -04:00
parent 9ce80d4bef
commit ef268ebc7f

View File

@@ -27,7 +27,6 @@ package net.runelite.client.ui.overlay.tooltip;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -52,6 +51,8 @@ public class TooltipOverlay extends Overlay
private final Client client; private final Client client;
private final RuneLiteConfig runeLiteConfig; private final RuneLiteConfig runeLiteConfig;
private int prevWidth, prevHeight;
@Inject @Inject
private TooltipOverlay(Client client, TooltipManager tooltipManager, final RuneLiteConfig runeLiteConfig) 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 canvasWidth = client.getCanvasWidth();
final int canvasHeight = client.getCanvasHeight(); final int canvasHeight = client.getCanvasHeight();
final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition(); 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 final int tooltipY = runeLiteConfig.tooltipPosition() == TooltipPositionType.ABOVE_CURSOR
? Math.max(0, mouseCanvasPosition.getY() - prevBounds.height) ? Math.max(0, mouseCanvasPosition.getY() - prevHeight)
: Math.min(canvasHeight - prevBounds.height, mouseCanvasPosition.getY() + UNDER_OFFSET); : Math.min(canvasHeight - prevHeight, mouseCanvasPosition.getY() + UNDER_OFFSET);
final Rectangle newBounds = new Rectangle(tooltipX, tooltipY, 0, 0);
int width = 0, height = 0;
for (Tooltip tooltip : tooltips) for (Tooltip tooltip : tooltips)
{ {
final LayoutableRenderableEntity entity; final LayoutableRenderableEntity entity;
@@ -121,14 +120,16 @@ public class TooltipOverlay extends Overlay
entity = tooltipComponent; entity = tooltipComponent;
} }
entity.setPreferredLocation(new Point(tooltipX, tooltipY + newBounds.height)); entity.setPreferredLocation(new Point(tooltipX, tooltipY + height));
final Dimension dimension = entity.render(graphics); final Dimension dimension = entity.render(graphics);
// Create incremental tooltip newBounds // Create incremental tooltip newBounds
newBounds.height += dimension.height + PADDING; height += dimension.height + PADDING;
newBounds.width = Math.max(newBounds.width, dimension.width); width = Math.max(width, dimension.width);
} }
return newBounds.getSize(); prevWidth = width;
prevHeight = height;
return null;
} }
} }