Merge pull request #851 from f0rmatme/fonts

runelite: font update
This commit is contained in:
Tyler Bochard
2019-07-02 03:06:46 -04:00
committed by GitHub
52 changed files with 459 additions and 171 deletions

View File

@@ -29,6 +29,7 @@ import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.File; import java.io.File;
@@ -66,6 +67,7 @@ import net.runelite.client.RuneLite;
import static net.runelite.client.RuneLite.PROFILES_DIR; import static net.runelite.client.RuneLite.PROFILES_DIR;
import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.EventBus;
import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ColorUtil;
import net.runelite.client.ui.FontManager;
@Singleton @Singleton
@Slf4j @Slf4j
@@ -508,6 +510,10 @@ public class ConfigManager
{ {
return Enum.valueOf((Class<? extends Enum>) type, str); return Enum.valueOf((Class<? extends Enum>) type, str);
} }
if (type == Font.class)
{
return FontManager.getFontOrDefault(FontManager.lookupFont(str));
}
if (type == Instant.class) if (type == Instant.class)
{ {
return Instant.parse(str); return Instant.parse(str);
@@ -564,6 +570,10 @@ public class ConfigManager
{ {
return ((Enum) object).name(); return ((Enum) object).name();
} }
if (object instanceof Font)
{
return FontManager.getFontName((Font)object);
}
if (object instanceof Dimension) if (object instanceof Dimension)
{ {
Dimension d = (Dimension) object; Dimension d = (Dimension) object;

View File

@@ -24,21 +24,18 @@
*/ */
package net.runelite.client.config; package net.runelite.client.config;
import java.awt.Font;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.runelite.client.ui.FontManager;
@Getter @Getter
@RequiredArgsConstructor @RequiredArgsConstructor
public enum FontType public enum FontType
{ {
REGULAR("Regular", FontManager.getRunescapeFont()), REGULAR("Regular"),
BOLD("Bold", FontManager.getRunescapeBoldFont()), BOLD("Bold"),
SMALL("Small", FontManager.getRunescapeSmallFont()); SMALL("Small");
private final String name; private final String name;
private final Font font;
@Override @Override
public String toString() public String toString()

View File

@@ -25,7 +25,9 @@
package net.runelite.client.config; package net.runelite.client.config;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import net.runelite.api.Constants; import net.runelite.api.Constants;
import net.runelite.client.ui.FontManager;
@ConfigGroup("runelite") @ConfigGroup("runelite")
public interface RuneLiteConfig extends Config public interface RuneLiteConfig extends Config
@@ -207,6 +209,17 @@ public interface RuneLiteConfig extends Config
return false; return false;
} }
@ConfigItem(
keyName = "clientFont",
name = "Font",
description = "Configure what font is used for the client and runelite added overlays",
position = 29
)
default Font clientFont()
{
return FontManager.getRunescapeFont();
}
@ConfigItem( @ConfigItem(
keyName = "fontType", keyName = "fontType",
name = "Dynamic Overlay Font", name = "Dynamic Overlay Font",

View File

@@ -33,6 +33,7 @@ import java.awt.Dimension;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Font;
import java.awt.event.FocusAdapter; import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
@@ -99,6 +100,7 @@ import net.runelite.client.plugins.PluginManager;
import net.runelite.client.plugins.PluginType; import net.runelite.client.plugins.PluginType;
import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.DynamicGridLayout; import net.runelite.client.ui.DynamicGridLayout;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.PluginPanel; import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.ComboBoxListRenderer; import net.runelite.client.ui.components.ComboBoxListRenderer;
import net.runelite.client.ui.components.IconButton; import net.runelite.client.ui.components.IconButton;
@@ -999,6 +1001,36 @@ public class ConfigPanel extends PluginPanel
item.add(button, BorderLayout.EAST); item.add(button, BorderLayout.EAST);
} }
if (cid.getType() == Font.class)
{
JComboBox box = new JComboBox(FontManager.getAvailableFontNames());
box.setPreferredSize(new Dimension(150, 25));
box.setRenderer(new ComboBoxListRenderer());
box.setForeground(Color.WHITE);
box.setFocusable(false);
String currentlyConfigured = configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName());
if (FontManager.lookupFont(currentlyConfigured) != null)
{
box.setSelectedItem(currentlyConfigured);
box.setToolTipText(currentlyConfigured);
}
else
{
log.debug("Selected font wasn't found on this system, resetting font back to runescape regular");
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), FontManager.getRunescapeFont());
}
box.addItemListener(e ->
{
if (e.getStateChange() == ItemEvent.SELECTED && box.getSelectedItem() != null)
{
final Font selected = FontManager.lookupFont(box.getSelectedItem().toString());
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), selected);
box.setToolTipText(box.getSelectedItem().toString());
}
});
item.add(box, BorderLayout.EAST);
}
mainPanel.add(item); mainPanel.add(item);
} }
} }

View File

@@ -27,7 +27,6 @@ package net.runelite.client.plugins.devtools;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Polygon; import java.awt.Polygon;
@@ -63,7 +62,6 @@ import net.runelite.api.coords.LocalPoint;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem; import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
@@ -77,7 +75,6 @@ class DevToolsOverlay extends Overlay
private static final int ITEM_EMPTY = 6512; private static final int ITEM_EMPTY = 6512;
private static final int ITEM_FILLED = 20594; private static final int ITEM_FILLED = 20594;
private static final Font FONT = FontManager.getRunescapeFont().deriveFont(Font.BOLD, 16);
private static final Color RED = new Color(221, 44, 0); private static final Color RED = new Color(221, 44, 0);
private static final Color GREEN = new Color(0, 200, 83); private static final Color GREEN = new Color(0, 200, 83);
private static final Color TURQOISE = new Color(0, 200, 157); private static final Color TURQOISE = new Color(0, 200, 157);
@@ -115,7 +112,6 @@ class DevToolsOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
graphics.setFont(FONT);
if (plugin.getPlayers().isActive()) if (plugin.getPlayers().isActive())
{ {
@@ -398,7 +394,7 @@ class DevToolsOverlay extends Overlay
Rectangle2D textBounds = fm.getStringBounds(idText, graphics); Rectangle2D textBounds = fm.getStringBounds(idText, graphics);
int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2));
int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2)); int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (fm.getHeight() / 2) - fm.getMaxDescent());
graphics.setColor(new Color(255, 255, 255, 65)); graphics.setColor(new Color(255, 255, 255, 65));
graphics.fill(slotBounds); graphics.fill(slotBounds);
@@ -540,7 +536,7 @@ class DevToolsOverlay extends Overlay
Rectangle2D textBounds = fm.getStringBounds(text, graphics); Rectangle2D textBounds = fm.getStringBounds(text, graphics);
int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2));
int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2)); int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (fm.getHeight() / 2) - fm.getMaxDescent());
graphics.setColor(Color.BLACK); graphics.setColor(Color.BLACK);
graphics.drawString(text, textX + 1, textY + 1); graphics.drawString(text, textX + 1, textY + 1);

View File

