using System; using System.Collections.Generic; using System.Windows.Media; using System.Windows.Media.Effects; namespace Dominion.NET_WPF.Caching { public static class DropShadowRepository { private static readonly Dictionary DSECache = new Dictionary(); public static DropShadowEffect GetDSE(int blurRadius, Color color, double opacity) { return GetDSE(blurRadius, color, opacity, true); } public static DropShadowEffect GetDSE(int blurRadius, Color color, double opacity, bool isFrozen) { var hashKey = 3 * blurRadius.GetHashCode() + 5 * color.GetHashCode() + 7 * opacity.GetHashCode(); if (!isFrozen || !DSECache.ContainsKey(hashKey)) { var dse = new DropShadowEffect { BlurRadius = blurRadius, Color = color, Opacity = opacity, ShadowDepth = 0, Direction = 0 }; if (!isFrozen) return dse; DSECache[hashKey] = dse; } if (DSECache[hashKey].CanFreeze) DSECache[hashKey].Freeze(); return DSECache[hashKey]; } } }