mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-12 09:41:03 +00:00
Handle themes with light text when picking contrasting colour. Refs #315
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user