Gradient editor - Added stops creation

Core - ColorGradient can now return a color at a certain position
This commit is contained in:
Robert committed 2020-03-11 20:11:42 +01:00
1 parent f95aaf2443
commit 0ccc1fed3d
5 files changed
+75 -40

No files matched your search

@@ -44,6 +44,31 @@ namespace Artemis.Core.Models.Profile
{
OnPropertyChanged(nameof(Colors));
}
public SKColor GetColor(float position)
{
var point = Colors.SingleOrDefault(f => f.Position == position);
if (point != null) return point.Color;
var before = Colors.First(w => w.Position == Colors.Min(m => m.Position));
var after = Colors.First(w => w.Position == Colors.Max(m => m.Position));
foreach (var gs in Colors)
{
if (gs.Position < position && gs.Position > before.Position)
before = gs;
if (gs.Position >= position && gs.Position < after.Position)
after = gs;
}
return new SKColor(
(byte) ((position - before.Position) * (after.Color.Red - before.Color.Red) / (after.Position - before.Position) + before.Color.Red),
(byte) ((position - before.Position) * (after.Color.Green - before.Color.Green) / (after.Position - before.Position) + before.Color.Green),
(byte) ((position - before.Position) * (after.Color.Blue - before.Color.Blue) / (after.Position - before.Position) + before.Color.Blue),
(byte) ((position - before.Position) * (after.Color.Alpha - before.Color.Alpha) / (after.Position - before.Position) + before.Color.Alpha)
);
}
}
public class ColorGradientColor : INotifyPropertyChanged