@@ -193,7 +193,7 @@ class VarInspector extends JFrame
{ {
lastTick = tick; lastTick = tick;
JLabel header = new JLabel("Tick " + tick); JLabel header = new JLabel("Tick " + tick);
header.setFont(FontManager.getRunescapeSmallFont()); header.setFont(FontManager.getSmallFont(getFont()));
header.setBorder(new CompoundBorder( header.setBorder(new CompoundBorder(
BorderFactory.createMatteBorder(0, 0, 1, 0, ColorScheme.LIGHT_GRAY_COLOR), BorderFactory.createMatteBorder(0, 0, 1, 0, ColorScheme.LIGHT_GRAY_COLOR),
BorderFactory.createEmptyBorder(3, 6, 0, 0) BorderFactory.createEmptyBorder(3, 6, 0, 0)

View File

@@ -221,14 +221,14 @@ class FeedPanel extends PluginPanel
Color darkerForeground = UIManager.getColor("Label.foreground").darker(); Color darkerForeground = UIManager.getColor("Label.foreground").darker();
JLabel titleLabel = new JLabel(item.getTitle()); JLabel titleLabel = new JLabel(item.getTitle());
titleLabel.setFont(FontManager.getRunescapeSmallFont()); titleLabel.setFont(FontManager.getSmallFont(getFont()));
titleLabel.setBackground(null); titleLabel.setBackground(null);
titleLabel.setForeground(darkerForeground); titleLabel.setForeground(darkerForeground);
titleLabel.setPreferredSize(new Dimension(CONTENT_WIDTH - TIME_WIDTH, 0)); titleLabel.setPreferredSize(new Dimension(CONTENT_WIDTH - TIME_WIDTH, 0));
Duration duration = Duration.between(Instant.ofEpochMilli(item.getTimestamp()), Instant.now()); Duration duration = Duration.between(Instant.ofEpochMilli(item.getTimestamp()), Instant.now());
JLabel timeLabel = new JLabel(durationToString(duration)); JLabel timeLabel = new JLabel(durationToString(duration));
timeLabel.setFont(FontManager.getRunescapeSmallFont()); timeLabel.setFont(FontManager.getSmallFont(getFont()));
timeLabel.setForeground(darkerForeground); timeLabel.setForeground(darkerForeground);
titleAndTime.add(titleLabel, BorderLayout.WEST); titleAndTime.add(titleLabel, BorderLayout.WEST);
@@ -237,9 +237,9 @@ class FeedPanel extends PluginPanel
JPanel content = new JPanel(new BorderLayout()); JPanel content = new JPanel(new BorderLayout());
content.setBackground(null); content.setBackground(null);
JLabel contentLabel = new JLabel(lineBreakText(item.getContent(), FontManager.getRunescapeSmallFont())); JLabel contentLabel = new JLabel(lineBreakText(item.getContent(), FontManager.getSmallFont(getFont())));
contentLabel.setBorder(new EmptyBorder(2, 0, 0, 0)); contentLabel.setBorder(new EmptyBorder(2, 0, 0, 0));
contentLabel.setFont(FontManager.getRunescapeSmallFont()); contentLabel.setFont(FontManager.getSmallFont(getFont()));
contentLabel.setForeground(darkerForeground); contentLabel.setForeground(darkerForeground);
content.add(contentLabel, BorderLayout.CENTER); content.add(contentLabel, BorderLayout.CENTER);

View File

@@ -131,11 +131,11 @@ public class GrandExchangeOfferSlot extends JPanel
itemName.setForeground(Color.WHITE); itemName.setForeground(Color.WHITE);
itemName.setVerticalAlignment(JLabel.BOTTOM); itemName.setVerticalAlignment(JLabel.BOTTOM);
itemName.setFont(FontManager.getRunescapeSmallFont()); itemName.setFont(FontManager.getSmallFont(getFont()));
offerInfo.setForeground(ColorScheme.LIGHT_GRAY_COLOR); offerInfo.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
offerInfo.setVerticalAlignment(JLabel.TOP); offerInfo.setVerticalAlignment(JLabel.TOP);
offerInfo.setFont(FontManager.getRunescapeSmallFont()); offerInfo.setFont(FontManager.getSmallFont(getFont()));
JLabel switchFaceViewIcon = new JLabel(); JLabel switchFaceViewIcon = new JLabel();
switchFaceViewIcon.setIcon(RIGHT_ARROW_ICON); switchFaceViewIcon.setIcon(RIGHT_ARROW_ICON);
@@ -162,11 +162,11 @@ public class GrandExchangeOfferSlot extends JPanel
itemPrice.setForeground(Color.WHITE); itemPrice.setForeground(Color.WHITE);
itemPrice.setVerticalAlignment(JLabel.BOTTOM); itemPrice.setVerticalAlignment(JLabel.BOTTOM);
itemPrice.setFont(FontManager.getRunescapeSmallFont()); itemPrice.setFont(FontManager.getSmallFont(getFont()));
offerSpent.setForeground(Color.WHITE); offerSpent.setForeground(Color.WHITE);
offerSpent.setVerticalAlignment(JLabel.TOP); offerSpent.setVerticalAlignment(JLabel.TOP);
offerSpent.setFont(FontManager.getRunescapeSmallFont()); offerSpent.setFont(FontManager.getSmallFont(getFont()));
JLabel switchDetailsViewIcon = new JLabel(); JLabel switchDetailsViewIcon = new JLabel();
switchDetailsViewIcon.setIcon(LEFT_ARROW_ICON); switchDetailsViewIcon.setIcon(LEFT_ARROW_ICON);

View File

@@ -26,6 +26,7 @@
package net.runelite.client.plugins.grounditems; package net.runelite.client.plugins.grounditems;
import java.awt.Color; import java.awt.Color;
import net.runelite.client.config.Alpha;
import net.runelite.client.config.Config; import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
@@ -57,6 +58,7 @@ public interface GroundItemsConfig extends Config
position = 2, position = 2,
parent = "colorsStub" parent = "colorsStub"
) )
@Alpha
default Color defaultColor() default Color defaultColor()
{ {
return Color.WHITE; return Color.WHITE;
@@ -69,6 +71,7 @@ public interface GroundItemsConfig extends Config
position = 3, position = 3,
parent = "colorsStub" parent = "colorsStub"
) )
@Alpha
default Color highlightedColor() default Color highlightedColor()
{ {
return Color.decode("#AA00FF"); return Color.decode("#AA00FF");
@@ -81,6 +84,7 @@ public interface GroundItemsConfig extends Config
position = 4, position = 4,
parent = "colorsStub" parent = "colorsStub"
) )
@Alpha
default Color hiddenColor() default Color hiddenColor()
{ {
return Color.GRAY; return Color.GRAY;
@@ -319,6 +323,7 @@ public interface GroundItemsConfig extends Config
position = 23, position = 23,
parent = "lowValueStub" parent = "lowValueStub"
) )
@Alpha
default Color lowValueColor() default Color lowValueColor()
{ {
return Color.decode("#66B2FF"); return Color.decode("#66B2FF");
@@ -366,6 +371,7 @@ public interface GroundItemsConfig extends Config
position = 27, position = 27,
parent = "mediumValueStub" parent = "mediumValueStub"
) )
@Alpha
default Color mediumValueColor() default Color mediumValueColor()
{ {
return Color.decode("#99FF99"); return Color.decode("#99FF99");
@@ -413,6 +419,7 @@ public interface GroundItemsConfig extends Config
position = 31, position = 31,
parent = "highValueStub" parent = "highValueStub"
) )
@Alpha
default Color highValueColor() default Color highValueColor()
{ {
return Color.decode("#FF9600"); return Color.decode("#FF9600");
@@ -460,6 +467,7 @@ public interface GroundItemsConfig extends Config
position = 35, position = 35,
parent = "insaneValueStub" parent = "insaneValueStub"
) )
@Alpha
default Color insaneValueColor() default Color insaneValueColor()
{ {
return Color.decode("#FF66B2"); return Color.decode("#FF66B2");
@@ -618,4 +626,16 @@ public interface GroundItemsConfig extends Config
{ {
return false; return false;
} }
@Alpha
@ConfigItem(
keyName = "bordercolor",
name = "Border color",
description = "Change the border color",
position = 49
)
default Color bordercolor()
{
return new Color(0, 0, 0, 150);
}
} }

View File

@@ -109,8 +109,6 @@ public class GroundItemsOverlay extends Overlay
{ {
return null; return null;
} }
final FontMetrics fm = graphics.getFontMetrics();
final Player player = client.getLocalPlayer(); final Player player = client.getLocalPlayer();
if (player == null || client.getViewportWidget() == null) if (player == null || client.getViewportWidget() == null)
@@ -118,6 +116,8 @@ public class GroundItemsOverlay extends Overlay
return null; return null;
} }
final FontMetrics fm = graphics.getFontMetrics();
offsetMap.clear(); offsetMap.clear();
final LocalPoint localLocation = player.getLocalLocation(); final LocalPoint localLocation = player.getLocalLocation();
final Point mousePos = client.getMouseCanvasPosition(); final Point mousePos = client.getMouseCanvasPosition();
@@ -319,14 +319,14 @@ public class GroundItemsOverlay extends Overlay
// Item bounds // Item bounds
int x = textX - 2; int x = textX - 2;
int y = textY - stringHeight - 2; int y = textY - stringHeight - 2 + fm.getMaxDescent();
int width = stringWidth + 4; int width = stringWidth + 4;
int height = stringHeight + 4; int height = stringHeight + 4;
final Rectangle itemBounds = new Rectangle(x, y, width, height); final Rectangle itemBounds = new Rectangle(x, y, width, height);
// Hidden box // Hidden box
x += width + 2; x += width + 2;
y = textY - (RECTANGLE_SIZE + stringHeight) / 2; y = textY - (fm.getMaxAscent() + RECTANGLE_SIZE) / 2;
width = height = RECTANGLE_SIZE; width = height = RECTANGLE_SIZE;
final Rectangle itemHiddenBox = new Rectangle(x, y, width, height); final Rectangle itemHiddenBox = new Rectangle(x, y, width, height);
@@ -376,7 +376,8 @@ public class GroundItemsOverlay extends Overlay
if (config.toggleOutline()) if (config.toggleOutline())
{ {
graphics.setColor(Color.BLACK); final Color bordercolor = config.bordercolor();
graphics.setColor(bordercolor);
graphics.drawString(itemString, textX + 1, textY + 1); graphics.drawString(itemString, textX + 1, textY + 1);
graphics.drawString(itemString, textX - 1, textY - 1); graphics.drawString(itemString, textX - 1, textY - 1);
graphics.drawString(itemString, textX - 1, textY + 1); graphics.drawString(itemString, textX - 1, textY + 1);
@@ -388,7 +389,6 @@ public class GroundItemsOverlay extends Overlay
textComponent.setPosition(new java.awt.Point(textX, textY)); textComponent.setPosition(new java.awt.Point(textX, textY));
textComponent.render(graphics); textComponent.render(graphics);
} }
return null; return null;
} }

View File

