# HG changeset patch # Parent 362268611cc9e381cbeb313dc4c2fdf1f46491d4 # User sbr # Date 1348905329 -7200 Feature(ette): Ensure proper contrast between colour and abbreviation for cargo buttons in CompanyStationsWindow. Calculate brightness of rating_colour to determine the text colour to use for writing the cargo abbrev (see http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx, http://alienryderflex.com/hsp.html and http://www.w3.org/TR/AERT#color-contrast). diff -r 362268611cc9 src/station_gui.cpp --- a/src/station_gui.cpp Tue Nov 06 18:45:08 2012 +0000 +++ b/src/station_gui.cpp Wed Nov 07 18:09:22 2012 +0100 @@ -30,6 +30,7 @@ #include "core/geometry_func.hpp" #include "vehiclelist.h" #include "town.h" +#include #include "widgets/station_widget.h" @@ -454,8 +455,13 @@ if (widget >= WID_STL_CARGOSTART) { const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART]; int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 2 : 1; + /* Ensure proper contrast between cargo abbrev and rating colour. */ + Colour rc = _cur_palette.palette[cs->rating_colour]; + uint brightness = (uint) sqrt(rc.r * rc.r * 0.299 + rc.g * rc.g * 0.587 + rc.b * rc.b * 0.114); + TextColour tc = brightness < 70 ? TC_WHITE : TC_BLACK; + GfxFillRect(r.left + cg_ofst, r.top + cg_ofst, r.right - 2 + cg_ofst, r.bottom - 2 + cg_ofst, cs->rating_colour); - DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, cs->abbrev, TC_BLACK, SA_HOR_CENTER); + DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, cs->abbrev, tc, SA_HOR_CENTER); } break; }