add SystemColors palette to color picker gui
This commit is contained in:
1 parent
87bf9a37cc
commit
18bdeea765
2 files changed
+31
-8
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using mbts.spark;
|
||||
using bts.collections;
|
||||
using mbts.spark;
|
||||
using mbts.spark.utilities;
|
||||
using ProtoBuf;
|
||||
using System.Collections.Generic;
|
||||
@@ -23,6 +24,7 @@ namespace mbts.ui.controls.color_picker {
|
||||
yield return factory_order_colors_palette(order_factory);
|
||||
yield return application_palette();
|
||||
yield return bts_palette();
|
||||
yield return system_palette();
|
||||
yield return blank_palette();
|
||||
}
|
||||
|
||||
@@ -109,6 +111,14 @@ namespace mbts.ui.controls.color_picker {
|
||||
}
|
||||
};
|
||||
|
||||
public static ColorPalette system_palette() =>
|
||||
new ColorPalette {
|
||||
group = "System",
|
||||
colors = ColorUtils.SystemColors.WrapReadOnlySelector(
|
||||
nc => new NamedColor(nc.value, nc.name))
|
||||
.ToList()
|
||||
};
|
||||
|
||||
public static ColorPalette blank_palette() =>
|
||||
new ColorPalette {
|
||||
group = "Custom",
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace mbts.ui.controls.color_picker {
|
||||
}.to_comparer();
|
||||
|
||||
static readonly Named<Color>[]
|
||||
_system_colors,
|
||||
// 'pure' means no grays
|
||||
_pure_web_colors,
|
||||
_gray_web_colors,
|
||||
@@ -32,15 +33,21 @@ namespace mbts.ui.controls.color_picker {
|
||||
_all_web_colors_grid;
|
||||
|
||||
static ColorUtils() {
|
||||
var named_color_lh_comp = LHComparer.wrap<Color, Named<Color>>(nc => nc.value);
|
||||
_system_colors = Array.ConvertAll(
|
||||
typeof(Colors).GetProperties(BindingFlags.Static | BindingFlags.Public),
|
||||
p => new Named<Color>(
|
||||
DisplayNameHelper.camel_to_title_case(p.Name),
|
||||
(Color)p.GetValue(null)));
|
||||
Array.Sort(_system_colors, named_color_lh_comp);
|
||||
_all_web_colors = Array.ConvertAll(
|
||||
typeof(System.Drawing.Color).GetProperties(BindingFlags.Public | BindingFlags.Static),
|
||||
p => {
|
||||
typeof(System.Drawing.Color)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Static),
|
||||
p => {
|
||||
var c = System.Drawing.Color.FromName(p.Name);
|
||||
return new Named<Color>(
|
||||
DisplayNameHelper.camel_to_title_case(p.Name),
|
||||
Color.FromArgb(c.A, c.R, c.G, c.B));
|
||||
return new Named<Color>(p.Name, Color.FromArgb(c.A, c.R, c.G, c.B));
|
||||
});
|
||||
Array.Sort(_all_web_colors, LHComparer.wrap<Color, Named<Color>>(n => n.value));
|
||||
Array.Sort(_all_web_colors, named_color_lh_comp);
|
||||
var all_web_colors_grid = new Named<Color>[_all_web_colors.Length - 1];
|
||||
int adj = 0;
|
||||
for (int i = 0; i < _all_web_colors.Length; i++) {
|
||||
@@ -74,6 +81,12 @@ namespace mbts.ui.controls.color_picker {
|
||||
_pure_web_colors_grid = pure_web_colors_grid;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<Named<Color>> SystemColors =>
|
||||
_system_colors;
|
||||
|
||||
public static IReadOnlyList<NamedColorVM> SystemColorVMs =>
|
||||
_system_colors.WrapSelectorRO(_mk_readonly_vm);
|
||||
|
||||
public static IReadOnlyList<Named<Color>> WebColors =>
|
||||
_all_web_colors;
|
||||
|
||||
@@ -280,4 +293,4 @@ namespace mbts.ui.controls.color_picker {
|
||||
static NamedColorVM _mk_readonly_vm(Named<Color> nc) =>
|
||||
new NamedColorVM(new NamedColor(nc.value, nc.name), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user