@@ -124,6 +124,7 @@ public class GroundItemsPlugin extends Plugin
private static final int EXAMINE_ITEM = MenuAction.EXAMINE_ITEM_GROUND.getId(); private static final int EXAMINE_ITEM = MenuAction.EXAMINE_ITEM_GROUND.getId();
private static final int WALK = MenuAction.WALK.getId(); private static final int WALK = MenuAction.WALK.getId();
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
private Map.Entry<Rectangle, GroundItem> textBoxBounds; private Map.Entry<Rectangle, GroundItem> textBoxBounds;

View File

@@ -295,7 +295,7 @@ public class HiscorePanel extends PluginPanel
private JPanel makeSkillPanel(HiscoreSkill skill) private JPanel makeSkillPanel(HiscoreSkill skill)
{ {
JLabel label = new JLabel(); JLabel label = new JLabel();
label.setFont(FontManager.getRunescapeSmallFont()); label.setFont(FontManager.getSmallFont(getFont()));
label.setText("--"); label.setText("--");
String skillName = (skill == null ? "combat" : skill.getName().toLowerCase()); String skillName = (skill == null ? "combat" : skill.getName().toLowerCase());

View File

@@ -115,7 +115,7 @@ public class InfoPanel extends PluginPanel
versionPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); versionPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
versionPanel.setLayout(new GridLayout(0, 1)); versionPanel.setLayout(new GridLayout(0, 1));
final Font smallFont = FontManager.getRunescapeSmallFont(); final Font smallFont = FontManager.getSmallFont(getFont());
JLabel version = new JLabel(htmlLabel("RuneLite version: ", runeLiteProperties.getVersion())); JLabel version = new JLabel(htmlLabel("RuneLite version: ", runeLiteProperties.getVersion()));
version.setFont(smallFont); version.setFont(smallFont);
@@ -191,7 +191,7 @@ public class InfoPanel extends PluginPanel
/** /**
* Builds a link panel with a given icon, text and url to redirect to. * Builds a link panel with a given icon, text and url to redirect to.
*/ */
private static JPanel buildLinkPanel(ImageIcon icon, String topText, String bottomText, String url) private JPanel buildLinkPanel(ImageIcon icon, String topText, String bottomText, String url)
{ {
return buildLinkPanel(icon, topText, bottomText, () -> LinkBrowser.browse(url)); return buildLinkPanel(icon, topText, bottomText, () -> LinkBrowser.browse(url));
} }
@@ -199,7 +199,7 @@ public class InfoPanel extends PluginPanel
/** /**
* Builds a link panel with a given icon, text and callable to call. * Builds a link panel with a given icon, text and callable to call.
*/ */
private static JPanel buildLinkPanel(ImageIcon icon, String topText, String bottomText, Runnable callback) private JPanel buildLinkPanel(ImageIcon icon, String topText, String bottomText, Runnable callback)
{ {
JPanel container = new JPanel(); JPanel container = new JPanel();
container.setBackground(ColorScheme.DARKER_GRAY_COLOR); container.setBackground(ColorScheme.DARKER_GRAY_COLOR);
@@ -253,11 +253,11 @@ public class InfoPanel extends PluginPanel
JLabel topLine = new JLabel(topText); JLabel topLine = new JLabel(topText);
topLine.setForeground(Color.WHITE); topLine.setForeground(Color.WHITE);
topLine.setFont(FontManager.getRunescapeSmallFont()); topLine.setFont(FontManager.getSmallFont(getFont()));
JLabel bottomLine = new JLabel(bottomText); JLabel bottomLine = new JLabel(bottomText);
bottomLine.setForeground(Color.WHITE); bottomLine.setForeground(Color.WHITE);
bottomLine.setFont(FontManager.getRunescapeSmallFont()); bottomLine.setFont(FontManager.getSmallFont(getFont()));
textContainer.add(topLine); textContainer.add(topLine);
textContainer.add(bottomLine); textContainer.add(bottomLine);

View File

@@ -166,7 +166,7 @@ class ItemChargeOverlay extends WidgetItemOverlay
final Rectangle bounds = itemWidget.getCanvasBounds(); final Rectangle bounds = itemWidget.getCanvasBounds();
final TextComponent textComponent = new TextComponent(); final TextComponent textComponent = new TextComponent();
textComponent.setPosition(new Point(bounds.x - 1, bounds.y + 15)); textComponent.setPosition(new Point(bounds.x, bounds.y + 1 + graphics.getFontMetrics().getMaxAscent() - graphics.getFontMetrics().getMaxDescent()));
textComponent.setText(charges < 0 ? "?" : String.valueOf(charges)); textComponent.setText(charges < 0 ? "?" : String.valueOf(charges));
textComponent.setColor(itemChargePlugin.getColor(charges)); textComponent.setColor(itemChargePlugin.getColor(charges));
textComponent.render(graphics); textComponent.render(graphics);

View File

@@ -47,7 +47,7 @@ class BookPanel extends JPanel
JLabel image = new JLabel(); JLabel image = new JLabel();
b.getIcon().addTo(image); b.getIcon().addTo(image);
JLabel name = new JLabel(b.getShortName()); JLabel name = new JLabel(b.getShortName());
location.setFont(FontManager.getRunescapeSmallFont()); location.setFont(FontManager.getSmallFont(getFont()));
layout.setVerticalGroup(layout.createParallelGroup() layout.setVerticalGroup(layout.createParallelGroup()
.addComponent(image) .addComponent(image)

View File

@@ -90,12 +90,12 @@ class LootTrackerBox extends JPanel
logTitle.setBackground(ColorScheme.DARKER_GRAY_COLOR.darker()); logTitle.setBackground(ColorScheme.DARKER_GRAY_COLOR.darker());
final JLabel titleLabel = new JLabel(Text.removeTags(id)); final JLabel titleLabel = new JLabel(Text.removeTags(id));
titleLabel.setFont(FontManager.getRunescapeSmallFont()); titleLabel.setFont(FontManager.getSmallFont(getFont()));
titleLabel.setForeground(Color.WHITE); titleLabel.setForeground(Color.WHITE);
logTitle.add(titleLabel, BorderLayout.WEST); logTitle.add(titleLabel, BorderLayout.WEST);
subTitleLabel.setFont(FontManager.getRunescapeSmallFont()); subTitleLabel.setFont(FontManager.getSmallFont(getFont()));
subTitleLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR); subTitleLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
logTitle.add(subTitleLabel, BorderLayout.CENTER); logTitle.add(subTitleLabel, BorderLayout.CENTER);
@@ -104,7 +104,7 @@ class LootTrackerBox extends JPanel
subTitleLabel.setText(subtitle); subTitleLabel.setText(subtitle);
} }
priceLabel.setFont(FontManager.getRunescapeSmallFont()); priceLabel.setFont(FontManager.getSmallFont(getFont()));
priceLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR); priceLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
logTitle.add(priceLabel, BorderLayout.EAST); logTitle.add(priceLabel, BorderLayout.EAST);

View File

@@ -293,8 +293,8 @@ class LootTrackerPanel extends PluginPanel
overallInfo.setBackground(ColorScheme.DARKER_GRAY_COLOR); overallInfo.setBackground(ColorScheme.DARKER_GRAY_COLOR);
overallInfo.setLayout(new GridLayout(2, 1)); overallInfo.setLayout(new GridLayout(2, 1));
overallInfo.setBorder(new EmptyBorder(2, 10, 2, 0)); overallInfo.setBorder(new EmptyBorder(2, 10, 2, 0));
overallKillsLabel.setFont(FontManager.getRunescapeSmallFont()); overallKillsLabel.setFont(FontManager.getSmallFont(getFont()));
overallGpLabel.setFont(FontManager.getRunescapeSmallFont()); overallGpLabel.setFont(FontManager.getSmallFont(getFont()));
overallInfo.add(overallKillsLabel); overallInfo.add(overallKillsLabel);
overallInfo.add(overallGpLabel); overallInfo.add(overallGpLabel);
overallPanel.add(overallIcon, BorderLayout.WEST); overallPanel.add(overallIcon, BorderLayout.WEST);

View File

@@ -51,7 +51,7 @@ public class MTAInventoryOverlay extends Overlay
{ {
if (room.inside()) if (room.inside())
{ {
graphics.setFont(FontManager.getRunescapeBoldFont()); graphics.setFont(FontManager.getSmallFont(graphics.getFont()));
room.over(graphics); room.over(graphics);
} }
} }

View File

@@ -51,7 +51,7 @@ public class MTASceneOverlay extends Overlay
{ {
if (room.inside()) if (room.inside())
{ {
graphics.setFont(FontManager.getRunescapeFont()); graphics.setFont(FontManager.getSmallFont(graphics.getFont()));
room.under(graphics); room.under(graphics);
} }
} }

View File

@@ -88,6 +88,10 @@ public class RunepouchOverlay extends WidgetItemOverlay
Point location = itemWidget.getCanvasLocation(); Point location = itemWidget.getCanvasLocation();
StringBuilder tooltipBuilder = new StringBuilder(); StringBuilder tooltipBuilder = new StringBuilder();
// location.getY() + graphics.getFontMetrics().getMaxAscent() - graphics.getFontMetrics().getMaxDescent()
// this will draw the character exactly on the border
int yLocation = location.getY() + 1 +
graphics.getFontMetrics().getMaxAscent() - graphics.getFontMetrics().getMaxDescent();
for (int i = 0; i < AMOUNT_VARBITS.length; i++) for (int i = 0; i < AMOUNT_VARBITS.length; i++)
{ {
Varbits amountVarbit = AMOUNT_VARBITS[i]; Varbits amountVarbit = AMOUNT_VARBITS[i];
@@ -117,9 +121,18 @@ public class RunepouchOverlay extends WidgetItemOverlay
continue; continue;
} }
// the reason this is not split up in maxascent and maxdescent to equal the height of the text like it should
// be is because numbers (afaik) dont use font descent so a 1 pixel seperator should be good and give
// consistent results across fonts
int yOffset = (1 + (graphics.getFontMetrics().getMaxAscent()) * i);
graphics.setColor(Color.black); graphics.setColor(Color.black);
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 13 : 6),
yLocation + yOffset);
graphics.setColor(config.fontColor());
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 12 : 5), graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 12 : 5),
location.getY() + 13 + (graphics.getFontMetrics().getHeight() - 1) * i); yLocation + yOffset);
graphics.setColor(config.fontColor()); graphics.setColor(config.fontColor());
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 11 : 4), graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 11 : 4),
@@ -134,7 +147,13 @@ public class RunepouchOverlay extends WidgetItemOverlay
if (image != null) if (image != null)
{ {
OverlayUtil.renderImageLocation(graphics, OverlayUtil.renderImageLocation(graphics,
new Point(location.getX() - 1, location.getY() + graphics.getFontMetrics().getHeight() * i - 1), //TODO :: SEE WHAT ONE IS RIGHT?
//new Point(location.getX() - 1, location.getY() + graphics.getFontMetrics().getMaxAscent() * i - 1),
//image);
//or
//new Point(location.getX(), location.getY() + (1 + graphics.getFontMetrics().getMaxAscent()) * i),
//image);
new Point(location.getX(), location.getY() + (1 + graphics.getFontMetrics().getMaxAscent()) * i),
image); image);
} }
} }

