diff --git a/ShareX.HelpersLib/Colors/GradientInfo.cs b/ShareX.HelpersLib/Colors/GradientInfo.cs index 5fa99cf47..8ef5716f6 100644 --- a/ShareX.HelpersLib/Colors/GradientInfo.cs +++ b/ShareX.HelpersLib/Colors/GradientInfo.cs @@ -42,7 +42,7 @@ public bool IsValid { get { - return Colors != null && Colors.Count >= 2 && Colors.Any(x => x.Location == 0f) && Colors.Any(x => x.Location == 100f); + return Colors != null && Colors.Count > 0; } } @@ -71,10 +71,21 @@ public void Draw(Graphics g, Rectangle rect) public ColorBlend GetColorBlend() { + List colors = new List(Colors.OrderBy(x => x.Location)); + + if (!colors.Any(x => x.Location == 0)) + { + colors.Insert(0, new GradientStop(colors[0].Color, 0f)); + } + + if (!colors.Any(x => x.Location == 100)) + { + colors.Add(new GradientStop(colors[colors.Count - 1].Color, 100f)); + } + ColorBlend colorBlend = new ColorBlend(); - IEnumerable gradient = Colors.OrderBy(x => x.Location); - colorBlend.Colors = gradient.Select(x => x.Color).ToArray(); - colorBlend.Positions = gradient.Select(x => x.Location / 100).ToArray(); + colorBlend.Colors = colors.Select(x => x.Color).ToArray(); + colorBlend.Positions = colors.Select(x => x.Location / 100).ToArray(); return colorBlend; } diff --git a/ShareX.HelpersLib/Colors/GradientStop.cs b/ShareX.HelpersLib/Colors/GradientStop.cs index 213ca0c58..0ee5dbf0e 100644 --- a/ShareX.HelpersLib/Colors/GradientStop.cs +++ b/ShareX.HelpersLib/Colors/GradientStop.cs @@ -32,7 +32,7 @@ namespace ShareX.HelpersLib public class GradientStop { [DefaultValue(typeof(Color), "Black"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))] - public Color Color { get; set; } + public Color Color { get; set; } = Color.Black; private float location; @@ -51,7 +51,6 @@ public float Location public GradientStop() { - this.ApplyDefaultPropertyValues(); } public GradientStop(Color color, float offset) diff --git a/ShareX.HelpersLib/Forms/GradientPickerForm.resx b/ShareX.HelpersLib/Forms/GradientPickerForm.resx index dfa415049..1bc783e00 100644 --- a/ShareX.HelpersLib/Forms/GradientPickerForm.resx +++ b/ShareX.HelpersLib/Forms/GradientPickerForm.resx @@ -146,6 +146,10 @@ 11 + + + NoControl + 8, 112 @@ -170,6 +174,9 @@ 9 + + NoControl + 8, 136 @@ -195,15 +202,14 @@ 8 - 64, 188 + 8, 216 - 56, 20 + 112, 20 5 - Center @@ -222,8 +228,11 @@ True + + NoControl + - 5, 192 + 5, 200 51, 13 @@ -270,6 +279,9 @@ True + + NoControl + 5, 88 @@ -294,6 +306,9 @@ 4 + + NoControl + 8, 280 @@ -318,6 +333,9 @@ 3 + + NoControl + 112, 280 @@ -342,6 +360,9 @@ 2 + + NoControl + 8, 26 @@ -366,6 +387,9 @@ True + + NoControl + 5, 8 @@ -390,8 +414,11 @@ 1 + + NoControl + - 8, 160 + 8, 168 112, 24 @@ -406,7 +433,7 @@ cbtnCurrentColor - ShareX.HelpersLib.ColorButton, ShareX.HelpersLib, Version=13.0.2.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.ColorButton, ShareX.HelpersLib, Version=13.1.1.0, Culture=neutral, PublicKeyToken=null $this