Merge pull request #4604 from Nightfirecat/exterminate-game-image-files

Remove item and sprite images from runelite-client resources directory
This commit is contained in:
Tomas Slusny
2018-08-04 12:59:02 +02:00
committed by GitHub
129 changed files with 1316 additions and 884 deletions

View File

@@ -28,16 +28,17 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.eventbus.Subscribe;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
@@ -46,26 +47,33 @@ import net.runelite.api.ClanMemberRank;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.IndexedSprite;
import net.runelite.api.SpriteID;
import net.runelite.api.events.ClanChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.Text;
@Singleton
@Slf4j
public class ClanManager
{
private static final String[] CLANCHAT_IMAGES =
private static final int[] CLANCHAT_IMAGES =
{
"Friend_clan_rank.png", "Recruit_clan_rank.png",
"Corporal_clan_rank.png", "Sergeant_clan_rank.png",
"Lieutenant_clan_rank.png", "Captain_clan_rank.png",
"General_clan_rank.png", "Owner_clan_rank.png",
"JMod_clan_rank.png"
SpriteID.CLAN_CHAT_RANK_SMILEY_FRIEND,
SpriteID.CLAN_CHAT_RANK_SINGLE_CHEVRON_RECRUIT,
SpriteID.CLAN_CHAT_RANK_DOUBLE_CHEVRON_CORPORAL,
SpriteID.CLAN_CHAT_RANK_TRIPLE_CHEVRON_SERGEANT,
SpriteID.CLAN_CHAT_RANK_BRONZE_STAR_LIEUTENANT,
SpriteID.CLAN_CHAT_RANK_SILVER_STAR_CAPTAIN,
SpriteID.CLAN_CHAT_RANK_GOLD_STAR_GENERAL,
SpriteID.CLAN_CHAT_RANK_KEY_CHANNEL_OWNER,
SpriteID.CLAN_CHAT_RANK_CROWN_JAGEX_MODERATOR,
};
private int modIconsLength;
private static final Dimension CLANCHAT_IMAGE_DIMENSION = new Dimension(11, 11);
private static final Color CLANCHAT_IMAGE_OUTLINE_COLOR = new Color(33, 33, 33);
private final Client client;
private final SpriteManager spriteManager;
private final BufferedImage[] clanChatImages = new BufferedImage[CLANCHAT_IMAGES.length];
private final LoadingCache<String, ClanMemberRank> clanRanksCache = CacheBuilder.newBuilder()
@@ -74,7 +82,7 @@ public class ClanManager
.build(new CacheLoader<String, ClanMemberRank>()
{
@Override
public ClanMemberRank load(String key) throws Exception
public ClanMemberRank load(@Nonnull String key)
{
final ClanMember[] clanMembersArr = client.getClanMembers();
@@ -92,27 +100,13 @@ public class ClanManager
}
});
private int modIconsLength;
@Inject
private ClanManager(Client client)
private ClanManager(Client client, SpriteManager spriteManager)
{
this.client = client;
int i = 0;
for (String resource : CLANCHAT_IMAGES)
{
try
{
final BufferedImage bufferedImage = rgbaToIndexedBufferedImage(ImageIO
.read(ClanManager.class.getResource(resource)));
clanChatImages[i] = bufferedImage;
}
catch (IOException e)
{
log.warn("unable to load clan image", e);
}
++i;
}
this.spriteManager = spriteManager;
}
public ClanMemberRank getRank(String playerName)
@@ -138,10 +132,9 @@ public class ClanManager
@Subscribe
public void onGameStateChanged(GameStateChanged gameStateChanged)
{
if (gameStateChanged.getGameState() == GameState.LOGIN_SCREEN
if (gameStateChanged.getGameState() == GameState.LOGGED_IN
&& modIconsLength == 0)
{
// this is after "Loading sprites" so we can modify modicons now
loadClanChatIcons();
}
}
@@ -154,25 +147,19 @@ public class ClanManager
private void loadClanChatIcons()
{
try
{
final IndexedSprite[] modIcons = client.getModIcons();
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + CLANCHAT_IMAGES.length);
int curPosition = newModIcons.length - CLANCHAT_IMAGES.length;
final IndexedSprite[] modIcons = client.getModIcons();
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + CLANCHAT_IMAGES.length);
int curPosition = newModIcons.length - CLANCHAT_IMAGES.length;
for (BufferedImage image : clanChatImages)
{
IndexedSprite sprite = createIndexedSprite(client, image);
newModIcons[curPosition++] = sprite;
}
client.setModIcons(newModIcons);
modIconsLength = newModIcons.length;
}
catch (IOException e)
for (int i = 0; i < CLANCHAT_IMAGES.length; i++, curPosition++)
{
log.warn("Failed loading of clan chat icons", e);
final int resource = CLANCHAT_IMAGES[i];
clanChatImages[i] = rgbaToIndexedBufferedImage(clanChatImageFromSprite(spriteManager.getSprite(resource, 0)));
newModIcons[curPosition] = createIndexedSprite(client, clanChatImages[i]);
}
client.setModIcons(newModIcons);
modIconsLength = newModIcons.length;
}
private static String sanitize(String lookup)
@@ -181,7 +168,7 @@ public class ClanManager
return cleaned.replace('\u00A0', ' ');
}
private static IndexedSprite createIndexedSprite(final Client client, final BufferedImage bufferedImage) throws IOException
private static IndexedSprite createIndexedSprite(final Client client, final BufferedImage bufferedImage)
{
final IndexColorModel indexedCM = (IndexColorModel) bufferedImage.getColorModel();
@@ -228,4 +215,10 @@ public class ClanManager
resultIndexedImage.getGraphics().drawImage(sourceBufferedImage, 0, 0, null);
return resultIndexedImage;
}
private static BufferedImage clanChatImageFromSprite(final BufferedImage clanSprite)
{
final BufferedImage clanChatCanvas = ImageUtil.resizeCanvas(clanSprite, CLANCHAT_IMAGE_DIMENSION.width, CLANCHAT_IMAGE_DIMENSION.height);
return ImageUtil.outlineImage(clanChatCanvas, CLANCHAT_IMAGE_OUTLINE_COLOR);
}
}

View File

@@ -25,11 +25,10 @@
package net.runelite.client.game;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Skill;
import net.runelite.client.util.ImageUtil;
@Singleton
@Slf4j
@@ -48,21 +47,11 @@ public class SkillIconManager
return imgCache[skillIdx];
}
try
{
String skillIconPath = (small ? "/skill_icons_small/" : "/skill_icons/")
+ skill.getName().toLowerCase() + ".png";
log.debug("Loading skill icon from {}", skillIconPath);
synchronized (ImageIO.class)
{
skillImage = ImageIO.read(SkillIconManager.class.getResourceAsStream(skillIconPath));
}
imgCache[skillIdx] = skillImage;
}
catch (IOException e)
{
log.debug("Error Loading skill icons {}", e);
}
String skillIconPath = (small ? "/skill_icons_small/" : "/skill_icons/")
+ skill.getName().toLowerCase() + ".png";
log.debug("Loading skill icon from {}", skillIconPath);
skillImage = ImageUtil.getResourceStreamFromClass(getClass(), skillIconPath);
imgCache[skillIdx] = skillImage;
return skillImage;
}

View File

