From 6e6890fa003874c081402aa3ccdb741673e00057 Mon Sep 17 00:00:00 2001 From: weisj Date: Mon, 25 May 2020 23:18:25 +0200 Subject: [PATCH] Ensure IconColorMapper reproduced all encounter tags. --- change_notes.md | 1 + .../components/color/PopupColorChooser.java | 1 - .../icons/control/volumeSliderFocused.svg | 2 +- .../weisj/darklaf/icons/IconColorMapper.java | 55 +++++++++++++------ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/change_notes.md b/change_notes.md index 53fcad5f..dfcfb5f7 100644 --- a/change_notes.md +++ b/change_notes.md @@ -43,3 +43,4 @@ - Poor performance when using bidirectional text with non zero margins. #167 252885df6fa18044c215361cbbe200cdf3358cf5 - Text isn't painted when using the toggle button slider variant. 0d1f2913dd25d5a684fa2567c37a94b549f030b0 - Kerning issues on macOS Catalina. #128 d3fd5dedabe11d84685e593a03b1941b8ea56836 +- Icons loose opaque parts after changing the theme. diff --git a/core/src/main/java/com/github/weisj/darklaf/components/color/PopupColorChooser.java b/core/src/main/java/com/github/weisj/darklaf/components/color/PopupColorChooser.java index 8b6e8df1..516954dd 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/color/PopupColorChooser.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/color/PopupColorChooser.java @@ -26,7 +26,6 @@ package com.github.weisj.darklaf.components.color; import java.awt.*; import java.awt.event.*; -import java.util.Arrays; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; diff --git a/core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderFocused.svg b/core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderFocused.svg index 9ffc8705..afcbb6f7 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderFocused.svg +++ b/core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderFocused.svg @@ -8,7 +8,7 @@ - + diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java index 2fba833c..7298eb0c 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java @@ -75,10 +75,11 @@ public final class IconColorMapper { for (Object child : children) { if (child instanceof LinearGradient) { String id = ((LinearGradient) child).getId(); - String[] fallbacks = getFallbacks((LinearGradient) child); - float opacity = getOpacity((LinearGradient) child); - Color c = resolveColor(id, fallbacks, FALLBACK_COLOR, defaults); - Pair result = createColor(c, id, opacity); + StyleAttribute fallbacks = getFallbacks((LinearGradient) child); + String opacityKey = getOpacityKey((LinearGradient) child); + float opacity = getOpacity(opacityKey); + Color c = resolveColor(id, getFallbacks(fallbacks), FALLBACK_COLOR, defaults); + Pair result = createColor(c, id, opacityKey, fallbacks, opacity); LinearGradient gradient = result.getFirst(); Runnable finalizer = result.getSecond(); themedDefs.loaderAddChild(null, gradient); @@ -101,39 +102,59 @@ public final class IconColorMapper { return color; } - private static String[] getFallbacks(final LinearGradient child) { + private static StyleAttribute getFallbacks(final LinearGradient child) { StyleAttribute attribute = new StyleAttribute(); attribute.setName("fallback"); try { child.getStyle(attribute); } catch (SVGException e) { - return new String[0]; + return null; } - return attribute.getStringList(); + return attribute; } - private static float getOpacity(final LinearGradient child) { - StyleAttribute attribute = new StyleAttribute(); - attribute.setName("opacity"); - try { - child.getStyle(attribute); - } catch (SVGException e) { - return 1; - } + private static String[] getFallbacks(final StyleAttribute fallbacks) { + if (fallbacks == null) return new String[0]; + return fallbacks.getStringList(); + } + + private static float getOpacity(final String key) { // UIManager defaults to 0, if the values isn't an integer (or null). - Object obj = UIManager.get(attribute.getStringValue()); + Object obj = UIManager.get(key); if (obj instanceof Integer) { return ((Integer) obj) / 100.0f; } + if (key != null && !key.isEmpty()) { + LOGGER.warning(obj + " is an invalid opacity value. Key = '" + key + "'"); + } // In this case we default to 1. return 1; } + private static String getOpacityKey(final LinearGradient child) { + StyleAttribute attribute = new StyleAttribute(); + attribute.setName("opacity"); + try { + child.getStyle(attribute); + } catch (SVGException e) { + e.printStackTrace(); + return null; + } + return attribute.getStringValue(); + } + private static Pair createColor(final Color c, - final String name, + final String name, final String opacityKey, + final StyleAttribute fallbacks, final float opacity) throws SVGElementException { LinearGradient grad = new LinearGradient(); grad.addAttribute("id", AnimationElement.AT_XML, name); + if (opacityKey != null) { + grad.addAttribute("opacity", AnimationElement.AT_XML, opacityKey); + } + if (fallbacks != null) { + grad.addAttribute(fallbacks.getName(), AnimationElement.AT_XML, fallbacks.getStringValue()); + } return new Pair<>(grad, () -> { Stop stop1 = new Stop(); Stop stop2 = new Stop();