From fa261207aed0b255a887570c662be81d9a2e5121 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 21 Nov 2016 23:08:13 +0000 Subject: [PATCH] Link graph GUI: Fix poor contrast in graph legend window cargo labels. Select foreground colour depending on brightness of background. --- src/gfx.cpp | 6 +++--- src/gfx_func.h | 2 +- src/linkgraph/linkgraph_gui.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index 4904e88e7f..84cc5b47ba 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -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; } /** diff --git a/src/gfx_func.h b/src/gfx_func.h index 58d9b47e9a..0276a9d37e 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -185,7 +185,7 @@ inline int GetCharacterHeight(FontSize size) extern DrawPixelInfo *_cur_dpi; -TextColour GetContrastColour(uint8 background); +TextColour GetContrastColour(uint8 background, uint8 threshold = 128); /** * All 16 colour gradients diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index 75c2ba66dc..6a1290b7cb 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -496,7 +496,7 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const if (this->IsWidgetDisabled(widget)) return; CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST); GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, cargo->legend_colour); - DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, cargo->abbrev, TC_BLACK, SA_HOR_CENTER); + DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, cargo->abbrev, GetContrastColour(cargo->legend_colour, 42), SA_HOR_CENTER); } }