@@ -26,9 +26,7 @@ package net.runelite.client.plugins.account;
import com.google.common.eventbus.Subscribe;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.ScheduledExecutorService;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.swing.JOptionPane;
import lombok.extern.slf4j.Slf4j;
@@ -40,6 +38,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.RunnableExceptionLogger;
@PluginDescriptor(
@@ -67,18 +66,8 @@ public class AccountPlugin extends Plugin
static
{
try
{
synchronized (ImageIO.class)
{
LOGIN_IMAGE = ImageIO.read(AccountPlugin.class.getResourceAsStream("login_icon.png"));
LOGOUT_IMAGE = ImageIO.read(AccountPlugin.class.getResourceAsStream("logout_icon.png"));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
LOGIN_IMAGE = ImageUtil.getResourceStreamFromClass(AccountPlugin.class, "login_icon.png");
LOGOUT_IMAGE = ImageUtil.getResourceStreamFromClass(AccountPlugin.class, "logout_icon.png");
}
@Override

View File

@@ -25,9 +25,7 @@
package net.runelite.client.plugins.agility;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.time.temporal.ChronoUnit;
import javax.imageio.ImageIO;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.infobox.Timer;
@@ -35,32 +33,9 @@ import net.runelite.client.ui.overlay.infobox.Timer;
@Slf4j
class AgilityArenaTimer extends Timer
{
AgilityArenaTimer(Plugin plugin)
AgilityArenaTimer(Plugin plugin, BufferedImage image)
{
super(1, ChronoUnit.MINUTES, getTicketImage(), plugin);
super(1, ChronoUnit.MINUTES, image, plugin);
setTooltip("Time left until location changes");
}
private static BufferedImage image;
private static BufferedImage getTicketImage()
{
if (image != null)
{
return image;
}
try
{
synchronized (ImageIO.class)
{
image = ImageIO.read(AgilityArenaTimer.class.getResourceAsStream( "agilityarenaticket.png"));
}
}
catch (IOException ex)
{
log.warn("unable to load image", ex);
}
return image;
}
}

View File

@@ -35,6 +35,7 @@ import lombok.Getter;
import net.runelite.api.Client;
import net.runelite.api.Item;
import net.runelite.api.ItemID;
import static net.runelite.api.ItemID.AGILITY_ARENA_TICKET;
import net.runelite.api.Player;
import static net.runelite.api.Skill.AGILITY;
import net.runelite.api.Tile;
@@ -60,6 +61,7 @@ import net.runelite.api.events.WallObjectDespawned;
import net.runelite.api.events.WallObjectSpawned;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
@@ -101,6 +103,9 @@ public class AgilityPlugin extends Plugin
@Inject
private AgilityConfig config;
@Inject
private ItemManager itemManager;
@Getter
private AgilitySession session;
@@ -275,7 +280,7 @@ public class AgilityPlugin extends Plugin
private void showNewAgilityArenaTimer()
{
removeAgilityArenaTimer();
infoBoxManager.addInfoBox(new AgilityArenaTimer(this));
infoBoxManager.addInfoBox(new AgilityArenaTimer(this, itemManager.getImage(AGILITY_ARENA_TICKET)));
}
@Subscribe

View File

@@ -30,7 +30,6 @@ import java.awt.Font;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
@@ -46,6 +45,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Barbarian Assault",
@@ -87,10 +87,7 @@ public class BarbarianAssaultPlugin extends Plugin
font = FontManager.getRunescapeFont()
.deriveFont(Font.BOLD, 24);
synchronized (ImageIO.class)
{
clockImage = ImageIO.read(getClass().getResourceAsStream("clock.png"));
}
clockImage = ImageUtil.getResourceStreamFromClass(getClass(), "clock.png");
}
@Override

View File

@@ -30,7 +30,6 @@ import com.google.inject.Provides;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.Getter;
@@ -49,6 +48,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Boosts Information",
@@ -118,11 +118,8 @@ public class BoostsPlugin extends Plugin
Arrays.fill(lastSkillLevels, -1);
// Add infoboxes for everything at startup and then determine inside if it will be rendered
synchronized (ImageIO.class)
{
infoBoxManager.addInfoBox(new StatChangeIndicator(true, ImageIO.read(getClass().getResourceAsStream("debuffed.png")), this, config));
infoBoxManager.addInfoBox(new StatChangeIndicator(false, ImageIO.read(getClass().getResourceAsStream("buffed.png")), this, config));
}
infoBoxManager.addInfoBox(new StatChangeIndicator(true, ImageUtil.getResourceStreamFromClass(getClass(), "debuffed.png"), this, config));
infoBoxManager.addInfoBox(new StatChangeIndicator(false, ImageUtil.getResourceStreamFromClass(getClass(), "buffed.png"), this, config));
for (final Skill skill : Skill.values())
{

View File

@@ -29,13 +29,11 @@ package net.runelite.client.plugins.cluescrolls;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -47,6 +45,7 @@ import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemComposition;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.NPC;
import net.runelite.api.Query;
import net.runelite.api.Scene;
@@ -83,6 +82,7 @@ import net.runelite.client.plugins.cluescrolls.clues.ObjectClueScroll;
import net.runelite.client.plugins.cluescrolls.clues.TextClueScroll;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.worldmap.WorldMapPointManager;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.QueryRunner;
import net.runelite.client.util.Text;
@@ -96,11 +96,6 @@ public class ClueScrollPlugin extends Plugin
{
private static final Duration WAIT_DURATION = Duration.ofMinutes(4);
public static final BufferedImage CLUE_SCROLL_IMAGE;
public static final BufferedImage MAP_ARROW;
public static final BufferedImage EMOTE_IMAGE;
public static final BufferedImage SPADE_IMAGE;
@Getter
private ClueScroll clue;
@@ -147,28 +142,12 @@ public class ClueScrollPlugin extends Plugin
@Inject
private WorldMapPointManager worldMapPointManager;
private BufferedImage emoteImage;
private BufferedImage mapArrow;
private Integer clueItemId;
private boolean clueItemChanged = false;
private boolean worldMapPointsSet = false;
static
{
try
{
synchronized (ImageIO.class)
{
CLUE_SCROLL_IMAGE = ImageIO.read(ClueScrollPlugin.class.getResourceAsStream("clue_scroll.png"));
MAP_ARROW = ImageIO.read(ClueScrollPlugin.class.getResourceAsStream("clue_arrow.png"));
EMOTE_IMAGE = ImageIO.read(ClueScrollPlugin.class.getResourceAsStream("emote.png"));
SPADE_IMAGE = ImageIO.read(ClueScrollPlugin.class.getResourceAsStream("spade.png"));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
@Provides
ClueScrollConfig getConfig(ConfigManager configManager)
{
@@ -411,6 +390,40 @@ public class ClueScrollPlugin extends Plugin
}
}
public BufferedImage getClueScrollImage()
{
return itemManager.getImage(ItemID.CLUE_SCROLL_MASTER);
}
public BufferedImage getEmoteImage()
{
if (emoteImage != null)
{
return emoteImage;
}
emoteImage = ImageUtil.getResourceStreamFromClass(getClass(), "emote.png");
return emoteImage;
}
public BufferedImage getSpadeImage()
{
return itemManager.getImage(ItemID.SPADE);
}
BufferedImage getMapArrow()
{
if (mapArrow != null)
{
return mapArrow;
}
mapArrow = ImageUtil.getResourceStreamFromClass(getClass(), "/util/clue_arrow.png");
return mapArrow;
}
private void resetClue()
{
if (!clueItemChanged)
@@ -594,7 +607,7 @@ public class ClueScrollPlugin extends Plugin
for (final WorldPoint point : points)
{
worldMapPointManager.add(new ClueScrollWorldMapPoint(point));
worldMapPointManager.add(new ClueScrollWorldMapPoint(point, this));
}
}
}

View File

@@ -32,41 +32,40 @@ import net.runelite.client.ui.overlay.worldmap.WorldMapPoint;
class ClueScrollWorldMapPoint extends WorldMapPoint
{
private static final BufferedImage CLUE_SCROLL_WORLD_IMAGE;
private static final Point CLUE_SCROLL_WORLD_IMAGE_POINT;
private final ClueScrollPlugin plugin;
private final BufferedImage clueScrollWorldImage;
private final Point clueScrollWorldImagePoint;
static
{
CLUE_SCROLL_WORLD_IMAGE = new BufferedImage(ClueScrollPlugin.MAP_ARROW.getWidth(), ClueScrollPlugin.MAP_ARROW.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = CLUE_SCROLL_WORLD_IMAGE.getGraphics();
graphics.drawImage(ClueScrollPlugin.MAP_ARROW, 0, 0, null);
graphics.drawImage(ClueScrollPlugin.CLUE_SCROLL_IMAGE, 0, 2, null);
CLUE_SCROLL_WORLD_IMAGE_POINT = new Point(
CLUE_SCROLL_WORLD_IMAGE.getWidth() / 2,
CLUE_SCROLL_WORLD_IMAGE.getHeight());
}
ClueScrollWorldMapPoint(final WorldPoint worldPoint)
ClueScrollWorldMapPoint(final WorldPoint worldPoint, ClueScrollPlugin plugin)
{
super(worldPoint, null);
clueScrollWorldImage = new BufferedImage(plugin.getMapArrow().getWidth(), plugin.getMapArrow().getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = clueScrollWorldImage.getGraphics();
graphics.drawImage(plugin.getMapArrow(), 0, 0, null);
graphics.drawImage(plugin.getClueScrollImage(), 0, 0, null);
clueScrollWorldImagePoint = new Point(
clueScrollWorldImage.getWidth() / 2,
clueScrollWorldImage.getHeight());
this.plugin = plugin;
this.setSnapToEdge(true);
this.setJumpOnClick(true);
this.setImage(CLUE_SCROLL_WORLD_IMAGE);
this.setImagePoint(CLUE_SCROLL_WORLD_IMAGE_POINT);
this.setImage(clueScrollWorldImage);
this.setImagePoint(clueScrollWorldImagePoint);
}
@Override
public void onEdgeSnap()
{
this.setImage(ClueScrollPlugin.CLUE_SCROLL_IMAGE);
this.setImage(plugin.getClueScrollImage());
this.setImagePoint(null);
}
@Override
public void onEdgeUnsnap()
{
this.setImage(CLUE_SCROLL_WORLD_IMAGE);
this.setImagePoint(CLUE_SCROLL_WORLD_IMAGE_POINT);
this.setImage(clueScrollWorldImage);
this.setImagePoint(clueScrollWorldImagePoint);
}
}

View File

@@ -33,7 +33,6 @@ import net.runelite.api.NPC;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.CLUE_SCROLL_IMAGE;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMAGE_Z_OFFSET;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
@@ -203,7 +202,7 @@ public class AnagramClue extends ClueScroll implements TextClueScroll, NpcClueSc
{
for (NPC npc : plugin.getNpcsToMark())
{
OverlayUtil.renderActorOverlayImage(graphics, npc, CLUE_SCROLL_IMAGE, Color.ORANGE, IMAGE_Z_OFFSET);
OverlayUtil.renderActorOverlayImage(graphics, npc, plugin.getClueScrollImage(), Color.ORANGE, IMAGE_Z_OFFSET);
}
}
}

View File

@@ -33,7 +33,6 @@ import net.runelite.api.NPC;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.CLUE_SCROLL_IMAGE;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMAGE_Z_OFFSET;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
@@ -112,7 +111,7 @@ public class CipherClue extends ClueScroll implements TextClueScroll, NpcClueScr
{
for (NPC npc : plugin.getNpcsToMark())
{
OverlayUtil.renderActorOverlayImage(graphics, npc, CLUE_SCROLL_IMAGE, Color.ORANGE, IMAGE_Z_OFFSET);
OverlayUtil.renderActorOverlayImage(graphics, npc, plugin.getClueScrollImage(), Color.ORANGE, IMAGE_Z_OFFSET);
}
}
}

View File

@@ -32,7 +32,6 @@ import net.runelite.api.ItemID;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.SPADE_IMAGE;
import net.runelite.client.plugins.cluescrolls.clues.emote.ItemRequirement;
import net.runelite.client.plugins.cluescrolls.clues.emote.SingleItemRequirement;
import net.runelite.client.ui.overlay.OverlayUtil;
@@ -77,6 +76,6 @@ public class CoordinateClue extends ClueScroll implements TextClueScroll, Locati
return;
}
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, SPADE_IMAGE, Color.ORANGE);
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, plugin.getSpadeImage(), Color.ORANGE);
}
}

View File

@@ -38,8 +38,6 @@ import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.CLUE_SCROLL_IMAGE;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.SPADE_IMAGE;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_BORDER_COLOR;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_FILL_COLOR;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_HOVER_BORDER_COLOR;
@@ -391,7 +389,7 @@ public class CrypticClue extends ClueScroll implements TextClueScroll, NpcClueSc
if (localLocation != null)
{
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, SPADE_IMAGE, Color.ORANGE);
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, plugin.getSpadeImage(), Color.ORANGE);
}
}
@@ -400,7 +398,7 @@ public class CrypticClue extends ClueScroll implements TextClueScroll, NpcClueSc
{
for (NPC npc : plugin.getNpcsToMark())
{
OverlayUtil.renderActorOverlayImage(graphics, npc, CLUE_SCROLL_IMAGE, Color.ORANGE, IMAGE_Z_OFFSET);
OverlayUtil.renderActorOverlayImage(graphics, npc, plugin.getClueScrollImage(), Color.ORANGE, IMAGE_Z_OFFSET);
}
}
@@ -416,7 +414,7 @@ public class CrypticClue extends ClueScroll implements TextClueScroll, NpcClueSc
OverlayUtil.renderHoverableArea(graphics, gameObject.getClickbox(), mousePosition,
CLICKBOX_FILL_COLOR, CLICKBOX_BORDER_COLOR, CLICKBOX_HOVER_BORDER_COLOR);
OverlayUtil.renderImageLocation(plugin.getClient(), graphics, gameObject.getLocalLocation(), CLUE_SCROLL_IMAGE, IMAGE_Z_OFFSET);
OverlayUtil.renderImageLocation(plugin.getClient(), graphics, gameObject.getLocalLocation(), plugin.getClueScrollImage(), IMAGE_Z_OFFSET);
}
}
}

View File

@@ -38,7 +38,6 @@ import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.EMOTE_IMAGE;
import net.runelite.client.plugins.cluescrolls.clues.emote.AllRequirementsCollection;
import net.runelite.client.plugins.cluescrolls.clues.emote.AnyRequirementCollection;
import net.runelite.client.plugins.cluescrolls.clues.emote.Emote;
@@ -285,7 +284,7 @@ public class EmoteClue extends ClueScroll implements TextClueScroll, LocationClu
return;
}
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, EMOTE_IMAGE, Color.ORANGE);
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, plugin.getEmoteImage(), Color.ORANGE);
}
public static EmoteClue forText(String text)

View File

@@ -34,7 +34,6 @@ import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.SPADE_IMAGE;
import net.runelite.client.plugins.cluescrolls.clues.emote.ItemRequirement;
import net.runelite.client.plugins.cluescrolls.clues.emote.SingleItemRequirement;
import net.runelite.client.ui.overlay.OverlayUtil;
@@ -102,7 +101,7 @@ public class FairyRingClue extends ClueScroll implements TextClueScroll, Locatio
return;
}
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, SPADE_IMAGE, Color.ORANGE);
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, plugin.getSpadeImage(), Color.ORANGE);
}
public static FairyRingClue forText(String text)

View File

