public void SetShadowMap(CacheSlot slot, Int32 cacheMapHandler) { if (cacheMap[slot] > 0) { throw new FieldAccessException("This cache map is already busy, first release it."); } cacheMap[slot] = cacheMapHandler; }
private static int SlotToFlag(CacheSlot slot) { // FxCop: Hashtable would be overkill, using switch instead switch (slot) { case CacheSlot.ActiveBorder: return (int)NativeMethods.Win32SystemColors.ActiveBorder; case CacheSlot.ActiveCaption: return (int)NativeMethods.Win32SystemColors.ActiveCaption; case CacheSlot.ActiveCaptionText: return (int)NativeMethods.Win32SystemColors.ActiveCaptionText; case CacheSlot.AppWorkspace: return (int)NativeMethods.Win32SystemColors.AppWorkspace; case CacheSlot.Control: return (int)NativeMethods.Win32SystemColors.Control; case CacheSlot.ControlDark: return (int)NativeMethods.Win32SystemColors.ControlDark; case CacheSlot.ControlDarkDark: return (int)NativeMethods.Win32SystemColors.ControlDarkDark; case CacheSlot.ControlLight: return (int)NativeMethods.Win32SystemColors.ControlLight; case CacheSlot.ControlLightLight: return (int)NativeMethods.Win32SystemColors.ControlLightLight; case CacheSlot.ControlText: return (int)NativeMethods.Win32SystemColors.ControlText; case CacheSlot.Desktop: return (int)NativeMethods.Win32SystemColors.Desktop; case CacheSlot.GradientActiveCaption: return (int)NativeMethods.Win32SystemColors.GradientActiveCaption; case CacheSlot.GradientInactiveCaption: return (int)NativeMethods.Win32SystemColors.GradientInactiveCaption; case CacheSlot.GrayText: return (int)NativeMethods.Win32SystemColors.GrayText; case CacheSlot.Highlight: return (int)NativeMethods.Win32SystemColors.Highlight; case CacheSlot.HighlightText: return (int)NativeMethods.Win32SystemColors.HighlightText; case CacheSlot.HotTrack: return (int)NativeMethods.Win32SystemColors.HotTrack; case CacheSlot.InactiveBorder: return (int)NativeMethods.Win32SystemColors.InactiveBorder; case CacheSlot.InactiveCaption: return (int)NativeMethods.Win32SystemColors.InactiveCaption; case CacheSlot.InactiveCaptionText: return (int)NativeMethods.Win32SystemColors.InactiveCaptionText; case CacheSlot.Info: return (int)NativeMethods.Win32SystemColors.Info; case CacheSlot.InfoText: return (int)NativeMethods.Win32SystemColors.InfoText; case CacheSlot.Menu: return (int)NativeMethods.Win32SystemColors.Menu; case CacheSlot.MenuBar: return (int)NativeMethods.Win32SystemColors.MenuBar; case CacheSlot.MenuHighlight: return (int)NativeMethods.Win32SystemColors.MenuHighlight; case CacheSlot.MenuText: return (int)NativeMethods.Win32SystemColors.MenuText; case CacheSlot.ScrollBar: return (int)NativeMethods.Win32SystemColors.ScrollBar; case CacheSlot.Window: return (int)NativeMethods.Win32SystemColors.Window; case CacheSlot.WindowFrame: return (int)NativeMethods.Win32SystemColors.WindowFrame; case CacheSlot.WindowText: return (int)NativeMethods.Win32SystemColors.WindowText; } return 0; }
private static SolidColorBrush MakeBrush(CacheSlot slot) { SolidColorBrush brush; lock (_brushCacheValid) { if (!_brushCacheValid[(int)slot]) { brush = new SolidColorBrush(GetSystemColor(slot)); brush.Freeze(); _brushCache[(int)slot] = brush; _brushCacheValid[(int)slot] = true; } else { brush = _brushCache[(int)slot]; } } return brush; }
/// <summary> /// Query for system colors. /// </summary> /// <param name="slot">The color slot.</param> /// <returns>The system color.</returns> private static Color GetSystemColor(CacheSlot slot) { Color color; lock (_colorCacheValid) { if (!_colorCacheValid[(int)slot]) { uint argb; int sysColor = SafeNativeMethods.GetSysColor(SlotToFlag(slot)); argb = (uint)FromWin32Value(sysColor); color = Color.FromArgb((byte)((argb & 0xff000000) >>24), (byte)((argb & 0x00ff0000) >>16), (byte)((argb & 0x0000ff00) >>8), (byte)(argb & 0x000000ff)); _colorCache[(int)slot] = color; _colorCacheValid[(int)slot] = true; } else { color = _colorCache[(int)slot]; } } return color; }
public Int32 GetShadowMap(CacheSlot slot) { return(cacheMap[slot]); }