Files
Artemis/Artemis/Artemis/Utilities/ColorHelpers.cs
T
Robert Beekman de3d2f2f53 Layer refactor (#118)
* Expanded Trace logging for Overwatch and RL, updated The Witcher 3 mod for 1.22

* Events WIP

* Moved some views around, added event views

* Implemented events

* Some improvements to Overwatch parsing.. some.

* Improved Overwatch parsing to work well with events

* Fixed ultimate ready false positive during ultimate usage

* Added debug window which currently shows Razer SDK keyboard output

* Expanded Overwatch data model (todo: sticky values to avoid false-positives)

* Added sticky values to Overwatch datamodel, should resolve most flickering/false positives

* Layer refactor WIP

* Moved layer types, animations, conditions and events to interfaces. (WIP)

* Code cleanup, moved all profile related models to their own folder/namespace

* Finished most of the profile refactoring

* More profile refactoring, app compiles again

* Switched from XML to JSON for profiles (refactor broke existing profiles anyway)

* Made animation event expiration generic and fixed all serialization issues I've come across so far

* Cleaned up settings, rigged basic LayerEditorView(Model) to refactored models

* Rigged most layer type viewmodels back up to the new models

* Fixed most view(models).
Added animations to mice and headset.
Replaced serialization-based cloning with NClone
Fixed some rendering issues that came up with refactoring

* Added Current Time to WindowsProfile

* Cloning fixes
Replaced glitchy cloning package with a simple serialization clone (that package looked so good :c)
Removed serialization cloning from render process

* Expanded Trace logging for Overwatch and RL, updated The Witcher 3 mod for 1.22

* Events WIP

* Moved some views around, added event views

* Implemented events

* Some improvements to Overwatch parsing.. some.

* Improved Overwatch parsing to work well with events

* Fixed ultimate ready false positive during ultimate usage

* Added debug window which currently shows Razer SDK keyboard output

* Expanded Overwatch data model (todo: sticky values to avoid false-positives)

* Added sticky values to Overwatch datamodel, should resolve most flickering/false positives

* Layer refactor WIP

* Moved layer types, animations, conditions and events to interfaces. (WIP)

* Code cleanup, moved all profile related models to their own folder/namespace

* Finished most of the profile refactoring

* More profile refactoring, app compiles again

* Switched from XML to JSON for profiles (refactor broke existing profiles anyway)

* Made animation event expiration generic and fixed all serialization issues I've come across so far

* Cleaned up settings, rigged basic LayerEditorView(Model) to refactored models

* Rigged most layer type viewmodels back up to the new models

* Fixed most view(models).
Added animations to mice and headset.
Replaced serialization-based cloning with NClone
Fixed some rendering issues that came up with refactoring

* Added Current Time to WindowsProfile

* Cloning fixes
Replaced glitchy cloning package with a simple serialization clone (that package looked so good :c)
Removed serialization cloning from render process
2016-07-06 20:17:46 +02:00

100 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace Artemis.Utilities
{
public static class ColorHelpers
{
private static readonly Random _rand = new Random();
/// <summary>
/// Comes up with a 'pure' psuedo-random color
/// </summary>
/// <returns>The color</returns>
public static Color GetRandomRainbowColor()
{
var colors = new List<int>();
for (var i = 0; i < 3; i++)
colors.Add(_rand.Next(0, 256));
var highest = colors.Max();
var lowest = colors.Min();
colors[colors.FindIndex(c => c == highest)] = 255;
colors[colors.FindIndex(c => c == lowest)] = 0;
var returnColor = Color.FromArgb(255, colors[0], colors[1], colors[2]);
return returnColor;
}
public static System.Windows.Media.Color GetRandomRainbowMediaColor()
{
var colors = new List<byte>();
for (var i = 0; i < 3; i++)
colors.Add((byte) _rand.Next(0, 256));
var highest = colors.Max();
var lowest = colors.Min();
colors[colors.FindIndex(c => c == highest)] = 255;
colors[colors.FindIndex(c => c == lowest)] = 0;
var returnColor = System.Windows.Media.Color.FromArgb(255, colors[0], colors[1], colors[2]);
return returnColor;
}
public static Color ShiftColor(Color c, int shiftAmount)
{
int newRed = c.R;
int newGreen = c.G;
int newBlue = c.B;
// Red to purple
if (c.R == 255 && c.B < 255 && c.G == 0)
newBlue = newBlue + shiftAmount;
// Purple to blue
else if (c.B == 255 && c.R > 0)
newRed = newRed - shiftAmount;
// Blue to light-blue
else if (c.B == 255 && c.G < 255)
newGreen = newGreen + shiftAmount;
// Light-blue to green
else if (c.G == 255 && c.B > 0)
newBlue = newBlue - shiftAmount;
// Green to yellow
else if (c.G == 255 && c.R < 255)
newRed = newRed + shiftAmount;
// Yellow to red
else if (c.R == 255 && c.G > 0)
newGreen = newGreen - shiftAmount;
newRed = BringIntInColorRange(newRed);
newGreen = BringIntInColorRange(newGreen);
newBlue = BringIntInColorRange(newBlue);
return Color.FromArgb(c.A, newRed, newGreen, newBlue);
}
private static int BringIntInColorRange(int i)
{
if (i < 0)
return 0;
if (i > 255)
return 255;
return i;
}
public static Color ToDrawingColor(System.Windows.Media.Color mColor)
{
return Color.FromArgb(mColor.A, mColor.R, mColor.G, mColor.B);
}
public static System.Windows.Media.Color ToMediaColor(Color dColor)
{
return System.Windows.Media.Color.FromArgb(dColor.A, dColor.R, dColor.G, dColor.B);
}
}
}