use of net.runelite.api.Client in project runelite by runelite.
the class TooltipOverlay method render.
@Override
public Dimension render(Graphics2D graphics) {
final List<Tooltip> tooltips = tooltipManager.getTooltips();
if (tooltips.isEmpty()) {
return null;
}
final Client client = clientProvider.get();
final Rectangle clientCanvasBounds = new Rectangle(client.getRealDimensions());
final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
final Point mousePosition = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + OFFSET);
final Rectangle bounds = new Rectangle(getBounds());
bounds.setLocation(mousePosition);
if (!clientCanvasBounds.contains(bounds)) {
final int clientX = (int) clientCanvasBounds.getMaxX();
final int clientY = (int) clientCanvasBounds.getMaxY();
final int boundsX = (int) bounds.getMaxX();
final int boundsY = (int) bounds.getMaxY();
if (boundsY > clientY) {
graphics.translate(0, -bounds.height - OFFSET);
}
if (boundsX > clientX) {
graphics.translate(-bounds.width, 0);
}
}
final Rectangle newBounds = new Rectangle(-1, -1, 0, 0);
for (Tooltip tooltip : tooltips) {
final TooltipComponent tooltipComponent = new TooltipComponent();
tooltipComponent.setModIcons(client.getModIcons());
tooltipComponent.setText(tooltip.getText());
if (newBounds.contains(mousePosition)) {
mousePosition.move(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + OFFSET + newBounds.height);
}
tooltipComponent.setPosition(mousePosition);
final Dimension dimension = tooltipComponent.render(graphics);
// Create incremental tooltip newBounds
newBounds.x = newBounds.x != -1 ? Math.min(newBounds.x, mousePosition.x) : mousePosition.x;
newBounds.y = newBounds.y != -1 ? Math.min(newBounds.y, mousePosition.y) : mousePosition.y;
newBounds.height += dimension.height + PADDING;
newBounds.width = Math.max(newBounds.width, dimension.width);
}
tooltipManager.clear();
return newBounds.getSize();
}
use of net.runelite.api.Client in project runelite by runelite.
the class OverlayRenderer method shouldInvalidateBounds.
private boolean shouldInvalidateBounds() {
final Client client = clientProvider.get();
final Widget chatbox = client.getWidget(WidgetInfo.CHATBOX_MESSAGES);
final boolean resizeableChanged = isResizeable != client.isResized();
boolean changed = false;
if (resizeableChanged) {
isResizeable = client.isResized();
changed = true;
}
final boolean chatboxBoundsChanged = chatbox == null || !chatbox.getBounds().equals(chatboxBounds);
if (chatboxBoundsChanged) {
chatboxBounds = chatbox != null ? chatbox.getBounds() : new Rectangle();
changed = true;
}
final boolean chatboxHiddenChanged = chatboxHidden != (chatbox == null || chatbox.isHidden());
if (chatboxHiddenChanged) {
chatboxHidden = chatbox == null || chatbox.isHidden();
changed = true;
}
final boolean viewportChanged = !client.getViewportWidget().getBounds().equals(viewportBounds);
if (viewportChanged) {
viewportBounds = client.getViewportWidget().getBounds();
changed = true;
}
return changed;
}
use of net.runelite.api.Client in project runelite by runelite.
the class ClientUI method init.
/**
* Initialize UI.
*
* @param client the client
* @throws Exception exception that can occur during creation of the UI
*/
public void init(@Nullable final Applet client) throws Exception {
this.client = client;
SwingUtilities.invokeAndWait(() -> {
// Set some sensible swing defaults
SwingUtil.setupDefaults();
// Use substance look and feel
SwingUtil.setTheme(new SubstanceGraphiteLookAndFeel());
// Use custom UI font
SwingUtil.setFont(FontManager.getRunescapeFont());
// Create main window
frame = new JFrame();
// Try to enable fullscreen on OSX
OSXUtil.tryEnableFullscreen(frame);
frame.setTitle(properties.getTitle());
frame.setIconImage(ICON);
// Prevent substance from using a resize cursor for pointing
frame.getLayeredPane().setCursor(Cursor.getDefaultCursor());
frame.setLocationRelativeTo(frame.getOwner());
frame.setResizable(true);
SwingUtil.addGracefulExitCallback(frame, runelite::shutdown, () -> client != null && client instanceof Client && ((Client) client).getGameState() != GameState.LOGIN_SCREEN);
final JPanel container = new JPanel();
container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
container.add(new ClientPanel(client));
navContainer = new JPanel();
navContainer.setLayout(new BorderLayout(0, 0));
navContainer.setMinimumSize(new Dimension(0, 0));
navContainer.setMaximumSize(new Dimension(0, Integer.MAX_VALUE));
container.add(navContainer);
pluginToolbar = new ClientPluginToolbar();
container.add(pluginToolbar);
titleToolbar = new ClientTitleToolbar();
frame.add(container);
});
}
use of net.runelite.api.Client in project runelite by runelite.
the class MenuManager method menuContainsCustomMenu.
private boolean menuContainsCustomMenu(WidgetMenuOption customMenuOption) {
Client client = clientProvider.get();
if (client == null) {
return false;
}
for (MenuEntry menuEntry : client.getMenuEntries()) {
String option = menuEntry.getOption();
String target = menuEntry.getTarget();
if (option.equals(customMenuOption.getMenuOption()) && target.equals(customMenuOption.getMenuTarget())) {
return true;
}
}
return false;
}
use of net.runelite.api.Client in project runelite by runelite.
the class ChatMessageManager method update.
public void update(final MessageNode target) {
if (Strings.isNullOrEmpty(target.getRuneLiteFormatMessage())) {
return;
}
final Client client = clientProvider.get();
final boolean transparent = client.isResized() && client.getSetting(Varbits.TRANSPARANT_CHATBOX) != 0;
final Set<ChatColor> chatColors = colorCache.get(target.getType());
// If we do not have any colors cached, simply set clean message
if (chatColors == null || chatColors.isEmpty()) {
target.setValue(target.getRuneLiteFormatMessage());
return;
}
target.setValue(recolorMessage(transparent, target.getRuneLiteFormatMessage(), target.getType()));
}
Aggregations