This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 569
/
NamedColorGroup.cs
60 lines (50 loc) · 1.89 KB
/
NamedColorGroup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Xamarin.FormsBook.Toolkit
{
public class NamedColorGroup : List<NamedColor>
{
// Instance members.
private NamedColorGroup(string title, string shortName, Color colorShade)
{
this.Title = title;
this.ShortName = shortName;
this.ColorShade = colorShade;
}
public string Title { private set; get; }
public string ShortName { private set; get; }
public Color ColorShade { private set; get; }
// Static members.
static NamedColorGroup()
{
// Create all the groups
List<NamedColorGroup> groups = new List<NamedColorGroup>
{
new NamedColorGroup("Grays", "Gry", new Color(0.75, 0.75, 0.75)),
new NamedColorGroup("Reds", "Red", new Color(1, 0.75, 0.75)),
new NamedColorGroup("Yellows", "Yel", new Color(1, 1, 0.75)),
new NamedColorGroup("Greens", "Grn", new Color(0.75, 1, 0.75)),
new NamedColorGroup("Cyans", "Cyn", new Color(0.75, 1, 1)),
new NamedColorGroup("Blues", "Blu", new Color(0.75, 0.75, 1)),
new NamedColorGroup("Magentas", "Mag", new Color(1, 0.75, 1))
};
foreach (NamedColor namedColor in NamedColor.All)
{
Color color = namedColor.Color;
int index = 0;
if (color.Saturation != 0)
{
index = 1 + (int)((12 * color.Hue + 1) / 2) % 6;
}
groups[index].Add(namedColor);
}
foreach (NamedColorGroup group in groups)
{
group.TrimExcess();
}
All = groups;
}
public static IList<NamedColorGroup> All { private set; get; }
}
}