mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 23:19:13 +08:00
Show color as a float and as a decimal value (#14548)
* #14020 and #12630 - Show color as a float and as a decimal value * getting stuff up-to-par * changing RGB Float to VEC4 * Getting Decimal to display correct. * tweaking VEC4 output. What would be better is if these actually pulled from a real output ... * Shifting to force decimal Co-authored-by: Clint Rutkas <crutkas@microsoft.com>
This commit is contained in:
parent
46244e8e84
commit
8743c2329e
@ -44,6 +44,14 @@ namespace ColorPicker.Helpers
|
||||
return (cyan, magenta, yellow, blackKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a given <see cref="Color"/> to a float color styling(0.1f, 0.1f, 0.1f)
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||
/// <returns>The int / 255d for each value to get value between 0 and 1</returns>
|
||||
internal static (double red, double green, double blue) ConvertToDouble(Color color)
|
||||
=> (color.R / 255d, color.G / 255d, color.B / 255d);
|
||||
|
||||
/// <summary>
|
||||
/// Convert a given <see cref="Color"/> to a HSB color (hue, saturation, brightness)
|
||||
/// </summary>
|
||||
|
@ -46,6 +46,8 @@ namespace ColorPicker.Helpers
|
||||
ColorRepresentationType.RGB => ColorToRGB(color),
|
||||
ColorRepresentationType.CIELAB => ColorToCIELAB(color),
|
||||
ColorRepresentationType.CIEXYZ => ColorToCIEXYZ(color),
|
||||
ColorRepresentationType.VEC4 => ColorToFloat(color),
|
||||
ColorRepresentationType.DecimalValue => ColorToDecimal(color),
|
||||
|
||||
// Fall-back value, when "_userSettings.CopiedColorRepresentation.Value" is incorrect
|
||||
_ => ColorToHex(color),
|
||||
@ -99,6 +101,29 @@ namespace ColorPicker.Helpers
|
||||
+ $", {brightness.ToString(CultureInfo.InvariantCulture)}%)";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="string"/> representation float color styling(0.1f, 0.1f, 0.1f)
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||
/// <returns>a string value (0.1f, 0.1f, 0.1f)</returns>
|
||||
private static string ColorToFloat(Color color)
|
||||
{
|
||||
var (red, green, blue) = ColorHelper.ConvertToDouble(color);
|
||||
var precision = 2;
|
||||
|
||||
return $"({Math.Round(red, precision).ToString("0.##", CultureInfo.InvariantCulture)}f, {Math.Round(green, precision).ToString("0.##", CultureInfo.InvariantCulture)}f, {Math.Round(blue, precision).ToString("0.##", CultureInfo.InvariantCulture)}f, 1f)";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="string"/> representation decimal color value
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="Color"/> to convert</param>
|
||||
/// <returns>a string value number</returns>
|
||||
private static string ColorToDecimal(Color color)
|
||||
{
|
||||
return $"{color.R + (color.G * 256) + (color.B * 65536)}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="string"/> representation of a HSI color
|
||||
/// </summary>
|
||||
|
@ -216,6 +216,18 @@ namespace ColorPicker.ViewModels
|
||||
FormatName = ColorRepresentationType.CIEXYZ.ToString(),
|
||||
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.CIEXYZ); },
|
||||
});
|
||||
_allColorRepresentations.Add(
|
||||
new ColorFormatModel()
|
||||
{
|
||||
FormatName = ColorRepresentationType.VEC4.ToString(),
|
||||
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.VEC4); },
|
||||
});
|
||||
_allColorRepresentations.Add(
|
||||
new ColorFormatModel()
|
||||
{
|
||||
FormatName = "Decimal",
|
||||
Convert = (Color color) => { return ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.DecimalValue); },
|
||||
});
|
||||
|
||||
_userSettings.VisibleColorFormats.CollectionChanged += VisibleColorFormats_CollectionChanged;
|
||||
|
||||
|
@ -24,6 +24,8 @@ namespace Microsoft.ColorPicker.UnitTests
|
||||
[DataRow(ColorRepresentationType.RGB, "rgb(0, 0, 0)")]
|
||||
[DataRow(ColorRepresentationType.CIELAB, "CIELab(0, 0, 0)")]
|
||||
[DataRow(ColorRepresentationType.CIEXYZ, "xyz(0, 0, 0)")]
|
||||
[DataRow(ColorRepresentationType.VEC4, "(0f, 0f, 0f, 1f)")]
|
||||
[DataRow(ColorRepresentationType.DecimalValue, "0")]
|
||||
|
||||
public void GetStringRepresentationTest(ColorRepresentationType type, string expected)
|
||||
{
|
||||
|
@ -65,5 +65,15 @@ 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 RGB float (red[0..1], green[0..1], blue[0..1])
|
||||
/// </summary>
|
||||
VEC4 = 11,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as integer decimal value 0-16777215
|
||||
/// </summary>
|
||||
DecimalValue = 12,
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,8 @@ 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.VEC4, "VEC4 - (1.0f, 0.7f, 0f, 1f)" },
|
||||
{ ColorRepresentationType.DecimalValue, "Decimal - 16755200" },
|
||||
};
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
@ -198,6 +200,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
var ncolFormatName = ColorRepresentationType.NCol.ToString();
|
||||
var cielabFormatName = ColorRepresentationType.CIELAB.ToString();
|
||||
var ciexyzFormatName = ColorRepresentationType.CIEXYZ.ToString();
|
||||
var vec4FormatName = ColorRepresentationType.VEC4.ToString();
|
||||
var decimalFormatName = "Decimal";
|
||||
|
||||
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]));
|
||||
@ -210,6 +214,8 @@ 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(vec4FormatName, "(0.94f, 0.41f, 1.00f, 1f)", visibleFormats.ContainsKey(vec4FormatName) && visibleFormats[vec4FormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(decimalFormatName, "15689983", visibleFormats.ContainsKey(decimalFormatName) && visibleFormats[decimalFormatName]));
|
||||
|
||||
foreach (var storedColorFormat in _colorPickerSettings.Properties.VisibleColorFormats)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user