Changeset - r19713:c1030be320af
[Not reviewed]
master
0 3 0
frosch - 12 years ago 2012-11-07 21:23:26
frosch@openttd.org
(svn r24668) -Feature(ette) [FS#5311]: Draw cargo labels in the station list black or white depending on the background colour. (sbr)
3 files changed with 20 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -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
src/gfx_func.h
Show inline comments
 
@@ -177,6 +177,8 @@ static inline byte GetCharacterHeight(Fo
 

	
 
extern DrawPixelInfo *_cur_dpi;
 

	
 
TextColour GetContrastColour(uint8 background);
 

	
 
/**
 
 * All 16 colour gradients
 
 * 8 colours per gradient from darkest (0) to lightest (7)
src/station_gui.cpp
Show inline comments
 
@@ -109,6 +109,7 @@ static void StationsWndShowStationRating
 
	if (!cs->IsValid()) return;
 

	
 
	int colour = cs->rating_colour;
 
	TextColour tc = GetContrastColour(colour);
 
	uint w = (minu(amount, units_full) + 5) / 36;
 

	
 
	int height = GetCharacterHeight(FS_SMALL);
 
@@ -126,7 +127,7 @@ static void StationsWndShowStationRating
 
		}
 
	}
 

	
 
	DrawString(left + 1, right, y, cs->abbrev, TC_BLACK);
 
	DrawString(left + 1, right, y, cs->abbrev, tc);
 

	
 
	/* Draw green/red ratings bar (fits into 14 pixels) */
 
	y += height + 2;
 
@@ -455,7 +456,8 @@ public:
 
					const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
 
					int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 2 : 1;
 
					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);
 
					TextColour tc = GetContrastColour(cs->rating_colour);
 
					DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, cs->abbrev, tc, SA_HOR_CENTER);
 
				}
 
				break;
 
		}
0 comments (0 inline, 0 general)