Browse Source

Ensure IconColorMapper reproduced all encounter tags.

pull/173/head
weisj 5 years ago
parent
commit
6e6890fa00
  1. 1
      change_notes.md
  2. 1
      core/src/main/java/com/github/weisj/darklaf/components/color/PopupColorChooser.java
  3. 2
      core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderFocused.svg
  4. 55
      property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java

1
change_notes.md

@ -43,3 +43,4 @@
- Poor performance when using bidirectional text with non zero margins. #167 252885df6fa18044c215361cbbe200cdf3358cf5 - Poor performance when using bidirectional text with non zero margins. #167 252885df6fa18044c215361cbbe200cdf3358cf5
- Text isn't painted when using the toggle button slider variant. 0d1f2913dd25d5a684fa2567c37a94b549f030b0 - Text isn't painted when using the toggle button slider variant. 0d1f2913dd25d5a684fa2567c37a94b549f030b0
- Kerning issues on macOS Catalina. #128 d3fd5dedabe11d84685e593a03b1941b8ea56836 - Kerning issues on macOS Catalina. #128 d3fd5dedabe11d84685e593a03b1941b8ea56836
- Icons loose opaque parts after changing the theme.

1
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.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer; import java.util.function.Consumer;

2
core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderFocused.svg

@ -8,7 +8,7 @@
<stop offset="0" stop-color="#466D94"/> <stop offset="0" stop-color="#466D94"/>
<stop offset="1" stop-color="#466D94"/> <stop offset="1" stop-color="#466D94"/>
</linearGradient> </linearGradient>
<linearGradient id="Icons.VolumeSliderFocused.glowFocus" opacity="Icons.VolumeSlider.glowOpacity"> <linearGradient id="Icons.VolumeSliderFocused.glowFocus" opacity="Icons.VolumeSliderFocused.glowOpacity">
<stop offset="0" stop-color="#3e84c9" stop-opacity="0.5"/> <stop offset="0" stop-color="#3e84c9" stop-opacity="0.5"/>
<stop offset="1" stop-color="#3e84c9" stop-opacity="0.5"/> <stop offset="1" stop-color="#3e84c9" stop-opacity="0.5"/>
</linearGradient> </linearGradient>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

55
property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java

@ -75,10 +75,11 @@ public final class IconColorMapper {
for (Object child : children) { for (Object child : children) {
if (child instanceof LinearGradient) { if (child instanceof LinearGradient) {
String id = ((LinearGradient) child).getId(); String id = ((LinearGradient) child).getId();
String[] fallbacks = getFallbacks((LinearGradient) child); StyleAttribute fallbacks = getFallbacks((LinearGradient) child);
float opacity = getOpacity((LinearGradient) child); String opacityKey = getOpacityKey((LinearGradient) child);
Color c = resolveColor(id, fallbacks, FALLBACK_COLOR, defaults); float opacity = getOpacity(opacityKey);
Pair<LinearGradient, Runnable> result = createColor(c, id, opacity); Color c = resolveColor(id, getFallbacks(fallbacks), FALLBACK_COLOR, defaults);
Pair<LinearGradient, Runnable> result = createColor(c, id, opacityKey, fallbacks, opacity);
LinearGradient gradient = result.getFirst(); LinearGradient gradient = result.getFirst();
Runnable finalizer = result.getSecond(); Runnable finalizer = result.getSecond();
themedDefs.loaderAddChild(null, gradient); themedDefs.loaderAddChild(null, gradient);
@ -101,39 +102,59 @@ public final class IconColorMapper {
return color; return color;
} }
private static String[] getFallbacks(final LinearGradient child) { private static StyleAttribute getFallbacks(final LinearGradient child) {
StyleAttribute attribute = new StyleAttribute(); StyleAttribute attribute = new StyleAttribute();
attribute.setName("fallback"); attribute.setName("fallback");
try { try {
child.getStyle(attribute); child.getStyle(attribute);
} catch (SVGException e) { } catch (SVGException e) {
return new String[0]; return null;
} }
return attribute.getStringList(); return attribute;
} }
private static float getOpacity(final LinearGradient child) { private static String[] getFallbacks(final StyleAttribute fallbacks) {
StyleAttribute attribute = new StyleAttribute(); if (fallbacks == null) return new String[0];
attribute.setName("opacity"); return fallbacks.getStringList();
try { }
child.getStyle(attribute);
} catch (SVGException e) { private static float getOpacity(final String key) {
return 1;
}
// UIManager defaults to 0, if the values isn't an integer (or null). // 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) { if (obj instanceof Integer) {
return ((Integer) obj) / 100.0f; 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. // In this case we default to 1.
return 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<LinearGradient, Runnable> createColor(final Color c, private static Pair<LinearGradient, Runnable> createColor(final Color c,
final String name, final String name, final String opacityKey,
final StyleAttribute fallbacks,
final float opacity) throws SVGElementException { final float opacity) throws SVGElementException {
LinearGradient grad = new LinearGradient(); LinearGradient grad = new LinearGradient();
grad.addAttribute("id", AnimationElement.AT_XML, name); 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, () -> { return new Pair<>(grad, () -> {
Stop stop1 = new Stop(); Stop stop1 = new Stop();
Stop stop2 = new Stop(); Stop stop2 = new Stop();

Loading…
Cancel
Save