mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 01:37:31 +13:00
If text color not visible in white background then use dark gray background color
This commit is contained in:
parent
b47a69c8bb
commit
cfcb879172
4 changed files with 14 additions and 12 deletions
|
@ -82,7 +82,7 @@ private void AddGradientStop(GradientStop gradientStop)
|
|||
ListViewItem lvi = new ListViewItem();
|
||||
lvi.Text = string.Format(" {0:0.##}%", gradientStop.Location);
|
||||
lvi.BackColor = gradientStop.Color;
|
||||
lvi.ForeColor = ColorHelpers.VisibleTextColor(gradientStop.Color);
|
||||
lvi.ForeColor = ColorHelpers.VisibleColor(gradientStop.Color);
|
||||
lvi.Tag = gradientStop;
|
||||
lvGradientPoints.Items.Add(lvi);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ private void cbtnCurrentColor_ColorChanged(Color color)
|
|||
GradientStop gradientStop = (GradientStop)lvi.Tag;
|
||||
gradientStop.Color = color;
|
||||
lvi.BackColor = gradientStop.Color;
|
||||
lvi.ForeColor = ColorHelpers.VisibleTextColor(gradientStop.Color);
|
||||
lvi.ForeColor = ColorHelpers.VisibleColor(gradientStop.Color);
|
||||
UpdatePreview();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -351,24 +351,24 @@ public static Color Mix(List<Color> colors)
|
|||
return Color.FromArgb(a / count, r / count, g / count, b / count);
|
||||
}
|
||||
|
||||
public static int PerceivedBrightness(Color c)
|
||||
public static int PerceivedBrightness(Color color)
|
||||
{
|
||||
return (int)Math.Sqrt(
|
||||
c.R * c.R * .299 +
|
||||
c.G * c.G * .587 +
|
||||
c.B * c.B * .114);
|
||||
return (int)Math.Sqrt(color.R * color.R * .299 + color.G * color.G * .587 + color.B * color.B * .114);
|
||||
}
|
||||
|
||||
public static Color VisibleTextColor(Color c)
|
||||
public static Color VisibleColor(Color color)
|
||||
{
|
||||
return PerceivedBrightness(c) > 130 ? Color.Black : Color.White;
|
||||
return VisibleColor(color, Color.White, Color.Black);
|
||||
}
|
||||
|
||||
public static Color VisibleColor(Color color, Color lightColor, Color darkColor)
|
||||
{
|
||||
return PerceivedBrightness(color) > 130 ? darkColor : lightColor;
|
||||
}
|
||||
|
||||
public static Color Lerp(Color from, Color to, float amount)
|
||||
{
|
||||
return Color.FromArgb((int)MathHelpers.Lerp(from.R, to.R, amount),
|
||||
(int)MathHelpers.Lerp(from.G, to.G, amount),
|
||||
(int)MathHelpers.Lerp(from.B, to.B, amount));
|
||||
return Color.FromArgb((int)MathHelpers.Lerp(from.R, to.R, amount), (int)MathHelpers.Lerp(from.G, to.G, amount), (int)MathHelpers.Lerp(from.B, to.B, amount));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -61,6 +61,7 @@ private void InitializeComponent()
|
|||
this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtInput.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.txtInput.Location = new System.Drawing.Point(8, 40);
|
||||
this.txtInput.Multiline = true;
|
||||
this.txtInput.Name = "txtInput";
|
||||
|
|
|
@ -174,6 +174,7 @@ private void UpdateInputBox()
|
|||
{
|
||||
txtInput.Font = new Font(Options.Font, Options.Size, Options.Style);
|
||||
txtInput.ForeColor = Options.Color;
|
||||
txtInput.BackColor = ColorHelpers.VisibleColor(Options.Color, Color.White, Color.FromArgb(50, 50, 50));
|
||||
|
||||
HorizontalAlignment horizontalAlignment;
|
||||
|
||||
|
|
Loading…
Reference in a new issue