Java Code Examples for net.runelite.api.widgets.WidgetItem#getCanvasBounds()
The following examples show how to use
net.runelite.api.widgets.WidgetItem#getCanvasBounds() .
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: PouchOverlay.java From plugins with GNU General Public License v3.0 | 6 votes |
@Override public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { switch (itemId) { case ItemID.MEDIUM_POUCH_5511: case ItemID.LARGE_POUCH_5513: case ItemID.GIANT_POUCH_5515: final Rectangle bounds = itemWidget.getCanvasBounds(); final BufferedImage outline = itemManager.getItemOutline(itemId, itemWidget.getQuantity(), Color.RED); graphics.drawImage(outline, (int) bounds.getX(), (int) bounds.getY(), null); break; case ItemID.MEDIUM_POUCH: OverlayUtil.renderTextLocation(graphics, itemWidget.getCanvasLocation(), "~" + plugin.getMediumCharges(), Color.WHITE); break; case ItemID.LARGE_POUCH: OverlayUtil.renderTextLocation(graphics, itemWidget.getCanvasLocation(), "~" + plugin.getLargeCharges(), Color.WHITE); break; case ItemID.GIANT_POUCH: OverlayUtil.renderTextLocation(graphics, itemWidget.getCanvasLocation(), "~" + plugin.getGiantCharges(), Color.WHITE); break; } }
Example 2
Source File: DevToolsOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderInventory(Graphics2D graphics) { Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (inventoryWidget == null || inventoryWidget.isHidden()) { return; } for (WidgetItem item : inventoryWidget.getWidgetItems()) { Rectangle slotBounds = item.getCanvasBounds(); String idText = "" + item.getId(); FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(idText, graphics); int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2)); graphics.setColor(new Color(255, 255, 255, 65)); graphics.fill(slotBounds); graphics.setColor(Color.BLACK); graphics.drawString(idText, textX + 1, textY + 1); graphics.setColor(YELLOW); graphics.drawString(idText, textX, textY); } }
Example 3
Source File: InventoryTagsOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { final String group = plugin.getTag(itemId); if (group != null) { final Color color = plugin.getGroupNameColor(group); if (color != null) { Rectangle bounds = itemWidget.getCanvasBounds(); final BufferedImage outline = itemManager.getItemOutline(itemId, itemWidget.getQuantity(), color); graphics.drawImage(outline, (int) bounds.getX(), (int) bounds.getY(), null); } } }
Example 4
Source File: WidgetInspectorOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private void renderWiw(Graphics2D g, Object wiw, Color color) { g.setColor(color); if (wiw instanceof WidgetItem) { WidgetItem wi = (WidgetItem) wiw; Rectangle bounds = wi.getCanvasBounds(); g.draw(bounds); String text = wi.getId() + ""; FontMetrics fm = g.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(text, g); int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2)); g.setColor(Color.BLACK); g.drawString(text, textX + 1, textY + 1); g.setColor(Color.ORANGE); g.drawString(text, textX, textY); } else { Widget w = (Widget) wiw; g.draw(w.getBounds()); } }
Example 5
Source File: DevToolsOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private void renderInventory(Graphics2D graphics) { Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (inventoryWidget == null || inventoryWidget.isHidden()) { return; } for (WidgetItem item : inventoryWidget.getWidgetItems()) { Rectangle slotBounds = item.getCanvasBounds(); String idText = "" + item.getId(); FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(idText, graphics); int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2)); graphics.setColor(new Color(255, 255, 255, 65)); graphics.fill(slotBounds); graphics.setColor(Color.BLACK); graphics.drawString(idText, textX + 1, textY + 1); graphics.setColor(YELLOW); graphics.drawString(idText, textX, textY); } }
Example 6
Source File: CustomSwapper.java From ExternalPlugins with GNU General Public License v3.0 | 5 votes |
private Rectangle invBounds(int id) { final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); for (WidgetItem item : inventoryWidget.getWidgetItems()) { if (item.getId() == id) { return item.getCanvasBounds(); } } return null; }
Example 7
Source File: HighAlchemyOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
@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 8
Source File: InventoryTagsOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
@Override public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { final String group = plugin.getTag(itemId); if (group != null) { final Color color = plugin.getGroupNameColor(group); if (color != null) { Rectangle bounds = itemWidget.getCanvasBounds(); final BufferedImage outline = itemManager.getItemOutline(itemId, itemWidget.getQuantity(), color); graphics.drawImage(outline, (int) bounds.getX(), (int) bounds.getY(), null); } } }
Example 9
Source File: WidgetInspectorOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderWiw(Graphics2D g, Object wiw, Color color) { g.setColor(color); if (wiw instanceof WidgetItem) { WidgetItem wi = (WidgetItem) wiw; Rectangle bounds = wi.getCanvasBounds(); g.draw(bounds); String text = wi.getId() + ""; FontMetrics fm = g.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(text, g); int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2)); g.setColor(Color.BLACK); g.drawString(text, textX + 1, textY + 1); g.setColor(Color.ORANGE); g.drawString(text, textX, textY); } else { Widget w = (Widget) wiw; g.draw(w.getBounds()); } }
Example 10
Source File: SlayerOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
@Override public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { if (!ALL_SLAYER_ITEMS.contains(itemId)) { return; } if (!config.showItemOverlay()) { return; } if (plugin.getCurrentTask() == null) { return; } int amount = plugin.getCurrentTask().getAmount(); if (amount <= 0) { return; } final Rectangle bounds = itemWidget.getCanvasBounds(); final TextComponent textComponent = new TextComponent(); textComponent.setText(String.valueOf(amount)); // Draw the counter in the bottom left for equipment, and top left for jewelry textComponent.setPosition(new Point(bounds.x - 1, bounds.y - 1 + (SLAYER_JEWELRY.contains(itemId) ? bounds.height : graphics.getFontMetrics().getHeight()))); textComponent.render(graphics); }
Example 11
Source File: ScreenMarkerWidgetHighlightOverlay.java From plugins with GNU General Public License v3.0 | 4 votes |
@Override public Dimension render(Graphics2D graphics) { if (!plugin.isCreatingScreenMarker() || plugin.isDrawingScreenMarker()) { return null; } final MenuEntry[] menuEntries = client.getMenuEntries(); if (client.isMenuOpen() || menuEntries.length == 0) { plugin.setSelectedWidgetBounds(null); return null; } final MenuEntry menuEntry = menuEntries[menuEntries.length - 1]; final int childIdx = menuEntry.getParam0(); final int widgetId = menuEntry.getParam1(); final int groupId = WidgetInfo.TO_GROUP(widgetId); final int componentId = WidgetInfo.TO_CHILD(widgetId); final Widget widget = client.getWidget(groupId, componentId); if (widget == null) { plugin.setSelectedWidgetBounds(null); return null; } Rectangle bounds = null; if (childIdx > -1) { if (widget.getType() == WidgetType.INVENTORY) { final WidgetItem widgetItem = widget.getWidgetItem(childIdx); if (widgetItem != null) { bounds = widgetItem.getCanvasBounds(); } } else { final Widget child = widget.getChild(childIdx); if (child != null) { bounds = child.getBounds(); } } } else { bounds = widget.getBounds(); } if (bounds == null) { plugin.setSelectedWidgetBounds(null); return null; } drawHighlight(graphics, bounds); plugin.setSelectedWidgetBounds(bounds); return null; }
Example 12
Source File: InventoryGridOverlay.java From plugins with GNU General Public License v3.0 | 4 votes |
@Override public Dimension render(Graphics2D graphics) { final Widget if1DraggingWidget = client.getIf1DraggedWidget(); final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (if1DraggingWidget == null || if1DraggingWidget != inventoryWidget || client.getItemPressedDuration() < config.dragDelay() / Constants.CLIENT_TICK_LENGTH) { initialMousePoint = null; hoverActive = false; return null; } final net.runelite.api.Point mouse = client.getMouseCanvasPosition(); final Point mousePoint = new Point(mouse.getX(), mouse.getY()); final int if1DraggedItemIndex = client.getIf1DraggedItemIndex(); final WidgetItem draggedItem = inventoryWidget.getWidgetItem(if1DraggedItemIndex); final Rectangle initialBounds = draggedItem.getCanvasBounds(false); if (initialMousePoint == null) { initialMousePoint = mousePoint; } if (draggedItem.getId() == -1 || !hoverActive && initialMousePoint.distance(mousePoint) < DISTANCE_TO_ACTIVATE_HOVER) { return null; } hoverActive = true; for (int i = 0; i < INVENTORY_SIZE; ++i) { WidgetItem targetWidgetItem = inventoryWidget.getWidgetItem(i); final Rectangle bounds = targetWidgetItem.getCanvasBounds(false); boolean inBounds = bounds.contains(mousePoint); if (config.showItem() && inBounds) { drawItem(graphics, bounds, draggedItem); drawItem(graphics, initialBounds, targetWidgetItem); } if (config.showHighlight() && inBounds) { graphics.setColor(config.highlightColor()); graphics.fill(bounds); } else if (config.showInventoryGrid()) { graphics.setColor(config.gridColor()); graphics.fill(bounds); } } return null; }
Example 13
Source File: AlchemyRoom.java From plugins with GNU General Public License v3.0 | 4 votes |
private void drawItem(Graphics2D graphics, WidgetItem item) { Rectangle bounds = item.getCanvasBounds(); graphics.setColor(Color.GREEN); graphics.draw(bounds); }
Example 14
Source File: WidgetItemOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@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; }
Example 15
Source File: SlayerOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { if (!ALL_SLAYER_ITEMS.contains(itemId)) { return; } if (!config.showItemOverlay()) { return; } int amount = plugin.getAmount(); if (amount <= 0) { return; } int slaughterCount = plugin.getSlaughterChargeCount(); int expeditiousCount = plugin.getExpeditiousChargeCount(); graphics.setFont(FontManager.getRunescapeSmallFont()); final Rectangle bounds = itemWidget.getCanvasBounds(); final TextComponent textComponent = new TextComponent(); switch (itemId) { case ItemID.EXPEDITIOUS_BRACELET: textComponent.setText(String.valueOf(expeditiousCount)); break; case ItemID.BRACELET_OF_SLAUGHTER: textComponent.setText(String.valueOf(slaughterCount)); break; default: textComponent.setText(String.valueOf(amount)); break; } // Draw the counter in the bottom left for equipment, and top left for jewelry textComponent.setPosition(new Point(bounds.x - 1, bounds.y - 1 + (SLAYER_JEWELRY.contains(itemId) ? bounds.height : graphics.getFontMetrics().getHeight()))); textComponent.render(graphics); }
Example 16
Source File: ItemChargeOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { if (!displayOverlay()) { return; } graphics.setFont(FontManager.getRunescapeSmallFont()); int charges; if (itemId == ItemID.DODGY_NECKLACE) { if (!config.showDodgyCount()) { return; } charges = config.dodgyNecklace(); } else if (itemId == ItemID.BINDING_NECKLACE) { if (!config.showBindingNecklaceCharges()) { return; } charges = config.bindingNecklace(); } else if (itemId >= ItemID.EXPLORERS_RING_1 && itemId <= ItemID.EXPLORERS_RING_4) { if (!config.showExplorerRingCharges()) { return; } charges = config.explorerRing(); } else if (itemId == ItemID.RING_OF_FORGING) { if (!config.showRingOfForgingCount()) { return; } charges = config.ringOfForging(); } else if (itemId == ItemID.AMULET_OF_CHEMISTRY) { if (!config.showAmuletOfChemistryCharges()) { return; } charges = config.amuletOfChemistry(); } else if (itemId == ItemID.AMULET_OF_BOUNTY) { if (!config.showAmuletOfBountyCharges()) { return; } charges = config.amuletOfBounty(); } else { ItemWithCharge chargeItem = ItemWithCharge.findItem(itemId); if (chargeItem == null) { return; } ItemChargeType type = chargeItem.getType(); if ((type == TELEPORT && !config.showTeleportCharges()) || (type == FUNGICIDE_SPRAY && !config.showFungicideCharges()) || (type == IMPBOX && !config.showImpCharges()) || (type == WATERCAN && !config.showWateringCanCharges()) || (type == WATERSKIN && !config.showWaterskinCharges()) || (type == BELLOWS && !config.showBellowCharges()) || (type == FRUIT_BASKET && !config.showBasketCharges()) || (type == SACK && !config.showSackCharges()) || (type == ABYSSAL_BRACELET && !config.showAbyssalBraceletCharges()) || (type == AMULET_OF_CHEMISTRY && !config.showAmuletOfChemistryCharges()) || (type == AMULET_OF_BOUNTY && !config.showAmuletOfBountyCharges()) || (type == POTION && !config.showPotionDoseCount())) { return; } charges = chargeItem.getCharges(); } final Rectangle bounds = itemWidget.getCanvasBounds(); final TextComponent textComponent = new TextComponent(); textComponent.setPosition(new Point(bounds.x - 1, bounds.y + 15)); textComponent.setText(charges < 0 ? "?" : String.valueOf(charges)); textComponent.setColor(itemChargePlugin.getColor(charges)); textComponent.render(graphics); }
Example 17
Source File: AlchemyRoom.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private void drawItem(Graphics2D graphics, WidgetItem item, Color border) { Rectangle bounds = item.getCanvasBounds(); graphics.setColor(border); graphics.draw(bounds); }
Example 18
Source File: ScreenMarkerWidgetHighlightOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Dimension render(Graphics2D graphics) { if (!plugin.isCreatingScreenMarker() || plugin.isDrawingScreenMarker()) { return null; } final MenuEntry[] menuEntries = client.getMenuEntries(); if (client.isMenuOpen() || menuEntries.length == 0) { plugin.setSelectedWidgetBounds(null); return null; } final MenuEntry menuEntry = menuEntries[menuEntries.length - 1]; final int childIdx = menuEntry.getParam0(); final int widgetId = menuEntry.getParam1(); final int groupId = WidgetInfo.TO_GROUP(widgetId); final int componentId = WidgetInfo.TO_CHILD(widgetId); final Widget widget = client.getWidget(groupId, componentId); if (widget == null) { plugin.setSelectedWidgetBounds(null); return null; } Rectangle bounds = null; if (childIdx > -1) { if (widget.getType() == WidgetType.INVENTORY) { final WidgetItem widgetItem = widget.getWidgetItem(childIdx); if (widgetItem != null) { bounds = widgetItem.getCanvasBounds(); } } else { final Widget child = widget.getChild(childIdx); if (child != null) { bounds = child.getBounds(); } } } else { bounds = widget.getBounds(); } if (bounds == null) { plugin.setSelectedWidgetBounds(null); return null; } drawHighlight(graphics, bounds); plugin.setSelectedWidgetBounds(bounds); return null; }
Example 19
Source File: InventoryGridOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Dimension render(Graphics2D graphics) { final Widget if1DraggingWidget = client.getIf1DraggedWidget(); final Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (if1DraggingWidget == null || if1DraggingWidget != inventoryWidget) { initialMousePoint = null; hoverActive = false; return null; } final net.runelite.api.Point mouse = client.getMouseCanvasPosition(); final Point mousePoint = new Point(mouse.getX(), mouse.getY()); final int if1DraggedItemIndex = client.getIf1DraggedItemIndex(); final WidgetItem draggedItem = inventoryWidget.getWidgetItem(if1DraggedItemIndex); final Rectangle initialBounds = draggedItem.getCanvasBounds(false); if (initialMousePoint == null) { initialMousePoint = mousePoint; } if (draggedItem.getId() == -1 || client.getItemPressedDuration() < config.dragDelay() / Constants.CLIENT_TICK_LENGTH || !hoverActive && initialMousePoint.distance(mousePoint) < DISTANCE_TO_ACTIVATE_HOVER) { return null; } hoverActive = true; for (int i = 0; i < INVENTORY_SIZE; ++i) { WidgetItem targetWidgetItem = inventoryWidget.getWidgetItem(i); final Rectangle bounds = targetWidgetItem.getCanvasBounds(false); boolean inBounds = bounds.contains(mousePoint); if (config.showItem() && inBounds) { drawItem(graphics, bounds, draggedItem); drawItem(graphics, initialBounds, targetWidgetItem); } if (config.showHighlight() && inBounds) { graphics.setColor(HIGHLIGHT); graphics.fill(bounds); } else if (config.showGrid()) { graphics.setColor(GRID); graphics.fill(bounds); } } return null; }