Java Code Examples for net.runelite.api.widgets.Widget#getWidth()

The following examples show how to use net.runelite.api.widgets.Widget#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LightBoxOverlay.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void highlightWidget(Graphics2D graphics, Widget window, Widget widget)
{
	net.runelite.api.Point canvasLocation = widget.getCanvasLocation();

	if (canvasLocation == null)
	{
		return;
	}

	// Don't draw outside the light box window
	net.runelite.api.Point windowLocation = window.getCanvasLocation();

	if (windowLocation.getY() > canvasLocation.getY()
		|| windowLocation.getY() + window.getHeight() < canvasLocation.getY() + widget.getHeight())
	{
		return;
	}

	Area widgetArea = new Area(new Rectangle(canvasLocation.getX(), canvasLocation.getY(), widget.getWidth(), widget.getHeight()));

	OverlayUtil.renderHoverableArea(graphics, widgetArea, client.getMouseCanvasPosition(),
		HIGHLIGHT_FILL_COLOR, HIGHLIGHT_BORDER_COLOR, HIGHLIGHT_HOVER_BORDER_COLOR);
}
 
Example 2
Source File: WidgetOverlay.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	final Widget widget = client.getWidget(widgetInfo);
	final Rectangle bounds = super.getBounds();
	final Rectangle parent = getParentBounds(widget);

	if (parent.isEmpty())
	{
		return null;
	}

	int x = bounds.x;
	int y = bounds.y;
	x = Math.max(parent.x, x);
	y = Math.max(parent.y, y);
	x = Math.min((int)parent.getMaxX() - bounds.width, x);
	y = Math.min((int)parent.getMaxY() - bounds.height, y);
	bounds.setLocation(x, y);
	widget.setOriginalX(0);
	widget.setOriginalY(0);
	widget.setRelativeX(bounds.x - parent.x);
	widget.setRelativeY(bounds.y - parent.y);
	return new Dimension(widget.getWidth(), widget.getHeight());
}
 
Example 3
Source File: FpsOverlay.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (!config.drawFps())
	{
		return null;
	}

	// On resizable bottom line mode the logout button is at the top right, so offset the overlay
	// to account for it
	Widget logoutButton = client.getWidget(WidgetInfo.RESIZABLE_MINIMAP_LOGOUT_BUTTON);
	int xOffset = X_OFFSET;
	if (logoutButton != null && !logoutButton.isHidden())
	{
		xOffset += logoutButton.getWidth();
	}

	final String text = client.getFPS() + FPS_STRING;
	final int textWidth = graphics.getFontMetrics().stringWidth(text);
	final int textHeight = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent();

	final int width = (int) client.getRealDimensions().getWidth();
	final Point point = new Point(width - textWidth - xOffset, textHeight + Y_OFFSET);
	OverlayUtil.renderTextLocation(graphics, point, text, getFpsValueColor());

	return null;
}
 
Example 4
Source File: WorldHopperPingOverlay.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (!worldHopperConfig.displayPing())
	{
		return null;
	}

	final int ping = worldHopperPlugin.getCurrentPing();
	if (ping < 0)
	{
		return null;
	}

	final String text = ping + " ms";
	final int textWidth = graphics.getFontMetrics().stringWidth(text);
	final int textHeight = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent();

	// Adjust ping offset for logout button
	Widget logoutButton = client.getWidget(WidgetInfo.RESIZABLE_MINIMAP_LOGOUT_BUTTON);
	int xOffset = X_OFFSET;
	if (logoutButton != null && !logoutButton.isHidden())
	{
		xOffset += logoutButton.getWidth();
	}

	final int width = (int) client.getRealDimensions().getWidth();
	final Point point = new Point(width - textWidth - xOffset, textHeight + Y_OFFSET);
	OverlayUtil.renderTextLocation(graphics, point, text, Color.YELLOW);

	return null;
}
 
