Merge pull request #180 from tylerthardy/infoboxTooltips
Add tooltips for InfoBoxes
This commit is contained in:
@@ -27,11 +27,13 @@ package net.runelite.client.ui.overlay;
|
|||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
public abstract class Overlay
|
public abstract class Overlay
|
||||||
{
|
{
|
||||||
private OverlayPosition position; // where to draw it
|
private OverlayPosition position; // where to draw it
|
||||||
private OverlayPriority priority; // if multiple overlays exist in the same position, who wins
|
private OverlayPriority priority; // if multiple overlays exist in the same position, who wins
|
||||||
|
private Rectangle bounds; //screen bounds of overlay after OverlayRenderer decides location
|
||||||
|
|
||||||
public Overlay(OverlayPosition position)
|
public Overlay(OverlayPosition position)
|
||||||
{
|
{
|
||||||
@@ -65,4 +67,14 @@ public abstract class Overlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract Dimension render(Graphics2D graphics);
|
public abstract Dimension render(Graphics2D graphics);
|
||||||
|
|
||||||
|
public Rectangle getBounds()
|
||||||
|
{
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void storeBounds(Rectangle bounds)
|
||||||
|
{
|
||||||
|
this.bounds = bounds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,11 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.runelite.client.ui.overlay;
|
package net.runelite.client.ui.overlay;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -61,6 +61,9 @@ public class TopDownRendererLeft implements Renderer
|
|||||||
if (dimension == null)
|
if (dimension == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
Rectangle bounds = new Rectangle(BORDER_LEFT, y, (int) dimension.getWidth(), (int) dimension.getHeight());
|
||||||
|
overlay.storeBounds(bounds);
|
||||||
|
|
||||||
y += dimension.getHeight() + PADDING;
|
y += dimension.getHeight() + PADDING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ package net.runelite.client.ui.overlay;
|
|||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -74,6 +75,9 @@ public class TopDownRendererRight implements Renderer
|
|||||||
graphics.drawImage(image, clientWidth - BORDER_RIGHT - (int) dimension.getWidth(), y, null);
|
graphics.drawImage(image, clientWidth - BORDER_RIGHT - (int) dimension.getWidth(), y, null);
|
||||||
graphics.dispose();
|
graphics.dispose();
|
||||||
|
|
||||||
|
Rectangle bounds = new Rectangle(clientWidth - BORDER_RIGHT - (int) dimension.getWidth(), y, (int) dimension.getWidth(), (int) dimension.getHeight());
|
||||||
|
overlay.storeBounds(bounds);
|
||||||
|
|
||||||
y += dimension.getHeight() + PADDING;
|
y += dimension.getHeight() + PADDING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ public abstract class InfoBox
|
|||||||
{
|
{
|
||||||
private final BufferedImage image;
|
private final BufferedImage image;
|
||||||
|
|
||||||
|
private String tooltip;
|
||||||
|
|
||||||
public InfoBox(BufferedImage image)
|
public InfoBox(BufferedImage image)
|
||||||
{
|
{
|
||||||
this.image = image;
|
this.image = image;
|
||||||
@@ -54,4 +56,14 @@ public abstract class InfoBox
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTooltip()
|
||||||
|
{
|
||||||
|
return tooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTooltip(String tooltip)
|
||||||
|
{
|
||||||
|
this.tooltip = tooltip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,12 @@ import java.awt.Color;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.Point;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||||
@@ -69,9 +71,14 @@ public class InfoBoxOverlay extends Overlay
|
|||||||
|
|
||||||
FontMetrics metrics = graphics.getFontMetrics();
|
FontMetrics metrics = graphics.getFontMetrics();
|
||||||
|
|
||||||
int width = infoBoxes.size() * BOXSIZE;
|
int width = infoBoxes.size() * (BOXSIZE + SEPARATOR);
|
||||||
|
|
||||||
|
Point mouse = client.getMouseCanvasPosition();
|
||||||
|
int mouseX = mouse.getX();
|
||||||
|
int mouseY = mouse.getY();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
|
||||||
|
Rectangle overlayBounds = this.getBounds();
|
||||||
for (InfoBox box : infoBoxes)
|
for (InfoBox box : infoBoxes)
|
||||||
{
|
{
|
||||||
if (!box.render())
|
if (!box.render())
|
||||||
@@ -101,6 +108,38 @@ public class InfoBoxOverlay extends Overlay
|
|||||||
graphics.setColor(color);
|
graphics.setColor(color);
|
||||||
graphics.drawString(str, x + ((BOXSIZE - metrics.stringWidth(str)) / 2), BOXSIZE - SEPARATOR);
|
graphics.drawString(str, x + ((BOXSIZE - metrics.stringWidth(str)) / 2), BOXSIZE - SEPARATOR);
|
||||||
|
|
||||||
|
if (overlayBounds == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String tooltip = box.getTooltip();
|
||||||
|
if (tooltip == null || tooltip.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle bounds = new Rectangle((int) overlayBounds.getX() + x, (int) overlayBounds.getY(), BOXSIZE, BOXSIZE);
|
||||||
|
if (bounds.contains(mouse.getX(), mouse.getY()))
|
||||||
|
{
|
||||||
|
int tooltipWidth = metrics.stringWidth(tooltip);
|
||||||
|
int height = metrics.getHeight();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Draws the outline of the rect
|
||||||
|
graphics.setColor(Color.BLACK);
|
||||||
|
graphics.drawRect(mouseX, mouseY - (height / 2), tooltipWidth + 6, height);
|
||||||
|
|
||||||
|
// Tooltip text
|
||||||
|
graphics.setColor(Color.WHITE);
|
||||||
|
graphics.drawString(tooltip, mouseX + 3, mouseY + 5);
|
||||||
|
}
|
||||||
|
|
||||||
x += BOXSIZE + SEPARATOR;
|
x += BOXSIZE + SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user