diff --git a/renderdocui/Code/Helpers.cs b/renderdocui/Code/Helpers.cs index 6e4e3c316..3375575d4 100644 --- a/renderdocui/Code/Helpers.cs +++ b/renderdocui/Code/Helpers.cs @@ -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 diff --git a/renderdocui/Interop/FetchInfo.cs b/renderdocui/Interop/FetchInfo.cs index 0b67eb6f6..ce17a5291 100644 --- a/renderdocui/Interop/FetchInfo.cs +++ b/renderdocui/Interop/FetchInfo.cs @@ -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; diff --git a/renderdocui/Windows/EventBrowser.cs b/renderdocui/Windows/EventBrowser.cs index 46b2f0760..f2886e268 100644 --- a/renderdocui/Windows/EventBrowser.cs +++ b/renderdocui/Windows/EventBrowser.cs @@ -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); } } } diff --git a/renderdocui/Windows/TimelineBar.cs b/renderdocui/Windows/TimelineBar.cs index 69e7f242c..5dfbf3cfd 100644 --- a/renderdocui/Windows/TimelineBar.cs +++ b/renderdocui/Windows/TimelineBar.cs @@ -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 {