Esempio n. 1
0
        /// <summary>
        /// Returns the cached brush corresponding to the parameters passed across. If no such brush
        /// has been cached then a new cached brush is created and returned.
        /// </summary>
        /// <param name="red"></param>
        /// <param name="green"></param>
        /// <param name="blue"></param>
        /// <param name="alpha"></param>
        /// <returns></returns>
        private VrsDrawing.IBrush GetOrCreateCachedBrush(int red, int green, int blue, int alpha)
        {
            var key = ColourHelper.PackColour(red, green, blue, alpha);

            var map = _SolidBrushCache;

            if (!map.TryGetValue(key, out var brush))
            {
                lock (_SyncLock) {
                    if (!_SolidBrushCache.TryGetValue(key, out brush))
                    {
                        brush = CreateBrushWrapper(red, green, blue, alpha, isCached: true);
                        map   = CollectionHelper.ShallowCopy(_SolidBrushCache);
                        map.Add(key, brush);
                        _SolidBrushCache = map;
                    }
                }
            }

            return(brush);
        }
Esempio n. 2
0
 /// <summary>
 /// See base docs.
 /// </summary>
 /// <returns></returns>
 public override int GetHashCode()
 {
     return(ColourHelper.PackColour(Red, Green, Blue, Alpha).GetHashCode());
 }