View File

@@ -69,7 +69,7 @@ public class ScreenMarkerCreationPanel extends JPanel
setBorder(new EmptyBorder(8, 8, 8, 8)); setBorder(new EmptyBorder(8, 8, 8, 8));
setLayout(new BorderLayout()); setLayout(new BorderLayout());
instructionsLabel.setFont(FontManager.getRunescapeSmallFont()); instructionsLabel.setFont(FontManager.getSmallFont(getFont()));
instructionsLabel.setForeground(Color.WHITE); instructionsLabel.setForeground(Color.WHITE);
JPanel actionsContainer = new JPanel(new GridLayout(1, 2, 8, 0)); JPanel actionsContainer = new JPanel(new GridLayout(1, 2, 8, 0));

View File

@@ -164,7 +164,7 @@ class ScreenMarkerPanel extends JPanel
nameActions.setBackground(ColorScheme.DARKER_GRAY_COLOR); nameActions.setBackground(ColorScheme.DARKER_GRAY_COLOR);
save.setVisible(false); save.setVisible(false);
save.setFont(FontManager.getRunescapeSmallFont()); save.setFont(FontManager.getSmallFont(getFont()));
save.setForeground(ColorScheme.PROGRESS_COMPLETE_COLOR); save.setForeground(ColorScheme.PROGRESS_COMPLETE_COLOR);
save.addMouseListener(new MouseAdapter() save.addMouseListener(new MouseAdapter()
{ {
@@ -188,7 +188,7 @@ class ScreenMarkerPanel extends JPanel
}); });
cancel.setVisible(false); cancel.setVisible(false);
cancel.setFont(FontManager.getRunescapeSmallFont()); cancel.setFont(FontManager.getSmallFont(getFont()));
cancel.setForeground(ColorScheme.PROGRESS_ERROR_COLOR); cancel.setForeground(ColorScheme.PROGRESS_ERROR_COLOR);
cancel.addMouseListener(new MouseAdapter() cancel.addMouseListener(new MouseAdapter()
{ {
@@ -211,7 +211,7 @@ class ScreenMarkerPanel extends JPanel
} }
}); });
rename.setFont(FontManager.getRunescapeSmallFont()); rename.setFont(FontManager.getSmallFont(getFont()));
rename.setForeground(ColorScheme.LIGHT_GRAY_COLOR.darker()); rename.setForeground(ColorScheme.LIGHT_GRAY_COLOR.darker());
rename.addMouseListener(new MouseAdapter() rename.addMouseListener(new MouseAdapter()
{ {

View File

@@ -252,7 +252,7 @@ class SkillCalculator extends JPanel
JCheckBox uiCheckbox = new JCheckBox(); JCheckBox uiCheckbox = new JCheckBox();
uiLabel.setForeground(Color.WHITE); uiLabel.setForeground(Color.WHITE);
uiLabel.setFont(FontManager.getRunescapeSmallFont()); uiLabel.setFont(FontManager.getSmallFont(getFont()));
uiOption.setBorder(BorderFactory.createEmptyBorder(3, 7, 3, 0)); uiOption.setBorder(BorderFactory.createEmptyBorder(3, 7, 3, 0));
uiOption.setBackground(ColorScheme.DARKER_GRAY_COLOR); uiOption.setBackground(ColorScheme.DARKER_GRAY_COLOR);

View File

@@ -125,7 +125,7 @@ class UIActionSlot extends JPanel
uiLabelName.setForeground(Color.WHITE); uiLabelName.setForeground(Color.WHITE);
uiLabelActions = new JShadowedLabel("Unknown"); uiLabelActions = new JShadowedLabel("Unknown");
uiLabelActions.setFont(FontManager.getRunescapeSmallFont()); uiLabelActions.setFont(FontManager.getSmallFont(getFont()));
uiLabelActions.setForeground(ColorScheme.LIGHT_GRAY_COLOR); uiLabelActions.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
uiInfo.add(uiLabelName); uiInfo.add(uiLabelName);

View File

@@ -123,7 +123,7 @@ class UICalculatorInputArea extends JPanel
uiInput.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR); uiInput.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR);
uiInput.setBorder(new EmptyBorder(5, 7, 5, 7)); uiInput.setBorder(new EmptyBorder(5, 7, 5, 7));
uiLabel.setFont(FontManager.getRunescapeSmallFont()); uiLabel.setFont(FontManager.getSmallFont(getFont()));
uiLabel.setBorder(new EmptyBorder(0, 0, 4, 0)); uiLabel.setBorder(new EmptyBorder(0, 0, 4, 0));
uiLabel.setForeground(Color.WHITE); uiLabel.setForeground(Color.WHITE);

View File

@@ -68,7 +68,7 @@ class UICombinedActionSlot extends JPanel
uiLabelTitle.setForeground(Color.WHITE); uiLabelTitle.setForeground(Color.WHITE);
uiLabelActions = new JShadowedLabel("Shift-click to select multiple"); uiLabelActions = new JShadowedLabel("Shift-click to select multiple");
uiLabelActions.setFont(FontManager.getRunescapeSmallFont()); uiLabelActions.setFont(FontManager.getSmallFont(getFont()));
uiLabelActions.setForeground(ColorScheme.LIGHT_GRAY_COLOR); uiLabelActions.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
uiInfo.add(uiLabelTitle); uiInfo.add(uiLabelTitle);

View File

@@ -117,7 +117,7 @@ class SlayerOverlay extends WidgetItemOverlay
return; return;
} }
graphics.setFont(FontManager.getRunescapeSmallFont()); graphics.setFont(FontManager.getSmallFont(graphics.getFont()));
final Rectangle bounds = itemWidget.getCanvasBounds(); final Rectangle bounds = itemWidget.getCanvasBounds();
final TextComponent textComponent = new TextComponent(); final TextComponent textComponent = new TextComponent();

View File

@@ -106,11 +106,11 @@ class OverviewItemPanel extends JPanel
JLabel titleLabel = new JLabel(title); JLabel titleLabel = new JLabel(title);
titleLabel.setForeground(Color.WHITE); titleLabel.setForeground(Color.WHITE);
titleLabel.setFont(FontManager.getRunescapeSmallFont()); titleLabel.setFont(FontManager.getSmallFont(getFont()));
statusLabel = new JLabel(); statusLabel = new JLabel();
statusLabel.setForeground(Color.GRAY); statusLabel.setForeground(Color.GRAY);
statusLabel.setFont(FontManager.getRunescapeSmallFont()); statusLabel.setFont(FontManager.getSmallFont(getFont()));
textContainer.add(titleLabel); textContainer.add(titleLabel);
textContainer.add(statusLabel); textContainer.add(statusLabel);

View File

