InfoBox tooltip fixes

This commit is contained in:
Tyler Hardy
2017-10-22 18:16:29 -05:00
committed by Adam
parent 4bfd2ec2f1
commit 258febb037

View File

@@ -110,34 +110,40 @@ public class InfoBoxOverlay extends Overlay
if (overlayBounds == null) if (overlayBounds == null)
{ {
x += BOXSIZE + SEPARATOR;
continue; continue;
} }
String tooltip = box.getTooltip(); String tooltip = box.getTooltip();
if (tooltip == null || tooltip.isEmpty()) if (tooltip == null || tooltip.isEmpty())
{ {
x += BOXSIZE + SEPARATOR;
continue; continue;
} }
Rectangle bounds = new Rectangle((int) overlayBounds.getX() + x, (int) overlayBounds.getY(), BOXSIZE, BOXSIZE); Rectangle infoboxBounds = new Rectangle((int) overlayBounds.getX() + x, (int) overlayBounds.getY(), BOXSIZE, BOXSIZE);
if (bounds.contains(mouse.getX(), mouse.getY())) if (infoboxBounds.contains(mouseX, mouseY))
{ {
int tooltipWidth = metrics.stringWidth(tooltip); int tooltipWidth = metrics.stringWidth(tooltip);
int height = metrics.getHeight(); int height = metrics.getHeight();
int tooltipY = mouseY - (int) infoboxBounds.getY();
if (tooltipY - height < 0)
tooltipY = height;
Color gray = new Color(Color.darkGray.getRed(), Color.darkGray.getGreen(), Color.darkGray.getBlue(), 190); Color gray = new Color(Color.darkGray.getRed(), Color.darkGray.getGreen(), Color.darkGray.getBlue(), 190);
graphics.setColor(gray); graphics.setColor(gray);
// Draws the background rect // Draws the background rect
graphics.fillRect(mouseX, mouseY - (height / 2), tooltipWidth + 6, height); graphics.fillRect(mouseX, tooltipY - height, tooltipWidth + 6, height);
// Draws the outline of the rect // Draws the outline of the rect
graphics.setColor(Color.BLACK); graphics.setColor(Color.yellow);
graphics.drawRect(mouseX, mouseY - (height / 2), tooltipWidth + 6, height); graphics.drawRect(mouseX, tooltipY - height, tooltipWidth + 6, height);
// Tooltip text // Tooltip text
graphics.setColor(Color.WHITE); graphics.setColor(Color.WHITE);
graphics.drawString(tooltip, mouseX + 3, mouseY + 5); graphics.drawString(tooltip, mouseX + 3, tooltipY - height / 2 + 5);
} }
x += BOXSIZE + SEPARATOR; x += BOXSIZE + SEPARATOR;