From 1a08cd6ae43b77ebd67f98c108351f23f5eace85 Mon Sep 17 00:00:00 2001 From: drdev Date: Mon, 2 Sep 2013 16:28:02 +0000 Subject: [PATCH] Support caching derived colors for reuse and actually updating colors when skin changed --- src/main/java/forge/gui/toolbox/FSkin.java | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/forge/gui/toolbox/FSkin.java b/src/main/java/forge/gui/toolbox/FSkin.java index 229bb18829c..58923360948 100644 --- a/src/main/java/forge/gui/toolbox/FSkin.java +++ b/src/main/java/forge/gui/toolbox/FSkin.java @@ -376,8 +376,9 @@ public enum FSkin { public static class SkinColor { private static final HashMap baseColors = new HashMap(); + private static final HashMap derivedColors = new HashMap(); private static final int NO_BRIGHTNESS_DELTA = 0; - private static final int NO_STEP = -10000; //needs to be large negative since small negative values are valid + private static final int NO_STEP = -999; //needs to be large negative since small negative values are valid private static final int NO_ALPHA = -1; private final Colors baseColor; @@ -398,20 +399,30 @@ public enum FSkin { this.updateColor(); } + private SkinColor getDerivedColor(int brightnessDelta0, int step0, int alpha0) { + String key = this.baseColor.name() + "|" + brightnessDelta0 + "|" + step0 + "|" + alpha0; + SkinColor derivedColor = derivedColors.get(key); + if (derivedColor == null) { + derivedColor = new SkinColor(this.baseColor, brightnessDelta0, step0, alpha0); + derivedColors.put(key, derivedColor); + } + return derivedColor; + } + public SkinColor brighter() { - return new SkinColor(this.baseColor, this.brightnessDelta + 1, this.step, this.alpha); + return getDerivedColor(this.brightnessDelta + 1, this.step, this.alpha); } public SkinColor darker() { - return new SkinColor(this.baseColor, this.brightnessDelta - 1, this.step, this.alpha); + return getDerivedColor(this.brightnessDelta - 1, this.step, this.alpha); } public SkinColor stepColor(int step0) { - return new SkinColor(this.baseColor, this.brightnessDelta, step0, this.alpha); + return getDerivedColor(this.brightnessDelta, step0, this.alpha); } public SkinColor alphaColor(int alpha0) { - return new SkinColor(this.baseColor, this.brightnessDelta, this.step, alpha0); + return getDerivedColor(this.brightnessDelta, this.step, alpha0); } private void updateColor() { @@ -472,6 +483,14 @@ public enum FSkin { SkinColor.baseColors.put(c, new SkinColor(c)); } } + else { //update existing SkinColors if baseColors already initialized + for (final SkinColor c : SkinColor.baseColors.values()) { + c.updateColor(); + } + for (final SkinColor c : SkinColor.derivedColors.values()) { + c.updateColor(); + } + } } private void updateColor() { @@ -837,6 +856,7 @@ public enum FSkin { prefs.save(); //load skin + loaded = false; //reset this temporarily until end of loadFull() loadLight(skinName, false); loadFull();