From df540aa7b8abc6a6f187e748e14b4cfd502c9c39 Mon Sep 17 00:00:00 2001 From: Charlie Waters Date: Thu, 15 Mar 2018 16:46:49 -0400 Subject: [PATCH] Fix bug with rendering more than two tooltips following mouse --- .../ui/overlay/tooltip/TooltipOverlay.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 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 763291c4d2..d84074e304 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 @@ -57,14 +57,14 @@ public class TooltipOverlay extends Overlay @Override public Dimension render(Graphics2D graphics, Point parent) { - List tooltips = tooltipManager.getTooltips(); + final List tooltips = tooltipManager.getTooltips(); if (tooltips.isEmpty()) { return null; } - final Rectangle lastLocation = new Rectangle(); + Rectangle lastLocation = null; for (Tooltip tooltip : tooltips) { @@ -88,14 +88,26 @@ public class TooltipOverlay extends Overlay position.setLocation(tooltip.getPosition()); } - if (lastLocation.contains(position)) + // check if this tooltip would overlap the last + if (lastLocation != null && lastLocation.contains(position)) { + // shift tooltip above previous position.translate(0, -lastLocation.height - PADDING); } + // render tooltip tooltipComponent.setPosition(position); - lastLocation.setLocation(position); - lastLocation.setSize(tooltipComponent.render(graphics, parent)); + final Dimension thisSize = tooltipComponent.render(graphics, parent); + + // update tooltip bounding rect + if (lastLocation == null) + { + lastLocation = new Rectangle(position, thisSize); + } + else + { + lastLocation.setSize(new Dimension(Math.max(lastLocation.width, thisSize.width), lastLocation.height + thisSize.height + PADDING)); + } } tooltipManager.clear();