Example 5
Source File: FpsOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (!config.drawFps())
	{
		return null;
	}

	// On resizable bottom line mode the logout button is at the top right, so offset the overlay
	// to account for it
	Widget logoutButton = client.getWidget(WidgetInfo.RESIZABLE_MINIMAP_LOGOUT_BUTTON);
	int xOffset = X_OFFSET;
	if (logoutButton != null && !logoutButton.isHidden())
	{
		xOffset += logoutButton.getWidth();
	}
	
	final String text = client.getFPS() + FPS_STRING;
	final int textWidth = graphics.getFontMetrics().stringWidth(text);
	final int textHeight = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent();

	final int width = (int) client.getRealDimensions().getWidth();
	final Point point = new Point(width - textWidth - xOffset, textHeight + Y_OFFSET);
	OverlayUtil.renderTextLocation(graphics, point, text, getFpsValueColor());

	return null;
}
 
Example 6
Source File: ChatboxPerformancePlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void fixWhiteLines(boolean upperLine)
{
	int currOpacity = 256;
	int prevWidth = 0;
	Widget[] children = client.getWidget(WidgetInfo.CHATBOX_TRANSPARENT_LINES).getDynamicChildren();
	Widget prev = null;
	for (Widget w : children)
	{
		if (w.getType() != WidgetType.RECTANGLE)
		{
			continue;
		}

		if ((w.getRelativeY() == 0 && !upperLine) ||
			(w.getRelativeY() != 0 && upperLine))
		{
			continue;
		}

		if (prev != null)
		{
			int width = w.getWidth();
			prev.setWidthMode(WidgetSizeMode.ABSOLUTE);
			prev.setRelativeX(width);
			prev.setOriginalX(width);
			prev.setWidth(prevWidth - width);
			prev.setOriginalWidth(prev.getWidth());
			prev.setOpacity(currOpacity);
		}

		prevWidth = w.getWidth();

		currOpacity -= upperLine ? 3 : 4; // Rough numbers, can't get exactly the same as Jagex because of rounding
		prev = w;
	}
	if (prev != null)
	{
		prev.setOpacity(currOpacity);
	}
}
 
Example 7
Source File: WorldHopperPingOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	if (!worldHopperConfig.displayPing())
	{
		return null;
	}

	final int ping = worldHopperPlugin.getCurrentPing();
	if (ping < 0)
	{
		return null;
	}

	final String text = ping + " ms";
	final int textWidth = graphics.getFontMetrics().stringWidth(text);
	final int textHeight = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent();

	// Adjust ping offset for logout button
	Widget logoutButton = client.getWidget(WidgetInfo.RESIZABLE_MINIMAP_LOGOUT_BUTTON);
	int xOffset = X_OFFSET;
	if (logoutButton != null && !logoutButton.isHidden())
	{
		xOffset += logoutButton.getWidth();
	}

	final int width = (int) client.getRealDimensions().getWidth();
	final Point point = new Point(width - textWidth - xOffset, textHeight + Y_OFFSET);
	OverlayUtil.renderTextLocation(graphics, point, text, Color.YELLOW);

	return null;
}
 
Example 8
Source File: MusicPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void teardownMusicOptions()
{
	for (MusicSlider slider : MusicSlider.values())
	{
		Widget icon = client.getWidget(slider.getWidgetID());
		// VolumeChanged can trigger us before the sliders interface is fully valid, so
		//  we check if the width is set before we copy it to all of our widgets
		if (icon == null || icon.getWidth() == 0)
		{
			return;
		}

		if (slider.getHandle() != null)
		{
			{
				Widget handle = slider.getHandle();
				Widget parent = handle.getParent();
				if (parent == null)
				{
					continue;
				}
				else
				{
					Widget[] siblings = parent.getChildren();
					if (siblings == null || handle.getIndex() >= siblings.length || siblings[handle.getIndex()] != handle)
					{
						continue;
					}
					siblings[slider.getTrack().getIndex()] = null;
					siblings[handle.getIndex()] = null;
				}
			}

			Object[] init = icon.getOnLoadListener();
			init[1] = slider.getWidgetID().getId();

			// Readd the var transmit triggers and rerun options_allsounds
			client.runScript(init);
			slider.setHandle(null);
			slider.setTrack(null);
		}
	}
}
 
