Files
@ 721656f9e923
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/Palette.cs - annotation
721656f9e923
1.3 KiB
text/x-csharp
Added a dialog for prompting resolution and pixel-width, so that the app can be used on retina systems. RC3.
b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 | using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace DesertPaintLab
{
public class Palette
{
static List<PaintColor> colors = new List<PaintColor>();
static Regex colorEntry = new Regex(@"\#(?<red>\w\w)(?<green>\w\w)(?<blue>\w\w)\s*(?<name>\w+)");
public Palette ()
{
}
public static void Load(string file)
{
string line;
Match match;
using (StreamReader reader = new StreamReader(file))
{
while ((line = reader.ReadLine()) != null)
{
match = colorEntry.Match(line);
if (match.Success)
{
colors.Add(new PaintColor(match.Groups["name"].Value,
match.Groups["red"].Value,
match.Groups["green"].Value,
match.Groups["blue"].Value));
}
}
}
}
public static string FindNearest(PaintColor color)
{
int bestDistSq = int.MaxValue;
PaintColor bestColor = null;
foreach (PaintColor paintColor in colors)
{
int distSq = paintColor.GetDistanceSquared(color);
if (distSq < bestDistSq)
{
bestDistSq = distSq;
bestColor = paintColor;
}
}
return bestColor.Name;
}
}
}
|