Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/com/histogram/HistogramConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public interface HistogramConfig extends Config
)
String advancedSection = "Advanced";

@ConfigItem(
keyName = "hidewheninventoryclosed",
name = "Hide When Inventory Closed",
description = "Hide the histogram whenever the inventory panel is hidden, so it comes and goes with the rest of the interface",
section = panelSection,
position = -1
)
default boolean hideWhenInventoryClosed()
{
return false;
}

@ConfigItem(
keyName = "panelsize",
name = "Panel size",
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/com/histogram/HistogramOverlay.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.histogram;

import net.runelite.api.Client;
import net.runelite.api.gameval.InterfaceID;
import net.runelite.api.widgets.Widget;
import net.runelite.client.ui.overlay.Overlay;
import java.awt.*;
import java.util.*;
Expand All @@ -26,12 +29,15 @@ private class Event

private HistogramConfig config;

private Client client;

private long lastnano;
private float delta;

HistogramOverlay(HistogramConfig config)
HistogramOverlay(HistogramConfig config, Client client)
{
this.config = config;
this.client = client;

events = new ArrayDeque<>();
lastnano = System.nanoTime();
Expand Down Expand Up @@ -61,16 +67,30 @@ public void addEvent(EventType type, float pingdelay, float serverdelay)

@Override
public Dimension render(Graphics2D graphics) {
// Age and prune events even while hidden, so the deque doesn't grow
// unbounded and `delta` doesn't spike on the frame the panel returns.
updateDelta();
updateEvents();

if (config.hideWhenInventoryClosed() && isInventoryHidden())
{
return null;
}

graphics.setColor(config.bgColor());
graphics.fillRect(0, 0, config.panelSize().width, config.panelSize().height);

updateDelta();
updateEvents();
drawEvents(graphics);

return config.panelSize();
}

private boolean isInventoryHidden()
{
Widget inventory = client.getWidget(InterfaceID.Inventory.ITEMS);
return inventory == null || inventory.isHidden();
}

private void drawEvents(Graphics2D graphics)
{
for (Event event : events)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/histogram/HistogramPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class HistogramPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
histogramOverlay = new HistogramOverlay(config);
histogramOverlay = new HistogramOverlay(config, client);
overlayManager.add(histogramOverlay);

pingThreads = Executors.newScheduledThreadPool(20);
Expand Down