@@ -45,8 +45,6 @@ import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.CLUE_SCROLL_IMAGE;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.SPADE_IMAGE;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMAGE_Z_OFFSET;
import net.runelite.client.plugins.cluescrolls.clues.hotcold.HotColdArea;
import net.runelite.client.plugins.cluescrolls.clues.hotcold.HotColdLocation;
@@ -196,7 +194,7 @@ public class HotColdClue extends ClueScroll implements LocationClueScroll, Locat
if (localLocation != null)
{
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, SPADE_IMAGE, Color.ORANGE);
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, plugin.getSpadeImage(), Color.ORANGE);
}
return;
@@ -210,7 +208,7 @@ public class HotColdClue extends ClueScroll implements LocationClueScroll, Locat
{
for (NPC npc : plugin.getNpcsToMark())
{
OverlayUtil.renderActorOverlayImage(graphics, npc, CLUE_SCROLL_IMAGE, Color.ORANGE, IMAGE_Z_OFFSET);
OverlayUtil.renderActorOverlayImage(graphics, npc, plugin.getClueScrollImage(), Color.ORANGE, IMAGE_Z_OFFSET);
}
}
}
@@ -229,7 +227,7 @@ public class HotColdClue extends ClueScroll implements LocationClueScroll, Locat
return;
}
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, SPADE_IMAGE, Color.ORANGE);
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, plugin.getSpadeImage(), Color.ORANGE);
}
}
}

View File

@@ -40,8 +40,6 @@ import static net.runelite.api.ObjectID.CRATE_6616;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.CLUE_SCROLL_IMAGE;
import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.SPADE_IMAGE;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_BORDER_COLOR;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_FILL_COLOR;
import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.CLICKBOX_HOVER_BORDER_COLOR;
@@ -179,14 +177,14 @@ public class MapClue extends ClueScroll implements ObjectClueScroll
OverlayUtil.renderHoverableArea(graphics, gameObject.getClickbox(), mousePosition,
CLICKBOX_FILL_COLOR, CLICKBOX_BORDER_COLOR, CLICKBOX_HOVER_BORDER_COLOR);
OverlayUtil.renderImageLocation(plugin.getClient(), graphics, gameObject.getLocalLocation(), CLUE_SCROLL_IMAGE, IMAGE_Z_OFFSET);
OverlayUtil.renderImageLocation(plugin.getClient(), graphics, gameObject.getLocalLocation(), plugin.getClueScrollImage(), IMAGE_Z_OFFSET);
}
}
}
// Mark tile
else
{
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, SPADE_IMAGE, Color.ORANGE);
OverlayUtil.renderTileOverlay(plugin.getClient(), graphics, localLocation, plugin.getSpadeImage(), Color.ORANGE);
}
}

View File

