From 9763b554f20d74d6f2eee5faba0ba36a6ad05e6b Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 30 Jul 2022 16:57:15 -0400 Subject: [PATCH] more general version of icon making --- app/src/processing/app/ui/Toolkit.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/processing/app/ui/Toolkit.java b/app/src/processing/app/ui/Toolkit.java index 1e061df3a..fb759442e 100644 --- a/app/src/processing/app/ui/Toolkit.java +++ b/app/src/processing/app/ui/Toolkit.java @@ -689,7 +689,18 @@ public class Toolkit { * @param size size in pixels (handling for 2x done automatically) */ static public ImageIcon renderIcon(String name, String color, int size) { - Image image = renderMonoImage(name, color, size); + return renderIcon(Platform.getContentFile("lib/" + name + ".svg"), color, size); + } + + + /** + * Create an Icon object from an SVG path name. + * @param file full path to icon + * @param color color to apply to the monochrome icon + * @param size size in pixels (handling for 2x done automatically) + */ + static public ImageIcon renderIcon(File file, String color, int size) { + Image image = renderMonoImage(file, color, size); if (image == null) { return null; } @@ -718,16 +729,10 @@ public class Toolkit { } - static protected Image renderMonoImage(String name, String color, int size) { - File file = Platform.getContentFile("lib/" + name + ".svg"); + static protected Image renderMonoImage(File file, String color, int size) { String xmlOrig = Util.loadFile(file); if (xmlOrig != null) { - /* - final String REPLACE_COLOR = "#9B9B9B"; - String xmlStr = xmlOrig.replace(REPLACE_COLOR, color); - return Toolkit.svgToImageMult(xmlStr, size, size); - */ StringDict replace = new StringDict(new String[][] { { "#9B9B9B", color } }); @@ -737,9 +742,11 @@ public class Toolkit { } + /* static private Image svgToImageMult(String xmlStr, int wide, int high) { return svgToImage(xmlStr, highResMultiply(wide), highResMultiply(high)); } + */ static public Image svgToImageMult(String xmlStr, int wide, int high, StringDict replacements) {