Java Code Examples for net.runelite.api.widgets.WidgetItem#getWidget()

The following examples show how to use net.runelite.api.widgets.WidgetItem#getWidget() . 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: HighAlchemyOverlay.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget)
{
	Widget widget = itemWidget.getWidget();
	int interfaceGroup = TO_GROUP(widget.getId());

	if (!plugin.getInterfaceGroups().contains(interfaceGroup))
	{
		return;
	}

	final int natPrice = itemManager.getItemPrice(ItemID.NATURE_RUNE, true);
	final int alchPriceNoStaff = natPrice + 5 * itemManager.getItemPrice(ItemID.FIRE_RUNE, true);

	final int id = getNotedId(itemId);
	final int gePrice = getGEPrice(id);
	final int haPrice = getHAPrice(id);
	final int materialCost = config.usingFireRunes() ? alchPriceNoStaff : natPrice;
	final int desiredProfit = config.minProfit();
	final int haProfit = getHAProfit(haPrice, gePrice, materialCost);

	if (gePrice > 0 && haPrice > 0 && haProfit >= desiredProfit)
	{
		final Color color = config.getHighlightColor();

		if (color != null)
		{
			Rectangle bounds = itemWidget.getCanvasBounds();
			final BufferedImage outline = itemManager.getItemOutline(itemId, itemWidget.getQuantity(), color);
			graphics.drawImage(outline, (int) bounds.getX() + 1, (int) bounds.getY() + 1, null);
		}
	}
}
 
Example 2
Source File: WidgetItemOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	final List<WidgetItem> itemWidgets = overlayManager.getItemWidgets();
	final Rectangle originalClipBounds = graphics.getClipBounds();
	Widget curClipParent = null;
	for (WidgetItem widgetItem : itemWidgets)
	{
		Widget widget = widgetItem.getWidget();
		int interfaceGroup = TO_GROUP(widget.getId());

		// Don't draw if this widget isn't one of the allowed nor in tag tab/item tab
		if (!interfaceGroups.contains(interfaceGroup) ||
			(interfaceGroup == BANK_GROUP_ID
				&& (widget.getParentId() == BANK_CONTENT_CONTAINER.getId() || widget.getParentId() == BANK_TAB_CONTAINER.getId())))
		{
			continue;
		}

		Widget parent = widget.getParent();
		Rectangle parentBounds = parent.getBounds();
		Rectangle itemCanvasBounds = widgetItem.getCanvasBounds();
		boolean dragging = widgetItem.getDraggingCanvasBounds() != null;

		boolean shouldClip;
		if (dragging)
		{
			// If dragging, clip if the dragged item is outside of the parent bounds
			shouldClip = itemCanvasBounds.x < parentBounds.x;
			shouldClip |= itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x + parentBounds.width;
			shouldClip |= itemCanvasBounds.y < parentBounds.y;
			shouldClip |= itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y + parentBounds.height;
		}
		else
		{
			// Otherwise, we only need to clip the overlay if it intersects the parent bounds,
			// since items completely outside of the parent bounds are not drawn
			shouldClip = itemCanvasBounds.y < parentBounds.y && itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y;
			shouldClip |= itemCanvasBounds.y < parentBounds.y + parentBounds.height && itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y + parentBounds.height;
			shouldClip |= itemCanvasBounds.x < parentBounds.x && itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x;
			shouldClip |= itemCanvasBounds.x < parentBounds.x + parentBounds.width && itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x + parentBounds.width;
		}
		if (shouldClip)
		{
			if (curClipParent != parent)
			{
				graphics.setClip(parentBounds);
				curClipParent = parent;
			}
		}
		else if (curClipParent != null && curClipParent != parent)
		{
			graphics.setClip(originalClipBounds);
			curClipParent = null;
		}

		renderItemOverlay(graphics, widgetItem.getId(), widgetItem);
	}
	return null;
}