private static void LoadColours() { settings.Clear(); foreach (ButtonEffect effect in Enum.GetValues(typeof(ButtonEffect))) { UserColourSetting setting = GetColourSettingFromRegistry(effect); if (setting != null) { settings.Add(effect, setting); } } }
public static Color GetFontColour(ButtonEffect effect, bool ignoreUserSettings) { if (ignoreUserSettings == false) { UserColourSetting setting = UserColourSettingManager.GetColourSettings(effect); if (setting != null) { return(setting.FontColour); } } return(Color.Black); }
public static ColorMatrix GetMatrix(ButtonEffect effect, bool ignoreUserSettings = false) { if (ignoreUserSettings == false) { UserColourSetting setting = UserColourSettingManager.GetColourSettings(effect); if (setting != null) { return(setting.Matrix); } } ColorMatrix cm = null; switch (effect) { case ButtonEffect.None: cm = new ColorMatrix(); break; case ButtonEffect.Mapped: cm = Blue(); break; case ButtonEffect.Disabled: cm = Darken(-0.3F); break; case ButtonEffect.MappedPending: cm = GreenyBlue(); break; case ButtonEffect.UnmappedPending: cm = Golden(); break; case ButtonEffect.DisabledPending: cm = DarkGold(); break; case ButtonEffect.EnabledPending: cm = GoldenDarken(); break; } return(cm); }
private static UserColourSetting GetColourSettingFromRegistry(ButtonEffect effect) { // Need to be defensively minded as user could change, // delete, or change type of registry settings. string subkey = AppController.ApplicationRegistryKeyName + @"\UserColours\" + effect.ToString(); RegistryKey reg = Registry.CurrentUser.OpenSubKey(subkey); if (reg == null) // No settings have been defined for this effect { return(null); } UserColourSetting setting = new UserColourSetting(); // User may have changed type of FontColour // Using nullable int as any possible integer value could be a valid // ToARGB() result (well, I'm assuming it could anyway) int?fontColourArgb; object value = reg.GetValue("FontColour"); if (value == null || reg.GetValueKind("FontColour") != RegistryValueKind.DWord) { fontColourArgb = Color.Black.ToArgb(); } else { fontColourArgb = (int?)value; } setting.FontColour = Color.FromArgb((int)fontColourArgb); ColorMatrix cm = new ColorMatrix(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { string name = "Matrix" + i.ToString(System.Globalization.CultureInfo.InvariantCulture) + j.ToString(System.Globalization.CultureInfo.InvariantCulture); value = reg.GetValue(name); if (value != null) { float svalue; if (float.TryParse(value.ToString(), out svalue)) { cm.GetType().GetProperty(name).SetValue(cm, svalue, null); } } } } setting.Matrix = cm; return(setting); }
private static UserColourSetting GetColourSettingFromRegistry(ButtonEffect effect) { // Need to be defensively minded as user could change, // delete, or change type of registry settings. string subkey = AppController.ApplicationRegistryKeyName + @"\UserColours\" + effect.ToString(); RegistryKey reg = Registry.CurrentUser.OpenSubKey(subkey); if (reg == null) // No settings have been defined for this effect return null; UserColourSetting setting = new UserColourSetting(); // User may have changed type of FontColour // Using nullable int as any possible integer value could be a valid // ToARGB() result (well, I'm assuming it could anyway) int? fontColourArgb; object value = reg.GetValue("FontColour"); if (value == null || reg.GetValueKind("FontColour") != RegistryValueKind.DWord) fontColourArgb = Color.Black.ToArgb(); else fontColourArgb = (int?)value; setting.FontColour = Color.FromArgb((int)fontColourArgb); ColorMatrix cm = new ColorMatrix(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { string name = "Matrix" + i.ToString(System.Globalization.CultureInfo.InvariantCulture) + j.ToString(System.Globalization.CultureInfo.InvariantCulture); value = reg.GetValue(name); if (value != null) { Single svalue; if (System.Single.TryParse(value.ToString(), out svalue)) { cm.GetType().GetProperty(name).SetValue(cm, svalue, null); } } } } setting.Matrix = cm; return setting; }