Java Code Examples for net.runelite.api.widgets.Widget#getBounds()
The following examples show how to use
net.runelite.api.widgets.Widget#getBounds() .
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: CombatLevelOverlay.java From plugins with GNU General Public License v3.0 | 6 votes |
@Override public Dimension render(Graphics2D graphics) { Widget combatLevelWidget = client.getWidget(WidgetInfo.COMBAT_LEVEL); if (!config.showLevelsUntil() || client.getLocalPlayer().getCombatLevel() == Experience.MAX_COMBAT_LEVEL || combatLevelWidget == null || combatLevelWidget.isHidden()) { return null; } Rectangle combatCanvas = combatLevelWidget.getBounds(); if (combatCanvas == null) { return null; } if (combatCanvas.contains(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY())) { tooltipManager.add(new Tooltip(getLevelsUntilTooltip())); } return null; }
Example 2
Source File: BarrowsOverlay.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Dimension render(Graphics2D graphics) { Widget puzzleAnswer = plugin.getPuzzleAnswer(); if (config.showBrotherLoc()) { renderBarrowsBrothers(graphics); } if (puzzleAnswer != null && config.showPuzzleAnswer() && !puzzleAnswer.isHidden()) { Rectangle answerRect = puzzleAnswer.getBounds(); graphics.setColor(Color.GREEN); graphics.draw(answerRect); } return null; }
Example 3
Source File: CustomSwapper.java From ExternalPlugins with GNU General Public License v3.0 | 6 votes |
private Rectangle equipBounds(int id) { final Widget equipmentWidget = client.getWidget(WidgetInfo.EQUIPMENT); if (equipmentWidget.getStaticChildren() == null) { return null; } for (Widget widgets : equipmentWidget.getStaticChildren()) { for (Widget items : widgets.getDynamicChildren()) { if (items.getItemId() == id) { return items.getBounds(); } } } return null; }
Example 4
Source File: CombatLevelOverlay.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Dimension render(Graphics2D graphics) { Widget combatLevelWidget = client.getWidget(WidgetInfo.COMBAT_LEVEL); if (!config.showLevelsUntil() || client.getLocalPlayer().getCombatLevel() == Experience.MAX_COMBAT_LEVEL || combatLevelWidget == null || combatLevelWidget.isHidden()) { return null; } Rectangle combatCanvas = combatLevelWidget.getBounds(); if (combatCanvas == null) { return null; } if (combatCanvas.contains(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY())) { tooltipManager.add(new Tooltip(getLevelsUntilTooltip())); } return null; }
Example 5
Source File: StatusOrbsOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderRegen(Graphics2D g, WidgetInfo widgetInfo, double percent, Color color) { Widget widget = client.getWidget(widgetInfo); if (widget == null || widget.isHidden()) { return; } Rectangle bounds = widget.getBounds(); Arc2D.Double arc = new Arc2D.Double(bounds.x + OFFSET, bounds.y + (bounds.height / 2 - DIAMETER / 2), DIAMETER, DIAMETER, 90.d, -360.d * percent, Arc2D.OPEN); final Stroke STROKE = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); g.setStroke(STROKE); g.setColor(color); g.draw(arc); }
Example 6
Source File: PoisonOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Dimension render(Graphics2D graphics) { if (plugin.getLastDamage() <= 0) { return null; } final Widget healthOrb = client.getWidget(WidgetInfo.MINIMAP_HEALTH_ORB); if (healthOrb == null || healthOrb.isHidden()) { return null; } final Rectangle bounds = healthOrb.getBounds(); if (bounds.getX() <= 0) { return null; } final Point mousePosition = client.getMouseCanvasPosition(); if (bounds.contains(mousePosition.getX(), mousePosition.getY())) { tooltipManager.add(new Tooltip(plugin.createTooltip())); } return null; }
Example 7
Source File: RegenMeterOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private void renderRegen(Graphics2D g, WidgetInfo widgetInfo, double percent, Color color) { Widget widget = client.getWidget(widgetInfo); if (widget == null || widget.isHidden()) { return; } Rectangle bounds = widget.getBounds(); Arc2D.Double arc = new Arc2D.Double(bounds.x + OFFSET, bounds.y + (bounds.height / 2 - DIAMETER / 2), DIAMETER, DIAMETER, 90.d, -360.d * percent, Arc2D.OPEN); final Stroke STROKE = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); g.setStroke(STROKE); g.setColor(color); g.draw(arc); }
Example 8
Source File: RegenMeterOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Dimension render(Graphics2D g) { g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); if (config.showHitpoints()) { renderRegen(g, WidgetInfo.MINIMAP_HEALTH_ORB, plugin.getHitpointsPercentage(), HITPOINTS_COLOR); } if (config.showSpecial()) { if (client.getVar(VarPlayer.SPECIAL_ATTACK_ENABLED) == 1) { final Widget widget = client.getWidget(WidgetInfo.MINIMAP_SPEC_ORB); if (widget != null && !widget.isHidden()) { final Rectangle bounds = widget.getBounds(); g.setColor(RegenMeterOverlay.OVERLAY_COLOR); g.fillOval( bounds.x + OFFSET, bounds.y + (int) (bounds.height / 2 - (DIAMETER) / 2), (int) DIAMETER, (int) DIAMETER); } } renderRegen(g, WidgetInfo.MINIMAP_SPEC_ORB, plugin.getSpecialPercentage(), SPECIAL_COLOR); } return null; }
Example 9
Source File: AboveWidgetsOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderTimer(Graphics2D graphics, Role role) { Widget roleText = client.getWidget(role.getRoleText()); Widget roleSprite = client.getWidget(role.getRoleSprite()); if (roleText == null || roleSprite == null) { return; } if (role == Role.COLLECTOR && config.showEggCountOverlay() && plugin.getWave() != null) { roleText.setText("(" + plugin.getWave().getCollectedEggCount() + ") " + formatClock()); } else if (role == Role.HEALER && config.showHpCountOverlay() && plugin.getWave() != null) { roleText.setText("(" + plugin.getWave().getHpHealed() + ") " + formatClock()); } else { roleText.setText(formatClock()); } Rectangle spriteBounds = roleSprite.getBounds(); graphics.drawImage(plugin.getClockImage(), spriteBounds.x, spriteBounds.y, null); roleSprite.setHidden(true); }
Example 10
Source File: TimerOverlay.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Dimension render(Graphics2D graphics) { Round round = plugin.getCurrentRound(); if (round == null) { return null; } Role role = round.getRoundRole(); if (role == null) { return null; } Widget roleText = client.getWidget(role.getRoleText()); Widget roleSprite = client.getWidget(role.getRoleSprite()); if (config.showTimer() && roleText != null && roleSprite != null) { roleText.setText(String.format("00:%02d", round.getTimeToChange())); Rectangle spriteBounds = roleSprite.getBounds(); roleSprite.setHidden(true); graphics.drawImage(plugin.getClockImage(), spriteBounds.x, spriteBounds.y, null); } return null; }
Example 11
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 12
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 13
Source File: PrayerDoseOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Dimension render(Graphics2D graphics) { final Widget xpOrb = client.getWidget(WidgetInfo.MINIMAP_QUICK_PRAYER_ORB); if (xpOrb == null || xpOrb.isHidden()) { return null; } final Rectangle bounds = xpOrb.getBounds(); if (bounds.getX() <= 0) { return null; } final Point mousePosition = client.getMouseCanvasPosition(); if (config.showPrayerStatistics() && bounds.contains(mousePosition.getX(), mousePosition.getY())) { final StringBuilder sb = new StringBuilder(); if (config.replaceOrbText()) { sb.append("Prayer points remaining: ").append(client.getBoostedSkillLevel(Skill.PRAYER)); } else { sb.append("Time Remaining: ").append(plugin.getEstimatedTimeRemaining(false)); } sb.append("</br>").append("Prayer Bonus: ").append(plugin.getPrayerBonus()); tooltipManager.add(new Tooltip(sb.toString())); } if (!config.showPrayerDoseIndicator() || !hasPrayerRestore) { return null; } final int currentPrayer = client.getBoostedSkillLevel(Skill.PRAYER); final int maxPrayer = client.getRealSkillLevel(Skill.PRAYER); final int prayerPointsMissing = maxPrayer - currentPrayer; if (prayerPointsMissing <= 0) { return null; } final double dosePercentage = hasHolyWrench ? .27 : .25; final int basePointsRestored = (int) Math.floor(maxPrayer * dosePercentage); final int pointsRestored = basePointsRestored + 7 + bonusPrayer; if (prayerPointsMissing < pointsRestored) { return null; } // Purposefully using height twice here as the bounds of the prayer orb includes the number sticking out the side final int orbInnerSize = (int) bounds.getHeight(); final int orbInnerX = (int) (bounds.getX() + 24); // x pos of the inside of the prayer orb final int orbInnerY = (int) (bounds.getY() - 1); // y pos of the inside of the prayer orb final long timeSinceLastTick = Duration.between(startOfLastTick, Instant.now()).toMillis(); final float tickProgress = Math.min(timeSinceLastTick / PULSE_TIME, 1); // Cap between 0 and 1 final double t = tickProgress * Math.PI; // Convert to 0 - pi graphics.setColor(ColorUtil.colorLerp(START_COLOR, END_COLOR, Math.sin(t))); graphics.setStroke(new BasicStroke(2)); graphics.drawOval(orbInnerX, orbInnerY, orbInnerSize, orbInnerSize); return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight()); }
Example 14
Source File: WorldMapRegionOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private void drawRegionOverlay(Graphics2D graphics) { RenderOverview ro = client.getRenderOverview(); Widget map = client.getWidget(WidgetInfo.WORLD_MAP_VIEW); Float pixelsPerTile = ro.getWorldMapZoom(); if (map == null) { return; } Rectangle worldMapRect = map.getBounds(); graphics.setClip(worldMapRect); int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile); int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile); Point worldMapPosition = ro.getWorldMapPosition(); // Offset in tiles from anchor sides int yTileMin = worldMapPosition.getY() - heightInTiles / 2; int xRegionMin = (worldMapPosition.getX() - widthInTiles / 2) & REGION_TRUNCATE; int xRegionMax = ((worldMapPosition.getX() + widthInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE; int yRegionMin = (yTileMin & REGION_TRUNCATE); int yRegionMax = ((worldMapPosition.getY() + heightInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE; int regionPixelSize = (int) Math.ceil(REGION_SIZE * pixelsPerTile); for (int x = xRegionMin; x < xRegionMax; x += REGION_SIZE) { for (int y = yRegionMin; y < yRegionMax; y += REGION_SIZE) { graphics.setColor(WHITE_TRANSLUCENT); int yTileOffset = -(yTileMin - y); int xTileOffset = x + widthInTiles / 2 - worldMapPosition.getX(); int xPos = ((int) (xTileOffset * pixelsPerTile)) + (int) worldMapRect.getX(); int yPos = (worldMapRect.height - (int) (yTileOffset * pixelsPerTile)) + (int) worldMapRect.getY(); // Offset y-position by a single region to correct for drawRect starting from the top yPos -= regionPixelSize; graphics.drawRect(xPos, yPos, regionPixelSize, regionPixelSize); int regionId = ((x >> 6) << 8) | (y >> 6); String regionText = String.valueOf(regionId); FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(regionText, graphics); int labelWidth = (int) textBounds.getWidth() + 2 * LABEL_PADDING; int labelHeight = (int) textBounds.getHeight() + 2 * LABEL_PADDING; graphics.fillRect(xPos, yPos, labelWidth, labelHeight); graphics.setColor(Color.BLACK); graphics.drawString(regionText, xPos + LABEL_PADDING, yPos + (int) textBounds.getHeight() + LABEL_PADDING); } } }
Example 15
Source File: OverlayRenderer.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private boolean shouldInvalidateBounds() { final Widget chatbox = client.getWidget(WidgetInfo.CHATBOX); 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; } final boolean viewportOffsetChanged = client.getViewportXOffset() != viewportOffset; if (viewportOffsetChanged) { viewportOffset = client.getViewportXOffset(); changed = true; } return changed; }
Example 16
Source File: WorldMapOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
/** * Get the screen coordinates for a WorldPoint on the world map * @param worldPoint WorldPoint to get screen coordinates of * @return Point of screen coordinates of the center of the world point */ public Point mapWorldPointToGraphicsPoint(WorldPoint worldPoint) { RenderOverview ro = client.getRenderOverview(); if (!ro.getWorldMapData().surfaceContainsPosition(worldPoint.getX(), worldPoint.getY())) { return null; } Float pixelsPerTile = ro.getWorldMapZoom(); Widget map = client.getWidget(WidgetInfo.WORLD_MAP_VIEW); if (map != null) { Rectangle worldMapRect = map.getBounds(); int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile); int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile); Point worldMapPosition = ro.getWorldMapPosition(); //Offset in tiles from anchor sides int yTileMax = worldMapPosition.getY() - heightInTiles / 2; int yTileOffset = (yTileMax - worldPoint.getY() - 1) * -1; int xTileOffset = worldPoint.getX() + widthInTiles / 2 - worldMapPosition.getX(); int xGraphDiff = ((int) (xTileOffset * pixelsPerTile)); int yGraphDiff = (int) (yTileOffset * pixelsPerTile); //Center on tile. yGraphDiff -= pixelsPerTile - Math.ceil(pixelsPerTile / 2); xGraphDiff += pixelsPerTile - Math.ceil(pixelsPerTile / 2); yGraphDiff = worldMapRect.height - yGraphDiff; yGraphDiff += (int) worldMapRect.getY(); xGraphDiff += (int) worldMapRect.getX(); return new Point(xGraphDiff, yGraphDiff); } return null; }
Example 17
Source File: RunEnergyOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Dimension render(Graphics2D graphics) { final Widget runOrb = client.getWidget(WidgetInfo.MINIMAP_TOGGLE_RUN_ORB); if (runOrb == null || runOrb.isHidden()) { return null; } final Rectangle bounds = runOrb.getBounds(); if (bounds.getX() <= 0) { return null; } final Point mousePosition = client.getMouseCanvasPosition(); if (bounds.contains(mousePosition.getX(), mousePosition.getY())) { StringBuilder sb = new StringBuilder(); sb.append("Weight: ").append(client.getWeight()).append(" kg</br>"); if (config.replaceOrbText()) { sb.append("Run Energy: ").append(client.getEnergy()).append("%"); } else { sb.append("Run Time Remaining: ").append(plugin.getEstimatedRunTimeRemaining(false)); } int secondsUntil100 = plugin.getEstimatedRecoverTimeRemaining(); if (secondsUntil100 > 0) { final int minutes = (int) Math.floor(secondsUntil100 / 60.0); final int seconds = (int) Math.floor(secondsUntil100 - (minutes * 60.0)); sb.append("</br>").append("100% Energy In: ").append(minutes).append(':').append(StringUtils.leftPad(Integer.toString(seconds), 2, "0")); } tooltipManager.add(new Tooltip(sb.toString())); } return null; }
Example 18
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 19
Source File: PrayerDoseOverlay.java From plugins with GNU General Public License v3.0 | 4 votes |
@Override public Dimension render(Graphics2D graphics) { final Widget xpOrb = client.getWidget(WidgetInfo.MINIMAP_QUICK_PRAYER_ORB); if (xpOrb == null || xpOrb.isHidden()) { return null; } final Rectangle bounds = xpOrb.getBounds(); if (bounds.getX() <= 0) { return null; } final Point mousePosition = client.getMouseCanvasPosition(); if (config.showPrayerStatistics() && bounds.contains(mousePosition.getX(), mousePosition.getY())) { final StringBuilder sb = new StringBuilder(); if (config.replaceOrbText()) { sb.append("Prayer points remaining: ").append(client.getBoostedSkillLevel(Skill.PRAYER)); } else { sb.append("Time Remaining: ").append(plugin.getEstimatedTimeRemaining(false)); } sb.append("</br>").append("Prayer Bonus: ").append(plugin.getPrayerBonus()); tooltipManager.add(new Tooltip(sb.toString())); } if (!config.showPrayerDoseIndicator() || !hasPrayerRestore) { return null; } final int currentPrayer = client.getBoostedSkillLevel(Skill.PRAYER); final int maxPrayer = client.getRealSkillLevel(Skill.PRAYER); final int prayerPointsMissing = maxPrayer - currentPrayer; if (prayerPointsMissing <= 0) { return null; } final double dosePercentage = hasHolyWrench ? .27 : .25; final int basePointsRestored = (int) Math.floor(maxPrayer * dosePercentage); final int pointsRestored = basePointsRestored + 7 + bonusPrayer; if (prayerPointsMissing < pointsRestored) { return null; } // Purposefully using height twice here as the bounds of the prayer orb includes the number sticking out the side final int orbInnerSize = (int) bounds.getHeight(); final int orbInnerX = (int) (bounds.getX() + 24); // x pos of the inside of the prayer orb final int orbInnerY = (int) (bounds.getY() - 1); // y pos of the inside of the prayer orb final long timeSinceLastTick = Duration.between(startOfLastTick, Instant.now()).toMillis(); final float tickProgress = Math.min(timeSinceLastTick / PULSE_TIME, 1); // Cap between 0 and 1 final double t = tickProgress * Math.PI; // Convert to 0 - pi graphics.setColor(ColorUtil.colorLerp(START_COLOR, END_COLOR, Math.sin(t))); graphics.setStroke(new BasicStroke(2)); graphics.drawOval(orbInnerX, orbInnerY, orbInnerSize, orbInnerSize); return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight()); }
Example 20
Source File: WorldMapRegionOverlay.java From plugins with GNU General Public License v3.0 | 4 votes |
private void drawRegionOverlay(Graphics2D graphics) { RenderOverview ro = client.getRenderOverview(); Widget map = client.getWidget(WidgetInfo.WORLD_MAP_VIEW); float pixelsPerTile = ro.getWorldMapZoom(); if (map == null) { return; } Rectangle worldMapRect = map.getBounds(); graphics.setClip(worldMapRect); int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile); int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile); Point worldMapPosition = ro.getWorldMapPosition(); // Offset in tiles from anchor sides int yTileMin = worldMapPosition.getY() - heightInTiles / 2; int xRegionMin = (worldMapPosition.getX() - widthInTiles / 2) & REGION_TRUNCATE; int xRegionMax = ((worldMapPosition.getX() + widthInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE; int yRegionMin = (yTileMin & REGION_TRUNCATE); int yRegionMax = ((worldMapPosition.getY() + heightInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE; int regionPixelSize = (int) Math.ceil(REGION_SIZE * pixelsPerTile); for (int x = xRegionMin; x < xRegionMax; x += REGION_SIZE) { for (int y = yRegionMin; y < yRegionMax; y += REGION_SIZE) { graphics.setColor(WHITE_TRANSLUCENT); int yTileOffset = -(yTileMin - y); int xTileOffset = x + widthInTiles / 2 - worldMapPosition.getX(); int xPos = ((int) (xTileOffset * pixelsPerTile)) + (int) worldMapRect.getX(); int yPos = (worldMapRect.height - (int) (yTileOffset * pixelsPerTile)) + (int) worldMapRect.getY(); // Offset y-position by a single region to correct for drawRect starting from the top yPos -= regionPixelSize; graphics.drawRect(xPos, yPos, regionPixelSize, regionPixelSize); int regionId = ((x >> 6) << 8) | (y >> 6); String regionText = String.valueOf(regionId); FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(regionText, graphics); int labelWidth = (int) textBounds.getWidth() + 2 * LABEL_PADDING; int labelHeight = (int) textBounds.getHeight() + 2 * LABEL_PADDING; graphics.fillRect(xPos, yPos, labelWidth, labelHeight); graphics.setColor(Color.BLACK); graphics.drawString(regionText, xPos + LABEL_PADDING, yPos + (int) textBounds.getHeight() + LABEL_PADDING); } } }