Link graph GUI: Fix poor contrast in graph legend window cargo labels.

Select foreground colour depending on brightness of background.
This commit is contained in:
Jonathan G Rennison
2016-11-21 23:08:13 +00:00
parent 55057110a5
commit fa261207ae
3 changed files with 5 additions and 5 deletions

View File

@@ -1113,14 +1113,14 @@ void DoPaletteAnimations()
* @param background Background colour.
* @return TC_BLACK or TC_WHITE depending on what gives a better contrast.
*/
TextColour GetContrastColour(uint8 background)
TextColour GetContrastColour(uint8 background, uint8 threshold)
{
Colour c = _cur_palette.palette[background];
/* Compute brightness according to http://www.w3.org/TR/AERT#color-contrast.
* The following formula computes 1000 * brightness^2, with brightness being in range 0 to 255. */
uint sq1000_brightness = c.r * c.r * 299 + c.g * c.g * 587 + c.b * c.b * 114;
/* Compare with threshold brightness 128 (50%) */
return sq1000_brightness < 128 * 128 * 1000 ? TC_WHITE : TC_BLACK;
/* Compare with threshold brightness which defaults to 128 (50%) */
return sq1000_brightness < threshold * 128 * 1000 ? TC_WHITE : TC_BLACK;
}
/**