summaryrefslogtreecommitdiff
path: root/src/gfx.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-11-07 21:23:26 +0000
committerfrosch <frosch@openttd.org>2012-11-07 21:23:26 +0000
commit3e367cd0875b036e51789fb77cfbc9a4af06714f (patch)
tree0f07e4570f35b43579cb606cdb93efc538e612de /src/gfx.cpp
parent28c98de6d9d48afa94fd148dddb6802309b28dec (diff)
downloadopenttd-3e367cd0875b036e51789fb77cfbc9a4af06714f.tar.xz
(svn r24668) -Feature(ette) [FS#5311]: Draw cargo labels in the station list black or white depending on the background colour. (sbr)
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r--src/gfx.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 93335de8a..eb62e56fb 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -1546,6 +1546,20 @@ void DoPaletteAnimations()
}
}
+/**
+ * Determine a contrasty text colour for a coloured background.
+ * @param background Background colour.
+ * @return TC_BLACK or TC_WHITE depending on what gives a better contrast.
+ */
+TextColour GetContrastColour(uint8 background)
+{
+ 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;
+}
/**
* Initialize _stringwidth_table cache