Example 9
Source File: StatusBarsOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D g)
{
	final Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
	if (widgetBankTitleBar != null && !widgetBankTitleBar.isHidden())
	{
		return null;
	}

	Viewport curViewport = null;
	Widget curWidget = null;

	for (Viewport viewport : Viewport.values())
	{
		final Widget viewportWidget = client.getWidget(viewport.getViewport());
		if (viewportWidget != null && !viewportWidget.isHidden())
		{
			curViewport = viewport;
			curWidget = viewportWidget;
			break;
		}
	}

	if (curViewport == null)
	{
		return null;
	}
	else
	{
		curWidget.isHidden();
	}

	final Point offsetLeft = curViewport.getOffsetLeft();
	final Point offsetRight = curViewport.getOffsetRight();
	final Point location = curWidget.getCanvasLocation();
	final int height, offsetLeftBarX, offsetLeftBarY, offsetRightBarX, offsetRightBarY;

	if (curViewport == Viewport.RESIZED_BOTTOM)
	{
		height = RESIZED_BOTTOM_HEIGHT;
		offsetLeftBarX = (location.getX() + RESIZED_BOTTOM_OFFSET_X - offsetLeft.getX());
		offsetLeftBarY = (location.getY() - RESIZED_BOTTOM_OFFSET_Y - offsetRight.getY());
		offsetRightBarX = (location.getX() + RESIZED_BOTTOM_OFFSET_X - offsetRight.getX());
		offsetRightBarY = (location.getY() - RESIZED_BOTTOM_OFFSET_Y - offsetRight.getY());
	}
	else
	{
		height = HEIGHT;
		offsetLeftBarX = (location.getX() - offsetLeft.getX());
		offsetLeftBarY = (location.getY() - offsetLeft.getY());
		offsetRightBarX = (location.getX() - offsetRight.getX()) + curWidget.getWidth();
		offsetRightBarY = (location.getY() - offsetRight.getY());
	}

	BarRenderer left = plugin.getBarRenderers().get(config.leftBarMode());
	BarRenderer right = plugin.getBarRenderers().get(config.rightBarMode());

	if (left != null)
	{
		left.draw(client, this, g, offsetLeftBarX, offsetLeftBarY, height);
	}

	if (right != null)
	{
		right.draw(client, this, g, offsetRightBarX, offsetRightBarY, height);
	}

	return null;
}
 
Example 10
Source File: ClueScrollPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
void highlightWidget(Graphics2D graphics, Widget toHighlight, Widget container, Rectangle padding, String text)
{
	padding = Objects.requireNonNullElse(padding, new Rectangle());

	Point canvasLocation = toHighlight.getCanvasLocation();

	if (canvasLocation == null)
	{
		return;
	}

	Point windowLocation = container.getCanvasLocation();

	if (windowLocation.getY() > canvasLocation.getY() + toHighlight.getHeight()
		|| windowLocation.getY() + container.getHeight() < canvasLocation.getY())
	{
		return;
	}

	// Visible area of widget
	Area widgetArea = new Area(
		new Rectangle(
			canvasLocation.getX() - padding.x,
			Math.max(canvasLocation.getY(), windowLocation.getY()) - padding.y,
			toHighlight.getWidth() + padding.x + padding.width,
			Math.min(
				Math.min(windowLocation.getY() + container.getHeight() - canvasLocation.getY(), toHighlight.getHeight()),
				Math.min(canvasLocation.getY() + toHighlight.getHeight() - windowLocation.getY(), toHighlight.getHeight())) + padding.y + padding.height
		));

	OverlayUtil.renderHoverableArea(graphics, widgetArea, client.getMouseCanvasPosition(),
		HIGHLIGHT_FILL_COLOR, HIGHLIGHT_BORDER_COLOR, HIGHLIGHT_HOVER_BORDER_COLOR);

	if (text == null)
	{
		return;
	}

	FontMetrics fontMetrics = graphics.getFontMetrics();

	textComponent.setPosition(new java.awt.Point(
		canvasLocation.getX() + toHighlight.getWidth() / 2 - fontMetrics.stringWidth(text) / 2,
		canvasLocation.getY() + fontMetrics.getHeight()));
	textComponent.setText(text);
	textComponent.render(graphics);
}
 
