mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
Added HEX2
This commit is contained in:
@@ -46,6 +46,7 @@ namespace ColorPicker.Helpers
|
||||
ColorRepresentationType.RGB => ColorToRGB(color),
|
||||
ColorRepresentationType.CIELAB => ColorToCIELAB(color),
|
||||
ColorRepresentationType.CIEXYZ => ColorToCIEXYZ(color),
|
||||
ColorRepresentationType.HEX2 => ColorToHex2(color),
|
||||
|
||||
// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
|
||||
_ => ColorToHex(color),
|
||||
@@ -77,7 +78,7 @@ namespace ColorPicker.Helpers
|
||||
/// <param name="color">The see cref="Color"/> for the hexadecimal presentation</param>
|
||||
/// <returns>A hexadecimal <see cref="string"/> representation of a RGB color</returns>
|
||||
private static string ColorToHex(Color color)
|
||||
=> $"#{color.R.ToString("X2", CultureInfo.InvariantCulture)}"
|
||||
=> $"{color.R.ToString("X2", CultureInfo.InvariantCulture)}"
|
||||
+ $"{color.G.ToString("X2", CultureInfo.InvariantCulture)}"
|
||||
+ $"{color.B.ToString("X2", CultureInfo.InvariantCulture)}";
|
||||
|
||||
@@ -234,5 +235,17 @@ namespace ColorPicker.Helpers
|
||||
$", {y.ToString(CultureInfo.InvariantCulture)}" +
|
||||
$", {z.ToString(CultureInfo.InvariantCulture)})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a hexadecimal <see cref="string"/> representation of a RGB color in lowercase and # included
|
||||
/// </summary>
|
||||
/// <param name="color">The see cref="Color"/> for the hexadecimal presentation</param>
|
||||
/// <returns>A hexadecimal <see cref="string"/> representation of a RGB color</returns>
|
||||
private static string ColorToHex2(Color color)
|
||||
#pragma warning disable CA1304 // Specify CultureInfo
|
||||
=> $"#{color.R.ToString("X2", CultureInfo.InvariantCulture).ToLower()}"
|
||||
+ $"{color.G.ToString("X2", CultureInfo.InvariantCulture).ToLower()}"
|
||||
+ $"{color.B.ToString("X2", CultureInfo.InvariantCulture).ToLower()}";
|
||||
#pragma warning restore CA1304 // Specify CultureInfo
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,6 +215,13 @@ namespace ColorPicker.ViewModels
|
||||
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.CIEXYZ); },
|
||||
});
|
||||
|
||||
_allColorRepresentations.Add(
|
||||
new ColorFormatModel()
|
||||
{
|
||||
FormatName = ColorRepresentationType.HEX2.ToString(),
|
||||
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HEX2); },
|
||||
});
|
||||
|
||||
_userSettings.VisibleColorFormats.CollectionChanged += VisibleColorFormats_CollectionChanged;
|
||||
|
||||
// Any other custom format to be added here as well that are read from settings
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Enumerations
|
||||
public enum ColorRepresentationType
|
||||
{
|
||||
/// <summary>
|
||||
/// Color presentation as hexadecimal color value without the alpha-value (e.g. #0055FF)
|
||||
/// Color presentation as hexadecimal color value without the alpha-value (e.g. 0055FF)
|
||||
/// </summary>
|
||||
HEX = 0,
|
||||
|
||||
@@ -65,5 +65,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Enumerations
|
||||
/// Color presentation as CIEXYZ color space (X[0..95], Y[0..100], Z[0..109]
|
||||
/// </summary>
|
||||
CIEXYZ = 10,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as hexadecimal color value without the alpha-value - lowercase and with # (e.g. #0055FF)
|
||||
/// </summary>
|
||||
HEX2 = 11,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
SelectableColorRepresentations = new Dictionary<ColorRepresentationType, string>
|
||||
{
|
||||
{ ColorRepresentationType.CMYK, "CMYK - cmyk(100%, 50%, 75%, 0%)" },
|
||||
{ ColorRepresentationType.HEX, "HEX - #FFAA00" },
|
||||
{ ColorRepresentationType.HEX, "HEX - FFAA00" },
|
||||
{ ColorRepresentationType.HSB, "HSB - hsb(100, 50%, 75%)" },
|
||||
{ ColorRepresentationType.HSI, "HSI - hsi(100, 50%, 75%)" },
|
||||
{ ColorRepresentationType.HSL, "HSL - hsl(100, 50%, 75%)" },
|
||||
@@ -55,6 +55,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{ ColorRepresentationType.RGB, "RGB - rgb(100, 50, 75)" },
|
||||
{ ColorRepresentationType.CIELAB, "CIE LAB - CIELab(76, 21, 80)" },
|
||||
{ ColorRepresentationType.CIEXYZ, "CIE XYZ - xyz(56, 50, 7)" },
|
||||
{ ColorRepresentationType.HEX2, "HEX - #ffaa00" },
|
||||
};
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
@@ -198,8 +199,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
var ncolFormatName = ColorRepresentationType.NCol.ToString();
|
||||
var cielabFormatName = ColorRepresentationType.CIELAB.ToString();
|
||||
var ciexyzFormatName = ColorRepresentationType.CIEXYZ.ToString();
|
||||
var hex2FormatName = ColorRepresentationType.HEX2.ToString();
|
||||
|
||||
formatsUnordered.Add(new ColorFormatModel(hexFormatName, "#EF68FF", visibleFormats.ContainsKey(hexFormatName) && visibleFormats[hexFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hexFormatName, "EF68FF", visibleFormats.ContainsKey(hexFormatName) && visibleFormats[hexFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(rgbFormatName, "rgb(239, 104, 255)", visibleFormats.ContainsKey(rgbFormatName) && visibleFormats[rgbFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hslFormatName, "hsl(294, 100%, 70%)", visibleFormats.ContainsKey(hslFormatName) && visibleFormats[hslFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hsvFormatName, "hsv(294, 59%, 100%)", visibleFormats.ContainsKey(hsvFormatName) && visibleFormats[hsvFormatName]));
|
||||
@@ -210,6 +212,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
formatsUnordered.Add(new ColorFormatModel(ncolFormatName, "R10, 50%, 75%", visibleFormats.ContainsKey(ncolFormatName) && visibleFormats[ncolFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(cielabFormatName, "CIELab(66, 72, -52)", visibleFormats.ContainsKey(cielabFormatName) && visibleFormats[cielabFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(ciexyzFormatName, "xyz(59, 35, 98)", visibleFormats.ContainsKey(ciexyzFormatName) && visibleFormats[ciexyzFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hex2FormatName, "#ef68ff", visibleFormats.ContainsKey(hex2FormatName) && visibleFormats[hex2FormatName]));
|
||||
|
||||
foreach (var storedColorFormat in _colorPickerSettings.Properties.VisibleColorFormats)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user