@@ -38,14 +38,12 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
@@ -89,7 +87,7 @@ import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.ComboBoxListRenderer;
import net.runelite.client.ui.components.IconButton;
import net.runelite.client.ui.components.IconTextField;
import net.runelite.client.util.SwingUtil;
import net.runelite.client.util.ImageUtil;
@Slf4j
public class ConfigPanel extends PluginPanel
@@ -124,20 +122,10 @@ public class ConfigPanel extends PluginPanel
static
{
try
{
synchronized (ImageIO.class)
{
BufferedImage backIcon = ImageIO.read(ConfigPanel.class.getResourceAsStream("config_back_icon.png"));
BACK_ICON = new ImageIcon(backIcon);
BACK_ICON_HOVER = new ImageIcon(SwingUtil.grayscaleOffset(backIcon, -100));
SEARCH = new ImageIcon(ImageIO.read(IconTextField.class.getResourceAsStream("search.png")));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_back_icon.png");
BACK_ICON = new ImageIcon(backIcon);
BACK_ICON_HOVER = new ImageIcon(ImageUtil.alphaOffset(backIcon, -100));
SEARCH = new ImageIcon(ImageUtil.getResourceStreamFromClass(IconTextField.class, "search.png"));
}
ConfigPanel(PluginManager pluginManager, ConfigManager configManager, ScheduledExecutorService executorService,

View File

@@ -27,7 +27,6 @@ package net.runelite.client.plugins.config;
import com.google.common.eventbus.Subscribe;
import java.awt.image.BufferedImage;
import java.util.concurrent.ScheduledExecutorService;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import net.runelite.client.config.ChatColorConfig;
@@ -39,6 +38,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginManager;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Configuration",
@@ -73,11 +73,7 @@ public class ConfigPlugin extends Plugin
{
configPanel = new ConfigPanel(pluginManager, configManager, executorService, runeLiteConfig, chatColorConfig);
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("config_icon.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "config_icon.png");
navButton = NavigationButton.builder()
.tooltip("Configuration")

View File

@@ -29,12 +29,10 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
@@ -45,7 +43,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.IconButton;
import net.runelite.client.util.SwingUtil;
import net.runelite.client.util.ImageUtil;
import org.apache.commons.text.similarity.JaroWinklerDistance;
class PluginListItem extends JPanel
@@ -84,26 +82,27 @@ class PluginListItem extends JPanel
static
{
try
{
BufferedImage configIcon;
synchronized (ImageIO.class)
{
configIcon = ImageIO.read(ConfigPanel.class.getResourceAsStream("config_edit_icon.png"));
CONFIG_ICON = new ImageIcon(configIcon);
ON_SWITCHER = new ImageIcon(ImageIO.read(ConfigPanel.class.getResourceAsStream("switchers/on.png")));
OFF_SWITCHER = new ImageIcon(ImageIO.read(ConfigPanel.class.getResourceAsStream("switchers/off.png")));
ON_STAR = new ImageIcon(ImageIO.read(ConfigPanel.class.getResourceAsStream("stars/on.png")));
OFF_STAR = new ImageIcon(ImageIO.read(ConfigPanel.class.getResourceAsStream("stars/off.png")));
}
CONFIG_ICON_HOVER = new ImageIcon(SwingUtil.grayscaleOffset(configIcon, -100));
}
catch (IOException e)
{
throw new RuntimeException(e);
}
BufferedImage configIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_edit_icon.png");
BufferedImage onSwitcher = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "switcher_on.png");
BufferedImage onStar = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "star_on.png");
CONFIG_ICON = new ImageIcon(configIcon);
ON_SWITCHER = new ImageIcon(onSwitcher);
ON_STAR = new ImageIcon(onStar);
CONFIG_ICON_HOVER = new ImageIcon(ImageUtil.grayscaleOffset(configIcon, -100));
BufferedImage offSwitcherImage = ImageUtil.flipImage(
ImageUtil.grayscaleOffset(
ImageUtil.grayscaleImage(onSwitcher),
0.61f
),
true,
false
);
OFF_SWITCHER = new ImageIcon(offSwitcherImage);
BufferedImage offStar = ImageUtil.grayscaleOffset(
ImageUtil.grayscaleImage(onStar),
0.77f
);
OFF_STAR = new ImageIcon(offStar);
}
/**

View File

@@ -28,17 +28,16 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Set;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import static net.runelite.api.AnimationID.DEATH;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.ItemID;
import net.runelite.api.Player;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.AnimationChanged;
@@ -46,11 +45,13 @@ import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.ui.overlay.infobox.Timer;
import net.runelite.client.ui.overlay.worldmap.WorldMapPointManager;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Death Indicator",
@@ -66,7 +67,6 @@ public class DeathIndicatorPlugin extends Plugin
12342, // Edgeville
11062 // Camelot
);
static BufferedImage BONES;
@Inject
private Client client;
@@ -80,27 +80,17 @@ public class DeathIndicatorPlugin extends Plugin
@Inject
private InfoBoxManager infoBoxManager;
@Inject
private ItemManager itemManager;
private BufferedImage mapArrow;
private Timer deathTimer;
private WorldPoint lastDeath;
private Instant lastDeathTime;
private int lastDeathWorld;
static
{
try
{
synchronized (ImageIO.class)
{
BONES = ImageIO.read(DeathIndicatorPlugin.class.getResourceAsStream("bones.png"));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
@Provides
DeathIndicatorConfig deathIndicatorConfig(ConfigManager configManager)
{
@@ -133,7 +123,7 @@ public class DeathIndicatorPlugin extends Plugin
if (config.showDeathOnWorldMap())
{
worldMapPointManager.removeIf(DeathWorldMapPoint.class::isInstance);
worldMapPointManager.add(new DeathWorldMapPoint(new WorldPoint(config.deathLocationX(), config.deathLocationY(), config.deathLocationPlane())));
worldMapPointManager.add(new DeathWorldMapPoint(new WorldPoint(config.deathLocationX(), config.deathLocationY(), config.deathLocationPlane()), this));
}
}
@@ -204,7 +194,7 @@ public class DeathIndicatorPlugin extends Plugin
if (config.showDeathOnWorldMap())
{
worldMapPointManager.removeIf(DeathWorldMapPoint.class::isInstance);
worldMapPointManager.add(new DeathWorldMapPoint(lastDeath));
worldMapPointManager.add(new DeathWorldMapPoint(lastDeath, this));
}
resetInfobox();
@@ -290,7 +280,7 @@ public class DeathIndicatorPlugin extends Plugin
if (config.showDeathOnWorldMap())
{
worldMapPointManager.removeIf(DeathWorldMapPoint.class::isInstance);
worldMapPointManager.add(new DeathWorldMapPoint(deathPoint));
worldMapPointManager.add(new DeathWorldMapPoint(deathPoint, this));
}
}
else
@@ -328,10 +318,27 @@ public class DeathIndicatorPlugin extends Plugin
Duration timeLeft = Duration.ofHours(1).minus(Duration.between(config.timeOfDeath(), now));
if (!timeLeft.isNegative() && !timeLeft.isZero())
{
deathTimer = new Timer(timeLeft.getSeconds(), ChronoUnit.SECONDS, BONES, this);
deathTimer = new Timer(timeLeft.getSeconds(), ChronoUnit.SECONDS, getBonesImage(), this);
deathTimer.setTooltip("Died on world: " + config.deathWorld());
infoBoxManager.addInfoBox(deathTimer);
}
}
}
BufferedImage getMapArrow()
{
if (mapArrow != null)
{
return mapArrow;
}
mapArrow = ImageUtil.getResourceStreamFromClass(getClass(), "/util/clue_arrow.png");
return mapArrow;
}
BufferedImage getBonesImage()
{
return itemManager.getImage(ItemID.BONES);
}
}

View File

@@ -26,56 +26,40 @@ package net.runelite.client.plugins.deathindicator;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import net.runelite.api.Point;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.deathindicator.DeathIndicatorPlugin.BONES;
import net.runelite.client.ui.overlay.worldmap.WorldMapPoint;
class DeathWorldMapPoint extends WorldMapPoint
{
private static final BufferedImage WORLDMAP_HINT_ARROW;
private static final Point WORLDMAP_HINT_ARROW_POINT;
private final DeathIndicatorPlugin plugin;
private final BufferedImage worldmapHintArrow;
private final Point worldmapHintArrowPoint;
static
{
BufferedImage MAP_ARROW;
try
{
synchronized (ImageIO.class)
{
MAP_ARROW = ImageIO.read(DeathWorldMapPoint.class.getResourceAsStream("clue_arrow.png"));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
WORLDMAP_HINT_ARROW = new BufferedImage(MAP_ARROW.getWidth(),
MAP_ARROW.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = WORLDMAP_HINT_ARROW.getGraphics();
graphics.drawImage(MAP_ARROW, 0, 0, null);
graphics.drawImage(BONES, 0, 1, null);
WORLDMAP_HINT_ARROW_POINT = new Point(WORLDMAP_HINT_ARROW.getWidth() / 2, WORLDMAP_HINT_ARROW.getHeight());
}
DeathWorldMapPoint(final WorldPoint worldPoint)
DeathWorldMapPoint(final WorldPoint worldPoint, final DeathIndicatorPlugin plugin)
{
super(worldPoint, null);
worldmapHintArrow = new BufferedImage(plugin.getMapArrow().getWidth(), plugin.getMapArrow().getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = worldmapHintArrow.getGraphics();
graphics.drawImage(plugin.getMapArrow(), 0, 0, null);
graphics.drawImage(plugin.getBonesImage(), 0, 0, null);
worldmapHintArrowPoint = new Point(
worldmapHintArrow.getWidth() / 2,
worldmapHintArrow.getHeight());
this.plugin = plugin;
this.setSnapToEdge(true);
this.setJumpOnClick(true);
this.setImage(WORLDMAP_HINT_ARROW);
this.setImagePoint(WORLDMAP_HINT_ARROW_POINT);
this.setImage(worldmapHintArrow);
this.setImagePoint(worldmapHintArrowPoint);
this.setTooltip("Death Location");
}
@Override
public void onEdgeSnap()
{
this.setImage(BONES);
this.setImage(plugin.getBonesImage());
this.setImagePoint(null);
this.setTooltip(null);
}
@@ -83,8 +67,8 @@ class DeathWorldMapPoint extends WorldMapPoint
@Override
public void onEdgeUnsnap()
{
this.setImage(WORLDMAP_HINT_ARROW);
this.setImagePoint(WORLDMAP_HINT_ARROW_POINT);
this.setImage(worldmapHintArrow);
this.setImagePoint(worldmapHintArrowPoint);
this.setTooltip("Death Location");
}
}

View File

@@ -32,7 +32,6 @@ import com.google.inject.Provides;
import java.awt.Font;
import java.awt.image.BufferedImage;
import static java.lang.Math.min;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
@@ -51,6 +50,7 @@ import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ImageUtil;
import org.slf4j.LoggerFactory;
@PluginDescriptor(
@@ -130,11 +130,7 @@ public class DevToolsPlugin extends Plugin
final DevToolsPanel panel = injector.getInstance(DevToolsPanel.class);
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("devtools_icon.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "devtools_icon.png");
navButton = NavigationButton.builder()
.tooltip("Developer Tools")

View File

@@ -33,7 +33,6 @@ import java.time.temporal.ChronoUnit;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import net.runelite.api.Client;
import static net.runelite.api.Constants.CHUNK_SIZE;
import net.runelite.api.GameState;
@@ -51,6 +50,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.task.Schedule;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.LinkBrowser;
@PluginDescriptor(
@@ -88,11 +88,7 @@ public class DiscordPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("discord.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "discord.png");
discordButton = NavigationButton.builder()
.tab(false)

View File

@@ -29,7 +29,6 @@ import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import lombok.extern.slf4j.Slf4j;
@@ -46,6 +45,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.task.Schedule;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Farming Tracker",
@@ -88,11 +88,7 @@ public class FarmingTrackerPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("farming.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "farming.png");
panel = new FarmingTrackerPanel(client, itemManager, configManager, config, farmingWorld);

View File

@@ -53,6 +53,7 @@ import lombok.extern.slf4j.Slf4j;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.PluginPanel;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.LinkBrowser;
import net.runelite.http.api.RuneLiteAPI;
import net.runelite.http.api.feed.FeedItem;
@@ -102,18 +103,8 @@ class FeedPanel extends PluginPanel
static
{
try
{
synchronized (ImageIO.class)
{
RUNELITE_ICON = new ImageIcon(ImageIO.read(FeedPanel.class.getResourceAsStream("runelite.png")));
OSRS_ICON = new ImageIcon(ImageIO.read(FeedPanel.class.getResourceAsStream("osrs.png")));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
RUNELITE_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(FeedPanel.class, "runelite.png"));
OSRS_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(FeedPanel.class, "osrs.png"));
}
private final FeedConfig config;

View File

@@ -33,7 +33,6 @@ import java.time.temporal.ChronoUnit;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.events.ConfigChanged;
@@ -43,6 +42,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.task.Schedule;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
import net.runelite.http.api.feed.FeedClient;
import net.runelite.http.api.feed.FeedResult;
@@ -86,11 +86,7 @@ public class FeedPlugin extends Plugin
{
feedPanel = new FeedPanel(config, feedSupplier);
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("icon.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "icon.png");
navButton = NavigationButton.builder()
.tooltip("News Feed")

View File

@@ -28,11 +28,11 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.SpriteID;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
@@ -47,17 +47,17 @@ public class FightCaveOverlay extends Overlay
private final Client client;
private final FightCavePlugin plugin;
private final SpriteManager spriteManager;
private final PanelComponent imagePanelComponent = new PanelComponent();
private BufferedImage protectFromMagicImg;
private BufferedImage protectFromMissilesImg;
@Inject
private FightCaveOverlay(Client client, FightCavePlugin plugin)
private FightCaveOverlay(Client client, FightCavePlugin plugin, SpriteManager spriteManager)
{
setPosition(OverlayPosition.BOTTOM_RIGHT);
setPriority(OverlayPriority.HIGH);
this.client = client;
this.plugin = plugin;
this.spriteManager = spriteManager;
}
@Override
@@ -83,43 +83,7 @@ public class FightCaveOverlay extends Overlay
private BufferedImage getPrayerImage(JadAttack attack)
{
return attack == JadAttack.MAGIC ? getProtectFromMagicImage() : getProtectFromMissilesImage();
}
private BufferedImage getProtectFromMagicImage()
{
if (protectFromMagicImg == null)
{
String path = "/prayers/protect_from_magic.png";
protectFromMagicImg = getImage(path);
}
return protectFromMagicImg;
}
private BufferedImage getProtectFromMissilesImage()
{
if (protectFromMissilesImg == null)
{
String path = "/prayers/protect_from_missiles.png";
protectFromMissilesImg = getImage(path);
}
return protectFromMissilesImg;
}
private BufferedImage getImage(String path)
{
BufferedImage image = null;
try
{
synchronized (ImageIO.class)
{
image = ImageIO.read(FightCaveOverlay.class.getResourceAsStream(path));
}
}
catch (IOException e)
{
log.warn("Error loading image", e);
}
return image;
final int prayerSpriteID = attack == JadAttack.MAGIC ? SpriteID.PRAYER_PROTECT_FROM_MAGIC : SpriteID.PRAYER_PROTECT_FROM_MISSILES;
return spriteManager.getSprite(prayerSpriteID, 0);
}
}

View File

@@ -36,9 +36,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
@@ -54,6 +52,7 @@ import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.components.ThinProgressBar;
import net.runelite.client.util.ColorUtil;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.StackFormatter;
@Slf4j
@@ -83,18 +82,9 @@ public class GrandExchangeOfferSlot extends JPanel
static
{
try
{
synchronized (ImageIO.class)
{
RIGHT_ARROW_ICON = new ImageIcon(ImageIO.read(GrandExchangeOfferSlot.class.getResourceAsStream("arrow_right.png")));
LEFT_ARROW_ICON = new ImageIcon(ImageIO.read(GrandExchangeOfferSlot.class.getResourceAsStream("arrow_left.png")));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
final BufferedImage rightArrow = ImageUtil.alphaOffset(ImageUtil.getResourceStreamFromClass(GrandExchangeOfferSlot.class, "/util/arrow_right.png"), 0.25f);
RIGHT_ARROW_ICON = new ImageIcon(rightArrow);
LEFT_ARROW_ICON = new ImageIcon(ImageUtil.flipImage(rightArrow, true, false));
}
/**

View File

@@ -32,7 +32,6 @@ import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.ScheduledExecutorService;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import lombok.AccessLevel;
@@ -66,6 +65,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.StackFormatter;
import net.runelite.client.util.Text;
import net.runelite.http.api.osbuddy.GrandExchangeClient;
@@ -134,15 +134,11 @@ public class GrandExchangePlugin extends Plugin
}
@Override
protected void startUp() throws IOException
protected void startUp()
{
panel = injector.getInstance(GrandExchangePanel.class);
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("ge_icon.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "ge_icon.png");
button = NavigationButton.builder()
.tooltip("Grand Exchange")

View File

@@ -31,11 +31,9 @@ import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
@@ -49,6 +47,7 @@ import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.components.IconTextField;
import net.runelite.client.ui.components.PluginErrorPanel;
import net.runelite.client.util.ImageUtil;
import net.runelite.http.api.item.Item;
import net.runelite.http.api.item.ItemPrice;
import net.runelite.http.api.item.SearchResult;
@@ -95,19 +94,9 @@ class GrandExchangeSearchPanel extends JPanel
static
{
try
{
synchronized (ImageIO.class)
{
SEARCH_ICON = new ImageIcon(ImageIO.read(IconTextField.class.getResourceAsStream("search_darker.png")));
LOADING_ICON = new ImageIcon(IconTextField.class.getResource("loading_spinner.gif"));
ERROR_ICON = new ImageIcon(ImageIO.read(IconTextField.class.getResourceAsStream("error.png")));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
SEARCH_ICON = new ImageIcon(ImageUtil.alphaOffset(ImageUtil.grayscaleOffset(ImageUtil.getResourceStreamFromClass(IconTextField.class, "search.png"), 0f), 1.75f));
LOADING_ICON = new ImageIcon(IconTextField.class.getResource("loading_spinner.gif"));
ERROR_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(IconTextField.class, "error.png"));
}
GrandExchangeSearchPanel(Client client, ItemManager itemManager, ScheduledExecutorService executor)

View File

@@ -41,7 +41,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
@@ -57,6 +56,7 @@ import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.IconTextField;
import net.runelite.client.ui.components.materialtabs.MaterialTab;
import net.runelite.client.ui.components.materialtabs.MaterialTabGroup;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.RunnableExceptionLogger;
import net.runelite.client.util.StackFormatter;
import net.runelite.http.api.hiscore.HiscoreClient;
@@ -146,19 +146,9 @@ public class HiscorePanel extends PluginPanel
static
{
try
{
synchronized (ImageIO.class)
{
SEARCH_ICON = new ImageIcon(ImageIO.read(IconTextField.class.getResourceAsStream("search.png")));
LOADING_ICON = new ImageIcon(IconTextField.class.getResource("loading_spinner_darker.gif"));
ERROR_ICON = new ImageIcon(ImageIO.read(IconTextField.class.getResourceAsStream("error.png")));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
SEARCH_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(IconTextField.class, "search.png"));
LOADING_ICON = new ImageIcon(IconTextField.class.getResource("loading_spinner_darker.gif"));
ERROR_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(IconTextField.class, "error.png"));
}
@Inject
@@ -220,51 +210,39 @@ public class HiscorePanel extends PluginPanel
for (HiscoreEndpoint endpoint : HiscoreEndpoint.values())
{
try
final BufferedImage iconImage = ImageUtil.getResourceStreamFromClass(getClass(), endpoint.name().toLowerCase() + ".png");
MaterialTab tab = new MaterialTab(new ImageIcon(iconImage), tabGroup, null);
tab.setToolTipText(endpoint.getName() + " Hiscores");
tab.setOnSelectEvent(() ->
{
BufferedImage iconImage;
synchronized (ImageIO.class)
if (loading)
{
iconImage = ImageIO.read(HiscorePanel.class.getResourceAsStream(
endpoint.name().toLowerCase() + ".png"));
return false;
}
MaterialTab tab = new MaterialTab(new ImageIcon(iconImage), tabGroup, null);
tab.setToolTipText(endpoint.getName() + " Hiscores");
tab.setOnSelectEvent(() ->
selectedEndPoint = endpoint;
return true;
});
// Adding the lookup method to a mouseListener instead of the above onSelectedEvent
// Because sometimes you might want to switch the tab, without calling for lookup
// Ex: selecting the normal hiscores as default
tab.addMouseListener(new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent mouseEvent)
{
if (loading)
{
return false;
return;
}
selectedEndPoint = endpoint;
return true;
});
executor.execute(HiscorePanel.this::lookup);
}
});
// Adding the lookup method to a mouseListener instead of the above onSelectedEvent
// Because sometimes you might want to switch the tab, without calling for lookup
// Ex: selecting the normal hiscores as default
tab.addMouseListener(new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent mouseEvent)
{
if (loading)
{
return;
}
executor.execute(HiscorePanel.this::lookup);
}
});
tabGroup.addTab(tab);
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
tabGroup.addTab(tab);
}
// Default selected tab is normal hiscores
@@ -328,22 +306,22 @@ public class HiscorePanel extends PluginPanel
label.setFont(FontManager.getRunescapeSmallFont());
label.setText("--");
String skillIcon = "skill_icons_small/" + (skill == null ? "combat" : skill.getName().toLowerCase()) + ".png";
String skillName = (skill == null ? "combat" : skill.getName().toLowerCase());
String directory = "/skill_icons";
if (skillName.equals("combat") || skillName.equals("overall"))
{
// Cannot use SpriteManager as HiscorePlugin loads before a Client is available
directory += "/";
}
else
{
directory += "_small/";
}
String skillIcon = directory + skillName + ".png";
log.debug("Loading skill icon from {}", skillIcon);
try
{
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(HiscorePanel.class.getResourceAsStream(skillIcon));
}
label.setIcon(new ImageIcon(icon));
}
catch (IOException ex)
{
log.warn(null, ex);
}
label.setIcon(new ImageIcon(ImageUtil.getResourceStreamFromClass(getClass(), skillIcon)));
boolean totalLabel = skill == HiscoreSkill.OVERALL || skill == null; //overall or combat
label.setIconTextGap(totalLabel ? 10 : 4);

View File

@@ -32,7 +32,6 @@ import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.swing.SwingUtilities;
@@ -49,6 +48,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.Text;
import org.apache.commons.lang3.ArrayUtils;
@@ -98,11 +98,7 @@ public class HiscorePlugin extends Plugin
{
hiscorePanel = injector.getInstance(HiscorePanel.class);
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("normal.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "normal.png");
navButton = NavigationButton.builder()
.tooltip("Hiscore")

View File

@@ -36,10 +36,8 @@ import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.inject.Singleton;
import javax.swing.Box;
import javax.swing.ImageIcon;
@@ -56,6 +54,7 @@ import net.runelite.client.account.SessionManager;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.PluginPanel;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.LinkBrowser;
import net.runelite.client.util.RunnableExceptionLogger;
@@ -92,21 +91,11 @@ public class InfoPanel extends PluginPanel
static
{
try
{
synchronized (ImageIO.class)
{
ARROW_RIGHT_ICON = new ImageIcon(ImageIO.read(InfoPanel.class.getResourceAsStream("arrow_right.png")));
GITHUB_ICON = new ImageIcon(ImageIO.read(InfoPanel.class.getResourceAsStream("github_icon.png")));
DISCORD_ICON = new ImageIcon(ImageIO.read(InfoPanel.class.getResourceAsStream("discord_icon.png")));
PATREON_ICON = new ImageIcon(ImageIO.read(InfoPanel.class.getResourceAsStream("patreon_icon.png")));
WIKI_ICON = new ImageIcon(ImageIO.read(InfoPanel.class.getResourceAsStream("wiki_icon.png")));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
ARROW_RIGHT_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(InfoPanel.class, "/util/arrow_right.png"));
GITHUB_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(InfoPanel.class, "github_icon.png"));
DISCORD_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(InfoPanel.class, "discord_icon.png"));
PATREON_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(InfoPanel.class, "patreon_icon.png"));
WIKI_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(InfoPanel.class, "wiki_icon.png"));
}
void init()

View File

@@ -25,12 +25,12 @@
package net.runelite.client.plugins.info;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Info Panel",
@@ -50,11 +50,7 @@ public class InfoPlugin extends Plugin
final InfoPanel panel = injector.getInstance(InfoPanel.class);
panel.init();
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("info_icon.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "info_icon.png");
navButton = NavigationButton.builder()
.tooltip("Info")

View File

@@ -26,16 +26,16 @@ package net.runelite.client.plugins.kingdomofmiscellania;
import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.Subscribe;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import static net.runelite.api.ItemID.TEAK_CHEST;
import net.runelite.api.Varbits;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
@@ -57,20 +57,13 @@ public class KingdomPlugin extends Plugin
@Inject
private InfoBoxManager infoBoxManager;
@Inject
private ItemManager itemManager;
@Getter
private int favor = 0, coffer = 0;
private KingdomCounter counter;
private BufferedImage counterImage;
@Override
protected void startUp() throws Exception
{
synchronized (ImageIO.class)
{
counterImage = ImageIO.read(getClass().getResourceAsStream("teak_chest.png"));
}
}
@Override
protected void shutDown() throws Exception
@@ -112,7 +105,7 @@ public class KingdomPlugin extends Plugin
{
if (counter == null)
{
counter = new KingdomCounter(counterImage, this);
counter = new KingdomCounter(itemManager.getImage(TEAK_CHEST), this);
infoBoxManager.addInfoBox(counter);
log.debug("Added Kingdom Infobox");
}

View File

@@ -33,14 +33,12 @@ import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.imageio.ImageIO;
import javax.inject.Singleton;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
@@ -52,7 +50,7 @@ import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.PluginPanel;
import net.runelite.client.util.SwingUtil;
import net.runelite.client.util.ImageUtil;
@Singleton
class KourendLibraryPanel extends PluginPanel
@@ -67,19 +65,9 @@ class KourendLibraryPanel extends PluginPanel
static
{
try
{
synchronized (ImageIO.class)
{
BufferedImage resetIcon = ImageIO.read(KourendLibraryPanel.class.getResourceAsStream("reset.png"));
RESET_ICON = new ImageIcon(resetIcon);
RESET_CLICK_ICON = new ImageIcon(SwingUtil.grayscaleOffset(resetIcon, -100));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
final BufferedImage resetIcon = ImageUtil.getResourceStreamFromClass(KourendLibraryPanel.class, "/util/reset.png");
RESET_ICON = new ImageIcon(resetIcon);
RESET_CLICK_ICON = new ImageIcon(ImageUtil.alphaOffset(resetIcon, -100));
}
void init()

View File

@@ -29,7 +29,6 @@ import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import lombok.extern.slf4j.Slf4j;
@@ -53,6 +52,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Kourend Library",
@@ -109,11 +109,7 @@ public class KourendLibraryPlugin extends Plugin
panel = injector.getInstance(KourendLibraryPanel.class);
panel.init();
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(Book.class.getResourceAsStream("panel_icon.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "panel_icon.png");
navButton = NavigationButton.builder()
.tooltip("Kourend Library")

View File

@@ -34,7 +34,6 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import lombok.extern.slf4j.Slf4j;
@@ -59,6 +58,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.Text;
import net.runelite.http.api.item.ItemPrice;
@@ -125,11 +125,7 @@ public class LootTrackerPlugin extends Plugin
panel = new LootTrackerPanel(itemManager);
spriteManager.getSpriteAsync(SpriteID.UNUSED_TAB_INVENTORY, 0, panel::loadHeaderIcon);
final BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(LootTrackerPanel.class.getResourceAsStream("panel_icon.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "panel_icon.png");
navButton = NavigationButton.builder()
.tooltip("Loot Tracker")

View File

@@ -25,12 +25,11 @@
package net.runelite.client.plugins.mta.alchemy;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.time.temporal.ChronoUnit;
import javax.imageio.ImageIO;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.infobox.Timer;
import net.runelite.client.util.ImageUtil;
@Slf4j
public class AlchemyRoomTimer extends Timer
@@ -51,17 +50,7 @@ public class AlchemyRoomTimer extends Timer
return image;
}
try
{
synchronized (ImageIO.class)
{
image = ImageIO.read(AlchemyRoomTimer.class.getResourceAsStream("reset.png"));
}
}
catch (IOException ex)
{
log.warn(null, ex);
}
image = ImageUtil.getResourceStreamFromClass(AlchemyRoomTimer.class, "/util/reset.png");
return image;
}

View File

@@ -27,7 +27,6 @@ package net.runelite.client.plugins.notes;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.events.SessionOpen;
@@ -36,6 +35,7 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Notes",
@@ -67,11 +67,7 @@ public class NotesPlugin extends Plugin
panel = injector.getInstance(NotesPanel.class);
panel.init(config);
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("notes_icon.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "notes_icon.png");
navButton = NavigationButton.builder()
.tooltip("Notes")

View File

@@ -25,14 +25,13 @@
package net.runelite.client.plugins.poh;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import static net.runelite.api.ObjectID.*;
import static net.runelite.api.NullObjectID.*;
import net.runelite.client.util.ImageUtil;
@Slf4j
public enum PohIcons
@@ -105,17 +104,7 @@ public enum PohIcons
return image;
}
try
{
synchronized (ImageIO.class)
{
image = ImageIO.read(PohIcons.class.getResourceAsStream(getImageResource() + ".png"));
}
}
catch (IOException ex)
{
log.warn("unable to load image", ex);
}
image = ImageUtil.getResourceStreamFromClass(getClass(), getImageResource() + ".png");
return image;
}

View File

@@ -32,14 +32,10 @@ import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
@@ -47,8 +43,10 @@ import net.runelite.api.GameState;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import static net.runelite.api.SpriteID.MINIMAP_DESTINATION_FLAG;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver;
import net.runelite.client.plugins.puzzlesolver.solver.PuzzleState;
import net.runelite.client.plugins.puzzlesolver.solver.heuristics.ManhattanDistance;
@@ -60,6 +58,7 @@ import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.BackgroundComponent;
import net.runelite.client.ui.overlay.components.TextComponent;
import net.runelite.client.util.ImageUtil;
@Slf4j
public class PuzzleSolverOverlay extends Overlay
@@ -78,18 +77,18 @@ public class PuzzleSolverOverlay extends Overlay
private final Client client;
private final PuzzleSolverConfig config;
private final ScheduledExecutorService executorService;
private final SpriteManager spriteManager;
private PuzzleSolver solver;
private Future<?> solverFuture;
private int[] cachedItems;
private BufferedImage downArrow;
private BufferedImage upArrow;
private BufferedImage leftArrow;
private BufferedImage rightArrow;
@Inject
public PuzzleSolverOverlay(Client client, PuzzleSolverConfig config, ScheduledExecutorService executorService)
public PuzzleSolverOverlay(Client client, PuzzleSolverConfig config, ScheduledExecutorService executorService, SpriteManager spriteManager)
{
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH);
@@ -97,6 +96,7 @@ public class PuzzleSolverOverlay extends Overlay
this.client = client;
this.config = config;
this.executorService = executorService;
this.spriteManager = spriteManager;
}
@Override
@@ -427,28 +427,14 @@ public class PuzzleSolverOverlay extends Overlay
private BufferedImage getDownArrow()
{
if (downArrow == null)
{
try
{
synchronized (ImageIO.class)
{
downArrow = ImageIO.read(PuzzleSolverOverlay.class.getResourceAsStream("arrow.png"));
}
}
catch (IOException e)
{
log.warn("Error loading image", e);
}
}
return downArrow;
return spriteManager.getSprite(MINIMAP_DESTINATION_FLAG, 1);
}
private BufferedImage getUpArrow()
{
if (upArrow == null)
{
upArrow = getRotatedImage(getDownArrow(), Math.PI);
upArrow = ImageUtil.rotateImage(getDownArrow(), Math.PI);
}
return upArrow;
}
@@ -457,7 +443,7 @@ public class PuzzleSolverOverlay extends Overlay
{
if (leftArrow == null)
{
leftArrow = getRotatedImage(getDownArrow(), Math.PI / 2);
leftArrow = ImageUtil.rotateImage(getDownArrow(), Math.PI / 2);
}
return leftArrow;
}
@@ -466,16 +452,8 @@ public class PuzzleSolverOverlay extends Overlay
{
if (rightArrow == null)
{
rightArrow = getRotatedImage(getDownArrow(), 3 * Math.PI / 2);
rightArrow = ImageUtil.rotateImage(getDownArrow(), 3 * Math.PI / 2);
}
return rightArrow;
}
private BufferedImage getRotatedImage(BufferedImage image, double theta)
{
AffineTransform transform = new AffineTransform();
transform.rotate(theta, image.getWidth() / 2, image.getHeight() / 2);
AffineTransformOp transformOp = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
return transformOp.filter(image, null);
}
}

View File

@@ -27,15 +27,12 @@ package net.runelite.client.plugins.raids;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Binder;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.DecimalFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -46,6 +43,7 @@ import net.runelite.api.InstanceTemplates;
import net.runelite.api.NullObjectID;
import static net.runelite.api.Perspective.SCENE_SIZE;
import net.runelite.api.Point;
import static net.runelite.api.SpriteID.TAB_QUESTS_BROWN_RAIDING_PARTY;
import net.runelite.api.Tile;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits;
@@ -60,6 +58,7 @@ import net.runelite.client.chat.ChatMessageBuilder;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.raids.solver.Layout;
@@ -86,7 +85,6 @@ public class RaidsPlugin extends Plugin
private static final String SPLIT_REGEX = "\\s*,\\s*";
private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)]");
private BufferedImage raidsIcon;
private RaidsTimer timer;
@Getter
@@ -116,6 +114,9 @@ public class RaidsPlugin extends Plugin
@Inject
private LayoutSolver layoutSolver;
@Inject
private SpriteManager spriteManager;
@Getter
private Raid raid;
@@ -270,7 +271,7 @@ public class RaidsPlugin extends Plugin
if (config.raidsTimer() && message.startsWith(RAID_START_MESSAGE))
{
timer = new RaidsTimer(getRaidsIcon(), this, Instant.now());
timer = new RaidsTimer(spriteManager.getSprite(TAB_QUESTS_BROWN_RAIDING_PARTY, 0), this, Instant.now());
infoBoxManager.addInfoBox(timer);
}
@@ -602,25 +603,4 @@ public class RaidsPlugin extends Plugin
return room;
}
private BufferedImage getRaidsIcon()
{
if (raidsIcon != null)
{
return raidsIcon;
}
try
{
synchronized (ImageIO.class)
{
raidsIcon = ImageIO.read(RaidsPlugin.class.getResourceAsStream("raids_icon.png"));
}
}
catch (IOException ex)
{
log.warn("Unable to load image", ex);
}
return raidsIcon;
}
}

View File

@@ -39,7 +39,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
@@ -53,6 +52,7 @@ import net.runelite.client.plugins.screenmarkers.ui.ScreenMarkerPluginPanel;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Screen Markers",
@@ -108,11 +108,7 @@ public class ScreenMarkerPlugin extends Plugin
pluginPanel = injector.getInstance(ScreenMarkerPluginPanel.class);
pluginPanel.rebuild();
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream(ICON_FILE));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), ICON_FILE);
navigationButton = NavigationButton.builder()
.tooltip(PLUGIN_NAME)

View File

@@ -29,8 +29,7 @@ import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
@@ -39,6 +38,7 @@ import net.runelite.client.plugins.screenmarkers.ScreenMarkerPlugin;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.components.shadowlabel.JShadowedLabel;
import net.runelite.client.util.ImageUtil;
public class ScreenMarkerCreationPanel extends JPanel
{
@@ -54,21 +54,13 @@ public class ScreenMarkerCreationPanel extends JPanel
static
{
try
{
synchronized (ImageIO.class)
{
CONFIRM_ICON = new ImageIcon(ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("confirm_icon.png")));
CONFIRM_HOVER_ICON = new ImageIcon(ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("confirm_hover_icon.png")));
CONFIRM_LOCKED_ICON = new ImageIcon(ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("confirm_locked_icon.png")));
CANCEL_ICON = new ImageIcon(ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("cancel_icon.png")));
CANCEL_HOVER_ICON = new ImageIcon(ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("cancel_hover_icon.png")));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
CONFIRM_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "confirm_icon.png"));
CANCEL_ICON = new ImageIcon(ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "cancel_icon.png"));
final BufferedImage confirmIcon = ImageUtil.bufferedImageFromImage(CONFIRM_ICON.getImage());
CONFIRM_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(confirmIcon, 0.54f));
CONFIRM_LOCKED_ICON = new ImageIcon(ImageUtil.grayscaleImage(confirmIcon));
CANCEL_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(ImageUtil.bufferedImageFromImage(CANCEL_ICON.getImage()), 0.6f));
}
ScreenMarkerCreationPanel(ScreenMarkerPlugin plugin)

View File

@@ -34,8 +34,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
@@ -55,7 +53,7 @@ import net.runelite.client.plugins.screenmarkers.ScreenMarkerPlugin;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.components.FlatTextField;
import net.runelite.client.util.SwingUtil;
import net.runelite.client.util.ImageUtil;
class ScreenMarkerPanel extends JPanel
{
@@ -108,48 +106,38 @@ class ScreenMarkerPanel extends JPanel
static
{
try
{
synchronized (ImageIO.class)
{
BufferedImage borderImg = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("border_color_icon.png"));
BORDER_COLOR_ICON = new ImageIcon(borderImg);
BORDER_COLOR_HOVER_ICON = new ImageIcon(SwingUtil.grayscaleOffset(borderImg, -100));
final BufferedImage borderImg = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "border_color_icon.png");
BORDER_COLOR_ICON = new ImageIcon(borderImg);
BORDER_COLOR_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(borderImg, -100));
BufferedImage noBorderImg = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("no_border_color_icon.png"));
NO_BORDER_COLOR_ICON = new ImageIcon(noBorderImg);
NO_BORDER_COLOR_HOVER_ICON = new ImageIcon(SwingUtil.grayscaleOffset(noBorderImg, -100));
final BufferedImage noBorderImg = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "no_border_color_icon.png");
NO_BORDER_COLOR_ICON = new ImageIcon(noBorderImg);
NO_BORDER_COLOR_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(noBorderImg, -100));
BufferedImage fillImg = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("fill_color_icon.png"));
FILL_COLOR_ICON = new ImageIcon(fillImg);
FILL_COLOR_HOVER_ICON = new ImageIcon(SwingUtil.grayscaleOffset(fillImg, -100));
final BufferedImage fillImg = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "fill_color_icon.png");
FILL_COLOR_ICON = new ImageIcon(fillImg);
FILL_COLOR_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(fillImg, -100));
BufferedImage noFillImg = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("no_fill_color_icon.png"));
NO_FILL_COLOR_ICON = new ImageIcon(noFillImg);
NO_FILL_COLOR_HOVER_ICON = new ImageIcon(SwingUtil.grayscaleOffset(noFillImg, -100));
final BufferedImage noFillImg = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "no_fill_color_icon.png");
NO_FILL_COLOR_ICON = new ImageIcon(noFillImg);
NO_FILL_COLOR_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(noFillImg, -100));
BufferedImage opacityImg = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("opacity_icon.png"));
FULL_OPACITY_ICON = new ImageIcon(opacityImg);
OPACITY_HOVER_ICON = new ImageIcon(SwingUtil.grayscaleOffset(opacityImg, -100));
NO_OPACITY_ICON = new ImageIcon(SwingUtil.grayscaleOffset(opacityImg, -150));
final BufferedImage opacityImg = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "opacity_icon.png");
FULL_OPACITY_ICON = new ImageIcon(opacityImg);
OPACITY_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(opacityImg, -100));
NO_OPACITY_ICON = new ImageIcon(ImageUtil.alphaOffset(opacityImg, -150));
BufferedImage visibleImg = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("visible_icon.png"));
VISIBLE_ICON = new ImageIcon(visibleImg);
VISIBLE_HOVER_ICON = new ImageIcon(SwingUtil.grayscaleOffset(visibleImg, -100));
final BufferedImage visibleImg = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "visible_icon.png");
VISIBLE_ICON = new ImageIcon(visibleImg);
VISIBLE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(visibleImg, -100));
BufferedImage invisibleImg = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("invisible_icon.png"));
INVISIBLE_ICON = new ImageIcon(invisibleImg);
INVISIBLE_HOVER_ICON = new ImageIcon(SwingUtil.grayscaleOffset(invisibleImg, -100));
final BufferedImage invisibleImg = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "invisible_icon.png");
INVISIBLE_ICON = new ImageIcon(invisibleImg);
INVISIBLE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(invisibleImg, -100));
BufferedImage deleteImg = ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("delete_icon.png"));
DELETE_ICON = new ImageIcon(deleteImg);
DELETE_HOVER_ICON = new ImageIcon(SwingUtil.grayscaleOffset(deleteImg, -100));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
final BufferedImage deleteImg = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "delete_icon.png");
DELETE_ICON = new ImageIcon(deleteImg);
DELETE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(deleteImg, -100));
}
ScreenMarkerPanel(ScreenMarkerPlugin plugin, ScreenMarkerOverlay marker)

View File

@@ -34,8 +34,7 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
@@ -47,6 +46,7 @@ import net.runelite.client.plugins.screenmarkers.ScreenMarkerPlugin;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.PluginErrorPanel;
import net.runelite.client.util.ImageUtil;
@Singleton
public class ScreenMarkerPluginPanel extends PluginPanel
@@ -80,18 +80,9 @@ public class ScreenMarkerPluginPanel extends PluginPanel
static
{
try
{
synchronized (ImageIO.class)
{
ADD_ICON = new ImageIcon(ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("add_icon.png")));
ADD_HOVER_ICON = new ImageIcon(ImageIO.read(ScreenMarkerPlugin.class.getResourceAsStream("add_hover_icon.png")));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
final BufferedImage addIcon = ImageUtil.getResourceStreamFromClass(ScreenMarkerPlugin.class, "add_icon.png");
ADD_ICON = new ImageIcon(addIcon);
ADD_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(addIcon, 0.53f));
}
public void init()

View File

@@ -31,16 +31,13 @@ import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.MainBufferProvider;
import net.runelite.client.ui.DrawManager;
@@ -50,41 +47,26 @@ import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
@Slf4j
public class ScreenshotOverlay extends Overlay
{
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MMM. dd, yyyy");
private static final int REPORT_BUTTON_X_OFFSET = 404;
private static BufferedImage REPORT_BUTTON;
static
{
try
{
synchronized (ImageIO.class)
{
REPORT_BUTTON = ImageIO.read(ScreenshotPlugin.class.getResourceAsStream("report_button.png"));
}
}
catch (IOException e)
{
log.warn("Report button image failed to load", e);
}
}
private final Client client;
private final DrawManager drawManager;
private final ScreenshotPlugin plugin;
private final Queue<Consumer<Image>> consumers = new ConcurrentLinkedQueue<>();
@Inject
public ScreenshotOverlay(Client client, DrawManager drawManager)
public ScreenshotOverlay(Client client, DrawManager drawManager, ScreenshotPlugin plugin)
{
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH);
setLayer(OverlayLayer.ABOVE_WIDGETS);
this.client = client;
this.drawManager = drawManager;
this.plugin = plugin;
}
@Override
@@ -97,9 +79,9 @@ public class ScreenshotOverlay extends Overlay
final MainBufferProvider bufferProvider = (MainBufferProvider) client.getBufferProvider();
final int imageHeight = ((BufferedImage) bufferProvider.getImage()).getHeight();
final int y = imageHeight - REPORT_BUTTON.getHeight() - 1;
final int y = imageHeight - plugin.getReportButton().getHeight() - 1;
graphics.drawImage(REPORT_BUTTON, REPORT_BUTTON_X_OFFSET, y, null);
graphics.drawImage(plugin.getReportButton(), REPORT_BUTTON_X_OFFSET, y, null);
graphics.setFont(FontManager.getRunescapeSmallFont());
FontMetrics fontMetrics = graphics.getFontMetrics();
@@ -108,8 +90,8 @@ public class ScreenshotOverlay extends Overlay
final int dateWidth = fontMetrics.stringWidth(date);
final int dateHeight = fontMetrics.getHeight();
final int textX = REPORT_BUTTON_X_OFFSET + REPORT_BUTTON.getWidth() / 2 - dateWidth / 2;
final int textY = y + REPORT_BUTTON.getHeight() / 2 + dateHeight / 2;
final int textX = REPORT_BUTTON_X_OFFSET + plugin.getReportButton().getWidth() / 2 - dateWidth / 2;
final int textY = y + plugin.getReportButton().getHeight() / 2 + dateHeight / 2;
graphics.setColor(Color.BLACK);
graphics.drawString(date, textX + 1, textY + 1);
@@ -130,7 +112,7 @@ public class ScreenshotOverlay extends Overlay
public void queueForTimestamp(Consumer<Image> screenshotConsumer)
{
if (REPORT_BUTTON == null)
if (plugin.getReportButton() == null)
{
return;
}

View File

@@ -52,13 +52,17 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.Point;
import net.runelite.api.SpriteID;
import net.runelite.api.WorldType;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget;
@@ -74,6 +78,7 @@ import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.Notifier;
import static net.runelite.client.RuneLite.SCREENSHOT_DIR;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.input.KeyManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
@@ -85,6 +90,7 @@ import net.runelite.client.ui.DrawManager;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.HotkeyListener;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.Text;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Call;
@@ -170,6 +176,12 @@ public class ScreenshotPlugin extends Plugin
@Inject
private KeyManager keyManager;
@Inject
private SpriteManager spriteManager;
@Getter(AccessLevel.PACKAGE)
private BufferedImage reportButton;
private NavigationButton titleBarButton;
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey())
@@ -194,42 +206,30 @@ public class ScreenshotPlugin extends Plugin
SCREENSHOT_DIR.mkdirs();
keyManager.registerKeyListener(hotkeyListener);
try
{
BufferedImage iconImage;
synchronized (ImageIO.class)
{
iconImage = ImageIO.read(ScreenshotPlugin.class.getResourceAsStream("screenshot.png"));
}
final BufferedImage iconImage = ImageUtil.getResourceStreamFromClass(getClass(), "screenshot.png");
titleBarButton = NavigationButton.builder()
.tab(false)
.tooltip("Take screenshot")
.icon(iconImage)
.onClick(() -> takeScreenshot(format(new Date())))
.popup(ImmutableMap
.<String, Runnable>builder()
.put("Open screenshot folder...", () ->
titleBarButton = NavigationButton.builder()
.tab(false)
.tooltip("Take screenshot")
.icon(iconImage)
.onClick(() -> takeScreenshot(format(new Date())))
.popup(ImmutableMap
.<String, Runnable>builder()
.put("Open screenshot folder...", () ->
{
try
{
try
{
Desktop.getDesktop().open(SCREENSHOT_DIR);
}
catch (IOException ex)
{
log.warn("Error opening screenshot dir", ex);
Desktop.getDesktop().open(SCREENSHOT_DIR);
}
catch (IOException ex)
{
log.warn("Error opening screenshot dir", ex);
}
})
.build())
.build();
}
})
.build())
.build();
clientToolbar.addNavigation(titleBarButton);
}
catch (IOException ex)
{
log.warn("Error adding screenshot button to titlebar", ex);
}
clientToolbar.addNavigation(titleBarButton);
}
@Override
@@ -240,6 +240,16 @@ public class ScreenshotPlugin extends Plugin
keyManager.unregisterKeyListener(hotkeyListener);
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
if (event.getGameState() == GameState.LOGGED_IN
&& reportButton == null)
{
reportButton = spriteManager.getSprite(SpriteID.CHATBOX_REPORT_BUTTON, 0);
}
}
@Subscribe
public void onGameTick(GameTick event)
{

View File

@@ -26,7 +26,6 @@
package net.runelite.client.plugins.skillcalculator;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.client.game.ItemManager;
@@ -37,6 +36,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Skill Calculator",
@@ -69,11 +69,7 @@ public class SkillCalculatorPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("calc.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "calc.png");
SkillCalculator.spriteManager = spriteManager;
SkillCalculator.itemManager = itemManager;

View File

@@ -25,10 +25,9 @@
*/
package net.runelite.client.plugins.worldmap;
import java.io.IOException;
import javax.imageio.ImageIO;
import lombok.Getter;
import net.runelite.client.ui.overlay.worldmap.WorldMapPoint;
import net.runelite.client.util.ImageUtil;
class TeleportPoint extends WorldMapPoint
{
@@ -42,13 +41,6 @@ class TeleportPoint extends WorldMapPoint
this.data = data;
setTooltip(data.getTooltip());
try
{
setImage(ImageIO.read(WorldMapPlugin.class.getResourceAsStream(data.getIconPath())));
}
catch (IOException e)
{
throw new RuntimeException(e);
}
setImage(ImageUtil.getResourceStreamFromClass(WorldMapPlugin.class, data.getIconPath()));
}
}

View File

@@ -29,9 +29,7 @@ import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Arrays;
import javax.imageio.ImageIO;
import net.runelite.api.Client;
import net.runelite.api.Experience;
import net.runelite.api.Skill;
@@ -41,6 +39,7 @@ import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.worldmap.WorldMapPointManager;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "World Map",
@@ -73,23 +72,13 @@ public class WorldMapPlugin extends Plugin
BLANK_ICON = new BufferedImage(iconBufferSize, iconBufferSize, BufferedImage.TYPE_INT_ARGB);
try
{
synchronized (ImageIO.class)
{
FAIRY_TRAVEL_ICON = new BufferedImage(iconBufferSize, iconBufferSize, BufferedImage.TYPE_INT_ARGB);
final BufferedImage icon = ImageIO.read(WorldMapPlugin.class.getResourceAsStream("fairy_ring_travel.png"));
FAIRY_TRAVEL_ICON.getGraphics().drawImage(icon, 1, 1, null);
FAIRY_TRAVEL_ICON = new BufferedImage(iconBufferSize, iconBufferSize, BufferedImage.TYPE_INT_ARGB);
final BufferedImage fairyTravelIcon = ImageUtil.getResourceStreamFromClass(WorldMapPlugin.class, "fairy_ring_travel.png");
FAIRY_TRAVEL_ICON.getGraphics().drawImage(fairyTravelIcon, 1, 1, null);
NOPE_ICON = new BufferedImage(iconBufferSize, iconBufferSize, BufferedImage.TYPE_INT_ARGB);
final BufferedImage nopeImage = ImageIO.read(WorldMapPlugin.class.getResourceAsStream("nope_icon.png"));
NOPE_ICON.getGraphics().drawImage(nopeImage, 1, 1, null);
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
NOPE_ICON = new BufferedImage(iconBufferSize, iconBufferSize, BufferedImage.TYPE_INT_ARGB);
final BufferedImage nopeImage = ImageUtil.getResourceStreamFromClass(WorldMapPlugin.class, "nope_icon.png");
NOPE_ICON.getGraphics().drawImage(nopeImage, 1, 1, null);
}
@Inject

View File

@@ -33,7 +33,6 @@ import java.awt.image.BufferedImage;
import java.time.temporal.ChronoUnit;
import java.util.EnumSet;
import java.util.Objects;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
@@ -53,6 +52,7 @@ import static net.runelite.client.plugins.xptracker.XpWorldType.NORMAL;
import net.runelite.client.task.Schedule;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.util.ImageUtil;
import net.runelite.http.api.xp.XpClient;
@PluginDescriptor(
@@ -102,11 +102,7 @@ public class XpTrackerPlugin extends Plugin
{
xpPanel = new XpPanel(this, client, skillIconManager);
BufferedImage icon;
synchronized (ImageIO.class)
{
icon = ImageIO.read(getClass().getResourceAsStream("xp.png"));
}
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "/skill_icons/overall.png");
navButton = NavigationButton.builder()
.tooltip("XP Tracker")

View File

@@ -38,9 +38,7 @@ import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.TrayIcon;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.swing.BoxLayout;
@@ -70,6 +68,7 @@ import net.runelite.client.events.NavigationButtonAdded;
import net.runelite.client.events.NavigationButtonRemoved;
import net.runelite.client.input.KeyManager;
import net.runelite.client.ui.skin.SubstanceRuneLiteLookAndFeel;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.OSType;
import net.runelite.client.util.OSXUtil;
import net.runelite.client.util.SwingUtil;
@@ -95,27 +94,9 @@ public class ClientUI
static
{
BufferedImage icon;
BufferedImage sidebarOpen;
BufferedImage sidebarClose;
try
{
synchronized (ImageIO.class)
{
icon = ImageIO.read(ClientUI.class.getResourceAsStream("/runelite.png"));
sidebarOpen = ImageIO.read(ClientUI.class.getResourceAsStream("open.png"));
sidebarClose = ImageIO.read(ClientUI.class.getResourceAsStream("close.png"));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
ICON = icon;
SIDEBAR_OPEN = sidebarOpen;
SIDEBAR_CLOSE = sidebarClose;
ICON = ImageUtil.getResourceStreamFromClass(ClientUI.class, "/runelite.png");
SIDEBAR_OPEN = ImageUtil.getResourceStreamFromClass(ClientUI.class, "open.png");
SIDEBAR_CLOSE = ImageUtil.flipImage(SIDEBAR_OPEN, true, false);
}
@Getter

View File

@@ -112,4 +112,14 @@ public class ColorUtil
{
return String.format("%06x", color.getRGB() & 0xFFFFFF);
}
static boolean isFullyTransparent(final Color color)
{
return color.getAlpha() == 0;
}
static boolean isNotFullyTransparent(final Color color)
{
return !isFullyTransparent(color);
}
}

View File

@@ -0,0 +1,410 @@
/*
* Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.util;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.io.IOException;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.GrayFilter;
import java.util.function.Predicate;
/**
* Various Image/BufferedImage utilities.
*/
public class ImageUtil
{
/**
* Creates a {@link BufferedImage} from an {@link Image}.
*
* @param image An Image to be converted to a BufferedImage.
* @return A BufferedImage instance of the same given image.
*/
public static BufferedImage bufferedImageFromImage(final Image image)
{
if (image instanceof BufferedImage)
{
return (BufferedImage) image;
}
final BufferedImage out = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = out.createGraphics();
g2d.drawImage(image, 0, 0, null);
g2d.dispose();
return out;
}
/**
* Offsets an image in the grayscale (darkens/brightens) by a given offset.
*
* @param image The image to be darkened or brightened.
* @param offset A signed 8-bit integer value to brighten or darken the image with.
* Values above 0 will brighten, and values below 0 will darken.
* @return The given image with its brightness adjusted by the given offset.
*/
public static BufferedImage grayscaleOffset(final BufferedImage image, final int offset)
{
final float offsetFloat = (float) offset;
final int numComponents = image.getColorModel().getNumComponents();
final float[] scales = new float[numComponents];
final float[] offsets = new float[numComponents];
Arrays.fill(scales, 1f);
for (int i = 0; i < numComponents; i++)
{
offsets[i] = offsetFloat;
}
// Set alpha to not offset
offsets[numComponents - 1] = 0f;
return offset(image, scales, offsets);
}
/**
* Offsets an image in the grayscale (darkens/brightens) by a given percentage.
*
* @param image The image to be darkened or brightened.
* @param percentage The ratio to darken or brighten the given image.
* Values above 1 will brighten, and values below 1 will darken.
* @return The given image with its brightness scaled by the given percentage.
*/
public static BufferedImage grayscaleOffset(final BufferedImage image, final float percentage)
{
final int numComponents = image.getColorModel().getNumComponents();
final float[] scales = new float[numComponents];
final float[] offsets = new float[numComponents];
Arrays.fill(offsets, 0f);
for (int i = 0; i < numComponents; i++)
{
scales[i] = percentage;
}
// Set alpha to not scale
scales[numComponents - 1] = 1f;
return offset(image, scales, offsets);
}
/**
* Offsets an image's alpha component by a given offset.
*
* @param image The image to be made more or less transparent.
* @param offset A signed 8-bit integer value to modify the image's alpha component with.
* Values above 0 will increase transparency, and values below 0 will decrease
* transparency.
* @return The given image with its alpha component adjusted by the given offset.
*/
public static BufferedImage alphaOffset(final BufferedImage image, final int offset)
{
final float offsetFloat = (float) offset;
final int numComponents = image.getColorModel().getNumComponents();
final float[] scales = new float[numComponents];
final float[] offsets = new float[numComponents];
Arrays.fill(scales, 1f);
Arrays.fill(offsets, 0f);
offsets[numComponents - 1] = offsetFloat;
return offset(image, scales, offsets);
}
/**
* Offsets an image's alpha component by a given percentage.
*
* @param image The image to be made more or less transparent.
* @param percentage The ratio to modify the image's alpha component with.
* Values above 1 will increase transparency, and values below 1 will decrease
* transparency.
* @return The given image with its alpha component scaled by the given percentage.
*/
public static BufferedImage alphaOffset(final BufferedImage image, final float percentage)
{
final int numComponents = image.getColorModel().getNumComponents();
final float[] scales = new float[numComponents];
final float[] offsets = new float[numComponents];
Arrays.fill(scales, 1f);
Arrays.fill(offsets, 0f);
scales[numComponents - 1] = percentage;
return offset(image, scales, offsets);
}
/**
* Creates a grayscale image from the given image.
*
* @param image The source image to be converted.
* @return A copy of the given imnage, with colors converted to grayscale.
*/
public static BufferedImage grayscaleImage(final BufferedImage image)
{
final Image grayImage = GrayFilter.createDisabledImage(image);
return ImageUtil.bufferedImageFromImage(grayImage);
}
/**
* Re-size a BufferedImage to the given dimensions.
*
* @param image the BufferedImage.
* @param newWidth The width to set the BufferedImage to.
* @param newHeight The height to set the BufferedImage to.
* @return The BufferedImage with the specified dimensions
*/
public static BufferedImage resizeImage(final BufferedImage image, final int newWidth, final int newHeight)
{
final Image resized = image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
return ImageUtil.bufferedImageFromImage(resized);
}
/**
* Re-size a BufferedImage's canvas to the given dimensions.
*
* @param image The image whose canvas should be re-sized.
* @param newWidth The width to set the BufferedImage to.
* @param newHeight The height to set the BufferedImage to.
* @return The BufferedImage centered within canvas of given dimensions.
*/
public static BufferedImage resizeCanvas(final BufferedImage image, final int newWidth, final int newHeight)
{
final BufferedImage dimg = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
final int centeredX = newWidth / 2 - image.getWidth() / 2;
final int centeredY = newHeight / 2 - image.getHeight() / 2;
final Graphics2D g2d = dimg.createGraphics();
g2d.drawImage(image, centeredX, centeredY, null);
g2d.dispose();
return dimg;
}
/**
* Rotates an image around its center by a given number of radians.
*
* @param image The image to be rotated.
* @param theta The number of radians to rotate the image.
* @return The given image, rotated by the given theta.
*/
public static BufferedImage rotateImage(final BufferedImage image, final double theta)
{
AffineTransform transform = new AffineTransform();
transform.rotate(theta, image.getWidth() / 2.0, image.getHeight() / 2.0);
AffineTransformOp transformOp = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
return transformOp.filter(image, null);
}
/**
* Flips an image horizontally and/or vertically.
*
* @param image The image to be flipped.
* @param horizontal Whether the image should be flipped horizontally.
* @param vertical Whether the image should be flipped vertically.
* @return The given image, flipped horizontally and/or vertically.
*/
public static BufferedImage flipImage(final BufferedImage image, final boolean horizontal, final boolean vertical)
{
int x = 0;
int y = 0;
int w = image.getWidth();
int h = image.getHeight();
final BufferedImage out = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = out.createGraphics();
if (horizontal)
{
x = w;
w *= -1;
}
if (vertical)
{
y = h;
h *= -1;
}
g2d.drawImage(image, x, y, w, h, null);
g2d.dispose();
return out;
}
/**
* Outlines non-transparent pixels of a BufferedImage with the given color.
*
* @param image The image to be outlined.
* @param color The color to use for the outline.
* @return The BufferedImage with its edges outlined with the given color.
*/
public static BufferedImage outlineImage(final BufferedImage image, final Color color)
{
return outlineImage(image, color, ColorUtil::isNotFullyTransparent, false);
}
/**
* Outlines pixels of a BufferedImage with the given color, using a given predicate to colorize
* the given image for outlining.
*
* @param image The image to be outlined.
* @param color The color to use for the outline.
* @param fillCondition The predicate to be consumed by {@link #fillImage(BufferedImage, Color, Predicate) fillImage(BufferedImage, Color, Predicate)}
* @return The BufferedImage with its edges outlined with the given color.
*/
public static BufferedImage outlineImage(final BufferedImage image, final Color color, final Predicate<Color> fillCondition)
{
return outlineImage(image, color, fillCondition, false);
}
/**
* Outlines non-transparent pixels of a BufferedImage with the given color. Optionally outlines
* corners in addition to edges.
*
* @param image The image to be outlined.
* @param color The color to use for the outline.
* @param outlineCorners Whether to draw an outline around corners, or only around edges.
* @return The BufferedImage with its edges--and optionally, corners--outlined
* with the given color.
*/
public static BufferedImage outlineImage(final BufferedImage image, final Color color, final Boolean outlineCorners)
{
return outlineImage(image, color, ColorUtil::isNotFullyTransparent, outlineCorners);
}
/**
* Outlines pixels of a BufferedImage with the given color, using a given predicate to colorize
* the given image for outlining. Optionally outlines corners in addition to edges.
*
* @param image The image to be outlined.
* @param color The color to use for the outline.
* @param fillCondition The predicate to be consumed by {@link #fillImage(BufferedImage, Color, Predicate) fillImage(BufferedImage, Color, Predicate)}
* @param outlineCorners Whether to draw an outline around corners, or only around edges.
* @return The BufferedImage with its edges--and optionally, corners--outlined
* with the given color.
*/
public static BufferedImage outlineImage(final BufferedImage image, final Color color, final Predicate<Color> fillCondition, final Boolean outlineCorners)
{
final BufferedImage filledImage = fillImage(image, color, fillCondition);
final BufferedImage outlinedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = outlinedImage.createGraphics();
for (int x = -1; x <= 1; x++)
{
for (int y = -1; y <= 1; y++)
{
if ((x == 0 && y == 0)
|| (!outlineCorners && Math.abs(x) + Math.abs(y) != 1))
{
continue;
}
g2d.drawImage(filledImage, x, y, null);
}
}
g2d.drawImage(image, 0, 0, null);
g2d.dispose();
return outlinedImage;
}
/**
* Reads an image resource from a given path relative to a given class.
* This method is primarily shorthand for the synchronization and error handling required for
* loading image resources from classes.
*
* @param c The class to be referenced for resource path.
* @param path The path, relative to the given class.
* @return A {@link BufferedImage} of the loaded image resource from the given path.
*/
public static BufferedImage getResourceStreamFromClass(final Class c, final String path)
{
try
{
synchronized (ImageIO.class)
{
return ImageIO.read(c.getResourceAsStream(path));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
/**
* Fills all non-transparent pixels of the given image with the given color.
*
* @param image The image which should have its non-transparent pixels filled.
* @param color The color with which to fill pixels.
* @return The given image with all non-transparent pixels set to the given color.
*/
static BufferedImage fillImage(final BufferedImage image, final Color color)
{
return fillImage(image, color, ColorUtil::isNotFullyTransparent);
}
/**
* Fills pixels of the given image with the given color based on a given fill condition
* predicate.
*
* @param image The image which should have its non-transparent pixels filled.
* @param color The color with which to fill pixels.
* @param fillCondition The condition on which to fill pixels with the given color.
* @return The given image with all pixels fulfilling the fill condition predicate
* set to the given color.
*/
static BufferedImage fillImage(final BufferedImage image, final Color color, final Predicate<Color> fillCondition)
{
final BufferedImage filledImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < filledImage.getWidth(); x++)
{
for (int y = 0; y < filledImage.getHeight(); y++)
{
final Color pixelColor = new Color(image.getRGB(x, y), true);
if (!fillCondition.test(pixelColor))
{
continue;
}
filledImage.setRGB(x, y, color.getRGB());
}
}
return filledImage;
}
/**
* Performs a rescale operation on the image's color components.
*
* @param image The image to be adjusted.
* @param scales An array of scale operations to be performed on the image's color components.
* @param offsets An array of offset operations to be performed on the image's color components.
* @return The modified image after applying the given adjustments.
*/
private static BufferedImage offset(final BufferedImage image, final float[] scales, final float[] offsets)
{
return new RescaleOp(scales, offsets, null).filter(image, null);
}
}

View File

@@ -29,10 +29,8 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
@@ -42,8 +40,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.image.LookupOp;
import java.awt.image.LookupTable;
import java.util.Enumeration;
import java.util.concurrent.Callable;
import java.util.function.BiConsumer;
@@ -106,40 +102,6 @@ public class SwingUtil
System.setProperty("sun.awt.noerasebackground", "true");
}
/**
* Offsets an image in the grayscale (darkens/brightens) by an offset
*/
public static BufferedImage grayscaleOffset(BufferedImage image, int offset)
{
int numComponents = image.getColorModel().getNumComponents();
int index = numComponents - 1;
LookupTable lookup = new LookupTable(0, numComponents)
{
@Override
public int[] lookupPixel(int[] src, int[] dest)
{
if (dest[index] != 0)
{
dest[index] = dest[index] + offset;
if (dest[index] < 0)
{
dest[index] = 0;
}
else if (dest[index] > 255)
{
dest[index] = 255;
}
}
return dest;
}
};
LookupOp op = new LookupOp(lookup, new RenderingHints(null));
return op.filter(image, null);
}
/**
* Safely sets Swing theme
*
@@ -280,25 +242,6 @@ public class SwingUtil
});
}
/**
* Re-size a BufferedImage to the given dimensions.
*
* @param image the BufferedImage.
* @param newWidth The width to set the BufferedImage to.
* @param newHeight The height to set the BufferedImage to.
* @return The BufferedImage with the specified dimensions
*/
private static BufferedImage resizeImage(BufferedImage image, int newWidth, int newHeight)
{
final Image tmp = image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
final BufferedImage dimg = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = dimg.createGraphics();
g2d.drawImage(tmp, 0, 0, null);
g2d.dispose();
return dimg;
}
/**
* Create swing button from navigation button.
*
@@ -314,7 +257,7 @@ public class SwingUtil
{
final BufferedImage scaledImage = iconSize > 0
? resizeImage(navigationButton.getIcon(), iconSize, iconSize)
? ImageUtil.resizeImage(navigationButton.getIcon(), iconSize, iconSize)
: navigationButton.getIcon();
final JButton button = new JButton();
@@ -364,5 +307,4 @@ public class SwingUtil
{
return SubstanceCoreUtilities.getTitlePaneComponent(frame) != null;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 742 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Some files were not shown because too many files have changed in this diff Show More