private void lstColors_DoubleClick(object sender, EventArgs e)
{
ListBox.SelectedIndexCollection indices = lstColors.SelectedIndices;
if ((_colorSource == null) || (indices.Count <= 0))
{
return;
}
int count = indices.Count;
if (count == 1)
{
int index = indices[0];
_dlgColor.Color = (Color)(ARGBPixel)lstColors.Items[index];
if (_dlgColor.ShowDialog(this) == DialogResult.OK)
{
ARGBPixel p = (ARGBPixel)_dlgColor.Color;
lstColors.Items[index] = p;
_colorSource.SetColor(index, p);
}
}
else
{
//Sort indices
int[] sorted = new int[count];
indices.CopyTo(sorted, 0);
Array.Sort(sorted);
_dlgGradient.StartColor = (Color)(ARGBPixel)lstColors.Items[sorted[0]];
_dlgGradient.EndColor = (Color)(ARGBPixel)lstColors.Items[sorted[count - 1]];
if (_dlgGradient.ShowDialog(this) == DialogResult.OK)
{
//Interpolate and apply to each in succession.
ARGBPixel start = (ARGBPixel)_dlgGradient.StartColor;
ARGBPixel end = (ARGBPixel)_dlgGradient.EndColor;
float stepA = (end.A - start.A) / (float)count;
float stepR = (end.R - start.R) / (float)count;
float stepG = (end.G - start.G) / (float)count;
float stepB = (end.B - start.B) / (float)count;
for (int i = 0; i < count; i++)
{
ARGBPixel p = new ARGBPixel(
(byte)(start.A + (i * stepA)),
(byte)(start.R + (i * stepR)),
(byte)(start.G + (i * stepG)),
(byte)(start.B + (i * stepB)));
lstColors.Items[sorted[i]] = p;
_colorSource.SetColor(sorted[i], p);
}
}
}
}