summaryrefslogtreecommitdiff
path: root/src/gfx.cpp
diff options
context:
space:
mode:
authorJonathan G Rennison <j.g.rennison@gmail.com>2018-06-24 17:34:42 +0100
committerMichael Lutz <michi@icosahedron.de>2018-06-24 19:32:04 +0200
commit458bc90678b93c0a087d0dda1e877166dac25a77 (patch)
treec54e322ec8c79e4ffd3260facaa5abc358d67388 /src/gfx.cpp
parent7fed8fe004b488c3cdb15de81b4ed213d22acab4 (diff)
downloadopenttd-458bc90678b93c0a087d0dda1e877166dac25a77.tar.xz
Fix: Poor contrast in cargo dest flow legend window cargo labels.
Select foreground colour depending on the brightness of the background. Previously all cargo labels were rendered using black text, even the background cargo colour was dark/black. As an example: FIRS coal was black text on a black background.
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r--src/gfx.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 187d197a3..c9c36019c 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -1111,16 +1111,17 @@ void DoPaletteAnimations()
/**
* Determine a contrasty text colour for a coloured background.
* @param background Background colour.
+ * @param threshold Background colour brightness threshold below which the background is considered dark and TC_WHITE is returned, range: 0 - 255, default 128.
* @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 < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
}
/**