/
Swatch.cs
50 lines (40 loc) · 1.56 KB
/
Swatch.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
namespace MaterialDesignColors
{
/// <summary>
/// Defines a single colour swatch.
/// </summary>
public class Swatch
{
public Swatch(string name, IEnumerable<Hue> primaryHues, IEnumerable<Hue> accentHues)
{
if (name == null) throw new ArgumentNullException(nameof(name));
if (primaryHues == null) throw new ArgumentNullException(nameof(primaryHues));
if (accentHues == null) throw new ArgumentNullException(nameof(accentHues));
var primaryHuesList = primaryHues.ToList();
if (primaryHuesList.Count == 0) throw new ArgumentException("Non primary hues provided.", nameof(primaryHues));
Name = name;
PrimaryHues = primaryHuesList;
var accentHuesList = accentHues.ToList();
AccentHues = accentHuesList;
ExemplarHue = primaryHuesList[Math.Min(5, primaryHuesList.Count-1)];
if (IsAccented)
AccentExemplarHue = accentHuesList[Math.Min(2, accentHuesList.Count - 1)];
}
public string Name { get; }
public Hue ExemplarHue { get; }
public Hue AccentExemplarHue { get; }
public IEnumerable<Hue> PrimaryHues { get; }
public IEnumerable<Hue> AccentHues { get; }
public bool IsAccented => AccentHues.Any();
public override string ToString()
{
return Name;
}
}
}