Handle themes with light text when picking contrasting colour. Refs #315

This commit is contained in:
baldurk
2016-08-05 11:19:56 +02:00
parent bf6a62c1b3
commit 12e0c301af
4 changed files with 22 additions and 10 deletions
+5
View File
@@ -90,6 +90,11 @@ namespace renderdocui.Code
return (x + (a - 1)) & (~(a - 1));
}
public static float GetLuminance(this System.Drawing.Color c)
{
return (float)(0.2126 * Math.Pow(c.R * 255.0, 2.2) + 0.7152 * Math.Pow(c.G * 255.0, 2.2) + 0.0722 * Math.Pow(c.B * 255.0, 2.2));
}
public static string SafeGetFileName(string filename)
{
try
+15 -7
View File
@@ -26,6 +26,7 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using renderdocui.Code;
namespace renderdoc
{
@@ -544,16 +545,23 @@ namespace renderdoc
);
}
public bool ShouldUseWhiteText()
public System.Drawing.Color GetTextColor(System.Drawing.Color defaultTextCol)
{
float red = markerColour[0];
float green = markerColour[1];
float blue = markerColour[2];
float alpha = markerColour[3];
float backLum = GetColor().GetLuminance();
float textLum = defaultTextCol.GetLuminance();
double luminance = 0.2126 * Math.Pow(red, 2.2) + 0.7152 * Math.Pow(green, 2.2) + 0.0722 * Math.Pow(blue, 2.2);
bool backDark = backLum < 0.2f;
bool textDark = textLum < 0.2f;
return luminance < 0.2;
// if they're contrasting, use the text colour desired
if (backDark != textDark)
return defaultTextCol;
// otherwise pick a contrasting colour
if (backDark)
return System.Drawing.Color.White;
else
return System.Drawing.Color.Black;
}
public UInt32 numIndices;
+1 -2
View File
@@ -277,8 +277,7 @@ namespace renderdocui.Windows
if (m_Core.Config.EventBrowser_ColourEventRow)
{
drawNode.BackColor = drawcall.GetColor();
if (drawcall.ShouldUseWhiteText())
drawNode.ForeColor = Color.White;
drawNode.ForeColor = drawcall.GetTextColor(eventView.ForeColor);
}
}
}
+1 -1
View File
@@ -371,7 +371,7 @@ namespace renderdocui.Windows
if (m_Core.Config.EventBrowser_ApplyColours)
{
sec.color = s[0].GetColor();
sec.textcolor = s[0].ShouldUseWhiteText() ? Color.White : Color.Black;
sec.textcolor = s[0].GetTextColor(Color.Black);
}
else
{