@@ -67,10 +67,10 @@ public class TimeablePanel<T> extends JPanel
infoPanel.setBorder(new EmptyBorder(4, 4, 4, 0)); infoPanel.setBorder(new EmptyBorder(4, 4, 4, 0));
final JLabel location = new JShadowedLabel(title); final JLabel location = new JShadowedLabel(title);
location.setFont(FontManager.getRunescapeSmallFont()); location.setFont(FontManager.getSmallFont(getFont()));
location.setForeground(Color.WHITE); location.setForeground(Color.WHITE);
estimate.setFont(FontManager.getRunescapeSmallFont()); estimate.setFont(FontManager.getSmallFont(getFont()));
estimate.setForeground(Color.GRAY); estimate.setForeground(Color.GRAY);
infoPanel.add(location); infoPanel.add(location);

View File

@@ -40,6 +40,7 @@ import net.runelite.client.plugins.timetracking.TimeTrackingPlugin;
import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.DynamicGridLayout; import net.runelite.client.ui.DynamicGridLayout;
import net.runelite.client.ui.FontManager; import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.IconButton; import net.runelite.client.ui.components.IconButton;
import net.runelite.client.ui.components.shadowlabel.JShadowedLabel; import net.runelite.client.ui.components.shadowlabel.JShadowedLabel;
import net.runelite.client.util.ImageUtil; import net.runelite.client.util.ImageUtil;
@@ -97,6 +98,13 @@ public class ClockTabPanel extends TabContentPanel
rebuild(); rebuild();
} }
// The max panel width is 225 but the + sign gets cut off at 225 so we set it at 223
@Override
public Dimension getPreferredSize()
{
return new Dimension(PluginPanel.PANEL_WIDTH - 2, super.getPreferredSize().height);
}
/** /**
* Clears and recreates the components of this panel. * Clears and recreates the components of this panel.
* This should be done whenever a clock is added or removed. * This should be done whenever a clock is added or removed.
@@ -147,7 +155,7 @@ public class ClockTabPanel extends TabContentPanel
JLabel headerLabel = new JLabel(title); JLabel headerLabel = new JLabel(title);
headerLabel.setForeground(Color.WHITE); headerLabel.setForeground(Color.WHITE);
headerLabel.setFont(FontManager.getRunescapeSmallFont()); headerLabel.setFont(FontManager.getSmallFont(getFont()));
panel.add(headerLabel, BorderLayout.CENTER); panel.add(headerLabel, BorderLayout.CENTER);
IconButton addButton = new IconButton(ADD_ICON, ADD_ICON_HOVER); IconButton addButton = new IconButton(ADD_ICON, ADD_ICON_HOVER);
@@ -167,7 +175,7 @@ public class ClockTabPanel extends TabContentPanel
JLabel infoLabel = new JShadowedLabel(text); JLabel infoLabel = new JShadowedLabel(text);
infoLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR.darker()); infoLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR.darker());
infoLabel.setFont(FontManager.getRunescapeSmallFont()); infoLabel.setFont(FontManager.getSmallFont(getFont()));
panel.add(infoLabel); panel.add(infoLabel);
return panel; return panel;

View File

@@ -129,7 +129,7 @@ class StopwatchPanel extends ClockPanel
private JLabel createSmallLabel(String text) private JLabel createSmallLabel(String text)
{ {
JLabel label = new JLabel(text, SwingConstants.CENTER); JLabel label = new JLabel(text, SwingConstants.CENTER);
label.setFont(FontManager.getRunescapeSmallFont()); label.setFont(FontManager.getSmallFont(getFont()));
label.setForeground(LAP_DATA_COLOR); label.setForeground(LAP_DATA_COLOR);
return label; return label;

View File

@@ -94,7 +94,7 @@ public class FarmingTabPanel extends TabContentPanel
groupLabel.setBorder(new EmptyBorder(15, 0, 0, 0)); groupLabel.setBorder(new EmptyBorder(15, 0, 0, 0));
} }
groupLabel.setFont(FontManager.getRunescapeSmallFont()); groupLabel.setFont(FontManager.getSmallFont(getFont()));
add(groupLabel, c); add(groupLabel, c);
c.gridy++; c.gridy++;

View File

@@ -102,7 +102,7 @@ class WorldTableHeader extends JPanel
}); });
textLabel.setText(title); textLabel.setText(title);
textLabel.setFont(FontManager.getRunescapeSmallFont()); textLabel.setFont(FontManager.getSmallFont(getFont()));
final JMenuItem refresh = new JMenuItem("Refresh worlds"); final JMenuItem refresh = new JMenuItem("Refresh worlds");
refresh.addActionListener(e -> refresh.addActionListener(e ->

View File

@@ -271,7 +271,7 @@ class WorldTableRow extends JPanel
column.setBorder(new EmptyBorder(0, 5, 0, 5)); column.setBorder(new EmptyBorder(0, 5, 0, 5));
playerCountField = new JLabel(world.getPlayers() + ""); playerCountField = new JLabel(world.getPlayers() + "");
playerCountField.setFont(FontManager.getRunescapeSmallFont()); playerCountField.setFont(FontManager.getSmallFont(getFont()));
column.add(playerCountField, BorderLayout.WEST); column.add(playerCountField, BorderLayout.WEST);
@@ -300,7 +300,7 @@ class WorldTableRow extends JPanel
column.setBorder(new EmptyBorder(0, 5, 0, 5)); column.setBorder(new EmptyBorder(0, 5, 0, 5));
activityField = new JLabel(world.getActivity()); activityField = new JLabel(world.getActivity());
activityField.setFont(FontManager.getRunescapeSmallFont()); activityField.setFont(FontManager.getSmallFont(getFont()));
column.add(activityField, BorderLayout.WEST); column.add(activityField, BorderLayout.WEST);

View File

@@ -187,7 +187,7 @@ public class XpGlobesOverlay extends Overlay
final FontMetrics metrics = graphics.getFontMetrics(); final FontMetrics metrics = graphics.getFontMetrics();
int drawX = x + (config.xpOrbSize() / 2) - (metrics.stringWidth(progress) / 2); int drawX = x + (config.xpOrbSize() / 2) - (metrics.stringWidth(progress) / 2);
int drawY = y + (config.xpOrbSize() / 2) + (metrics.getHeight() / 2); int drawY = y + (config.xpOrbSize() / 2) + (metrics.getHeight() / 2) - metrics.getMaxDescent();
OverlayUtil.renderTextLocation(graphics, new Point(drawX, drawY), progress, Color.WHITE); OverlayUtil.renderTextLocation(graphics, new Point(drawX, drawY), progress, Color.WHITE);
} }

View File

@@ -175,10 +175,10 @@ class XpInfoBox extends JPanel
statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR); statsPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
statsPanel.setBorder(new EmptyBorder(6, 5, 0, 2)); statsPanel.setBorder(new EmptyBorder(6, 5, 0, 2));
expGained.setFont(FontManager.getRunescapeSmallFont()); expGained.setFont(FontManager.getSmallFont(getFont()));
expHour.setFont(FontManager.getRunescapeSmallFont()); expHour.setFont(FontManager.getSmallFont(getFont()));
expLeft.setFont(FontManager.getRunescapeSmallFont()); expLeft.setFont(FontManager.getSmallFont(getFont()));
actionsLeft.setFont(FontManager.getRunescapeSmallFont()); actionsLeft.setFont(FontManager.getSmallFont(getFont()));
statsPanel.add(expGained); statsPanel.add(expGained);
statsPanel.add(expLeft); statsPanel.add(expLeft);

View File

@@ -113,8 +113,8 @@ class XpPanel extends PluginPanel
overallInfo.setLayout(new GridLayout(2, 1)); overallInfo.setLayout(new GridLayout(2, 1));
overallInfo.setBorder(new EmptyBorder(0, 10, 0, 0)); overallInfo.setBorder(new EmptyBorder(0, 10, 0, 0));
overallExpGained.setFont(FontManager.getRunescapeSmallFont()); overallExpGained.setFont(FontManager.getSmallFont(getFont()));
overallExpHour.setFont(FontManager.getRunescapeSmallFont()); overallExpHour.setFont(FontManager.getSmallFont(getFont()));
overallInfo.add(overallExpGained); overallInfo.add(overallExpGained);
overallInfo.add(overallExpHour); overallInfo.add(overallExpHour);

View File

@@ -24,11 +24,18 @@
*/ */
package net.runelite.client.ui; package net.runelite.client.ui;
import com.google.common.collect.ImmutableBiMap;
import java.awt.Canvas;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.awt.Font; import java.awt.Font;
import java.awt.FontFormatException; import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.io.IOException; import java.io.IOException;
import javax.swing.text.StyleContext; import lombok.Getter;
import net.runelite.client.config.FontType;
public class FontManager public class FontManager
{ {
@@ -36,37 +43,59 @@ public class FontManager
private static final Font runescapeSmallFont; private static final Font runescapeSmallFont;
private static final Font runescapeBoldFont; private static final Font runescapeBoldFont;
@Getter
private static class CachedFont
{
private final Font reg;
private final Font small;
private final Font bold;
private CachedFont(Font f)
{
reg = f.deriveFont(14.0f);
small = getFontOffCorrectSize(f);
bold = f.deriveFont(Font.BOLD, 14.0f);
}
}
private static final ImmutableBiMap<String, Font> fontMap;
private static final HashMap<Font, CachedFont> derivedFontMap = new HashMap<>();
static static
{ {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try try
{ {
Font font = Font.createFont(Font.TRUETYPE_FONT, runescapeFont = Font.createFont(Font.TRUETYPE_FONT,
FontManager.class.getResourceAsStream("runescape.ttf")) FontManager.class.getResourceAsStream("runescape.ttf"))
.deriveFont(Font.PLAIN, 16); .deriveFont(Font.PLAIN, 16);
ge.registerFont(font);
runescapeFont = StyleContext.getDefaultStyleContext() runescapeSmallFont = Font.createFont(Font.TRUETYPE_FONT,
.getFont(font.getName(), Font.PLAIN, 16);
ge.registerFont(runescapeFont);
Font smallFont = Font.createFont(Font.TRUETYPE_FONT,
FontManager.class.getResourceAsStream("runescape_small.ttf")) FontManager.class.getResourceAsStream("runescape_small.ttf"))
.deriveFont(Font.PLAIN, 16); .deriveFont(Font.PLAIN, 16);
ge.registerFont(smallFont);
runescapeSmallFont = StyleContext.getDefaultStyleContext() runescapeBoldFont = Font.createFont(Font.TRUETYPE_FONT,
.getFont(smallFont.getName(), Font.PLAIN, 16);
ge.registerFont(runescapeSmallFont);
Font boldFont = Font.createFont(Font.TRUETYPE_FONT,
FontManager.class.getResourceAsStream("runescape_bold.ttf")) FontManager.class.getResourceAsStream("runescape_bold.ttf"))
.deriveFont(Font.PLAIN, 16); .deriveFont(Font.PLAIN, 16);
ge.registerFont(boldFont);
runescapeBoldFont = StyleContext.getDefaultStyleContext() final LinkedHashMap<String, Font> _fontMap = new LinkedHashMap<>();
.getFont(boldFont.getName(), Font.PLAIN, 16); _fontMap.put("Runescape", runescapeFont);
// Get all available fonts on the system
Font[] availableFonts = ge.getAllFonts();
// build bidirectional map
Arrays.stream(availableFonts).sorted(Comparator.comparing(Font::getFontName)).forEach(f ->
{
if (!_fontMap.containsKey(f.getFontName()))
{
_fontMap.put(f.getFontName(), f);
}
});
fontMap = ImmutableBiMap.copyOf(_fontMap);
ge.registerFont(runescapeFont);
ge.registerFont(runescapeSmallFont);
ge.registerFont(runescapeBoldFont); ge.registerFont(runescapeBoldFont);
} }
catch (FontFormatException ex) catch (FontFormatException ex)
@@ -79,6 +108,25 @@ public class FontManager
} }
} }
public static Font getFontOffCorrectSize(Font f)
{
// Size of the font is already set
if (f.getSize2D() > 1)
{
return f;
}
// Dummy canvas for font metrics
Canvas c = new Canvas();
f = f.deriveFont(12f);
if (c.getFontMetrics(f).getMaxAscent() > 11)
{
f = f.deriveFont(11f);
}
return f;
}
public static Font getRunescapeFont() public static Font getRunescapeFont()
{ {
return runescapeFont; return runescapeFont;
@@ -93,4 +141,93 @@ public class FontManager
{ {
return runescapeBoldFont; return runescapeBoldFont;
} }
}
private static boolean isRunescapeFont(Font f)
{
return f.equals(runescapeFont) || f.equals(runescapeSmallFont) || f.equals(runescapeBoldFont);
}
public static Font getSmallFont(Font f)
{
if (isRunescapeFont(f))
{
return runescapeSmallFont;
}
if (derivedFontMap.containsKey(f))
{
return derivedFontMap.get(f).getSmall();
}
// cache and return
CachedFont cachedFont = new CachedFont(f);
derivedFontMap.put(f, cachedFont);
return cachedFont.getSmall();
}
public static Font getFontFromType(Font f, FontType type)
{
switch (type)
{
case SMALL:
return getSmallFont(f);
case BOLD:
if (isRunescapeFont(f))
{
return runescapeBoldFont;
}
if (derivedFontMap.containsKey(f))
{
return derivedFontMap.get(f).getBold();
}
// cache and return
CachedFont cachedBoldFont = new CachedFont(f);
derivedFontMap.put(f, cachedBoldFont);
return cachedBoldFont.getBold();
default: //in this case regular
if (isRunescapeFont(f))
{
return runescapeFont;
}
if (derivedFontMap.containsKey(f))
{
return derivedFontMap.get(f).getReg();
}
// cache and return
CachedFont cachedFont = new CachedFont(f);
derivedFontMap.put(f, cachedFont);
return cachedFont.getReg();
}
}
public static Font lookupFont(String fontName)
{
return fontMap.get(fontName);
}
public static String getFontName(Font font)
{
return fontMap.inverse().get(font);
}
public static String[] getAvailableFontNames()
{
return fontMap.keySet().toArray(new String[fontMap.keySet().size()]);
}
public static boolean isAvailable(Font font)
{
return fontMap.containsKey(font.getFontName());
}
public static Font getFontOrDefault(Font font)
{
if (font == null || !fontMap.containsKey(font.getFontName()))
{
return getRunescapeFont();
}
return getFontOffCorrectSize(font);
}
}

