Skip to content

Commit

Permalink
InfoBox tooltip fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerthardy authored and Adam- committed Oct 22, 2017
1 parent 4bfd2ec commit 258febb
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,34 +110,40 @@ public Dimension render(Graphics2D graphics)

if (overlayBounds == null)
{
x += BOXSIZE + SEPARATOR;
continue;
}

String tooltip = box.getTooltip();
if (tooltip == null || tooltip.isEmpty())
{
x += BOXSIZE + SEPARATOR;
continue;
}

Rectangle bounds = new Rectangle((int) overlayBounds.getX() + x, (int) overlayBounds.getY(), BOXSIZE, BOXSIZE);
if (bounds.contains(mouse.getX(), mouse.getY()))
Rectangle infoboxBounds = new Rectangle((int) overlayBounds.getX() + x, (int) overlayBounds.getY(), BOXSIZE, BOXSIZE);
if (infoboxBounds.contains(mouseX, mouseY))
{
int tooltipWidth = metrics.stringWidth(tooltip);
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);
graphics.setColor(gray);

// 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
graphics.setColor(Color.BLACK);
graphics.drawRect(mouseX, mouseY - (height / 2), tooltipWidth + 6, height);
graphics.setColor(Color.yellow);
graphics.drawRect(mouseX, tooltipY - height, tooltipWidth + 6, height);

// Tooltip text
graphics.setColor(Color.WHITE);
graphics.drawString(tooltip, mouseX + 3, mouseY + 5);
graphics.drawString(tooltip, mouseX + 3, tooltipY - height / 2 + 5);
}

x += BOXSIZE + SEPARATOR;
Expand Down

0 comments on commit 258febb

Please sign in to comment.