Changeset - r28812:d6d9465e39a0
[Not reviewed]
master
0 23 0
Peter Nelson - 4 months ago 2023-12-24 22:51:55
peter1138@openttd.org
Codechange: Remove direct access to _colour_gradient.

Access is now through GetColourGradient, which ensures parameters are in range.
23 files changed with 98 insertions and 65 deletions:
0 comments (0 inline, 0 general)
src/bootstrap_gui.cpp
Show inline comments
 
@@ -385,9 +385,9 @@ bool HandleBootstrap()
 
	 * This way the mauve and gray colours work and we can show the user interface. */
 
	GfxInitPalettes();
 
	static const int offsets[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0x04, 0x08 };
 
	for (uint i = 0; i != 16; i++) {
 
	for (Colours i = COLOUR_BEGIN; i != COLOUR_END; i++) {
 
		for (int j = 0; j < 8; j++) {
 
			_colour_gradient[i][j] = offsets[i] + j;
 
			SetColourGradient(i, j, offsets[i] + j);
 
		}
 
	}
 

	
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -1017,7 +1017,7 @@ void DrawEngineList(VehicleType type, co
 
	int sprite_right = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_right;
 
	int sprite_width = sprite_left + sprite_right;
 
	int circle_width = std::max(GetScaledSpriteSize(SPR_CIRCLE_FOLDED).width, GetScaledSpriteSize(SPR_CIRCLE_UNFOLDED).width);
 
	int linecolour = _colour_gradient[COLOUR_ORANGE][4];
 
	int linecolour = GetColourGradient(COLOUR_ORANGE, 4);
 

	
 
	Rect ir      = r.WithHeight(step_size).Shrink(WidgetDimensions::scaled.matrix);
 
	int sprite_y_offset = ScaleSpriteTrad(sprite_y_offsets[type]) + ir.Height() / 2;
src/company_cmd.cpp
Show inline comments
 
@@ -146,8 +146,8 @@ void SetLocalCompany(CompanyID new_compa
 
 */
 
TextColour GetDrawStringCompanyColour(CompanyID company)
 
{
 
	if (!Company::IsValidID(company)) return (TextColour)_colour_gradient[COLOUR_WHITE][4] | TC_IS_PALETTE_COLOUR;
 
	return (TextColour)_colour_gradient[_company_colours[company]][4] | TC_IS_PALETTE_COLOUR;
 
	if (!Company::IsValidID(company)) return (TextColour)GetColourGradient(COLOUR_WHITE, 4) | TC_IS_PALETTE_COLOUR;
 
	return (TextColour)GetColourGradient(_company_colours[company], 4) | TC_IS_PALETTE_COLOUR;
 
}
 

	
 
/**
 
@@ -477,7 +477,7 @@ static Colours GenerateCompanyColour()
 
	Colours colours[COLOUR_END];
 

	
 
	/* Initialize array */
 
	for (uint i = 0; i < COLOUR_END; i++) colours[i] = (Colours)i;
 
	for (uint i = 0; i < COLOUR_END; i++) colours[i] = static_cast<Colours>(i);
 

	
 
	/* And randomize it */
 
	for (uint i = 0; i < 100; i++) {
src/console_gui.cpp
Show inline comments
 
@@ -493,8 +493,8 @@ bool IsValidConsoleColour(TextColour c)
 
	/* A text colour from the palette is used; must be the company
 
	 * colour gradient, so it must be one of those. */
 
	c &= ~TC_IS_PALETTE_COLOUR;
 
	for (uint i = COLOUR_BEGIN; i < COLOUR_END; i++) {
 
		if (_colour_gradient[i][4] == c) return true;
 
	for (Colours i = COLOUR_BEGIN; i < COLOUR_END; i++) {
 
		if (GetColourGradient(i, 4) == c) return true;
 
	}
 

	
 
	return false;
src/depot_gui.cpp
Show inline comments
 
@@ -384,7 +384,7 @@ struct DepotWindow : Window {
 
		 */
 
		if (this->type == VEH_TRAIN && _consistent_train_width != 0) {
 
			int w = ScaleSpriteTrad(2 * _consistent_train_width);
 
			int col = _colour_gradient[wid->colour][4];
 
			int col = GetColourGradient(wid->colour, 4);
 
			Rect image = ir.Indent(this->header_width, rtl).Indent(this->count_width, !rtl);
 
			int first_line = w + (-this->hscroll->GetPosition()) % w;
 
			if (rtl) {
src/gfx_type.h
Show inline comments
 
@@ -11,6 +11,7 @@
 
#define GFX_TYPE_H
 

	
 
#include "core/endian_type.hpp"
 
#include "core/enum_type.hpp"
 
#include "core/geometry_type.hpp"
 
#include "zoom_type.h"
 

	
 
@@ -247,6 +248,7 @@ enum Colours : byte {
 
	COLOUR_END,
 
	INVALID_COLOUR = 0xFF,
 
};
 
DECLARE_POSTFIX_INCREMENT(Colours)
 
DECLARE_ENUM_AS_ADDABLE(Colours)
 

	
 
/** Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palette.png */
src/graph_gui.cpp
Show inline comments
 
@@ -627,7 +627,7 @@ public:
 
		for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
 
			const Company *c = Company::GetIfValid(k);
 
			if (c != nullptr) {
 
				this->colours[numd] = _colour_gradient[c->colour][6];
 
				this->colours[numd] = GetColourGradient(c->colour, 6);
 
				for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
 
					if (j >= c->num_valid_stat_ent) {
 
						this->cost[numd][i] = INVALID_DATAPOINT;
 
@@ -1294,8 +1294,8 @@ struct PerformanceRatingDetailWindow : W
 
		ScoreID score_type = (ScoreID)(widget - WID_PRD_SCORE_FIRST);
 

	
 
		/* The colours used to show how the progress is going */
 
		int colour_done = _colour_gradient[COLOUR_GREEN][4];
 
		int colour_notdone = _colour_gradient[COLOUR_RED][4];
 
		int colour_done = GetColourGradient(COLOUR_GREEN, 4);
 
		int colour_notdone = GetColourGradient(COLOUR_RED, 4);
 

	
 
		/* Draw all the score parts */
 
		int64_t val    = _score_part[company][score_type];
src/group_gui.cpp
Show inline comments
 
@@ -262,7 +262,7 @@ private:
 
	{
 
		/* Highlight the group if a vehicle is dragged over it */
 
		if (g_id == this->group_over) {
 
			GfxFillRect(left + WidgetDimensions::scaled.bevel.left, y + WidgetDimensions::scaled.framerect.top, right - WidgetDimensions::scaled.bevel.right, y + this->tiny_step_height - 1 - WidgetDimensions::scaled.framerect.bottom, _colour_gradient[COLOUR_GREY][7]);
 
			GfxFillRect(left + WidgetDimensions::scaled.bevel.left, y + WidgetDimensions::scaled.framerect.top, right - WidgetDimensions::scaled.bevel.right, y + this->tiny_step_height - 1 - WidgetDimensions::scaled.framerect.bottom, GetColourGradient(COLOUR_GREY, 7));
 
		}
 

	
 
		if (g_id == NEW_GROUP) return;
 
@@ -630,7 +630,7 @@ public:
 
					for (size_t i = this->vscroll->GetPosition(); i < max; ++i) {
 
						const Vehicle *v = this->vehgroups[i].GetSingleVehicle();
 
						if (v->group_id != this->vli.index) {
 
							GfxFillRect(mr.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[COLOUR_GREY][3], FILLRECT_CHECKER);
 
							GfxFillRect(mr.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(COLOUR_GREY, 3), FILLRECT_CHECKER);
 
						}
 
						mr = mr.Translate(0, this->resize.step_height);
 
					}
src/linkgraph/linkgraph_gui.cpp
Show inline comments
 
@@ -312,7 +312,7 @@ void LinkGraphOverlay::DrawContent(Point
 
		GfxDrawLine(pta.x, pta.y + offset_y, ptb.x, ptb.y + offset_y, colour, width, dash);
 
	}
 

	
 
	GfxDrawLine(pta.x, pta.y, ptb.x, ptb.y, _colour_gradient[COLOUR_GREY][1], width);
 
	GfxDrawLine(pta.x, pta.y, ptb.x, ptb.y, GetColourGradient(COLOUR_GREY, 1), width);
 
}
 

	
 
/**
 
@@ -331,9 +331,9 @@ void LinkGraphOverlay::DrawStationDots(c
 
		uint r = width * 2 + width * 2 * std::min(200U, i.second) / 200;
 

	
 
		LinkGraphOverlay::DrawVertex(pt.x, pt.y, r,
 
				_colour_gradient[st->owner != OWNER_NONE ?
 
						Company::Get(st->owner)->colour : COLOUR_GREY][5],
 
				_colour_gradient[COLOUR_GREY][1]);
 
				GetColourGradient(st->owner != OWNER_NONE ?
 
						Company::Get(st->owner)->colour : COLOUR_GREY, 5),
 
				GetColourGradient(COLOUR_GREY, 1));
 
	}
 
}
 

	
src/main_gui.cpp
Show inline comments
 
@@ -540,11 +540,12 @@ void ShowSelectGameWindow();
 
 */
 
void SetupColoursAndInitialWindow()
 
{
 
	for (uint i = 0; i != 16; i++) {
 
	for (Colours i = COLOUR_BEGIN; i != COLOUR_END; i++) {
 
		const byte *b = GetNonSprite(GENERAL_SPRITE_COLOUR(i), SpriteType::Recolour);
 

	
 
		assert(b);
 
		memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
 
		assert(b != nullptr);
 
		for (uint j = 0; j < 8; j++) {
 
			SetColourGradient(i, j, b[0xC6 + j]);
 
		}
 
	}
 

	
 
	new MainWindow(&_main_window_desc);
src/misc_gui.cpp
Show inline comments
 
@@ -794,7 +794,7 @@ void QueryString::DrawEditBox(const Wind
 

	
 
	DrawFrameRect(cr, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
 
	DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, SA_CENTER);
 
	if (this->text.bytes == 1) GfxFillRect(cr.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
 
	if (this->text.bytes == 1) GfxFillRect(cr.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(wi->colour, 2), FILLRECT_CHECKER);
 

	
 
	DrawFrameRect(fr, wi->colour, FR_LOWERED | FR_DARKENED);
 
	GfxFillRect(fr.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK);
src/network/network_gui.cpp
Show inline comments
 
@@ -1946,7 +1946,7 @@ public:
 
			DrawFrameRect(r, button->colour, FR_NONE);
 
			DrawSprite(button->sprite, PAL_NONE, r.left + WidgetDimensions::scaled.framerect.left, r.top + WidgetDimensions::scaled.framerect.top);
 
			if (button->disabled) {
 
				GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[button->colour & 0xF][2], FILLRECT_CHECKER);
 
				GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(button->colour, 2), FILLRECT_CHECKER);
 
			}
 

	
 
			int width = button->width + WidgetDimensions::scaled.hsep_normal;
src/order_gui.cpp
Show inline comments
 
@@ -1124,7 +1124,7 @@ public:
 
					int top = (this->order_over < this->selected_order ? y : y + line_height) - WidgetDimensions::scaled.framerect.top;
 
					int bottom = std::min(top + 2, ir.bottom);
 
					top = std::max(top - 3, ir.top);
 
					GfxFillRect(ir.left, top, ir.right, bottom, _colour_gradient[COLOUR_GREY][7]);
 
					GfxFillRect(ir.left, top, ir.right, bottom, GetColourGradient(COLOUR_GREY, 7));
 
					break;
 
				}
 
				y += line_height;
src/palette.cpp
Show inline comments
 
@@ -23,8 +23,6 @@
 

	
 
Palette _cur_palette;
 

	
 
byte _colour_gradient[COLOUR_END][8];
 

	
 
static std::recursive_mutex _palette_mutex; ///< To coordinate access to _cur_palette.
 

	
 
/**
 
@@ -295,3 +293,38 @@ TextColour GetContrastColour(uint8_t bac
 
	/* Compare with threshold brightness which defaults to 128 (50%) */
 
	return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
 
}
 

	
 
/**
 
 * Lookup table of colour shades for all 16 colour gradients.
 
 * 8 colours per gradient from darkest (0) to lightest (7)
 
 */
 
struct ColourGradients
 
{
 
	using ColourGradient = std::array<byte, 8>;
 

	
 
	static inline std::array<ColourGradient, COLOUR_END> gradient{};
 
};
 

	
 
/**
 
 * Get colour gradient palette index.
 
 * @param colour Colour.
 
 * @param shade Shade level from 1 to 7.
 
 * @returns palette index of colour.
 
 */
 
byte GetColourGradient(Colours colour, uint8_t shade)
 
{
 
	return ColourGradients::gradient[colour % COLOUR_END][shade % 8];
 
}
 

	
 
/**
 
 * Set colour gradient palette index.
 
 * @param colour Colour.
 
 * @param shade Shade level from 1 to 7.
 
 * @param palette_index Palette index to set.
 
 */
 
void SetColourGradient(Colours colour, uint8_t shade, byte palette_index)
 
{
 
	assert(colour < COLOUR_END);
 
	assert(shade < 8);
 
	ColourGradients::gradient[colour % COLOUR_END][shade % 8] = palette_index;
 
}
src/palette_func.h
Show inline comments
 
@@ -39,11 +39,8 @@ inline bool IsValidColours(Colours colou
 

	
 
TextColour GetContrastColour(uint8_t background, uint8_t threshold = 128);
 

	
 
/**
 
 * All 16 colour gradients
 
 * 8 colours per gradient from darkest (0) to lightest (7)
 
 */
 
extern byte _colour_gradient[COLOUR_END][8];
 
byte GetColourGradient(Colours colour, uint8_t shade);
 
void SetColourGradient(Colours colour, uint8_t shade, byte palette_colour);
 

	
 
/**
 
 * Return the colour for a particular greyscale level.
src/settings_gui.cpp
Show inline comments
 
@@ -1414,7 +1414,7 @@ uint BaseSettingEntry::Draw(GameSettings
 

	
 
	int x = rtl ? right : left;
 
	if (cur_row >= first_row) {
 
		int colour = _colour_gradient[COLOUR_ORANGE][4];
 
		int colour = GetColourGradient(COLOUR_ORANGE, 4);
 
		y += (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
 

	
 
		/* Draw vertical for parent nesting levels */
 
@@ -2909,7 +2909,7 @@ void ShowGameSettings()
 
 */
 
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
 
{
 
	int colour = _colour_gradient[button_colour][2];
 
	int colour = GetColourGradient(button_colour, 2);
 
	Dimension dim = NWidgetScrollbar::GetHorizontalDimension();
 

	
 
	Rect lr = {x,                  y, x + (int)dim.width     - 1, y + (int)dim.height - 1};
 
@@ -2940,7 +2940,7 @@ void DrawArrowButtons(int x, int y, Colo
 
 */
 
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
 
{
 
	int colour = _colour_gradient[button_colour][2];
 
	int colour = GetColourGradient(button_colour, 2);
 

	
 
	Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
 

	
src/smallmap_gui.cpp
Show inline comments
 
@@ -346,7 +346,7 @@ void BuildOwnerLegend()
 

	
 
	int i = NUM_NO_COMPANY_ENTRIES;
 
	for (const Company *c : Company::Iterate()) {
 
		_legend_land_owners[i].colour = _colour_gradient[c->colour][5];
 
		_legend_land_owners[i].colour = GetColourGradient(c->colour, 5);
 
		_legend_land_owners[i].company = c->index;
 
		_legend_land_owners[i].show_on_map = true;
 
		_legend_land_owners[i].col_break = false;
src/train_gui.cpp
Show inline comments
 
@@ -76,7 +76,7 @@ static int HighlightDragPosition(int px,
 
		int top = y - height / 2;
 
		Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1};
 
		/* Sprite-scaling is used here as the area is from sprite size */
 
		GfxFillRect(r.Shrink(ScaleSpriteTrad(1)), _colour_gradient[COLOUR_GREY][7]);
 
		GfxFillRect(r.Shrink(ScaleSpriteTrad(1)), GetColourGradient(COLOUR_GREY, 7));
 
	}
 

	
 
	return drag_hlight_width;
 
@@ -399,7 +399,7 @@ void DrawTrainDetails(const Train *v, co
 
				if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
 
					int py = r.top - line_height * vscroll_pos + text_y_offset;
 
					if (i > 0 || separate_sprite_row) {
 
						if (vscroll_pos != 0) GfxFillRect(r.left, py - WidgetDimensions::scaled.matrix.top - 1, r.right, py - WidgetDimensions::scaled.matrix.top, _colour_gradient[COLOUR_GREY][5]);
 
						if (vscroll_pos != 0) GfxFillRect(r.left, py - WidgetDimensions::scaled.matrix.top - 1, r.right, py - WidgetDimensions::scaled.matrix.top, GetColourGradient(COLOUR_GREY, 5));
 
					}
 
					switch (det_tab) {
 
						case TDW_TAB_CARGO:
src/vehicle_gui.cpp
Show inline comments
 
@@ -624,7 +624,7 @@ static void DrawVehicleRefitWindow(const
 
	bool rtl = _current_text_dir == TD_RTL;
 
	uint iconwidth = std::max(GetSpriteSize(SPR_CIRCLE_FOLDED).width, GetSpriteSize(SPR_CIRCLE_UNFOLDED).width);
 
	uint iconheight = GetSpriteSize(SPR_CIRCLE_FOLDED).height;
 
	int linecolour = _colour_gradient[COLOUR_ORANGE][4];
 
	int linecolour = GetColourGradient(COLOUR_ORANGE, 4);
 

	
 
	int iconleft   = rtl ? ir.right - iconwidth     : ir.left;
 
	int iconcenter = rtl ? ir.right - iconwidth / 2 : ir.left + iconwidth / 2;
src/viewport.cpp
Show inline comments
 
@@ -1716,7 +1716,7 @@ static void ViewportDrawStrings(ZoomLeve
 
				/* Don't draw the rectangle.
 
				 * Real colours need the TC_IS_PALETTE_COLOUR flag.
 
				 * Otherwise colours from _string_colourmap are assumed. */
 
				colour = (TextColour)_colour_gradient[ss.colour][6] | TC_IS_PALETTE_COLOUR;
 
				colour = (TextColour)GetColourGradient(ss.colour, 6) | TC_IS_PALETTE_COLOUR;
 
			} else {
 
				/* Draw the rectangle if 'transparent station signs' is off,
 
				 * or if we are drawing a general text sign (STR_WHITE_SIGN). */
src/widget.cpp
Show inline comments
 
@@ -275,17 +275,17 @@ WidgetID GetWidgetFromPos(const Window *
 
 * @param top    Top edge of the frame
 
 * @param right  Right edge of the frame
 
 * @param bottom Bottom edge of the frame
 
 * @param colour Colour table to use. @see _colour_gradient
 
 * @param colour Colour table to use. @see Colours
 
 * @param flags  Flags controlling how to draw the frame. @see FrameFlags
 
 */
 
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
 
{
 
	assert(colour < COLOUR_END);
 

	
 
	uint dark         = _colour_gradient[colour][3];
 
	uint medium_dark  = _colour_gradient[colour][5];
 
	uint medium_light = _colour_gradient[colour][6];
 
	uint light        = _colour_gradient[colour][7];
 
	uint dark         = GetColourGradient(colour, 3);
 
	uint medium_dark  = GetColourGradient(colour, 5);
 
	uint medium_light = GetColourGradient(colour, 6);
 
	uint light        = GetColourGradient(colour, 7);
 

	
 
	if (flags & FR_TRANSPARENT) {
 
		GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR);
 
@@ -423,7 +423,7 @@ static inline void DrawMatrix(const Rect
 
		row_height = r.Height() / num_rows;
 
	}
 

	
 
	int col = _colour_gradient[colour & 0xF][6];
 
	int col = GetColourGradient(colour, 6);
 

	
 
	int x = r.left;
 
	for (int ctr = num_columns; ctr > 1; ctr--) {
 
@@ -437,7 +437,7 @@ static inline void DrawMatrix(const Rect
 
		GfxFillRect(r.left + WidgetDimensions::scaled.bevel.left, x, r.right - WidgetDimensions::scaled.bevel.right, x + WidgetDimensions::scaled.bevel.top - 1, col);
 
	}
 

	
 
	col = _colour_gradient[colour & 0xF][4];
 
	col = GetColourGradient(colour, 4);
 

	
 
	x = r.left - 1;
 
	for (int ctr = num_columns; ctr > 1; ctr--) {
 
@@ -469,8 +469,8 @@ static inline void DrawVerticalScrollbar
 
	DrawImageButtons(r.WithHeight(height, false),  NWID_VSCROLLBAR, colour, up_clicked,   SPR_ARROW_UP,   SA_CENTER);
 
	DrawImageButtons(r.WithHeight(height, true),   NWID_VSCROLLBAR, colour, down_clicked, SPR_ARROW_DOWN, SA_CENTER);
 

	
 
	int c1 = _colour_gradient[colour & 0xF][3];
 
	int c2 = _colour_gradient[colour & 0xF][7];
 
	int c1 = GetColourGradient(colour, 3);
 
	int c2 = GetColourGradient(colour, 7);
 

	
 
	/* draw "shaded" background */
 
	GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
 
@@ -508,8 +508,8 @@ static inline void DrawHorizontalScrollb
 
	DrawImageButtons(r.WithWidth(width, false), NWID_HSCROLLBAR, colour, left_clicked,  SPR_ARROW_LEFT,  SA_CENTER);
 
	DrawImageButtons(r.WithWidth(width, true),  NWID_HSCROLLBAR, colour, right_clicked, SPR_ARROW_RIGHT, SA_CENTER);
 

	
 
	int c1 = _colour_gradient[colour & 0xF][3];
 
	int c2 = _colour_gradient[colour & 0xF][7];
 
	int c1 = GetColourGradient(colour, 3);
 
	int c2 = GetColourGradient(colour, 7);
 

	
 
	/* draw "shaded" background */
 
	GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
 
@@ -547,8 +547,8 @@ static inline void DrawFrame(const Rect 
 

	
 
	if (str != STR_NULL) x2 = DrawString(r.left + WidgetDimensions::scaled.frametext.left, r.right - WidgetDimensions::scaled.frametext.right, r.top, str, text_colour, align, false, fs);
 

	
 
	int c1 = _colour_gradient[colour][3];
 
	int c2 = _colour_gradient[colour][7];
 
	int c1 = GetColourGradient(colour, 3);
 
	int c2 = GetColourGradient(colour, 7);
 

	
 
	/* If the frame has text, adjust the top bar to fit half-way through */
 
	Rect inner = r.Shrink(ScaleGUITrad(1));
 
@@ -645,7 +645,7 @@ static inline void DrawResizeBox(const R
 
	if (bevel) {
 
		DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
 
	} else if (clicked) {
 
		GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[colour][6]);
 
		GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(colour, 6));
 
	}
 
	DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), at_left ? (SA_LEFT | SA_BOTTOM | SA_FORCE) : (SA_RIGHT | SA_BOTTOM | SA_FORCE));
 
}
 
@@ -685,7 +685,7 @@ void DrawCaption(const Rect &r, Colours 
 
	DrawFrameRect(ir, colour, company_owned ? FR_LOWERED | FR_DARKENED | FR_BORDERONLY : FR_LOWERED | FR_DARKENED);
 

	
 
	if (company_owned) {
 
		GfxFillRect(ir.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[_company_colours[owner]][4]);
 
		GfxFillRect(ir.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(_company_colours[owner], 4));
 
	}
 

	
 
	if (str != STR_NULL) {
 
@@ -1906,7 +1906,7 @@ NWidgetCore *NWidgetMatrix::GetWidgetFro
 
/* virtual */ void NWidgetMatrix::Draw(const Window *w)
 
{
 
	/* Fill the background. */
 
	GfxFillRect(this->GetCurrentRect(), _colour_gradient[this->colour & 0xF][5]);
 
	GfxFillRect(this->GetCurrentRect(), GetColourGradient(this->colour, 5));
 

	
 
	/* Set up a clipping area for the previews. */
 
	bool rtl = _current_text_dir == TD_RTL;
 
@@ -2171,7 +2171,7 @@ void NWidgetBackground::Draw(const Windo
 
	if (this->child != nullptr) this->child->Draw(w);
 

	
 
	if (this->IsDisabled()) {
 
		GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
 
		GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(this->colour, 2), FILLRECT_CHECKER);
 
	}
 

	
 
	DrawOutline(w, this);
 
@@ -2416,7 +2416,7 @@ void NWidgetScrollbar::Draw(const Window
 
	}
 

	
 
	if (this->IsDisabled()) {
 
		GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
 
		GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(this->colour, 2), FILLRECT_CHECKER);
 
	}
 

	
 
	DrawOutline(w, this);
 
@@ -2867,7 +2867,7 @@ void NWidgetLeaf::Draw(const Window *w)
 
	if (this->index >= 0) w->DrawWidget(r, this->index);
 

	
 
	if (this->IsDisabled()) {
 
		GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
 
		GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(this->colour, 2), FILLRECT_CHECKER);
 
	}
 

	
 
	DrawOutline(w, this);
src/widgets/dropdown_type.h
Show inline comments
 
@@ -37,7 +37,7 @@ public:
 

	
 
	virtual void Draw(const Rect &full, const Rect &, bool, Colours bg_colour) const
 
	{
 
		if (this->masked) GfxFillRect(full, _colour_gradient[bg_colour][5], FILLRECT_CHECKER);
 
		if (this->masked) GfxFillRect(full, GetColourGradient(bg_colour, 5), FILLRECT_CHECKER);
 
	}
 

	
 
	TextColour GetColour(bool sel) const
 
@@ -63,8 +63,8 @@ public:
 

	
 
	void Draw(const Rect &full, const Rect &, bool, Colours bg_colour) const override
 
	{
 
		uint8_t c1 = _colour_gradient[bg_colour][3];
 
		uint8_t c2 = _colour_gradient[bg_colour][7];
 
		uint8_t c1 = GetColourGradient(bg_colour, 3);
 
		uint8_t c2 = GetColourGradient(bg_colour, 7);
 

	
 
		int mid = CenterBounds(full.top, full.bottom, 0);
 
		GfxFillRect(full.left, mid - WidgetDimensions::scaled.bevel.bottom, full.right, mid - 1, c1);
src/widgets/slider.cpp
Show inline comments
 
@@ -41,9 +41,9 @@ void DrawSliderWidget(Rect r, int min_va
 
	int wx1 = r.left  + sw / 2;
 
	int wx2 = r.right - sw / 2;
 
	if (_current_text_dir == TD_RTL) std::swap(wx1, wx2);
 
	const uint shadow = _colour_gradient[COLOUR_GREY][3];
 
	const uint fill = _colour_gradient[COLOUR_GREY][6];
 
	const uint light = _colour_gradient[COLOUR_GREY][7];
 
	const uint shadow = GetColourGradient(COLOUR_GREY, 3);
 
	const uint fill = GetColourGradient(COLOUR_GREY, 6);
 
	const uint light = GetColourGradient(COLOUR_GREY, 7);
 
	const std::vector<Point> wedge{ Point{wx1, r.bottom - ha}, Point{wx2, r.top + ha}, Point{wx2, r.bottom - ha} };
 
	GfxFillPolygon(wedge, fill);
 
	GfxDrawLine(wedge[0].x, wedge[0].y, wedge[2].x, wedge[2].y, light, t);
0 comments (0 inline, 0 general)