View File

@@ -52,7 +52,7 @@ public class PluginErrorPanel extends JPanel
noResultsTitle.setForeground(Color.WHITE); noResultsTitle.setForeground(Color.WHITE);
noResultsTitle.setHorizontalAlignment(SwingConstants.CENTER); noResultsTitle.setHorizontalAlignment(SwingConstants.CENTER);
noResultsDescription.setFont(FontManager.getRunescapeSmallFont()); noResultsDescription.setFont(FontManager.getSmallFont(getFont()));
noResultsDescription.setForeground(Color.GRAY); noResultsDescription.setForeground(Color.GRAY);
noResultsDescription.setHorizontalAlignment(SwingConstants.CENTER); noResultsDescription.setHorizontalAlignment(SwingConstants.CENTER);

View File

@@ -69,18 +69,26 @@ public class ProgressBar extends DimmableJPanel
setPreferredSize(new Dimension(100, 16)); setPreferredSize(new Dimension(100, 16));
leftLabel.setFont(FontManager.getRunescapeSmallFont()); int topIndent = 0;
if (getFont().equals(FontManager.getRunescapeSmallFont())
|| getFont().equals(FontManager.getRunescapeFont())
|| getFont().equals(FontManager.getRunescapeBoldFont()))
{
topIndent = 2;
}
leftLabel.setFont(FontManager.getSmallFont(getFont()));
leftLabel.setForeground(Color.WHITE); leftLabel.setForeground(Color.WHITE);
leftLabel.setBorder(new EmptyBorder(2, 5, 0, 0)); leftLabel.setBorder(new EmptyBorder(topIndent, 5, 0, 0));
rightLabel.setFont(FontManager.getRunescapeSmallFont()); rightLabel.setFont(FontManager.getSmallFont(getFont()));
rightLabel.setForeground(Color.WHITE); rightLabel.setForeground(Color.WHITE);
rightLabel.setBorder(new EmptyBorder(2, 0, 0, 5)); rightLabel.setBorder(new EmptyBorder(topIndent, 0, 0, 5));
centerLabel.setFont(FontManager.getRunescapeSmallFont()); centerLabel.setFont(FontManager.getSmallFont(getFont()));
centerLabel.setForeground(Color.WHITE); centerLabel.setForeground(Color.WHITE);
centerLabel.setHorizontalAlignment(SwingConstants.CENTER); centerLabel.setHorizontalAlignment(SwingConstants.CENTER);
centerLabel.setBorder(new EmptyBorder(2, 0, 0, 0)); centerLabel.setBorder(new EmptyBorder(topIndent, 0, 0, 0));
// Adds components to be automatically redrawn when paintComponents is called // Adds components to be automatically redrawn when paintComponents is called
add(leftLabel, BorderLayout.WEST); add(leftLabel, BorderLayout.WEST);

View File

@@ -25,7 +25,11 @@
package net.runelite.client.ui.components.shadowlabel; package net.runelite.client.ui.components.shadowlabel;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Toolkit;
import java.util.Map;
import javax.swing.JLabel; import javax.swing.JLabel;
import lombok.Getter; import lombok.Getter;
@@ -61,4 +65,17 @@ public class JShadowedLabel extends JLabel
revalidate(); revalidate();
repaint(); repaint();
} }
@Override
public void paint(Graphics g)
{
// Set font rendering properties like the OS's font rendering
Toolkit tk = Toolkit.getDefaultToolkit();
Map desktopHints = (Map)(tk.getDesktopProperty("awt.font.desktophints"));
if (desktopHints != null)
{
((Graphics2D)g).addRenderingHints(desktopHints);
}
super.paint(g);
}
} }

View File

