private void UpdateContrastColors(IColorPaletteEntry value) { if (value?.ContrastColors != null) { List <ContrastListItem> contrastList = new List <ContrastListItem>(); ContrastListItem CreateContrastListItem(IColorPaletteEntry colorValue, ContrastColorWrapper contrastColor, double minContrast = 4.5) { if (IsAlphaEnabled && contrastColor.BackgroundColor != null) { return(new ContrastListItem(colorValue, contrastColor.Color, contrastColor.BackgroundColor, minContrast)); } return(new ContrastListItem(colorValue, contrastColor.Color, minContrast)); } foreach (var c in value.ContrastColors) { if (c.ShowInContrastList) { if (c.ShowContrastErrors) { contrastList.Add(CreateContrastListItem(value, c)); } else { contrastList.Add(CreateContrastListItem(value, c, 0)); } } } SetValue(ContrastListProperty, contrastList); } }
public static EditableColorPaletteEntry Parse(JsonObject data, IColorPaletteEntry sourceColor, IReadOnlyList <ContrastColorWrapper> contrastColors) { Color customColor; if (data.ContainsKey("CustomColor")) { customColor = data["CustomColor"].GetColor(); } else { customColor = default(Color); } bool useCustomColor = false; if (data.ContainsKey("UseCustomColor")) { useCustomColor = data["UseCustomColor"].GetBoolean(); } ColorStringFormat activeColorStringFormat = ColorStringFormat.PoundRGB; if (data.ContainsKey("ActiveColorStringFormat")) { activeColorStringFormat = data.GetEnum <ColorStringFormat>(); } return(new EditableColorPaletteEntry(sourceColor, customColor, useCustomColor, data.GetOptionalString("Title"), data.GetOptionalString("Description"), activeColorStringFormat, contrastColors)); }
private void OnColorPaletteEntryChanged(IColorPaletteEntry oldValue, IColorPaletteEntry newValue) { if (oldValue != null) { oldValue.ActiveColorChanged -= ColorPaletteEntry_ActiveColorChanged; oldValue.ContrastColorChanged -= ColorPaletteEntry_ContrastColorChanged; } if (newValue != null) { ActiveColorBrush.Color = newValue.ActiveColor; ContrastColorBrush.Color = newValue.BestContrastColor != null ? newValue.BestContrastColor.Color.ActiveColor : default(Color); newValue.ActiveColorChanged += ColorPaletteEntry_ActiveColorChanged; newValue.ContrastColorChanged += ColorPaletteEntry_ContrastColorChanged; if (_flyoutContent != null) { _flyoutContent.Content = newValue; } } else { HideFlyout(); ActiveColorBrush.Color = default(Color); ContrastColorBrush.Color = default(Color); } UpdateCaption(); }
private string GenerateMappingDescription(IColorPaletteEntry paletteEntry, List <ThemeColorMapping> mappings) { string retVal = string.Empty; foreach (var mapping in mappings) { if (mapping.Source == paletteEntry) { if (retVal != string.Empty) { retVal += ", "; } retVal += mapping.Target.ToString(); } } if (retVal != string.Empty) { return(string.Format(_stringProvider.GetString("ColorFlyoutMappingDescription"), retVal)); } else { return(null); } }
public ContrastListItem(IColorPaletteEntry baseColor, IColorPaletteEntry contrastColor, double minContrast = 4.5) { _minContrast = minContrast; _baseColorBrush = new SolidColorBrush(); _contrastColorBrush = new SolidColorBrush(); BaseColor = baseColor; ContrastColor = contrastColor; }
private void OnColorPaletteEntryChanged(IColorPaletteEntry oldValue, IColorPaletteEntry newValue) { if (oldValue != null) { oldValue.ActiveColorChanged -= ColorPaletteEntry_ActiveColorChanged; } if (newValue != null) { ColorPicker.Color = newValue.ActiveColor; newValue.ActiveColorChanged += ColorPaletteEntry_ActiveColorChanged; if (string.IsNullOrEmpty(newValue.Title)) { TitleField.Visibility = Visibility.Collapsed; TitleField.Text = string.Empty; } else { TitleField.Visibility = Visibility.Visible; TitleField.Text = newValue.Title; } if (string.IsNullOrEmpty(newValue.Description)) { DescriptionField.Visibility = Visibility.Collapsed; DescriptionField.Text = string.Empty; } else { DescriptionField.Visibility = Visibility.Visible; DescriptionField.Text = newValue.Description; } if (newValue is EditableColorPaletteEntry editableNewValue) { RevertButton.Visibility = Visibility.Visible; RevertButton.IsEnabled = editableNewValue.UseCustomColor; } else { RevertButton.Visibility = Visibility.Collapsed; } if (newValue.ContrastColors != null) { UpdateContrastColors(newValue); } else { SetValue(ContrastListProperty, null); } } else { ColorPicker.Color = default(Color); SetValue(ContrastListProperty, null); } }
private void ColorPaletteEntry_ContrastColorChanged(IColorPaletteEntry obj) { var paletteEntry = ColorPaletteEntry; if (paletteEntry == null) { return; } ContrastColorBrush.Color = paletteEntry.BestContrastColor != null ? paletteEntry.BestContrastColor.Color.ActiveColor : default(Color); }
public static List <ColorMapping> ParseList(JsonArray data, IColorPaletteEntry lightRegion, IColorPaletteEntry darkRegion, ColorPalette lightBase, ColorPalette darkBase, ColorPalette lightPrimary, ColorPalette darkPrimary, IColorPaletteEntry white, IColorPaletteEntry black) { List <ColorMapping> retVal = new List <ColorMapping>(); foreach (var node in data) { retVal.Add(ColorMapping.Parse(node.GetObject(), lightRegion, darkRegion, lightBase, darkBase, lightPrimary, darkPrimary, white, black)); } return(retVal); }
public ContrastColorWrapper(IColorPaletteEntry color, bool showInContrastList, bool showContrastErrors) { if (color == null) { throw new ArgumentNullException("color"); } Color = color; ShowInContrastList = showInContrastList; ShowContrastErrors = showContrastErrors; }
public ColorMappingInstance(IColorPaletteEntry source, ColorTarget targetColor, ColorPaletteResources targetResources) { _source = source; _targetColor = targetColor; _targetResources = targetResources; Apply(); _source.ActiveColorChanged += Source_ActiveColorChanged; }
public ThemeColorMappingInstance(IColorPaletteEntry source, ThemeColorTarget targetColor, ColorPaletteResources targetResources, ThemeExtraPalette extraPalette) { _source = source; _targetColor = targetColor; _targetResources = targetResources; _extraPalette = extraPalette; Apply(); _source.ActiveColorChanged += Source_ActiveColorChanged; }
private void ColorPaletteEntry_ActiveColorChanged(IColorPaletteEntry obj) { if (obj is EditableColorPaletteEntry editablePaletteEntry) { RevertButton.IsEnabled = editablePaletteEntry.UseCustomColor; } if (obj != null) { ColorPicker.Color = obj.ActiveColor; } }
private void ColorPaletteEntry_ActiveColorChanged(IColorPaletteEntry obj) { var paletteEntry = ColorPaletteEntry; if (paletteEntry == null) { return; } ActiveColorBrush.Color = paletteEntry.ActiveColor; UpdateCaption(); }
public static ColorPalette Parse(JsonObject data, IReadOnlyList <ContrastColorWrapper> contrastColors) { IColorPaletteEntry baseColor = null; if (data.ContainsKey("EditableBaseColor")) { baseColor = EditableColorPaletteEntry.Parse(data["EditableBaseColor"].GetObject(), null, contrastColors); } else if (data.ContainsKey("BaseColor")) { baseColor = ColorPaletteEntry.Parse(data["BaseColor"].GetObject(), contrastColors); } int steps = data["Steps"].GetInt(); return(new ColorPalette(steps, baseColor, contrastColors)); }
public new static EditableColorPaletteEntry Parse(JsonObject data, IColorPaletteEntry sourceColor, IReadOnlyList <ContrastColorWrapper> contrastColors) { Color customColor; if (data.ContainsKey("CustomColor")) { customColor = data["CustomColor"].GetColor(); } else { customColor = default(Color); } bool useCustomColor = false; if (data.ContainsKey("UseCustomColor")) { useCustomColor = data["UseCustomColor"].GetBoolean(); } FluentEditorShared.Utils.ColorStringFormat activeColorStringFormat = FluentEditorShared.Utils.ColorStringFormat.PoundRGB; if (data.ContainsKey("ActiveColorStringFormat")) { activeColorStringFormat = data["ActiveColorStringFormat"].GetEnum <FluentEditorShared.Utils.ColorStringFormat>(); } if (data.ContainsKey(nameof(IsHostBackdrop)) && data.ContainsKey(nameof(TintOpacity)) && data.ContainsKey(nameof(TintLuminosityOpacity))) { var isHostBackdrop = data[nameof(IsHostBackdrop)].GetBoolean(); var tintOpacity = data[nameof(TintOpacity)].GetNumber(); double?tintLuminosityOpacity = null; var tintLuminosityOpacityString = data[nameof(TintLuminosityOpacity)].GetString(); if (double.TryParse(tintLuminosityOpacityString, out var value)) { tintLuminosityOpacity = value; } return(new ThemeEditableAcrylicPaletteEntry(isHostBackdrop, tintOpacity, tintLuminosityOpacity, sourceColor, customColor, useCustomColor, data.GetOptionalString("Title"), data.GetOptionalString("Description"), activeColorStringFormat, contrastColors)); } return(new EditableColorPaletteEntry(sourceColor, customColor, useCustomColor, data.GetOptionalString("Title"), data.GetOptionalString("Description"), activeColorStringFormat, contrastColors)); }
public EditableColorPaletteEntry(IColorPaletteEntry sourceColor, Color customColor, bool useCustomColor, string title, string description, ColorStringFormat activeColorStringFormat, IReadOnlyList <ContrastColorWrapper> contrastColors) { _sourceColor = sourceColor; _customColor = customColor; _useCustomColor = useCustomColor; _title = title; _description = description; _activeColorStringFormat = activeColorStringFormat; if (_useCustomColor || _sourceColor == null) { _activeColor = _customColor; } else { _activeColor = _sourceColor.ActiveColor; } ContrastColors = contrastColors; }
public static ColorMapping Parse(JsonObject data, IColorPaletteEntry lightRegion, IColorPaletteEntry darkRegion, ColorPalette lightBase, ColorPalette darkBase, ColorPalette lightPrimary, ColorPalette darkPrimary, IColorPaletteEntry white, IColorPaletteEntry black) { var target = data["Target"].GetEnum <ColorTarget>(); var source = data["Source"].GetEnum <ColorSource>(); int index = 0; if (data.ContainsKey("SourceIndex")) { index = data["SourceIndex"].GetInt(); } switch (source) { case ColorSource.LightRegion: return(new ColorMapping(lightRegion, target)); case ColorSource.DarkRegion: return(new ColorMapping(darkRegion, target)); case ColorSource.LightBase: return(new ColorMapping(lightBase.Palette[index], target)); case ColorSource.DarkBase: return(new ColorMapping(darkBase.Palette[index], target)); case ColorSource.LightPrimary: return(new ColorMapping(lightPrimary.Palette[index], target)); case ColorSource.DarkPrimary: return(new ColorMapping(darkPrimary.Palette[index], target)); case ColorSource.White: return(new ColorMapping(white, target)); case ColorSource.Black: return(new ColorMapping(black, target)); } return(null); }
public ColorPalette(int steps, IColorPaletteEntry baseColor) { if (baseColor == null) { throw new ArgumentNullException("baseColor"); } if (_steps <= 0) { throw new ArgumentException("steps must > 0"); } _steps = steps; _baseColor = baseColor; var scale = GetPaletteScale(); _palette = new List <ColorPaletteEntry>(_steps); for (int i = 0; i < _steps; i++) { var c = scale.GetColor((double)i / (double)(_steps - 1), _interpolationMode); _palette.Add(new ColorPaletteEntry(c)); } }
public ColorPalette(int steps, IColorPaletteEntry baseColor, IReadOnlyList <ContrastColorWrapper> contrastColors, IPaletteEntryData paletteEntryData) { if (baseColor == null) { throw new ArgumentNullException("baseColor"); } if (_steps <= 0) { throw new ArgumentException("steps must > 0"); } _contrastColors = contrastColors; _steps = steps; _baseColor = baseColor; _baseColor.ActiveColorChanged += BaseColor_ActiveColorChanged; _palette = new List <EditableColorPaletteEntry>(_steps); for (int i = 0; i < _steps; i++) { _palette.Add(paletteEntryData.GetColorPaletteEntry(baseColor, i)); } UpdatePaletteColors(); }
public ColorPalette(int steps, IColorPaletteEntry baseColor, IReadOnlyList <ContrastColorWrapper> contrastColors) { if (baseColor == null) { throw new ArgumentNullException("baseColor"); } if (_steps <= 0) { throw new ArgumentException("steps must > 0"); } _contrastColors = contrastColors; _steps = steps; _baseColor = baseColor; _baseColor.ActiveColorChanged += BaseColor_ActiveColorChanged; _palette = new List <EditableColorPaletteEntry>(_steps); for (int i = 0; i < _steps; i++) { string title = baseColor.Title + " " + (i * 100).ToString("000"); _palette.Add(new EditableColorPaletteEntry(null, default(Color), false, title, baseColor.Description, ColorStringFormat.PoundRGB, _contrastColors)); } UpdatePaletteColors(); }
private void Source_ActiveColorChanged(IColorPaletteEntry obj) { Apply(); ForceThemeUpdateInLinkedElement(); }
private void OnColorPaletteEntryChanged(IColorPaletteEntry oldValue, IColorPaletteEntry newValue) { if (oldValue != null) { oldValue.ActiveColorChanged -= ColorPaletteEntry_ActiveColorChanged; } if (newValue != null) { ColorPicker.Color = newValue.ActiveColor; newValue.ActiveColorChanged += ColorPaletteEntry_ActiveColorChanged; if (string.IsNullOrEmpty(newValue.Title)) { TitleField.Visibility = Visibility.Collapsed; TitleField.Text = string.Empty; } else { TitleField.Visibility = Visibility.Visible; TitleField.Text = newValue.Title; } if (string.IsNullOrEmpty(newValue.Description)) { DescriptionField.Visibility = Visibility.Collapsed; DescriptionField.Text = string.Empty; } else { DescriptionField.Visibility = Visibility.Visible; DescriptionField.Text = newValue.Description; } if (newValue is EditableColorPaletteEntry editableNewValue) { RevertButton.Visibility = Visibility.Visible; RevertButton.IsEnabled = editableNewValue.UseCustomColor; } else { RevertButton.Visibility = Visibility.Collapsed; } if (newValue.ContrastColors != null) { List <ContrastListItem> contrastList = new List <ContrastListItem>(); foreach (var c in newValue.ContrastColors) { if (c.ShowInContrastList) { if (c.ShowContrastErrors) { contrastList.Add(new ContrastListItem(newValue, c.Color)); } else { contrastList.Add(new ContrastListItem(newValue, c.Color, 0)); } } } SetValue(ContrastListProperty, contrastList); } else { SetValue(ContrastListProperty, null); } } else { ColorPicker.Color = default(Color); SetValue(ContrastListProperty, null); } }
public ThemeColorMapping(IColorPaletteEntry source, ThemeColorTarget targetColor) { _source = source; _targetColor = targetColor; }
private void DarkRegion_ActiveColorChanged(IColorPaletteEntry obj) { _darkRegionBrush.Color = obj.ActiveColor; }
private void LightRegion_ActiveColorChanged(IColorPaletteEntry obj) { _lightRegionBrush.Color = obj.ActiveColor; }
public ColorPalette(int steps, IColorPaletteEntry baseColor, IReadOnlyList <ContrastColorWrapper> contrastColors) : this(steps, baseColor, contrastColors, new PaletteEntryData(baseColor, contrastColors)) { }
private void PaletteEntry_ActiveColorChanged(IColorPaletteEntry obj) { UpdateActivePreset(); }
public virtual EditableColorPaletteEntry GetColorPaletteEntry(IColorPaletteEntry baseColor, int idx) { return(new EditableColorPaletteEntry(null, default(Color), false, GetPaletteEntryTitle(idx), GetPaletteEntryDescription(idx), baseColor.ActiveColorStringFormat, GetPaletteEntryContrastColors(idx))); }
public PaletteEntryData(IColorPaletteEntry baseColor, IReadOnlyList <ContrastColorWrapper> contrastColors) { _baseColor = baseColor; _contrastColors = contrastColors; }
private void BaseColor_ActiveColorChanged(IColorPaletteEntry obj) { UpdatePaletteColors(); }