Example 11
Source File: ChatboxItemSearch.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected void update()
{
	Widget container = chatboxPanelManager.getContainerWidget();
	container.deleteAllChildren();

	Widget promptWidget = container.createChild(-1, WidgetType.TEXT);
	promptWidget.setText(getPrompt());
	promptWidget.setTextColor(0x800000);
	promptWidget.setFontId(getFontID());
	promptWidget.setOriginalX(0);
	promptWidget.setOriginalY(5);
	promptWidget.setXPositionMode(WidgetPositionMode.ABSOLUTE_CENTER);
	promptWidget.setYPositionMode(WidgetPositionMode.ABSOLUTE_TOP);
	promptWidget.setOriginalHeight(FONT_SIZE);
	promptWidget.setXTextAlignment(WidgetTextAlignment.CENTER);
	promptWidget.setYTextAlignment(WidgetTextAlignment.CENTER);
	promptWidget.setWidthMode(WidgetSizeMode.MINUS);
	promptWidget.revalidate();

	buildEdit(0, 5 + FONT_SIZE, container.getWidth(), FONT_SIZE);

	Widget separator = container.createChild(-1, WidgetType.LINE);
	separator.setOriginalX(0);
	separator.setOriginalY(8 + (FONT_SIZE * 2));
	separator.setXPositionMode(WidgetPositionMode.ABSOLUTE_CENTER);
	separator.setYPositionMode(WidgetPositionMode.ABSOLUTE_TOP);
	separator.setOriginalHeight(0);
	separator.setOriginalWidth(16);
	separator.setWidthMode(WidgetSizeMode.MINUS);
	separator.setTextColor(0x666666);
	separator.revalidate();

	int x = PADDING;
	int y = PADDING * 3;
	int idx = 0;
	for (ItemComposition itemComposition : results.values())
	{
		Widget item = container.createChild(-1, WidgetType.GRAPHIC);
		item.setXPositionMode(WidgetPositionMode.ABSOLUTE_LEFT);
		item.setYPositionMode(WidgetPositionMode.ABSOLUTE_TOP);
		item.setOriginalX(x);
		item.setOriginalY(y + FONT_SIZE * 2);
		item.setOriginalHeight(ICON_HEIGHT);
		item.setOriginalWidth(ICON_WIDTH);
		item.setName("<col=ff9040>" + itemComposition.getName());
		item.setItemId(itemComposition.getId());
		item.setItemQuantity(10000);
		item.setItemQuantityMode(ItemQuantityMode.NEVER);
		item.setBorderType(1);
		item.setAction(0, tooltipText);
		item.setHasListener(true);

		if (index == idx)
		{
			item.setOpacity(HOVERED_OPACITY);
		}
		else
		{
			item.setOnMouseOverListener((JavaScriptCallback) ev -> item.setOpacity(HOVERED_OPACITY));
			item.setOnMouseLeaveListener((JavaScriptCallback) ev -> item.setOpacity(0));
		}

		item.setOnOpListener((JavaScriptCallback) ev ->
		{
			if (onItemSelected != null)
			{
				onItemSelected.accept(itemComposition.getId());
			}

			chatboxPanelManager.close();
		});

		x += ICON_WIDTH + PADDING;
		if (x + ICON_WIDTH >= container.getWidth())
		{
			y += ICON_HEIGHT + PADDING;
			x = PADDING;
		}

		item.revalidate();
		++idx;
	}
}
 