@@ -30,9 +30,11 @@ import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@@ -53,6 +55,7 @@ import net.runelite.client.input.MouseAdapter;
import net.runelite.client.input.MouseManager; import net.runelite.client.input.MouseManager;
import net.runelite.client.ui.JagexColors; import net.runelite.client.ui.JagexColors;
import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ColorUtil;
import net.runelite.client.ui.FontManager;
import net.runelite.client.util.MiscUtils; import net.runelite.client.util.MiscUtils;
@Singleton @Singleton
@@ -165,6 +168,14 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener
return; return;
} }
// Set font rendering properties like the OS's font rendering
Toolkit tk = Toolkit.getDefaultToolkit();
Map desktopHints = (Map)(tk.getDesktopProperty("awt.font.desktophints"));
if (desktopHints != null)
{
graphics.addRenderingHints(desktopHints);
}
if (shouldInvalidateBounds()) if (shouldInvalidateBounds())
{ {
snapCorners = buildSnapCorners(); snapCorners = buildSnapCorners();
@@ -446,15 +457,15 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener
// Set font based on configuration // Set font based on configuration
if (position == OverlayPosition.DYNAMIC || position == OverlayPosition.DETACHED) if (position == OverlayPosition.DYNAMIC || position == OverlayPosition.DETACHED)
{ {
subGraphics.setFont(runeLiteConfig.fontType().getFont()); subGraphics.setFont(FontManager.getFontFromType(runeLiteConfig.clientFont(), runeLiteConfig.fontType()));
} }
else if (position == OverlayPosition.TOOLTIP) else if (position == OverlayPosition.TOOLTIP)
{ {
subGraphics.setFont(runeLiteConfig.tooltipFontType().getFont()); subGraphics.setFont(FontManager.getFontFromType(runeLiteConfig.clientFont(), runeLiteConfig.tooltipFontType()));
} }
else else
{ {
subGraphics.setFont(runeLiteConfig.interfaceFontType().getFont()); subGraphics.setFont(FontManager.getFontFromType(runeLiteConfig.clientFont(), runeLiteConfig.interfaceFontType()));
} }
subGraphics.translate(point.x, point.y); subGraphics.translate(point.x, point.y);

View File

@@ -39,7 +39,7 @@ import net.runelite.client.ui.FontManager;
@Setter @Setter
public class InfoBoxComponent implements LayoutableRenderableEntity public class InfoBoxComponent implements LayoutableRenderableEntity
{ {
private static final int SEPARATOR = 3; private static final int SEPARATOR = 2;
private static final int DEFAULT_SIZE = 32; private static final int DEFAULT_SIZE = 32;
@Getter @Getter
@@ -63,7 +63,14 @@ public class InfoBoxComponent implements LayoutableRenderableEntity
return new Dimension(); return new Dimension();
} }
graphics.setFont(getSize() < DEFAULT_SIZE ? FontManager.getRunescapeSmallFont() : FontManager.getRunescapeFont()); if (graphics.getFont().equals(FontManager.getRunescapeFont()) && getSize() > DEFAULT_SIZE)
{
graphics.setFont(FontManager.getRunescapeFont());
}
else
{
graphics.setFont(FontManager.getSmallFont(graphics.getFont()));
}
final int baseX = preferredLocation.x; final int baseX = preferredLocation.x;
final int baseY = preferredLocation.y; final int baseY = preferredLocation.y;
@@ -92,7 +99,7 @@ public class InfoBoxComponent implements LayoutableRenderableEntity
final TextComponent textComponent = new TextComponent(); final TextComponent textComponent = new TextComponent();
textComponent.setColor(color); textComponent.setColor(color);
textComponent.setText(text); textComponent.setText(text);
textComponent.setPosition(new Point(baseX + ((size - metrics.stringWidth(text)) / 2), baseY + size - SEPARATOR)); textComponent.setPosition(new Point(baseX + ((size - metrics.stringWidth(text)) / 2), baseY + size - metrics.getMaxDescent() - SEPARATOR));
textComponent.render(graphics); textComponent.render(graphics);
} }

View File

@@ -68,7 +68,7 @@ public class LineComponent implements LayoutableRenderableEntity
final FontMetrics metrics = graphics.getFontMetrics(); final FontMetrics metrics = graphics.getFontMetrics();
final int baseX = preferredLocation.x; final int baseX = preferredLocation.x;
final int baseY = preferredLocation.y + metrics.getHeight(); final int baseY = preferredLocation.y;
int x = baseX; int x = baseX;
int y = baseY; int y = baseY;
final int leftFullWidth = getLineWidth(left, metrics); final int leftFullWidth = getLineWidth(left, metrics);
@@ -92,6 +92,7 @@ public class LineComponent implements LayoutableRenderableEntity
for (int i = 0; i < lineCount; i++) for (int i = 0; i < lineCount; i++)
{ {
y += metrics.getMaxAscent();
String leftText = ""; String leftText = "";
String rightText = ""; String rightText = "";
@@ -116,7 +117,7 @@ public class LineComponent implements LayoutableRenderableEntity
rightLineComponent.setText(rightText); rightLineComponent.setText(rightText);
rightLineComponent.setColor(rightColor); rightLineComponent.setColor(rightColor);
rightLineComponent.render(graphics); rightLineComponent.render(graphics);
y += metrics.getHeight(); y += metrics.getMaxDescent();
} }
final Dimension dimension = new Dimension(preferredSize.width, y - baseY); final Dimension dimension = new Dimension(preferredSize.width, y - baseY);
@@ -124,6 +125,7 @@ public class LineComponent implements LayoutableRenderableEntity
bounds.setSize(dimension); bounds.setSize(dimension);
return dimension; return dimension;
} }
y += metrics.getMaxAscent();
final TextComponent leftLineComponent = new TextComponent(); final TextComponent leftLineComponent = new TextComponent();
leftLineComponent.setPosition(new Point(x, y)); leftLineComponent.setPosition(new Point(x, y));
@@ -136,7 +138,7 @@ public class LineComponent implements LayoutableRenderableEntity
rightLineComponent.setText(right); rightLineComponent.setText(right);
rightLineComponent.setColor(rightColor); rightLineComponent.setColor(rightColor);
rightLineComponent.render(graphics); rightLineComponent.render(graphics);
y += metrics.getHeight(); y += metrics.getMaxDescent();
final Dimension dimension = new Dimension(preferredSize.width, y - baseY); final Dimension dimension = new Dimension(preferredSize.width, y - baseY);
bounds.setLocation(preferredLocation); bounds.setLocation(preferredLocation);

View File

@@ -109,7 +109,7 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
final int width = preferredSize.width; final int width = preferredSize.width;
final int height = Math.max(preferredSize.height, 16); final int height = Math.max(preferredSize.height, 16);
final int progressTextX = barX + (width - metrics.stringWidth(textToWrite)) / 2; final int progressTextX = barX + (width - metrics.stringWidth(textToWrite)) / 2;
final int progressTextY = barY + ((height - metrics.getHeight()) / 2) + metrics.getHeight(); final int progressTextY = barY + ((height - metrics.getHeight()) / 2) + metrics.getMaxAscent();
final int progressFill = (int) (width * Math.min(1, pc)); final int progressFill = (int) (width * Math.min(1, pc));
// Draw bar // Draw bar

View File

@@ -24,11 +24,15 @@
*/ */
package net.runelite.client.ui.overlay.components; package net.runelite.client.ui.overlay.components;
import java.awt.AlphaComposite;
import java.awt.Color; import java.awt.Color;
import java.awt.Composite;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Shape;
import java.awt.font.GlyphVector;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import lombok.Setter; import lombok.Setter;
import net.runelite.client.ui.overlay.RenderableEntity; import net.runelite.client.ui.overlay.RenderableEntity;
@@ -43,6 +47,7 @@ public class TextComponent implements RenderableEntity
private String text; private String text;
private Point position = new Point(); private Point position = new Point();
private Color color = Color.WHITE; private Color color = Color.WHITE;
private Color borderColor = Color.BLACK;
public static String textWithoutColTags(String text) public static String textWithoutColTags(String text)
{ {
@@ -64,28 +69,43 @@ public class TextComponent implements RenderableEntity
final String textWithoutCol = textWithoutColTags(textSplitOnCol); final String textWithoutCol = textWithoutColTags(textSplitOnCol);
final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">"));
// shadow renderText(graphics, x, position.y, textWithoutCol, Color.decode("#" + colColor), borderColor);
graphics.setColor(Color.BLACK);
graphics.drawString(textWithoutCol, x + 1, position.y + 1);
// actual text
graphics.setColor(Color.decode("#" + colColor));
graphics.drawString(textWithoutCol, x, position.y);
x += fontMetrics.stringWidth(textWithoutCol); x += fontMetrics.stringWidth(textWithoutCol);
} }
} }
else else
{ {
// shadow renderText(graphics, position.x, position.y, text, color, borderColor);
graphics.setColor(Color.BLACK);
graphics.drawString(text, position.x + 1, position.y + 1);
// actual text
graphics.setColor(color);
graphics.drawString(text, position.x, position.y);
} }
return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight()); return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight());
} }
private void renderText(Graphics2D graphics, int x, int y, String text, Color color, Color border)
{
// remember previous composite
Composite originalComposite = graphics.getComposite();
// create a vector of the text
GlyphVector vector = graphics.getFont().createGlyphVector(graphics.getFontRenderContext(), text);
// compute the text shape
Shape stroke = vector.getOutline(x + 1, y + 1);
Shape shape = vector.getOutline(x, y);
// draw text border
graphics.setColor(border);
graphics.fill(stroke);
// replace the pixels instead of overlaying
graphics.setComposite(AlphaComposite.Src);
// draw actual text
graphics.setColor(color);
graphics.fill(shape);
// reset composite to original
graphics.setComposite(originalComposite);
}
} }

View File

@@ -64,7 +64,7 @@ public class TitleComponent implements LayoutableRenderableEntity
titleComponent.setColor(color); titleComponent.setColor(color);
titleComponent.setPosition(new Point( titleComponent.setPosition(new Point(
baseX + ((preferredSize.width - metrics.stringWidth(text)) / 2), baseX + ((preferredSize.width - metrics.stringWidth(text)) / 2),
baseY + metrics.getHeight())); baseY + metrics.getMaxAscent()));
final Dimension rendered = titleComponent.render(graphics); final Dimension rendered = titleComponent.render(graphics);
final Dimension dimension = new Dimension(preferredSize.width, rendered.height); final Dimension dimension = new Dimension(preferredSize.width, rendered.height);
bounds.setLocation(preferredLocation); bounds.setLocation(preferredLocation);

View File

@@ -104,7 +104,7 @@ public class TooltipComponent implements RenderableEntity
textComponent.setColor(nextColor); textComponent.setColor(nextColor);
String text = line.substring(begin, j); String text = line.substring(begin, j);
textComponent.setText(text); textComponent.setText(text);
textComponent.setPosition(new Point(lineX, textY + (i + 1) * textHeight - textDescent)); textComponent.setPosition(new Point(lineX, textY + (i + 1) * metrics.getMaxAscent() + i * metrics.getMaxDescent()));
textComponent.render(graphics); textComponent.render(graphics);
lineX += metrics.stringWidth(text); lineX += metrics.stringWidth(text);
@@ -141,7 +141,7 @@ public class TooltipComponent implements RenderableEntity
textComponent.setColor(nextColor); textComponent.setColor(nextColor);
String text = line.substring(begin, j + 1); String text = line.substring(begin, j + 1);
textComponent.setText(text); textComponent.setText(text);
textComponent.setPosition(new Point(lineX, textY + (i + 1) * textHeight - textDescent)); textComponent.setPosition(new Point(lineX, textY + (i + 1) * metrics.getMaxAscent() + i * metrics.getMaxDescent()));
textComponent.render(graphics); textComponent.render(graphics);
lineX += metrics.stringWidth(text); lineX += metrics.stringWidth(text);
@@ -155,7 +155,7 @@ public class TooltipComponent implements RenderableEntity
final TextComponent textComponent = new TextComponent(); final TextComponent textComponent = new TextComponent();
textComponent.setColor(nextColor); textComponent.setColor(nextColor);
textComponent.setText(line.substring(begin)); textComponent.setText(line.substring(begin));
textComponent.setPosition(new Point(lineX, textY + (i + 1) * textHeight - textDescent)); textComponent.setPosition(new Point(lineX, textY + (i + 1) * metrics.getMaxAscent() + i * metrics.getMaxDescent()));
textComponent.render(graphics); textComponent.render(graphics);
} }

View File

@@ -278,7 +278,7 @@ public class WorldMapOverlay extends Overlay
graphics.setColor(JagexColors.TOOLTIP_BORDER); graphics.setColor(JagexColors.TOOLTIP_BORDER);
graphics.drawRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight()); graphics.drawRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight());
graphics.setColor(JagexColors.TOOLTIP_TEXT); graphics.setColor(JagexColors.TOOLTIP_TEXT);
graphics.drawString(tooltip, drawPoint.getX(), drawPoint.getY() + height); graphics.drawString(tooltip, drawPoint.getX(), drawPoint.getY() + fm.getMaxAscent());
} }
private Point clipToRectangle(Point drawPoint, Rectangle mapDisplayRectangle) private Point clipToRectangle(Point drawPoint, Rectangle mapDisplayRectangle)

View File

@@ -309,6 +309,8 @@ public class SwingUtil
// Use substance look and feel // Use substance look and feel
SwingUtil.setTheme(new SubstanceRuneLiteLookAndFeel()); SwingUtil.setTheme(new SubstanceRuneLiteLookAndFeel());
// Use custom UI font // Use custom UI font
//TODO : SUPPORT CUSTOM FONT?
//SwingUtil.setFont(FontManager.getFontOrDefault(config.clientFont()));
SwingUtil.setFont(FontManager.getRunescapeFont()); SwingUtil.setFont(FontManager.getRunescapeFont());
} }
} }

View File

@@ -25,33 +25,24 @@
package net.runelite.client.ui.overlay.components; package net.runelite.client.ui.overlay.components;
import java.awt.Color; import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import org.mockito.Mock;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class TextComponentTest public class TextComponentTest
{ {
@Mock
private Graphics2D graphics; private Graphics2D graphics;
private BufferedImage dest;
@Before @Before
public void before() public void before()
{ {
when(graphics.getFontMetrics()).thenReturn(mock(FontMetrics.class)); dest = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
graphics = (Graphics2D) dest.getGraphics();
} }
@Test @Test
public void testRender() public void testRender()
{ {
@@ -59,29 +50,29 @@ public class TextComponentTest
textComponent.setText("test"); textComponent.setText("test");
textComponent.setColor(Color.RED); textComponent.setColor(Color.RED);
textComponent.render(graphics); textComponent.render(graphics);
verify(graphics, times(2)).drawString(eq("test"), anyInt(), anyInt());
verify(graphics, atLeastOnce()).setColor(Color.RED);
} }
@Test @Test
public void testRender2() public void testRender2()
{ {
TextComponent textComponent = new TextComponent(); TextComponent textComponent = new TextComponent();
textComponent.setText("<col=0000ff>test"); textComponent.setText("<col=0000ff>test");
textComponent.render(graphics); textComponent.render(graphics);
verify(graphics, times(2)).drawString(eq("test"), anyInt(), anyInt());
verify(graphics, atLeastOnce()).setColor(Color.BLUE);
} }
@Test @Test
public void testRender3() public void testRender3()
{ {
TextComponent textComponent = new TextComponent(); TextComponent textComponent = new TextComponent();
textComponent.setText("<col=0000ff>test<col=00ff00> test"); textComponent.setText("<col=0000ff>test<col=00ff00> test");
textComponent.render(graphics); textComponent.render(graphics);
verify(graphics, atLeastOnce()).drawString(eq("test"), anyInt(), anyInt());
verify(graphics, atLeastOnce()).drawString(eq(" test"), anyInt(), anyInt());
verify(graphics, atLeastOnce()).setColor(Color.BLUE);
verify(graphics, atLeastOnce()).setColor(Color.GREEN);
} }
@After
public void after()
{
graphics.dispose();
dest.flush();
}
} }

View File

@@ -25,32 +25,28 @@
package net.runelite.client.ui.overlay.components.table; package net.runelite.client.ui.overlay.components.table;
import java.awt.Color; import java.awt.Color;
import java.awt.FontMetrics; import java.awt.image.BufferedImage;
import org.junit.After;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import org.mockito.Mock; import org.mockito.Mock;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class TableComponentTest public class TableComponentTest
{ {
@Mock @Mock
private Graphics2D graphics; private Graphics2D graphics;
private BufferedImage dest;
@Before @Before
public void before() public void before()
{ {
when(graphics.getFontMetrics()).thenReturn(mock(FontMetrics.class)); dest = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
graphics = (Graphics2D) dest.getGraphics();
} }
@Test @Test
@@ -61,8 +57,6 @@ public class TableComponentTest
tableComponent.setDefaultAlignment(TableAlignment.CENTER); tableComponent.setDefaultAlignment(TableAlignment.CENTER);
tableComponent.setDefaultColor(Color.RED); tableComponent.setDefaultColor(Color.RED);
tableComponent.render(graphics); tableComponent.render(graphics);
verify(graphics, times(2)).drawString(eq("test"), anyInt(), anyInt());
verify(graphics, atLeastOnce()).setColor(Color.RED);
} }
@Test @Test
@@ -76,10 +70,13 @@ public class TableComponentTest
elements.get(1).setColor(Color.GREEN); elements.get(1).setColor(Color.GREEN);
elements.get(2).setColor(Color.BLUE); elements.get(2).setColor(Color.BLUE);
tableComponent.render(graphics); tableComponent.render(graphics);
verify(graphics, atLeastOnce()).setColor(Color.RED);
verify(graphics, atLeastOnce()).setColor(Color.GREEN);
verify(graphics, atLeastOnce()).setColor(Color.BLUE);
verify(graphics, atLeastOnce()).setColor(Color.YELLOW);
verify(graphics, atLeastOnce()).setColor(Color.WHITE);
} }
@After
public void after()
{
graphics.dispose();
dest.flush();
}
} }