Example 12
Source File: ClueScrollPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void highlightWidget(Graphics2D graphics, Widget toHighlight, Widget container, Rectangle padding, String text)
{
	padding = MoreObjects.firstNonNull(padding, new Rectangle());

	Point canvasLocation = toHighlight.getCanvasLocation();

	if (canvasLocation == null)
	{
		return;
	}

	Point windowLocation = container.getCanvasLocation();

	if (windowLocation.getY() > canvasLocation.getY() + toHighlight.getHeight()
		|| windowLocation.getY() + container.getHeight() < canvasLocation.getY())
	{
		return;
	}

	// Visible area of widget
	Area widgetArea = new Area(
		new Rectangle(
			canvasLocation.getX() - padding.x,
			Math.max(canvasLocation.getY(), windowLocation.getY()) - padding.y,
			toHighlight.getWidth() + padding.x + padding.width,
			Math.min(
				Math.min(windowLocation.getY() + container.getHeight() - canvasLocation.getY(), toHighlight.getHeight()),
				Math.min(canvasLocation.getY() + toHighlight.getHeight() - windowLocation.getY(), toHighlight.getHeight())) + padding.y + padding.height
		));

	OverlayUtil.renderHoverableArea(graphics, widgetArea, client.getMouseCanvasPosition(),
		HIGHLIGHT_FILL_COLOR, HIGHLIGHT_BORDER_COLOR, HIGHLIGHT_HOVER_BORDER_COLOR);

	if (text == null)
	{
		return;
	}

	FontMetrics fontMetrics = graphics.getFontMetrics();

	textComponent.setPosition(new java.awt.Point(
		canvasLocation.getX() + toHighlight.getWidth() / 2 - fontMetrics.stringWidth(text) / 2,
		canvasLocation.getY() + fontMetrics.getHeight()));
	textComponent.setText(text);
	textComponent.render(graphics);
}
 
Example 13
Source File: Perspective.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Translates two-dimensional ground coordinates within the 3D world to
 * their corresponding coordinates on the Minimap.
 *
 * @param client the game client
 * @param point ground coordinate
 * @param distance max distance from local player to minimap point
 * @return a {@link Point} on screen corresponding to the position in
 * 3D-space
 */
@Nullable
public static Point localToMinimap(@Nonnull Client client, @Nonnull LocalPoint point, int distance)
{
	LocalPoint localLocation = client.getLocalPlayer().getLocalLocation();
	int x = point.getX() / 32 - localLocation.getX() / 32;
	int y = point.getY() / 32 - localLocation.getY() / 32;

	int dist = x * x + y * y;
	if (dist < distance)
	{
		Widget minimapDrawWidget;
		if (client.isResized())
		{
			if (client.getVar(Varbits.SIDE_PANELS) == 1)
			{
				minimapDrawWidget = client.getWidget(WidgetInfo.RESIZABLE_MINIMAP_DRAW_AREA);
			}
			else
			{
				minimapDrawWidget = client.getWidget(WidgetInfo.RESIZABLE_MINIMAP_STONES_DRAW_AREA);
			}
		}
		else
		{
			minimapDrawWidget = client.getWidget(WidgetInfo.FIXED_VIEWPORT_MINIMAP_DRAW_AREA);
		}

		if (minimapDrawWidget == null || minimapDrawWidget.isHidden())
		{
			return null;
		}

		final int angle = client.getMapAngle() & 0x7FF;

		final int sin = SINE[angle];
		final int cos = COSINE[angle];

		final int xx = y * sin + cos * x >> 16;
		final int yy = sin * x - y * cos >> 16;

		Point loc = minimapDrawWidget.getCanvasLocation();
		int miniMapX = loc.getX() + xx + minimapDrawWidget.getWidth() / 2;
		int miniMapY = minimapDrawWidget.getHeight() / 2 + loc.getY() + yy;
		return new Point(miniMapX, miniMapY);
	}

	return null;
}