Codechange: separate TextColour enumeration and flags

This commit is contained in:
Rubidium
2026-04-27 11:30:30 +02:00
committed by rubidium42
parent 31424f700e
commit c59d64c132
86 changed files with 575 additions and 511 deletions
+4 -4
View File
@@ -181,10 +181,10 @@ struct AIConfigWindow : public Window {
*/
TextColour GetSlotColour(CompanyID cid, CompanyID max_slot) const
{
if (this->selected_slot == cid) return TC_WHITE;
if (IsEditable(cid)) return cid < max_slot ? TC_ORANGE : TC_SILVER;
if (Company::IsValidAiID(cid)) return TC_GREEN;
return TC_SILVER;
if (this->selected_slot == cid) return TextColour::White;
if (IsEditable(cid)) return cid < max_slot ? TextColour::Orange : TextColour::Silver;
if (Company::IsValidAiID(cid)) return TextColour::Green;
return TextColour::Silver;
}
void DrawWidget(const Rect &r, WidgetID widget) const override
+2 -2
View File
@@ -400,7 +400,7 @@ public:
if (!as->IsAvailable()) {
GfxFillRect(row, PC_BLACK, FillRectMode::Checker);
}
DrawString(text, as->name, (static_cast<int>(as->index) == _selected_airport_index) ? TC_WHITE : TC_BLACK);
DrawString(text, as->name, (static_cast<int>(as->index) == _selected_airport_index) ? TextColour::White : TextColour::Black);
row = row.Translate(0, this->line_height);
text = text.Translate(0, this->line_height);
}
@@ -419,7 +419,7 @@ public:
const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_ADDITIONAL_TEXT);
if (string != STR_UNDEFINED) {
DrawStringMultiLine(r, string, TC_BLACK);
DrawStringMultiLine(r, string, TextColour::Black);
}
}
break;
+1 -1
View File
@@ -450,7 +450,7 @@ public:
str = GetString(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED);
}
DrawString(r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect), std::move(str), TC_BLACK, SA_HOR_CENTER);
DrawString(r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect), std::move(str), TextColour::Black, SA_HOR_CENTER);
break;
}
+2 -2
View File
@@ -110,7 +110,7 @@ public:
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget == WID_BEM_MESSAGE) {
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_ERROR, TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_ERROR, TextColour::FromString, SA_CENTER);
}
}
@@ -239,7 +239,7 @@ public:
{
if (widget != WID_BAFD_QUESTION) return;
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_SET_MESSAGE, TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_SET_MESSAGE, TextColour::FromString, SA_CENTER);
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
+5 -5
View File
@@ -61,7 +61,7 @@ uint GetEngineListHeight(VehicleType type)
static constexpr std::initializer_list<NWidgetPart> _nested_build_vehicle_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::Grey),
NWidget(WWT_CAPTION, Colours::Grey, WID_BV_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::Grey, WID_BV_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_SHADEBOX, Colours::Grey),
NWidget(WWT_DEFSIZEBOX, Colours::Grey),
NWidget(WWT_STICKYBOX, Colours::Grey),
@@ -803,7 +803,7 @@ static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
{
auto text = GetNewGRFAdditionalText(engine);
if (!text) return y;
return DrawStringMultiLine(left, right, y, INT32_MAX, *text, TC_BLACK);
return DrawStringMultiLine(left, right, y, INT32_MAX, *text, TextColour::Black);
}
void TestedEngineDetails::FillDefaultCapacities(const Engine *e)
@@ -898,7 +898,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
const GRFConfig *config = GetGRFConfig(e->GetGRFID());
if (_settings_client.gui.show_newgrf_name && config != nullptr)
{
DrawString(left, right, y, config->GetName(), TC_BLACK);
DrawString(left, right, y, config->GetName(), TextColour::Black);
y += GetCharacterHeight(FontSize::Normal);
}
@@ -1023,7 +1023,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
Rect cr = tr.WithWidth(count_width, !rtl);
tr = tr.Indent(count_width + WidgetDimensions::scaled.hsep_normal, !rtl);
DrawString(cr.left, cr.right, textr.top + small_text_y_offset, GetString(STR_JUST_COMMA, num_engines), TC_BLACK, SA_RIGHT | SA_FORCE, false, FontSize::Small);
DrawString(cr.left, cr.right, textr.top + small_text_y_offset, GetString(STR_JUST_COMMA, num_engines), TextColour::Black, SA_RIGHT | SA_FORCE, false, FontSize::Small);
if (EngineHasReplacementForCompany(Company::Get(_local_company), item.engine_id, selected_group)) {
DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, rr, SA_CENTER);
@@ -1038,7 +1038,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
bool hidden = e->company_hidden.Test(_local_company);
StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
TextColour tc = (item.engine_id == selected_id) ? TC_WHITE : ((hidden | shaded) ? (TC_GREY | TC_FORCED | TC_NO_SHADE) : TC_BLACK);
ExtendedTextColour tc = (item.engine_id == selected_id) ? TextColour::White : ((hidden | shaded) ? ExtendedTextColour{TextColour::Grey, {ExtendedTextColourFlag::Forced, ExtendedTextColourFlag::NoShade}} : TextColour::Black);
/* Draw the value of the currently selected sort property to the right (or left in RTL), if applicable */
std::string sort_prop_detail;
+1 -1
View File
@@ -364,7 +364,7 @@ struct CheatWindow : Window {
editable && value != (sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : min_val), editable && static_cast<uint32_t>(value) != max_val);
}
auto [param1, param2] = sd->GetValueParams(value);
DrawString(text.left, text.right, text.top, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), TC_LIGHT_BLUE);
DrawString(text.left, text.right, text.top, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), TextColour::LightBlue);
}
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
+3 -3
View File
@@ -154,10 +154,10 @@ void SetLocalCompany(CompanyID new_company)
* @param company Company to get the colour of.
* @return Colour of \a company.
*/
TextColour GetDrawStringCompanyColour(CompanyID company)
ExtendedTextColour GetDrawStringCompanyColour(CompanyID company)
{
if (!Company::IsValidID(company)) return GetColourGradient(Colours::White, Shade::Normal).ToTextColour();
return GetColourGradient(_company_colours[company], Shade::Normal).ToTextColour();
if (!Company::IsValidID(company)) return ExtendedTextColour{GetColourGradient(Colours::White, Shade::Normal)};
return ExtendedTextColour{GetColourGradient(_company_colours[company], Shade::Normal)};
}
/**
+22 -22
View File
@@ -188,12 +188,12 @@ static void DrawCategories(const Rect &r)
{
int y = r.top;
/* Draw description of 12-minute economic period. */
DrawString(r.left, r.right, y, (TimerGameEconomy::UsingWallclockUnits() ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION), TC_FROMSTRING, SA_LEFT, true);
DrawString(r.left, r.right, y, (TimerGameEconomy::UsingWallclockUnits() ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION), TextColour::FromString, SA_LEFT, true);
y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_wide;
for (const ExpensesList &list : _expenses_list_types) {
/* Draw category title and advance y */
DrawString(r.left, r.right, y, list.title, TC_FROMSTRING, SA_LEFT);
DrawString(r.left, r.right, y, list.title, TextColour::FromString, SA_LEFT);
y += GetCharacterHeight(FontSize::Normal);
/* Draw category items and advance y */
@@ -204,7 +204,7 @@ static void DrawCategories(const Rect &r)
y += WidgetDimensions::scaled.vsep_normal;
/* Draw category total and advance y */
DrawString(r.left, r.right, y, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT);
DrawString(r.left, r.right, y, STR_FINANCES_TOTAL_CAPTION, TextColour::FromString, SA_RIGHT);
y += GetCharacterHeight(FontSize::Normal);
/* Advance y by a blockspace after this category block */
@@ -213,7 +213,7 @@ static void DrawCategories(const Rect &r)
/* Draw total profit/loss */
y += WidgetDimensions::scaled.vsep_normal;
DrawString(r.left, r.right, y, STR_FINANCES_PROFIT, TC_FROMSTRING, SA_LEFT);
DrawString(r.left, r.right, y, STR_FINANCES_PROFIT, TextColour::FromString, SA_LEFT);
}
/**
@@ -252,14 +252,14 @@ static Money DrawYearCategory(const Rect &r, int start_y, const ExpensesList &li
for (const ExpensesType &et : list.items) {
Money cost = tbl[et];
sum += cost;
if (cost != 0) DrawPrice(cost, r.left, r.right, y, TC_BLACK);
if (cost != 0) DrawPrice(cost, r.left, r.right, y, TextColour::Black);
y += GetCharacterHeight(FontSize::Normal);
}
/* Draw the total at the bottom of the category. */
GfxFillRect(r.left, y, r.right, y + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK);
y += WidgetDimensions::scaled.vsep_normal;
if (sum != 0) DrawPrice(sum, r.left, r.right, y, TC_WHITE);
if (sum != 0) DrawPrice(sum, r.left, r.right, y, TextColour::White);
/* Return the sum for the yearly total. */
return sum;
@@ -279,7 +279,7 @@ static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Exp
Money sum;
/* Year header */
DrawString(r.left, r.right, y, GetString(STR_FINANCES_YEAR, year), TC_FROMSTRING, SA_RIGHT | SA_FORCE, true);
DrawString(r.left, r.right, y, GetString(STR_FINANCES_YEAR, year), TextColour::FromString, SA_RIGHT | SA_FORCE, true);
y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_wide;
/* Categories */
@@ -293,7 +293,7 @@ static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Exp
/* Total income. */
GfxFillRect(r.left, y, r.right, y + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK);
y += WidgetDimensions::scaled.vsep_normal;
DrawPrice(sum, r.left, r.right, y, TC_WHITE);
DrawPrice(sum, r.left, r.right, y, TextColour::White);
}
static constexpr std::initializer_list<NWidgetPart> _nested_company_finances_widgets = {
@@ -892,16 +892,16 @@ public:
/* Helper function to draw livery info. */
auto draw_livery = [&](std::string_view str, const Livery &livery, bool is_selected, bool is_default_scheme, int indent) {
/* Livery Label. */
DrawString(sch.left + (rtl ? 0 : indent), sch.right - (rtl ? indent : 0), y + text_offs, str, is_selected ? TC_WHITE : TC_BLACK);
DrawString(sch.left + (rtl ? 0 : indent), sch.right - (rtl ? indent : 0), y + text_offs, str, is_selected ? TextColour::White : TextColour::Black);
/* Text below the first dropdown. */
DrawSprite(SPR_SQUARE, GetColourPalette(livery.colour1), pri_squ.left, y + square_offs);
DrawString(pri.left, pri.right, y + text_offs, (is_default_scheme || livery.in_use.Test(Livery::Flag::Primary)) ? STR_COLOUR_DARK_BLUE + to_underlying(livery.colour1) : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
DrawString(pri.left, pri.right, y + text_offs, (is_default_scheme || livery.in_use.Test(Livery::Flag::Primary)) ? STR_COLOUR_DARK_BLUE + to_underlying(livery.colour1) : STR_COLOUR_DEFAULT, is_selected ? TextColour::White : TextColour::Gold);
/* Text below the second dropdown. */
if (sec.right > sec.left) { // Second dropdown has non-zero size.
DrawSprite(SPR_SQUARE, GetColourPalette(livery.colour2), sec_squ.left, y + square_offs);
DrawString(sec.left, sec.right, y + text_offs, (is_default_scheme || livery.in_use.Test(Livery::Flag::Secondary)) ? STR_COLOUR_DARK_BLUE + to_underlying(livery.colour2) : STR_COLOUR_DEFAULT, is_selected ? TC_WHITE : TC_GOLD);
DrawString(sec.left, sec.right, y + text_offs, (is_default_scheme || livery.in_use.Test(Livery::Flag::Secondary)) ? STR_COLOUR_DARK_BLUE + to_underlying(livery.colour2) : STR_COLOUR_DEFAULT, is_selected ? TextColour::White : TextColour::Gold);
}
y += this->line_height;
@@ -927,7 +927,7 @@ public:
if (this->vscroll->GetCount() == 0) {
constexpr VehicleTypeIndexArray<const StringID> empty_labels = { STR_LIVERY_TRAIN_GROUP_EMPTY, STR_LIVERY_ROAD_VEHICLE_GROUP_EMPTY, STR_LIVERY_SHIP_GROUP_EMPTY, STR_LIVERY_AIRCRAFT_GROUP_EMPTY };
VehicleType vtype = (VehicleType)(this->livery_class - LC_GROUP_RAIL);
DrawString(ir.left, ir.right, y + text_offs, empty_labels[vtype], TC_BLACK);
DrawString(ir.left, ir.right, y + text_offs, empty_labels[vtype], TextColour::Black);
}
}
}
@@ -1361,7 +1361,7 @@ public:
Rect tr = ir.Shrink(RectPadding::zero, WidgetDimensions::scaled.matrix).CentreToHeight(GetCharacterHeight(FontSize::Normal)).Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
DrawArrowButtons(br.left, br.top, Colours::Yellow, this->selected_var == UINT_MAX - 1 ? this->click_state : 0, true, true);
DrawString(tr, GetString(STR_FACE_SETTING_NUMERIC, STR_FACE_STYLE, this->face.style + 1, GetNumCompanyManagerFaceStyles()), TC_WHITE);
DrawString(tr, GetString(STR_FACE_SETTING_NUMERIC, STR_FACE_STYLE, this->face.style + 1, GetNumCompanyManagerFaceStyles()), TextColour::White);
break;
}
@@ -1382,10 +1382,10 @@ public:
uint val = vars[var].GetBits(this->face);
if (facevar.type == FaceVarType::Toggle) {
DrawBoolButton(br.left, br.top, Colours::Yellow, Colours::Grey, val == 1, true);
DrawString(tr, GetString(STR_FACE_SETTING_TOGGLE, facevar.name, val == 1 ? STR_FACE_YES : STR_FACE_NO), TC_WHITE);
DrawString(tr, GetString(STR_FACE_SETTING_TOGGLE, facevar.name, val == 1 ? STR_FACE_YES : STR_FACE_NO), TextColour::White);
} else {
DrawArrowButtons(br.left, br.top, Colours::Yellow, this->selected_var == var ? this->click_state : 0, true, true);
DrawString(tr, GetString(STR_FACE_SETTING_NUMERIC, facevar.name, val + 1, facevar.valid_values), TC_WHITE);
DrawString(tr, GetString(STR_FACE_SETTING_NUMERIC, facevar.name, val + 1, facevar.valid_values), TextColour::White);
}
ir = ir.Translate(0, this->line_height);
@@ -1797,7 +1797,7 @@ struct CompanyInfrastructureWindow : Window
switch (it->type) {
case InfrastructureItemType::Header:
/* Header is allowed to fill the window's width. */
DrawString(ir.left, ir.right, labelr.top, GetString(it->label), TC_ORANGE);
DrawString(ir.left, ir.right, labelr.top, GetString(it->label), TextColour::Orange);
break;
case InfrastructureItemType::Spacer:
@@ -1806,14 +1806,14 @@ struct CompanyInfrastructureWindow : Window
case InfrastructureItemType::Total:
/* Draw line in the spacer above the total. */
GfxFillRect(costr.Translate(0, -WidgetDimensions::scaled.vsep_normal).WithHeight(WidgetDimensions::scaled.fullbevel.top), PC_WHITE);
DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TC_BLACK, SA_RIGHT | SA_FORCE);
DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TextColour::Black, SA_RIGHT | SA_FORCE);
break;
case InfrastructureItemType::Value:
DrawString(labelr.Indent(WidgetDimensions::scaled.hsep_indent, rtl), GetString(it->label), TC_WHITE);
DrawString(countr, GetString(STR_JUST_COMMA, it->count), TC_WHITE, SA_RIGHT | SA_FORCE);
DrawString(labelr.Indent(WidgetDimensions::scaled.hsep_indent, rtl), GetString(it->label), TextColour::White);
DrawString(countr, GetString(STR_JUST_COMMA, it->count), TextColour::White, SA_RIGHT | SA_FORCE);
if (_settings_game.economy.infrastructure_maintenance) {
DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TC_BLACK, SA_RIGHT | SA_FORCE);
DrawString(costr, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR, it->cost * 12), TextColour::Black, SA_RIGHT | SA_FORCE);
}
break;
}
@@ -2135,7 +2135,7 @@ struct CompanyWindow : Window
break;
case WID_C_FACE_TITLE:
DrawStringMultiLine(r, GetString(STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, c->index), TC_FROMSTRING, SA_HOR_CENTER);
DrawStringMultiLine(r, GetString(STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE, c->index), TextColour::FromString, SA_HOR_CENTER);
break;
case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: {
@@ -2401,7 +2401,7 @@ struct BuyCompanyWindow : Window {
case WID_BC_QUESTION: {
const Company *c = Company::Get(this->window_number);
DrawStringMultiLine(r, GetString(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, c->index, this->company_value), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, GetString(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, c->index, this->company_value), TextColour::FromString, SA_CENTER);
break;
}
}
+1 -1
View File
@@ -14,7 +14,7 @@
#include "group.h"
#include "gfx_type.h"
TextColour GetDrawStringCompanyColour(CompanyID company);
ExtendedTextColour GetDrawStringCompanyColour(CompanyID company);
void DrawCompanyIcon(CompanyID c, int x, int y);
void ShowCompanyLiveryWindow(CompanyID company, GroupID group);
+1 -1
View File
@@ -87,7 +87,7 @@ void IConsoleFree()
* @param colour_code The colour of the command.
* @param string The message to output on the console (notice, error, etc.)
*/
void IConsolePrint(TextColour colour_code, const std::string &string)
void IConsolePrint(ExtendedTextColour colour_code, const std::string &string)
{
assert(IsValidConsoleColour(colour_code));
+4 -4
View File
@@ -1344,8 +1344,8 @@ static bool ConEchoC(std::span<std::string_view> argv)
if (argv.size() < 3) return false;
auto colour = ParseInteger(argv[1]);
if (!colour.has_value() || !IsInsideMM(*colour, TC_BEGIN, TC_END)) {
IConsolePrint(CC_ERROR, "The colour must be a number between {} and {}.", TC_BEGIN, TC_END - 1);
if (!colour.has_value() || !IsInsideMM(*colour, to_underlying(TextColour::Begin), to_underlying(TextColour::End))) {
IConsolePrint(CC_ERROR, "The colour must be a number between {} and {}.", TextColour::Begin, to_underlying(TextColour::End) - 1);
return true;
}
@@ -1962,7 +1962,7 @@ static bool ConHelp(std::span<std::string_view> argv)
return true;
}
IConsolePrint(TC_LIGHT_BLUE, " ---- OpenTTD Console Help ---- ");
IConsolePrint(TextColour::LightBlue, " ---- OpenTTD Console Help ---- ");
IConsolePrint(CC_DEFAULT, " - commands: the command to list all commands is 'list_cmds'.");
IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
IConsolePrint(CC_DEFAULT, " - to assign strings, or use them as arguments, enclose it within quotes.");
@@ -2641,7 +2641,7 @@ static bool ConNewGRFProfile(std::span<std::string_view> argv)
auto profiler = std::ranges::find(_newgrf_profilers, &grf, &NewGRFProfiler::grffile);
bool selected = profiler != _newgrf_profilers.end();
bool active = selected && profiler->active;
TextColour tc = active ? TC_LIGHT_BLUE : selected ? TC_GREEN : CC_INFO;
TextColour tc = active ? TextColour::LightBlue : selected ? TextColour::Green : CC_INFO;
std::string_view statustext = active ? " (active)" : selected ? " (selected)" : "";
IConsolePrint(tc, "{}: [{:08X}] {}{}", i, std::byteswap(grf.grfid), grf.filename, statustext);
i++;
+3 -3
View File
@@ -22,7 +22,7 @@ void IConsoleFree();
void IConsoleClose();
/* console output */
void IConsolePrint(TextColour colour_code, const std::string &string);
void IConsolePrint(ExtendedTextColour colour_code, const std::string &string);
/**
* Handle the printing of text entered into the console or redirected there
@@ -38,7 +38,7 @@ void IConsolePrint(TextColour colour_code, const std::string &string);
* @tparam Args The types of the other arguments.
*/
template <typename A, typename ... Args>
inline void IConsolePrint(TextColour colour_code, fmt::format_string<A, Args...> format, A&& first_arg, Args&&... other_args)
inline void IConsolePrint(ExtendedTextColour colour_code, fmt::format_string<A, Args...> format, A&& first_arg, Args&&... other_args)
{
/* The separate first_arg argument is added to aid overloading.
* Otherwise the calls that do no need formatting will still use this function. */
@@ -48,6 +48,6 @@ inline void IConsolePrint(TextColour colour_code, fmt::format_string<A, Args...>
/* Parser */
void IConsoleCmdExec(std::string_view command_string, const uint recurse_count = 0);
bool IsValidConsoleColour(TextColour c);
bool IsValidConsoleColour(ExtendedTextColour c);
#endif /* CONSOLE_FUNC_H */
+9 -10
View File
@@ -41,10 +41,10 @@ static const uint ICON_BOTTOM_BORDERWIDTH = 12;
*/
struct IConsoleLine {
std::string buffer; ///< The data to store.
TextColour colour; ///< The colour of the line.
ExtendedTextColour colour; ///< The colour of the line.
uint16_t time; ///< The amount of time the line is in the backlog.
IConsoleLine() : buffer(), colour(TC_BEGIN), time(0)
IConsoleLine() : buffer(), colour(TextColour::Begin), time(0)
{
}
@@ -54,7 +54,7 @@ struct IConsoleLine {
* @param buffer the data to print.
* @param colour the colour of the line.
*/
IConsoleLine(std::string buffer, TextColour colour) :
IConsoleLine(std::string buffer, ExtendedTextColour colour) :
buffer(std::move(buffer)),
colour(colour),
time(0)
@@ -216,7 +216,7 @@ struct IConsoleWindow : Window
DrawString(this->line_offset + delta, right, this->height - this->line_height, _iconsole_cmdline.GetText(), static_cast<TextColour>(CC_COMMAND), SA_LEFT | SA_FORCE);
if (_focused_window == this && _iconsole_cmdline.caret) {
DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TC_WHITE, SA_LEFT | SA_FORCE);
DrawString(this->line_offset + delta + _iconsole_cmdline.caretxoffs, right, this->height - this->line_height, "_", TextColour::White, SA_LEFT | SA_FORCE);
}
}
@@ -388,7 +388,7 @@ void IConsoleGUIInit()
IConsoleClearBuffer();
IConsolePrint(TC_LIGHT_BLUE, "OpenTTD Game Console Revision 7 - {}", _openttd_revision);
IConsolePrint(TextColour::LightBlue, "OpenTTD Game Console Revision 7 - {}", _openttd_revision);
IConsolePrint(CC_WHITE, "------------------------------------");
IConsolePrint(CC_WHITE, "use \"help\" for more information.");
IConsolePrint(CC_WHITE, "");
@@ -499,7 +499,7 @@ static void IConsoleHistoryNavigate(int direction)
* @param colour_code the colour of the command. Red in case of errors, etc.
* @param str the message entered or output on the console (notice, error, etc.)
*/
void IConsoleGUIPrint(TextColour colour_code, const std::string &str)
void IConsoleGUIPrint(ExtendedTextColour colour_code, const std::string &str)
{
_iconsole_buffer.push_front(IConsoleLine(str, colour_code));
SetWindowDirty(WC_CONSOLE, 0);
@@ -539,16 +539,15 @@ static bool TruncateBuffer()
* @param c The text colour to compare to.
* @return true iff the TextColour is valid for console usage.
*/
bool IsValidConsoleColour(TextColour c)
bool IsValidConsoleColour(ExtendedTextColour c)
{
/* A normal text colour is used. */
if (!(c & TC_IS_PALETTE_COLOUR)) return TC_BEGIN <= c && c < TC_END;
if (!c.flags.Test(ExtendedTextColourFlag::IsPaletteColour)) return TextColour::Begin <= c.colour && c.colour < TextColour::End;
/* 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 (Colours i = Colours::Begin; i < Colours::End; i++) {
if (GetColourGradient(i, Shade::Normal).p == c) return true;
if (ExtendedTextColour{GetColourGradient(i, Shade::Normal)} == c) return true;
}
return false;
+1 -1
View File
@@ -94,6 +94,6 @@ void IConsoleStdLibRegister();
void IConsoleGUIInit();
void IConsoleGUIFree();
void IConsoleGUIPrint(TextColour colour_code, const std::string &string);
void IConsoleGUIPrint(ExtendedTextColour colour_code, const std::string &string);
#endif /* CONSOLE_INTERNAL_H */
+8 -8
View File
@@ -20,13 +20,13 @@ enum IConsoleModes : uint8_t {
};
/* Colours of the console messages. */
static const TextColour CC_DEFAULT = TC_SILVER; ///< Default colour of the console.
static const TextColour CC_ERROR = TC_RED; ///< Colour for error lines.
static const TextColour CC_WARNING = TC_LIGHT_BLUE; ///< Colour for warning lines.
static const TextColour CC_HELP = TC_LIGHT_BLUE; ///< Colour for help lines.
static const TextColour CC_INFO = TC_YELLOW; ///< Colour for information lines.
static const TextColour CC_DEBUG = TC_LIGHT_BROWN; ///< Colour for debug output.
static const TextColour CC_COMMAND = TC_GOLD; ///< Colour for the console's commands.
static const TextColour CC_WHITE = TC_WHITE; ///< White console lines for various things such as the welcome.
static const TextColour CC_DEFAULT = TextColour::Silver; ///< Default colour of the console.
static const TextColour CC_ERROR = TextColour::Red; ///< Colour for error lines.
static const TextColour CC_WARNING = TextColour::LightBlue; ///< Colour for warning lines.
static const TextColour CC_HELP = TextColour::LightBlue; ///< Colour for help lines.
static const TextColour CC_INFO = TextColour::Yellow; ///< Colour for information lines.
static const TextColour CC_DEBUG = TextColour::LightBrown; ///< Colour for debug output.
static const TextColour CC_COMMAND = TextColour::Gold; ///< Colour for the console's commands.
static const TextColour CC_WHITE = TextColour::White; ///< White console lines for various things such as the welcome.
#endif /* CONSOLE_TYPE_H */
+2 -2
View File
@@ -365,7 +365,7 @@ struct DepotWindow : Window {
Rect count = text.WithWidth(this->count_width - WidgetDimensions::scaled.hsep_normal, !rtl);
DrawString(count.left, count.right, count.bottom - GetCharacterHeight(FontSize::Small) + 1,
GetString(STR_JUST_DECIMAL, CeilDiv(length * 10, TILE_SIZE), 1),
TC_BLACK, SA_RIGHT | SA_FORCE, false, FontSize::Small); // Draw the counter
TextColour::Black, SA_RIGHT | SA_FORCE, false, FontSize::Small); // Draw the counter
break;
}
@@ -393,7 +393,7 @@ struct DepotWindow : Window {
Rect flag = r.WithWidth(this->flag_size.width, rtl).WithHeight(this->flag_size.height).Translate(0, diff_y);
DrawSpriteIgnorePadding((v->vehstatus.Test(VehState::Stopped)) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, SA_CENTER);
DrawString(text, GetString(STR_JUST_COMMA, v->unitnumber), (v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) >= v->age ? TC_BLACK : TC_RED);
DrawString(text, GetString(STR_JUST_COMMA, v->unitnumber), (v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) >= v->age ? TextColour::Black : TextColour::Red);
}
}
+3 -3
View File
@@ -84,10 +84,10 @@ public:
* @param sel Whether the item is selected or not.
* @return The text colour.
*/
TextColour GetColour(bool sel) const
ExtendedTextColour GetColour(bool sel) const
{
if (this->shaded) return (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
return sel ? TC_WHITE : TC_BLACK;
if (this->shaded) return ExtendedTextColour{sel ? TextColour::Silver : TextColour::Grey, ExtendedTextColourFlag::NoShade};
return sel ? TextColour::White : TextColour::Black;
}
};
+3 -3
View File
@@ -169,15 +169,15 @@ struct EnginePreviewWindow : Window {
if (this->selected_index >= this->engines.size()) return;
EngineID engine = this->engines[selected_index];
int y = DrawStringMultiLine(r, GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
int y = DrawStringMultiLine(r, GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), TextColour::FromString, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
DrawString(r.left, r.right, y, GetString(STR_ENGINE_NAME, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), TC_BLACK, SA_HOR_CENTER);
DrawString(r.left, r.right, y, GetString(STR_ENGINE_NAME, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), TextColour::Black, SA_HOR_CENTER);
y += GetCharacterHeight(FontSize::Normal);
DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
y += this->vehicle_space;
DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_BLACK, SA_CENTER);
DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TextColour::Black, SA_CENTER);
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
+6 -6
View File
@@ -192,14 +192,14 @@ public:
case WID_EM_MESSAGE:
if (this->detailed_msg.empty()) {
DrawStringMultiLineWithClipping(r, this->summary_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
DrawStringMultiLineWithClipping(r, this->summary_msg.GetDecodedString(), TextColour::White, SA_CENTER);
} else if (this->extra_msg.empty()) {
/* Extra space when message is shorter than company face window */
int extra = (r.Height() - this->height_summary - this->height_detailed - WidgetDimensions::scaled.vsep_wide) / 2;
/* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */
DrawStringMultiLineWithClipping(r.WithHeight(this->height_summary + extra, false), this->summary_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
DrawStringMultiLineWithClipping(r.WithHeight(this->height_detailed + extra, true), this->detailed_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
DrawStringMultiLineWithClipping(r.WithHeight(this->height_summary + extra, false), this->summary_msg.GetDecodedString(), TextColour::White, SA_CENTER);
DrawStringMultiLineWithClipping(r.WithHeight(this->height_detailed + extra, true), this->detailed_msg.GetDecodedString(), TextColour::White, SA_CENTER);
} else {
/* Extra space when message is shorter than company face window */
int extra = (r.Height() - this->height_summary - this->height_detailed - this->height_extra - (WidgetDimensions::scaled.vsep_wide * 2)) / 3;
@@ -208,9 +208,9 @@ public:
Rect top_section = r.WithHeight(this->height_summary + extra, false);
Rect bottom_section = r.WithHeight(this->height_extra + extra, true);
Rect middle_section = top_section.WithY(top_section.bottom, bottom_section.top);
DrawStringMultiLineWithClipping(top_section, this->summary_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
DrawStringMultiLineWithClipping(middle_section, this->detailed_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
DrawStringMultiLineWithClipping(bottom_section, this->extra_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
DrawStringMultiLineWithClipping(top_section, this->summary_msg.GetDecodedString(), TextColour::White, SA_CENTER);
DrawStringMultiLineWithClipping(middle_section, this->detailed_msg.GetDecodedString(), TextColour::White, SA_CENTER);
DrawStringMultiLineWithClipping(bottom_section, this->extra_msg.GetDecodedString(), TextColour::White, SA_CENTER);
}
break;
+13 -13
View File
@@ -303,16 +303,16 @@ static constexpr std::initializer_list<NWidgetPart> _nested_save_dialog_widgets
};
/** Text colours of #DetailedFileType fios entries in the window. */
static const EnumIndexArray<TextColour, DetailedFileType, DetailedFileType::End> _fios_colours = {
TC_LIGHT_BROWN, // DetailedFileType::OldGameFile
TC_ORANGE, // DetailedFileType::GameFile
TC_YELLOW, // DetailedFileType::HeightmapBmp
TC_ORANGE, // DetailedFileType::HeightmapPng
TC_LIGHT_BROWN, // DetailedFileType::TownDataJson
TC_LIGHT_BLUE, // DetailedFileType::FiosDrive
TC_DARK_GREEN, // DetailedFileType::FiosParent
TC_DARK_GREEN, // DetailedFileType::FiosDirectory
TC_ORANGE, // DetailedFileType::FiosDirect
static const EnumIndexArray<ExtendedTextColour, DetailedFileType, DetailedFileType::End> _fios_colours = {
TextColour::LightBrown, // DetailedFileType::OldGameFile
TextColour::Orange, // DetailedFileType::GameFile
TextColour::Yellow, // DetailedFileType::HeightmapBmp
TextColour::Orange, // DetailedFileType::HeightmapPng
TextColour::LightBrown, // DetailedFileType::TownDataJson
TextColour::LightBlue, // DetailedFileType::FiosDrive
TextColour::DarkGreen, // DetailedFileType::FiosParent
TextColour::DarkGreen, // DetailedFileType::FiosDirectory
TextColour::Orange, // DetailedFileType::FiosDirect
};
/**
@@ -533,7 +533,7 @@ public:
} else {
DrawString(ir.left, ir.right, ir.top + GetCharacterHeight(FontSize::Normal), STR_ERROR_UNABLE_TO_READ_DRIVE);
}
DrawString(ir.left, ir.right, ir.top, path, TC_BLACK);
DrawString(ir.left, ir.right, ir.top, path, TextColour::Black);
break;
}
@@ -574,7 +574,7 @@ public:
/* Create the nice lighter rectangle at the details top */
GfxFillRect(r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.bevel.left, WidgetDimensions::scaled.bevel.top, WidgetDimensions::scaled.bevel.right, 0), GetColourGradient(Colours::Grey, Shade::Lightest));
DrawString(hr.left, hr.right, hr.top, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(hr.left, hr.right, hr.top, STR_SAVELOAD_DETAIL_CAPTION, TextColour::FromString, SA_HOR_CENTER);
if (this->selected == nullptr) return;
@@ -588,7 +588,7 @@ public:
tr.top += GetCharacterHeight(FontSize::Normal);
} else if (_load_check_data.error != INVALID_STRING_ID) {
/* Incompatible / broken savegame */
tr.top = DrawStringMultiLine(tr, GetString(_load_check_data.error, _load_check_data.error_msg), TC_RED);
tr.top = DrawStringMultiLine(tr, GetString(_load_check_data.error, _load_check_data.error_msg), TextColour::Red);
} else {
/* Mapsize */
DrawString(tr, GetString(STR_NETWORK_SERVER_LIST_MAP_SIZE, _load_check_data.map_size_x, _load_check_data.map_size_y));
+15 -15
View File
@@ -599,14 +599,14 @@ struct FramerateWindow : Window {
int32_t skip = sb->GetPosition();
int drawable = this->num_displayed;
int y = r.top;
DrawString(r.left, r.right, y, heading_str, TC_FROMSTRING, SA_CENTER, true);
DrawString(r.left, r.right, y, heading_str, TextColour::FromString, SA_CENTER, true);
y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal;
for (PerformanceElement e : DISPLAY_ORDER_PFE) {
if (_pf_data[e].num_valid == 0) continue;
if (skip > 0) {
skip--;
} else {
DrawString(r.left, r.right, y, GetString(values[e].strid, values[e].GetValue(), values[e].GetDecimals()), TC_FROMSTRING, SA_RIGHT | SA_FORCE);
DrawString(r.left, r.right, y, GetString(values[e].strid, values[e].GetValue(), values[e].GetDecimals()), TextColour::FromString, SA_RIGHT | SA_FORCE);
y += GetCharacterHeight(FontSize::Normal);
drawable--;
if (drawable == 0) break;
@@ -620,7 +620,7 @@ struct FramerateWindow : Window {
int32_t skip = sb->GetPosition();
int drawable = this->num_displayed;
int y = r.top;
DrawString(r.left, r.right, y, STR_FRAMERATE_MEMORYUSE, TC_FROMSTRING, SA_CENTER, true);
DrawString(r.left, r.right, y, STR_FRAMERATE_MEMORYUSE, TextColour::FromString, SA_CENTER, true);
y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal;
for (PerformanceElement e : DISPLAY_ORDER_PFE) {
if (_pf_data[e].num_valid == 0) continue;
@@ -628,12 +628,12 @@ struct FramerateWindow : Window {
skip--;
} else if (e == PFE_GAMESCRIPT || e >= PFE_AI0) {
uint64_t value = e == PFE_GAMESCRIPT ? Game::GetInstance()->GetAllocatedMemory() : Company::Get(e - PFE_AI0)->ai_instance->GetAllocatedMemory();
DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, value), TC_FROMSTRING, SA_RIGHT | SA_FORCE);
DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, value), TextColour::FromString, SA_RIGHT | SA_FORCE);
y += GetCharacterHeight(FontSize::Normal);
drawable--;
if (drawable == 0) break;
} else if (e == PFE_SOUND) {
DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, GetSoundPoolAllocatedMemory()), TC_FROMSTRING, SA_RIGHT | SA_FORCE);
DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, GetSoundPoolAllocatedMemory()), TextColour::FromString, SA_RIGHT | SA_FORCE);
y += GetCharacterHeight(FontSize::Normal);
drawable--;
if (drawable == 0) break;
@@ -661,9 +661,9 @@ struct FramerateWindow : Window {
skip--;
} else {
if (e < PFE_AI0) {
DrawString(r.left, r.right, y, STR_FRAMERATE_GAMELOOP + e, TC_FROMSTRING, SA_LEFT);
DrawString(r.left, r.right, y, STR_FRAMERATE_GAMELOOP + e, TextColour::FromString, SA_LEFT);
} else {
DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_AI, e - PFE_AI0 + 1, GetAIName(e - PFE_AI0)), TC_FROMSTRING, SA_LEFT);
DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_AI, e - PFE_AI0 + 1, GetAIName(e - PFE_AI0)), TextColour::FromString, SA_LEFT);
}
y += GetCharacterHeight(FontSize::Normal);
drawable--;
@@ -732,7 +732,7 @@ static WindowDesc _framerate_display_desc(
static constexpr std::initializer_list<NWidgetPart> _frametime_graph_window_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::Grey),
NWidget(WWT_CAPTION, Colours::Grey, WID_FGW_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::Grey, WID_FGW_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_STICKYBOX, Colours::Grey),
EndContainer(),
NWidget(WWT_PANEL, Colours::Grey),
@@ -931,11 +931,11 @@ struct FrametimeGraphWindow : Window {
if ((TimingMeasurement)this->vertical_scale > TIMESTAMP_PRECISION) {
DrawString(r.left, x_zero - WidgetDimensions::scaled.hsep_normal, y - GetCharacterHeight(FontSize::Small),
GetString(STR_FRAMERATE_GRAPH_SECONDS, this->vertical_scale * division / 10 / TIMESTAMP_PRECISION),
TC_GREY, SA_RIGHT | SA_FORCE, false, FontSize::Small);
TextColour::Grey, SA_RIGHT | SA_FORCE, false, FontSize::Small);
} else {
DrawString(r.left, x_zero - WidgetDimensions::scaled.hsep_normal, y - GetCharacterHeight(FontSize::Small),
GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, this->vertical_scale * division / 10 * 1000 / TIMESTAMP_PRECISION),
TC_GREY, SA_RIGHT | SA_FORCE, false, FontSize::Small);
TextColour::Grey, SA_RIGHT | SA_FORCE, false, FontSize::Small);
}
}
}
@@ -946,7 +946,7 @@ struct FrametimeGraphWindow : Window {
if (division % 2 == 0) {
DrawString(x, x_max, y_zero + WidgetDimensions::scaled.vsep_normal,
GetString(STR_FRAMERATE_GRAPH_SECONDS, division * horz_div_scl / 2),
TC_GREY, SA_LEFT | SA_FORCE, false, FontSize::Small);
TextColour::Grey, SA_LEFT | SA_FORCE, false, FontSize::Small);
}
}
@@ -1001,7 +1001,7 @@ struct FrametimeGraphWindow : Window {
/* If the peak value is significantly larger than the average, mark and label it */
if (points_drawn > 0 && peak_value > TIMESTAMP_PRECISION / 100 && 2 * peak_value > 3 * value_sum / points_drawn) {
TextColour tc_peak = c_peak.ToTextColour();
ExtendedTextColour tc_peak{c_peak};
GfxFillRect(peak_point.x - 1, peak_point.y - 1, peak_point.x + 1, peak_point.y + 1, c_peak);
uint64_t value = peak_value * 1000 / TIMESTAMP_PRECISION;
int label_y = std::max(y_max, peak_point.y - GetCharacterHeight(FontSize::Small));
@@ -1048,7 +1048,7 @@ void ConPrintFramerate()
const int count2 = NUM_FRAMERATE_POINTS / 4;
const int count3 = NUM_FRAMERATE_POINTS / 1;
IConsolePrint(TC_SILVER, "Based on num. data points: {} {} {}", count1, count2, count3);
IConsolePrint(TextColour::Silver, "Based on num. data points: {} {} {}", count1, count2, count3);
static const std::array<std::string_view, PFE_MAX> MEASUREMENT_NAMES = {
"Game loop",
@@ -1073,7 +1073,7 @@ void ConPrintFramerate()
for (const auto &e : { PFE_GAMELOOP, PFE_DRAWING, PFE_VIDEO }) {
auto &pf = _pf_data[e];
if (pf.num_valid == 0) continue;
IConsolePrint(TC_GREEN, "{} rate: {:.2f}fps (expected: {:.2f}fps)",
IConsolePrint(TextColour::Green, "{} rate: {:.2f}fps (expected: {:.2f}fps)",
MEASUREMENT_NAMES[e],
pf.GetRate(),
pf.expected_rate);
@@ -1090,7 +1090,7 @@ void ConPrintFramerate()
ai_name_buf = fmt::format("AI {} {}", e - PFE_AI0 + 1, GetAIName(e - PFE_AI0));
name = ai_name_buf;
}
IConsolePrint(TC_LIGHT_BLUE, "{} times: {:.2f}ms {:.2f}ms {:.2f}ms",
IConsolePrint(TextColour::LightBlue, "{} times: {:.2f}ms {:.2f}ms {:.2f}ms",
name,
pf.GetAverageDurationMilliseconds(count1),
pf.GetAverageDurationMilliseconds(count2),
+1 -1
View File
@@ -176,7 +176,7 @@ struct GSConfigWindow : public Window {
switch (widget) {
case WID_GSC_GSLIST: {
/* There is only one slot, unlike with the GS GUI, so it should never be white */
DrawString(r.Shrink(WidgetDimensions::scaled.matrix), this->GetText(), (IsEditable() ? TC_ORANGE : TC_SILVER));
DrawString(r.Shrink(WidgetDimensions::scaled.matrix), this->GetText(), (IsEditable() ? TextColour::Orange : TextColour::Silver));
break;
}
case WID_GSC_SETTINGS: {
+4 -4
View File
@@ -224,7 +224,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_heightmap_load_widge
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
/* Heightmap name label. */
NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_MAPGEN_HEIGHTMAP_NAME_TOOLTIP),
NWidget(WWT_TEXT, Colours::Invalid, WID_GL_HEIGHTMAP_NAME_TEXT), SetTextStyle(TC_ORANGE), SetToolTip(STR_MAPGEN_HEIGHTMAP_NAME_TOOLTIP), SetFill(1, 0),
NWidget(WWT_TEXT, Colours::Invalid, WID_GL_HEIGHTMAP_NAME_TEXT), SetTextStyle(TextColour::Orange), SetToolTip(STR_MAPGEN_HEIGHTMAP_NAME_TOOLTIP), SetFill(1, 0),
EndContainer(),
/* Generation options. */
@@ -1444,17 +1444,17 @@ struct GenerateProgressWindow : public Window {
DrawFrameRect(r, Colours::Grey, {FrameFlag::BorderOnly, FrameFlag::Lowered});
Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
DrawFrameRect(br.WithWidth(br.Width() * GenWorldStatus::percent / 100, _current_text_dir == TD_RTL), Colours::Mauve, {});
DrawString(br.CentreToHeight(GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, GenWorldStatus::percent), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(br.CentreToHeight(GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, GenWorldStatus::percent), TextColour::FromString, SA_HOR_CENTER);
break;
}
case WID_GP_PROGRESS_TEXT:
/* Tell which class we are generating */
DrawString(r.left, r.right, r.top, GenWorldStatus::cls, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left, r.right, r.top, GenWorldStatus::cls, TextColour::FromString, SA_HOR_CENTER);
/* And say where we are in that class */
DrawString(r.left, r.right, r.top + GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal,
GetString(STR_GENERATION_PROGRESS_NUM, GenWorldStatus::current, GenWorldStatus::total), TC_FROMSTRING, SA_HOR_CENTER);
GetString(STR_GENERATION_PROGRESS_NUM, GenWorldStatus::current, GenWorldStatus::total), TextColour::FromString, SA_HOR_CENTER);
}
}
};
+18 -19
View File
@@ -473,17 +473,16 @@ void DrawRectOutline(const Rect &r, PixelColour colour, int width, int dash)
* Set the colour remap to be for the given colour.
* @param colour the new colour of the remap.
*/
static void SetColourRemap(TextColour colour)
static void SetColourRemap(ExtendedTextColour colour)
{
if (colour == TC_INVALID) return;
if (colour == TextColour::Invalid) return;
/* Black strings have no shading ever; the shading is black, so it
* would be invisible at best, but it actually makes it illegible. */
bool no_shade = (colour & TC_NO_SHADE) != 0 || colour == TC_BLACK;
bool raw_colour = (colour & TC_IS_PALETTE_COLOUR) != 0;
colour &= ~(TC_NO_SHADE | TC_IS_PALETTE_COLOUR | TC_FORCED);
bool no_shade = colour.flags.Test(ExtendedTextColourFlag::NoShade) || colour.colour == TextColour::Black;
bool raw_colour = colour.flags.Test(ExtendedTextColourFlag::IsPaletteColour);
_string_colourremap[1] = raw_colour ? (uint8_t)colour : _string_colourmap[colour].p;
_string_colourremap[1] = raw_colour ? to_underlying(colour.colour) : _string_colourmap[to_underlying(colour.colour)].p;
_string_colourremap[2] = no_shade ? 0 : 1;
_colour_remap_ptr = _string_colourremap;
}
@@ -504,7 +503,7 @@ static void SetColourRemap(TextColour colour)
* @return In case of left or center alignment the right most pixel we have drawn to.
* In case of right alignment the left most pixel we have drawn to.
*/
static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, int right, StringAlignment align, bool underline, bool truncation, TextColour default_colour)
static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, int right, StringAlignment align, bool underline, bool truncation, ExtendedTextColour default_colour)
{
if (line.CountRuns() == 0) return 0;
@@ -586,11 +585,11 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
const uint shadow_offset = ScaleGUITrad(1);
auto draw_line = [&](const ParagraphLayouter::Line &line, bool do_shadow, int left, int min_x, int max_x, bool truncation, TextColour initial_colour) {
auto draw_line = [&](const ParagraphLayouter::Line &line, bool do_shadow, int left, int min_x, int max_x, bool truncation, ExtendedTextColour initial_colour) {
const DrawPixelInfo *dpi = _cur_dpi;
int dpi_left = dpi->left;
int dpi_right = dpi->left + dpi->width - 1;
TextColour last_colour = initial_colour;
ExtendedTextColour last_colour{initial_colour};
for (size_t run_index = 0; run_index < line.CountRuns(); run_index++) {
const ParagraphLayouter::VisualRun &run = line.GetVisualRun(run_index);
@@ -599,13 +598,13 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
const Font *f = run.GetFont();
FontCache *fc = f->fc;
TextColour colour = f->colour;
if (colour == TC_INVALID || HasFlag(initial_colour, TC_FORCED)) colour = initial_colour;
bool colour_has_shadow = (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
ExtendedTextColour colour{f->colour};
if (colour == TextColour::Invalid || initial_colour.flags.Test(ExtendedTextColourFlag::Forced)) colour = initial_colour;
bool colour_has_shadow = !colour.flags.Test(ExtendedTextColourFlag::NoShade) && colour != TextColour::Black;
/* Update the last colour for the truncation ellipsis. */
last_colour = colour;
if (do_shadow && (!fc->GetDrawGlyphShadow() || !colour_has_shadow)) continue;
SetColourRemap(do_shadow ? TC_BLACK : colour);
SetColourRemap(do_shadow ? TextColour::Black : colour);
for (size_t i = 0; i < run.GetGlyphCount(); i++) {
GlyphID glyph = glyphs[i];
@@ -634,7 +633,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
/* Draw shadow, then foreground */
for (bool do_shadow : {true, false}) {
TextColour colour = draw_line(line, do_shadow, left - offset_x, min_x, max_x, truncation, default_colour);
ExtendedTextColour colour = draw_line(line, do_shadow, left - offset_x, min_x, max_x, truncation, default_colour);
if (truncation) {
int x = (_current_text_dir == TD_RTL) ? left : (right - truncation_width);
@@ -666,7 +665,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
* @return In case of left or center alignment the right most pixel we have drawn to.
* In case of right alignment the left most pixel we have drawn to.
*/
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
{
/* The string may contain control chars to change the font, just use the biggest font for clipping. */
int max_height = std::max({GetCharacterHeight(FontSize::Small), GetCharacterHeight(FontSize::Normal), GetCharacterHeight(FontSize::Large), GetCharacterHeight(FontSize::Monospace)});
@@ -702,7 +701,7 @@ int DrawString(int left, int right, int top, std::string_view str, TextColour co
* @return In case of left or center alignment the right most pixel we have drawn to.
* In case of right alignment the left most pixel we have drawn to.
*/
int DrawString(int left, int right, int top, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
int DrawString(int left, int right, int top, StringID str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
{
return DrawString(left, right, top, GetString(str), colour, align, underline, fontsize);
}
@@ -785,7 +784,7 @@ Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &s
*
* @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written.
*/
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
{
int maxw = right - left + 1;
int maxh = bottom - top + 1;
@@ -847,7 +846,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_vi
*
* @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written.
*/
int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
{
return DrawStringMultiLine(left, right, top, bottom, GetString(str), colour, align, underline, fontsize);
}
@@ -870,7 +869,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
*
* @return true iff the string was drawn.
*/
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
{
/* The string may contain control chars to change the font, just use the biggest font for clipping. */
int max_height = std::max({GetCharacterHeight(FontSize::Small), GetCharacterHeight(FontSize::Normal), GetCharacterHeight(FontSize::Large), GetCharacterHeight(FontSize::Monospace)});
+12 -12
View File
@@ -96,11 +96,11 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, StringAlignment align); /* widget.cpp */
std::unique_ptr<uint32_t[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom = _gui_zoom);
int DrawString(int left, int right, int top, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal);
int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal);
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal);
int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal);
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal);
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal);
int DrawString(int left, int right, int top, StringID str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal);
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal);
int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal);
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal);
void DrawCharCentered(char32_t c, const Rect &r, TextColour colour);
@@ -121,13 +121,13 @@ void DrawRectOutline(const Rect &r, PixelColour colour, int width = 1, int dash
* @param fontsize The size of the initial characters.
* @return In case of left or center alignment the right most pixel we have drawn to. In case of right alignment the left most pixel we have drawn to.
*/
inline int DrawString(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal)
inline int DrawString(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal)
{
return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize);
}
/** @copydoc DrawString(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal) */
inline int DrawString(const Rect &r, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal)
/** @copydoc DrawString(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal) */
inline int DrawString(const Rect &r, StringID str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FontSize::Normal)
{
return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize);
}
@@ -144,13 +144,13 @@ inline int DrawString(const Rect &r, StringID str, TextColour colour = TC_FROMST
*
* @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written.
*/
inline int DrawStringMultiLine(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal)
inline int DrawStringMultiLine(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal)
{
return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize);
}
/** @copydoc DrawStringMultiLine(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal) */
inline int DrawStringMultiLine(const Rect &r, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal)
/** @copydoc DrawStringMultiLine(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal) */
inline int DrawStringMultiLine(const Rect &r, StringID str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal)
{
return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize);
}
@@ -169,7 +169,7 @@ inline int DrawStringMultiLine(const Rect &r, StringID str, TextColour colour =
*
* @return \c true iff the string was drawn.
*/
inline bool DrawStringMultiLineWithClipping(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal)
inline bool DrawStringMultiLineWithClipping(const Rect &r, std::string_view str, ExtendedTextColour colour = TextColour::FromString, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FontSize::Normal)
{
return DrawStringMultiLineWithClipping(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize);
}
+3 -3
View File
@@ -46,7 +46,7 @@ EnumIndexArray<Layouter::FontColourMap, FontSize, FontSize::End> Layouter::fonts
* @param size The font size to use for this font.
* @param colour The colour to draw this font in.
*/
Font::Font(FontSize size, TextColour colour) :
Font::Font(FontSize size, ExtendedTextColour colour) :
fc(FontCache::Get(size)), colour(colour)
{
assert(size < FontSize::End);
@@ -128,7 +128,7 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view s
*/
Layouter::Layouter(std::string_view str, int maxw, FontSize fontsize) : string(str)
{
FontState state(TC_INVALID, fontsize);
FontState state(TextColour::Invalid, fontsize);
while (true) {
auto line_length = str.find_first_of('\n');
@@ -346,7 +346,7 @@ ptrdiff_t Layouter::GetCharAtPosition(int x, size_t line_index) const
* @param colour The font's colour.
* @return The cached font.
*/
Font *Layouter::GetFont(FontSize size, TextColour colour)
Font *Layouter::GetFont(FontSize size, ExtendedTextColour colour)
{
FontColourMap::iterator it = fonts[size].find(colour);
if (it != fonts[size].end()) return it->second.get();
+36 -15
View File
@@ -22,12 +22,18 @@
* of the same text, e.g. on line breaks.
*/
struct FontState {
FontSize fontsize; ///< Current font size.
TextColour cur_colour; ///< Current text colour.
std::vector<TextColour> colour_stack; ///< Stack of colours to assist with colour switching.
FontSize fontsize; ///< Current font size.
ExtendedTextColour cur_colour; ///< Current text colour.
std::vector<ExtendedTextColour> colour_stack; ///< Stack of colours to assist with colour switching.
FontState() : fontsize(FontSize::End), cur_colour(TC_INVALID) {}
FontState(TextColour colour, FontSize fontsize) : fontsize(fontsize), cur_colour(colour) {}
/** Create the font state with an invalid state. */
FontState() : fontsize(FontSize::End), cur_colour(TextColour::Invalid) {}
/**
* Create the font state.
* @param colour The colour of the font.
* @param fontsize The size of the font.
*/
FontState(ExtendedTextColour colour, FontSize fontsize) : fontsize(fontsize), cur_colour(colour) {}
auto operator<=>(const FontState &) const = default;
@@ -35,11 +41,11 @@ struct FontState {
* Switch to new colour \a c.
* @param c New colour to use.
*/
inline void SetColour(TextColour c)
inline void SetColour(ExtendedTextColour c)
{
assert(((c & TC_COLOUR_MASK) >= TC_BLUE && (c & TC_COLOUR_MASK) <= TC_BLACK) || (c & TC_COLOUR_MASK) == TC_INVALID);
assert((c & (TC_COLOUR_MASK | TC_FLAGS_MASK)) == c);
if ((this->cur_colour & TC_FORCED) == 0) this->cur_colour = c;
assert((c.colour >= TextColour::Begin && c.colour < TextColour::End) || c.colour == TextColour::Invalid);
assert(!c.flags.Test(ExtendedTextColourFlag::IsPaletteColour));
if (!this->cur_colour.flags.Test(ExtendedTextColourFlag::Forced)) this->cur_colour = c;
}
/**
@@ -81,12 +87,27 @@ template <typename T> struct std::hash<std::vector<T>> {
}
};
/** Instantiation of a hash for an ExtendedTextColour. */
template <> struct std::hash<ExtendedTextColour> {
/**
* Hash the text colour.
* @param tc The colour to hash.
* @return The hashed value.
*/
std::size_t operator()(const ExtendedTextColour &tc) const noexcept
{
size_t h1 = std::hash<TextColour>{}(tc.colour);
size_t h2 = std::hash<uint8_t>{}(tc.flags.base());
return h1 ^ (h2 << 1);
}
};
template <> struct std::hash<FontState> {
std::size_t operator()(const FontState &state) const noexcept
{
size_t h1 = std::hash<FontSize>{}(state.fontsize);
size_t h2 = std::hash<TextColour>{}(state.cur_colour);
size_t h3 = std::hash<std::vector<TextColour>>{}(state.colour_stack);
size_t h2 = std::hash<ExtendedTextColour>{}(state.cur_colour);
size_t h3 = std::hash<std::vector<ExtendedTextColour>>{}(state.colour_stack);
return h1 ^ (h2 << 1) ^ (h3 << 2);
}
};
@@ -97,9 +118,9 @@ template <> struct std::hash<FontState> {
class Font {
public:
FontCache *fc; ///< The font we are using.
TextColour colour; ///< The colour this font has to be.
ExtendedTextColour colour; ///< The colour this font has to be.
Font(FontSize size, TextColour colour);
Font(FontSize size, ExtendedTextColour colour);
};
/** Mapping from index to font. The pointer is owned by FontColourMap. */
@@ -278,10 +299,10 @@ private:
static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state);
using FontColourMap = std::map<TextColour, std::unique_ptr<Font>>;
using FontColourMap = std::map<ExtendedTextColour, std::unique_ptr<Font>>;
static EnumIndexArray<FontColourMap, FontSize, FontSize::End> fonts; ///< The colour mapping of each of the fonts.
public:
static Font *GetFont(FontSize size, TextColour colour);
static Font *GetFont(FontSize size, ExtendedTextColour colour);
Layouter(std::string_view str, int maxw = INT32_MAX, FontSize fontsize = FontSize::Normal);
Dimension GetBounds();
+76 -40
View File
@@ -303,38 +303,84 @@ enum class Colours : uint8_t {
};
DECLARE_INCREMENT_DECREMENT_OPERATORS(Colours)
/** Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palette.png */
enum TextColour : uint16_t {
TC_BEGIN = 0x00,
TC_FROMSTRING = 0x00,
TC_BLUE = 0x00,
TC_SILVER = 0x01,
TC_GOLD = 0x02,
TC_RED = 0x03,
TC_PURPLE = 0x04,
TC_LIGHT_BROWN = 0x05,
TC_ORANGE = 0x06,
TC_GREEN = 0x07,
TC_YELLOW = 0x08,
TC_DARK_GREEN = 0x09,
TC_CREAM = 0x0A,
TC_BROWN = 0x0B,
TC_WHITE = 0x0C,
TC_LIGHT_BLUE = 0x0D,
TC_GREY = 0x0E,
TC_DARK_BLUE = 0x0F,
TC_BLACK = 0x10,
TC_END,
TC_INVALID = 0xFF,
/** Colour for pixel/line drawing. */
struct PixelColour {
uint8_t p; ///< Palette index.
TC_IS_PALETTE_COLOUR = 0x100, ///< Colour value is already a real palette colour index, not an index of a StringColour.
TC_NO_SHADE = 0x200, ///< Do not add shading to this text colour.
TC_FORCED = 0x400, ///< Ignore colour changes from strings.
TC_COLOUR_MASK = 0xFF, ///< Mask to test if TextColour (without flags) is within limits.
TC_FLAGS_MASK = 0x700, ///< Mask to test if TextColour (with flags) is within limits.
constexpr PixelColour() : p(0) {}
explicit constexpr PixelColour(uint8_t p) : p(p) {}
};
/** Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palette.png */
enum class TextColour : uint8_t {
Begin = 0x00, ///< Marker for the begin of the range.
FromString = Begin, ///< Marker for telling to use the colour from the string.
Blue = Begin, ///< Blue colour.
Silver, ///< Silver colour.
Gold, ///< Gold colour.
Red, ///< Red colour.
Purple, ///< Purple colour.
LightBrown, ///< Light brown colour.
Orange, ///< Orange colour.
Green, ///< Green colour.
Yellow, ///< Yellow colour.
DarkGreen, ///< Dark green colour.
Cream, ///< Cream colour.
Brown, ///< Brown colour.
White, ///< White colour.
LightBlue, ///< Light blue colour.
Grey, ///< Grey colour.
DarkBlue, ///< Dark blue colour.
Black, ///< Black colour.
End, ///< Marker for the end of the range.
Invalid = 0xFF, ///< Invalid colour.
};
/** Enumeration of the flags of ExtendedTextColour. */
enum class ExtendedTextColourFlag : uint8_t{
IsPaletteColour, ///< Colour value is already a real palette colour index, not an index of a StringColour.
NoShade, ///< Do not add shading to this text colour.
Forced, ///< Ignore colour changes from strings.
};
using ExtendedTextColourFlags = EnumBitSet<ExtendedTextColourFlag, uint8_t>; ///< Bitset of the flags of ExtendedTextColour. */
/** Container for the text colour and some text colour related flags for drawing. */
struct ExtendedTextColour {
/**
* Create the extended text colour based on a TextColour and optional flags.
* @param colour The colour.
* @param flags The flags.
*/
constexpr ExtendedTextColour(TextColour colour = TextColour::Invalid, ExtendedTextColourFlags flags = {}) : colour(colour), flags(flags) {}
/**
* Create the extended text colour based on a PixelColour.
* @param pc The pixel colour for this colour.
*/
constexpr ExtendedTextColour(PixelColour pc) : colour(static_cast<TextColour>(pc.p)), flags(ExtendedTextColourFlag::IsPaletteColour) {}
TextColour colour; ///< The colour
ExtendedTextColourFlags flags{}; ///< The flags.
/**
* Compare with another instance of this class.
* @return The std::strong_ordering of the comparison.
*/
constexpr auto operator<=>(const ExtendedTextColour &) const = default;
/**
* Decode the network encoded text colour.
* @param tc The network encoded colour.
* @return The decoded colour.
*/
constexpr static ExtendedTextColour FromNetwork(uint16_t tc) { return ExtendedTextColour{static_cast<TextColour>(tc & 0xFF), ExtendedTextColourFlags(tc >> 8)}; }
/**
* Encode this text colour for sending over the network.
* @return The encoded colour.
*/
constexpr uint16_t ToNetwork() const { return to_underlying(this->colour) | this->flags.base() << 8; }
};
DECLARE_ENUM_AS_BIT_SET(TextColour)
/* A few values that are related to animations using palette changes */
static constexpr uint8_t PALETTE_ANIM_SIZE = 28; ///< number of animated colours
@@ -410,14 +456,4 @@ enum class DirectionKey {
};
using DirectionKeys = EnumBitSet<DirectionKey, uint8_t>; ///< Bitset of the direction keys.
/** Colour for pixel/line drawing. */
struct PixelColour {
uint8_t p; ///< Palette index.
constexpr PixelColour() : p(0) {}
explicit constexpr PixelColour(uint8_t p) : p(p) {}
constexpr inline TextColour ToTextColour() const { return static_cast<TextColour>(this->p) | TC_IS_PALETTE_COLOUR; }
};
#endif /* GFX_TYPE_H */
+2 -2
View File
@@ -210,7 +210,7 @@ struct GoalListWindow : public Window {
case GC_PROGRESS:
if (!s->progress.empty()) {
StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
DrawString(r.WithWidth(progress_col_width, !rtl), GetString(str, s->progress.GetDecodedString()), TC_FROMSTRING, SA_RIGHT | SA_FORCE);
DrawString(r.WithWidth(progress_col_width, !rtl), GetString(str, s->progress.GetDecodedString()), TextColour::FromString, SA_RIGHT | SA_FORCE);
}
break;
}
@@ -476,5 +476,5 @@ static WindowDesc _goal_question_list_desc[] = {
void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const EncodedString &question)
{
assert(type < GQT_END);
new GoalQuestionWindow(_goal_question_list_desc[type], id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
new GoalQuestionWindow(_goal_question_list_desc[type], id, type == 3 ? TextColour::White : TextColour::Black, button_mask, question);
}
+15 -15
View File
@@ -78,7 +78,7 @@ struct GraphLegendWindow : Window {
DrawCompanyIcon(cid, rtl ? ir.right - d.width : ir.left, CentreBounds(ir.top, ir.bottom, d.height));
const Rect tr = ir.Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl);
DrawString(tr.left, tr.right, CentreBounds(tr.top, tr.bottom, GetCharacterHeight(FontSize::Normal)), GetString(STR_COMPANY_NAME_COMPANY_NUM, cid, cid), _legend_excluded_companies.Test(cid) ? TC_BLACK : TC_WHITE);
DrawString(tr.left, tr.right, CentreBounds(tr.top, tr.bottom, GetCharacterHeight(FontSize::Normal)), GetString(STR_COMPANY_NAME_COMPANY_NUM, cid, cid), _legend_excluded_companies.Test(cid) ? TextColour::Black : TextColour::White);
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
@@ -184,7 +184,7 @@ protected:
static const int ECONOMY_QUARTER_MINUTES = 3; ///< Minutes per economic quarter.
static const int ECONOMY_MONTH_MINUTES = 1; ///< Minutes per economic month.
static const TextColour GRAPH_AXIS_LABEL_COLOUR = TC_BLACK; ///< colour of the graph axis label.
static const TextColour GRAPH_AXIS_LABEL_COLOUR = TextColour::Black; ///< colour of the graph axis label.
static const int MIN_GRAPH_NUM_LINES_Y = 9; ///< Minimal number of horizontal lines to draw.
static const int MIN_GRID_PIXEL_SIZE = 20; ///< Minimum distance between graph lines.
@@ -722,7 +722,7 @@ public:
if (lowered) DrawFrameRect(line, Colours::Brown, FrameFlag::Lowered);
const Rect text = line.Shrink(WidgetDimensions::scaled.framerect);
DrawString(text, str, (this->highlight_state && this->highlight_range == index) ? TC_WHITE : TC_BLACK, SA_CENTER, false, FontSize::Small);
DrawString(text, str, (this->highlight_state && this->highlight_range == index) ? TextColour::White : TextColour::Black, SA_CENTER, false, FontSize::Small);
if (HasBit(this->masked_range, index)) {
GfxFillRect(line.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(Colours::Brown, Shade::Darker), FillRectMode::Checker);
@@ -742,7 +742,7 @@ public:
/* Redraw frame if selected */
if (selected_month_increment == scale.month_increment) DrawFrameRect(line, Colours::Brown, FrameFlag::Lowered);
DrawString(line.Shrink(WidgetDimensions::scaled.framerect), scale.label, TC_BLACK, SA_CENTER, false, FontSize::Small);
DrawString(line.Shrink(WidgetDimensions::scaled.framerect), scale.label, TextColour::Black, SA_CENTER, false, FontSize::Small);
line = line.Translate(0, line_height);
}
@@ -956,7 +956,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_operating_profit_wid
NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND),
NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -1010,7 +1010,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_income_graph_widgets
NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND),
NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -1062,7 +1062,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_delivered_cargo_grap
NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND),
NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -1121,7 +1121,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_performance_history_
NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND),
NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -1173,7 +1173,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_company_value_graph_
NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND),
NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -1445,7 +1445,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_cargo_payment_rates_
NWidget(WWT_STICKYBOX, Colours::Brown),
EndContainer(),
NWidget(WWT_PANEL, Colours::Brown, WID_GRAPH_BACKGROUND), SetMinimalSize(568, 128),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_HEADER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetStringTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_HEADER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetStringTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
@@ -1462,7 +1462,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_cargo_payment_rates_
NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -1609,7 +1609,7 @@ struct PerformanceRatingDetailWindow : Window {
DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + to_underlying(score_type));
/* Draw the score */
DrawString(this->score_info_left, this->score_info_right, text_top, GetString(STR_JUST_COMMA, score), TC_BLACK, SA_RIGHT);
DrawString(this->score_info_left, this->score_info_right, text_top, GetString(STR_JUST_COMMA, score), TextColour::Black, SA_RIGHT);
/* Calculate the %-bar */
uint x = Clamp<int64_t>(val, 0, needed) * this->bar_width / needed;
@@ -1625,7 +1625,7 @@ struct PerformanceRatingDetailWindow : Window {
if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height - 1, rtl ? colour_done : colour_notdone);
/* Draw it */
DrawString(this->bar_left, this->bar_right, text_top, GetString(STR_PERFORMANCE_DETAIL_PERCENT, Clamp<int64_t>(val, 0, needed) * 100 / needed), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(this->bar_left, this->bar_right, text_top, GetString(STR_PERFORMANCE_DETAIL_PERCENT, Clamp<int64_t>(val, 0, needed) * 100 / needed), TextColour::FromString, SA_HOR_CENTER);
/* ScoreID::Loan is inverted */
if (score_type == ScoreID::Loan) val = needed - val;
@@ -1867,7 +1867,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_industry_production_
NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -2031,7 +2031,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_town_cargo_graph_wid
NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TC_BLACK, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_TEXT, Colours::Invalid, WID_GRAPH_FOOTER), SetFill(1, 0), SetResize(1, 0), SetPadding(2, 0, 2, 0), SetTextStyle(TextColour::Black, FontSize::Small), SetAlignment(SA_CENTER),
NWidget(WWT_RESIZEBOX, Colours::Brown, WID_GRAPH_RESIZE), SetResizeWidgetTypeTip(ResizeWidgetType::HideBevel, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
+7 -7
View File
@@ -349,7 +349,7 @@ private:
if (g_id == NEW_GROUP) return;
/* draw the selected group in white, else we draw it in black */
TextColour colour = g_id == this->vli.ToGroupID() ? TC_WHITE : TC_BLACK;
TextColour colour = g_id == this->vli.ToGroupID() ? TextColour::White : TextColour::Black;
const GroupStatistics &stats = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype);
bool rtl = _current_text_dir == TD_RTL;
@@ -662,18 +662,18 @@ public:
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_THIS_PERIOD : STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, this_year), TC_BLACK, SA_RIGHT);
DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_THIS_PERIOD : STR_GROUP_PROFIT_THIS_YEAR, TextColour::Black);
DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, this_year), TextColour::Black, SA_RIGHT);
tr.top += GetCharacterHeight(FontSize::Normal);
DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_LAST_PERIOD : STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, last_year), TC_BLACK, SA_RIGHT);
DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_GROUP_PROFIT_LAST_PERIOD : STR_GROUP_PROFIT_LAST_YEAR, TextColour::Black);
DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, last_year), TextColour::Black, SA_RIGHT);
tr.top += GetCharacterHeight(FontSize::Normal);
DrawString(tr, STR_GROUP_OCCUPANCY, TC_BLACK);
DrawString(tr, STR_GROUP_OCCUPANCY, TextColour::Black);
const size_t vehicle_count = this->vehicles.size();
if (vehicle_count > 0) {
DrawString(tr, GetString(STR_GROUP_OCCUPANCY_VALUE, occupancy / vehicle_count), TC_BLACK, SA_RIGHT);
DrawString(tr, GetString(STR_GROUP_OCCUPANCY_VALUE, occupancy / vehicle_count), TextColour::Black, SA_RIGHT);
}
break;
+4 -4
View File
@@ -158,11 +158,11 @@ struct EndGameWindow : EndGameHighScoreBaseWindow {
if (this->background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/
DrawStringMultiLine(pt.x + ScaleSpriteTrad(15), pt.x + ScaleSpriteTrad(640) - ScaleSpriteTrad(25), pt.y + ScaleSpriteTrad(90), pt.y + ScaleSpriteTrad(160),
GetString(STR_HIGHSCORE_PRESIDENT_OF_COMPANY_ACHIEVES_STATUS, c->index, c->index, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history)),
TC_FROMSTRING, SA_CENTER);
TextColour::FromString, SA_CENTER);
} else {
DrawStringMultiLine(pt.x + ScaleSpriteTrad(36), pt.x + ScaleSpriteTrad(640), pt.y + ScaleSpriteTrad(140), pt.y + ScaleSpriteTrad(206),
GetString(STR_HIGHSCORE_COMPANY_ACHIEVES_STATUS, c->index, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history)),
TC_FROMSTRING, SA_CENTER);
TextColour::FromString, SA_CENTER);
}
}
};
@@ -202,7 +202,7 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow {
Point pt = this->GetTopLeft(ScaleSpriteTrad(640), ScaleSpriteTrad(480));
/* Draw the title. */
DrawStringMultiLine(pt.x + ScaleSpriteTrad(70), pt.x + ScaleSpriteTrad(570), pt.y, pt.y + ScaleSpriteTrad(140), STR_HIGHSCORE_TOP_COMPANIES, TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(pt.x + ScaleSpriteTrad(70), pt.x + ScaleSpriteTrad(570), pt.y, pt.y + ScaleSpriteTrad(140), STR_HIGHSCORE_TOP_COMPANIES, TextColour::FromString, SA_CENTER);
/* Draw Highscore peepz */
for (uint8_t i = 0; i < ClampTo<uint8_t>(hs.size()); i++) {
@@ -210,7 +210,7 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow {
GetString(STR_HIGHSCORE_POSITION, i + 1));
if (!hs[i].name.empty()) {
TextColour colour = (this->rank == i) ? TC_RED : TC_BLACK; // draw new highscore in red
TextColour colour = (this->rank == i) ? TextColour::Red : TextColour::Black; // draw new highscore in red
DrawString(pt.x + ScaleSpriteTrad(71), pt.x + ScaleSpriteTrad(569), pt.y + ScaleSpriteTrad(140 + i * 55),
GetString(STR_JUST_BIG_RAW_STRING, hs[i].name), colour);
+11 -11
View File
@@ -534,10 +534,10 @@ public:
}
/* Draw the name of the industry in white is selected, otherwise, in orange */
DrawString(tr, indsp->name, selected ? TC_WHITE : TC_ORANGE);
DrawString(tr, indsp->name, selected ? TextColour::White : TextColour::Orange);
GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK);
GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), indsp->map_colour);
DrawString(tr, GetString(STR_JUST_COMMA, Industry::GetIndustryTypeCount(type)), TC_BLACK, SA_RIGHT, false, FontSize::Small);
DrawString(tr, GetString(STR_JUST_COMMA, Industry::GetIndustryTypeCount(type)), TextColour::Black, SA_RIGHT, false, FontSize::Small);
text = text.Translate(0, this->resize.step_height);
icon = icon.Translate(0, this->resize.step_height);
@@ -588,7 +588,7 @@ public:
str = GetGRFStringWithTextStack(indsp->grf_prop.grffile, GRFSTR_MISC_GRF_TEXT + callback_res, regs100);
}
if (!str.empty()) {
DrawStringMultiLine(ir, str, TC_YELLOW);
DrawStringMultiLine(ir, str, TextColour::Yellow);
}
}
}
@@ -974,14 +974,14 @@ public:
}
if (!str.empty()) {
ir.top += WidgetDimensions::scaled.vsep_wide;
ir.top = DrawStringMultiLine(ir, str, TC_YELLOW);
ir.top = DrawStringMultiLine(ir, str, TextColour::Yellow);
}
}
}
if (!i->text.empty()) {
ir.top += WidgetDimensions::scaled.vsep_wide;
ir.top = DrawStringMultiLine(ir, i->text.GetDecodedString(), TC_BLACK);
ir.top = DrawStringMultiLine(ir, i->text.GetDecodedString(), TextColour::Black);
}
/* Return required bottom position, the last pixel row plus some padding. */
@@ -1717,11 +1717,11 @@ public:
const CargoType acf_cargo_type = this->accepted_cargo_filter_criteria;
auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->industries);
for (auto it = first; it != last; ++it) {
TextColour tc = TC_FROMSTRING;
ExtendedTextColour tc{TextColour::FromString};
if (acf_cargo_type != CargoFilterCriteria::CF_ANY && acf_cargo_type != CargoFilterCriteria::CF_NONE) {
Industry *ind = const_cast<Industry *>(*it);
if (IndustryTemporarilyRefusesCargo(ind, acf_cargo_type)) {
tc = TC_GREY | TC_FORCED;
tc = ExtendedTextColour{TextColour::Grey, ExtendedTextColourFlag::Forced};
}
}
DrawString(ir, this->GetIndustryString(*it), tc);
@@ -2151,7 +2151,7 @@ struct CargoesField {
case CargoesFieldType::Header:
ypos += (small_height - GetCharacterHeight(FontSize::Normal)) / 2;
DrawString(xpos, xpos + industry_width, ypos, this->u.header, TC_WHITE, SA_HOR_CENTER);
DrawString(xpos, xpos + industry_width, ypos, this->u.header, TextColour::White, SA_HOR_CENTER);
break;
case CargoesFieldType::Industry: {
@@ -2162,7 +2162,7 @@ struct CargoesField {
ypos += (normal_height - GetCharacterHeight(FontSize::Normal)) / 2;
if (this->u.industry.ind_type < NUM_INDUSTRYTYPES) {
const IndustrySpec *indsp = GetIndustrySpec(this->u.industry.ind_type);
DrawString(xpos, xpos2, ypos, indsp->name, TC_WHITE, SA_HOR_CENTER);
DrawString(xpos, xpos2, ypos, indsp->name, TextColour::White, SA_HOR_CENTER);
/* Draw the industry legend. */
int blob_left, blob_right;
@@ -2176,7 +2176,7 @@ struct CargoesField {
GfxFillRect(blob_left, ypos2 - blob_distance - CargoesField::legend.height, blob_right, ypos2 - blob_distance, PC_BLACK); // Border
GfxFillRect(blob_left + 1, ypos2 - blob_distance - CargoesField::legend.height + 1, blob_right - 1, ypos2 - blob_distance - 1, indsp->map_colour);
} else {
DrawString(xpos, xpos2, ypos, STR_INDUSTRY_CARGOES_HOUSES, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(xpos, xpos2, ypos, STR_INDUSTRY_CARGOES_HOUSES, TextColour::FromString, SA_HOR_CENTER);
}
/* Draw the other_produced/other_accepted cargoes. */
@@ -2266,7 +2266,7 @@ struct CargoesField {
for (uint i = 0; i < MAX_CARGOES; i++) {
if (IsValidCargoType(this->u.cargo_label.cargoes[i])) {
const CargoSpec *csp = CargoSpec::Get(this->u.cargo_label.cargoes[i]);
DrawString(xpos + WidgetDimensions::scaled.framerect.left, xpos + industry_width - 1 - WidgetDimensions::scaled.framerect.right, ypos, csp->name, TC_WHITE,
DrawString(xpos + WidgetDimensions::scaled.framerect.left, xpos + industry_width - 1 - WidgetDimensions::scaled.framerect.right, ypos, csp->name, TextColour::White,
(this->u.cargo_label.left_align) ? SA_LEFT : SA_RIGHT);
}
ypos += GetCharacterHeight(FontSize::Normal) + CargoesField::cargo_space.height;
+2 -2
View File
@@ -267,11 +267,11 @@ struct SelectGameWindow : public Window {
{
switch (widget) {
case WID_SGI_BASESET:
DrawStringMultiLine(r, GetString(STR_INTRO_BASESET, _missing_extra_graphics), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, GetString(STR_INTRO_BASESET, _missing_extra_graphics), TextColour::FromString, SA_CENTER);
break;
case WID_SGI_TRANSLATION:
DrawStringMultiLine(r, GetString(STR_INTRO_TRANSLATION, _current_language->missing), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, GetString(STR_INTRO_TRANSLATION, _current_language->missing), TextColour::FromString, SA_CENTER);
break;
}
}
+4 -4
View File
@@ -318,7 +318,7 @@ public:
Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
if (!lt->header.empty()) {
ir.top = DrawStringMultiLine(ir, lt->header.GetDecodedString(), TC_BLACK) + WidgetDimensions::scaled.vsep_wide;
ir.top = DrawStringMultiLine(ir, lt->header.GetDecodedString(), TextColour::Black) + WidgetDimensions::scaled.vsep_wide;
}
int icon_y_offset = (this->line_height - this->icon_size.height) / 2;
@@ -335,14 +335,14 @@ public:
for (const auto &[rank, lte] : this->rows) {
DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset, GetString(STR_COMPANY_LEAGUE_COMPANY_RANK, rank + 1));
if (this->icon_size.width > 0 && lte->company != CompanyID::Invalid()) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset);
DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, lte->text.GetDecodedString(), TC_BLACK);
DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, lte->score.GetDecodedString(), TC_BLACK, SA_RIGHT | SA_FORCE);
DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, lte->text.GetDecodedString(), TextColour::Black);
DrawString(score_rect.left, score_rect.right, ir.top + text_y_offset, lte->score.GetDecodedString(), TextColour::Black, SA_RIGHT | SA_FORCE);
ir.top += this->line_height;
}
if (!lt->footer.empty()) {
ir.top += WidgetDimensions::scaled.vsep_wide;
ir.top = DrawStringMultiLine(ir, lt->footer.GetDecodedString(), TC_BLACK);
ir.top = DrawStringMultiLine(ir, lt->footer.GetDecodedString(), TextColour::Black);
}
}
+1 -1
View File
@@ -622,7 +622,7 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, WidgetID widget) const
str = STR_LINKGRAPH_LEGEND_SATURATED;
}
if (str != STR_NULL) {
DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FontSize::Small)), str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER, false, FontSize::Small);
DrawString(br.left, br.right, CentreBounds(br.top, br.bottom, GetCharacterHeight(FontSize::Small)), str, ExtendedTextColour{GetContrastColour(colour), ExtendedTextColourFlag::Forced}, SA_HOR_CENTER, false, FontSize::Small);
}
}
if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
+1 -1
View File
@@ -272,7 +272,7 @@ struct MainWindow : Window
}
int text_y = this->height - GetCharacterHeight(FontSize::Normal) * 2;
DrawString(0, this->width - 1, text_y, STR_INTRO_VERSION, TC_WHITE, SA_CENTER);
DrawString(0, this->width - 1, text_y, STR_INTRO_VERSION, TextColour::White, SA_CENTER);
}
}
+9 -9
View File
@@ -75,12 +75,12 @@ public:
Rect ir = r.Shrink(WidgetDimensions::scaled.frametext);
for (size_t i = 0; i < this->landinfo_data.size(); i++) {
DrawString(ir, this->landinfo_data[i], i == 0 ? TC_LIGHT_BLUE : TC_FROMSTRING, SA_HOR_CENTER);
DrawString(ir, this->landinfo_data[i], i == 0 ? TextColour::LightBlue : TextColour::FromString, SA_HOR_CENTER);
ir.top += GetCharacterHeight(FontSize::Normal) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal);
}
if (!this->cargo_acceptance.empty()) {
DrawStringMultiLine(ir, GetString(STR_JUST_RAW_STRING, this->cargo_acceptance), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(ir, GetString(STR_JUST_RAW_STRING, this->cargo_acceptance), TextColour::FromString, SA_CENTER);
}
}
@@ -454,7 +454,7 @@ struct AboutWindow : public Window {
/* Show all scrolling _credits */
for (const auto &str : _credits) {
if (y >= r.top + 7 && y < r.bottom - this->line_height) {
DrawString(r.left, r.right, y, str, TC_BLACK, SA_LEFT | SA_FORCE);
DrawString(r.left, r.right, y, str, TextColour::Black, SA_LEFT | SA_FORCE);
}
y += this->line_height;
}
@@ -654,7 +654,7 @@ struct TooltipsWindow : public Window
GfxFillRect(r, PC_BLACK);
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_LIGHT_YELLOW);
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.fullbevel), this->text.GetDecodedString(), TC_BLACK, SA_CENTER);
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.fullbevel), this->text.GetDecodedString(), TextColour::Black, SA_CENTER);
}
void OnMouseLoop() override
@@ -769,14 +769,14 @@ void QueryString::DrawEditBox(const Window *w, WidgetID wid) const
/* If we have a marked area, draw a background highlight. */
if (tb->marklength != 0) GfxFillRect(fr.left + tb->markxoffs, fr.top, fr.left + tb->markxoffs + tb->marklength - 1, fr.bottom, PC_GREY);
DrawString(fr.left, fr.right, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), tb->GetText(), TC_YELLOW);
DrawString(fr.left, fr.right, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), tb->GetText(), TextColour::Yellow);
bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid);
if (focussed && tb->caret) {
int caret_width = GetCaretWidth();
if (rtl) {
DrawString(fr.right - tb->pixels + tb->caretxoffs - caret_width, fr.right - tb->pixels + tb->caretxoffs, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), "_", TC_WHITE);
DrawString(fr.right - tb->pixels + tb->caretxoffs - caret_width, fr.right - tb->pixels + tb->caretxoffs, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), "_", TextColour::White);
} else {
DrawString(fr.left + tb->caretxoffs, fr.left + tb->caretxoffs + caret_width, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), "_", TC_WHITE);
DrawString(fr.left + tb->caretxoffs, fr.left + tb->caretxoffs + caret_width, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), "_", TextColour::White);
}
}
}
@@ -1029,7 +1029,7 @@ public:
static constexpr std::initializer_list<NWidgetPart> _nested_query_string_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::Grey),
NWidget(WWT_CAPTION, Colours::Grey, WID_QS_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::Grey, WID_QS_CAPTION), SetTextStyle(TextColour::White),
EndContainer(),
NWidget(WWT_PANEL, Colours::Grey),
NWidget(WWT_EDITBOX, Colours::Grey, WID_QS_TEXT), SetMinimalSize(256, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
@@ -1134,7 +1134,7 @@ struct QueryWindow : public Window {
{
if (widget != WID_Q_TEXT) return;
DrawStringMultiLine(r, this->message.GetDecodedString(), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, this->message.GetDecodedString(), TextColour::FromString, SA_CENTER);
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
+7 -7
View File
@@ -759,9 +759,9 @@ struct MusicWindow : public Window {
}
Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
if (_music.IsPlaying()) {
DrawString(ir, GetString(STR_MUSIC_TRACK_DIGIT, _music.GetCurrentSong().tracknr, 2), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(ir, GetString(STR_MUSIC_TRACK_DIGIT, _music.GetCurrentSong().tracknr, 2), TextColour::FromString, SA_HOR_CENTER);
} else {
DrawString(ir, STR_MUSIC_TRACK_NONE, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(ir, STR_MUSIC_TRACK_NONE, TextColour::FromString, SA_HOR_CENTER);
}
break;
}
@@ -772,22 +772,22 @@ struct MusicWindow : public Window {
MusicSystem::PlaylistEntry entry(_music.GetCurrentSong());
if (BaseMusic::GetUsedSet()->num_available == 0) {
DrawString(ir, STR_MUSIC_TITLE_NOMUSIC, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(ir, STR_MUSIC_TITLE_NOMUSIC, TextColour::FromString, SA_HOR_CENTER);
} else if (_music.IsPlaying()) {
DrawString(ir, GetString(STR_MUSIC_TITLE_NAME, entry.songname), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(ir, GetString(STR_MUSIC_TITLE_NAME, entry.songname), TextColour::FromString, SA_HOR_CENTER);
} else {
DrawString(ir, STR_MUSIC_TITLE_NONE, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(ir, STR_MUSIC_TITLE_NONE, TextColour::FromString, SA_HOR_CENTER);
}
break;
}
case WID_M_MUSIC_VOL:
DrawSliderWidget(r, Colours::Grey, Colours::Grey, TC_BLACK, 0, INT8_MAX, 0, _settings_client.music.music_vol, nullptr);
DrawSliderWidget(r, Colours::Grey, Colours::Grey, TextColour::Black, 0, INT8_MAX, 0, _settings_client.music.music_vol, nullptr);
break;
case WID_M_EFFECT_VOL:
DrawSliderWidget(r, Colours::Grey, Colours::Grey, TC_BLACK, 0, INT8_MAX, 0, _settings_client.music.effect_vol, nullptr);
DrawSliderWidget(r, Colours::Grey, Colours::Grey, TextColour::Black, 0, INT8_MAX, 0, _settings_client.music.effect_vol, nullptr);
break;
}
}
+1 -1
View File
@@ -241,7 +241,7 @@ uint8_t NetworkSpectatorCount()
* @param str Arbitrary extra string, depending on the action. For example a complete message or company name.
* @param data Arbitrary extra data, depending on the action. For example a client's ID or an amount of money that was given.
*/
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, std::string_view name, std::string_view str, StringParameter &&data)
void NetworkTextMessage(NetworkAction action, ExtendedTextColour colour, bool self_send, std::string_view name, std::string_view str, StringParameter &&data)
{
std::string message;
StringBuilder builder(message);
+4 -4
View File
@@ -814,12 +814,12 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::ReceiveAdminExternalChat(Pack
if (this->status <= ADMIN_STATUS_AUTHENTICATE) return this->SendError(NetworkErrorCode::NotExpected);
std::string source = p.Recv_string(NETWORK_CHAT_LENGTH);
TextColour colour = (TextColour)p.Recv_uint16();
ExtendedTextColour colour = ExtendedTextColour::FromNetwork(p.Recv_uint16());
std::string user = p.Recv_string(NETWORK_CHAT_LENGTH);
std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
if (!IsValidConsoleColour(colour)) {
Debug(net, 1, "[admin] Not supported chat colour {} ({}, {}, {}) from '{}' ({}).", (uint16_t)colour, source, user, msg, this->admin_name, this->admin_version);
Debug(net, 1, "[admin] Not supported chat colour {} ({}, {}, {}) from '{}' ({}).", colour.ToNetwork(), source, user, msg, this->admin_name, this->admin_version);
return this->SendError(NetworkErrorCode::IllegalPacket);
}
@@ -1050,9 +1050,9 @@ void NetworkAdminChat(NetworkAction action, NetworkChatDestinationType desttype,
* @param colour_code The colour of the string.
* @param string The string to show.
*/
void NetworkServerSendAdminRcon(AdminID admin_index, TextColour colour_code, std::string_view string)
void NetworkServerSendAdminRcon(AdminID admin_index, ExtendedTextColour colour_code, std::string_view string)
{
ServerNetworkAdminSocketHandler::Get(admin_index)->SendRcon(colour_code, string);
ServerNetworkAdminSocketHandler::Get(admin_index)->SendRcon(colour_code.ToNetwork(), string);
}
/**
+1 -1
View File
@@ -122,7 +122,7 @@ void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bc
void NetworkAdminChat(NetworkAction action, NetworkChatDestinationType desttype, ClientID client_id, std::string_view msg, int64_t data = 0, bool from_admin = false);
void NetworkAdminUpdate(AdminUpdateFrequency freq);
void NetworkServerSendAdminRcon(AdminID admin_index, TextColour colour_code, std::string_view string);
void NetworkServerSendAdminRcon(AdminID admin_index, ExtendedTextColour colour_code, std::string_view string);
void NetworkAdminConsole(std::string_view origin, std::string_view string);
void NetworkAdminGameScript(std::string_view json);
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket &cp);
+3 -7
View File
@@ -36,7 +36,7 @@ static const uint NETWORK_CHAT_LINE_SPACING = 3;
/** Container for a message. */
struct ChatMessage {
std::string message; ///< The action message.
TextColour colour; ///< The colour of the message.
ExtendedTextColour colour; ///< The colour of the message.
std::chrono::steady_clock::time_point remove_time; ///< The time to remove the message.
};
@@ -82,17 +82,13 @@ static inline bool HaveChatMessages(bool show_all)
* @param duration The duration of the chat message in seconds
* @param message message itself
*/
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
void CDECL NetworkAddChatMessage(ExtendedTextColour colour, uint duration, const std::string &message)
{
if (_chatmsg_list.size() == MAX_CHAT_MESSAGES) {
_chatmsg_list.pop_back();
}
ChatMessage *cmsg = &_chatmsg_list.emplace_front();
cmsg->message = message;
cmsg->colour = colour;
cmsg->remove_time = std::chrono::steady_clock::now() + std::chrono::seconds(duration);
_chatmsg_list.emplace_front(message, colour, std::chrono::steady_clock::now() + std::chrono::seconds(duration));
_chatmessage_dirty_time = std::chrono::steady_clock::now();
_chatmessage_dirty = true;
}
+4 -4
View File
@@ -1034,7 +1034,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::ReceiveServerExternalChat(Pack
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
std::string source = p.Recv_string(NETWORK_CHAT_LENGTH);
TextColour colour = (TextColour)p.Recv_uint16();
ExtendedTextColour colour = ExtendedTextColour::FromNetwork(p.Recv_uint16());
std::string user = p.Recv_string(NETWORK_CHAT_LENGTH);
std::string msg = p.Recv_string(NETWORK_CHAT_LENGTH);
@@ -1146,12 +1146,12 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::ReceiveServerRemoteConsoleComm
Debug(net, 9, "Client::ReceiveServerRemoteConsoleCommand()");
TextColour colour_code = (TextColour)p.Recv_uint16();
if (!IsValidConsoleColour(colour_code)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
ExtendedTextColour colour = ExtendedTextColour::FromNetwork(p.Recv_uint16());
if (!IsValidConsoleColour(colour)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
std::string rcon_out = p.Recv_string(NETWORK_RCONCOMMAND_LENGTH);
IConsolePrint(colour_code, rcon_out);
IConsolePrint(colour, rcon_out);
return NETWORK_RECV_STATUS_OKAY;
}
+9 -9
View File
@@ -161,19 +161,19 @@ void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, WidgetID
DrawFrameRect(ir.WithWidth((uint64_t)ir.Width() * this->downloaded_bytes / this->total_bytes, _current_text_dir == TD_RTL), Colours::Mauve, {});
DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)),
GetString(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, this->downloaded_bytes, this->total_bytes, this->downloaded_bytes * 100LL / this->total_bytes),
TC_FROMSTRING, SA_HOR_CENTER);
TextColour::FromString, SA_HOR_CENTER);
break;
}
case WID_NCDS_PROGRESS_TEXT:
if (this->downloaded_bytes == this->total_bytes) {
DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_COMPLETE, TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_COMPLETE, TextColour::FromString, SA_CENTER);
} else if (!this->name.empty()) {
DrawStringMultiLine(r,
GetString(STR_CONTENT_DOWNLOAD_FILE, this->name, this->downloaded_files, this->total_files),
TC_FROMSTRING, SA_CENTER);
TextColour::FromString, SA_CENTER);
} else {
DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_INITIALISE, TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_INITIALISE, TextColour::FromString, SA_CENTER);
}
break;
}
@@ -694,12 +694,12 @@ public:
DrawSpriteIgnorePadding(sprite, pal, checkbox.WithY(mr), SA_CENTER);
StringID str = GetContentTypeString(ci->type);
DrawString(type.left, type.right, mr.top + text_y_offset, str, TC_BLACK, SA_HOR_CENTER);
DrawString(type.left, type.right, mr.top + text_y_offset, str, TextColour::Black, SA_HOR_CENTER);
int x = DrawString(name.left, name.right, mr.top + version_y_offset, ci->version, TC_BLACK, SA_RIGHT, false, FontSize::Small);
int x = DrawString(name.left, name.right, mr.top + version_y_offset, ci->version, TextColour::Black, SA_RIGHT, false, FontSize::Small);
x += rtl ? WidgetDimensions::scaled.hsep_wide : -WidgetDimensions::scaled.hsep_wide;
DrawString(rtl ? x : name.left, rtl ? name.right : x, mr.top + text_y_offset, ci->name, TC_BLACK);
DrawString(rtl ? x : name.left, rtl ? name.right : x, mr.top + text_y_offset, ci->name, TextColour::Black);
mr = mr.Translate(0, step_height);
}
}
@@ -719,7 +719,7 @@ public:
/* Create the nice darker rectangle at the details top */
GfxFillRect(r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.bevel.left, WidgetDimensions::scaled.bevel.top, WidgetDimensions::scaled.bevel.right, 0), GetColourGradient(Colours::LightBlue, Shade::Normal));
DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TextColour::FromString, SA_HOR_CENTER);
/* Draw the total download size */
DrawString(tr.left, tr.right, tr.bottom - GetCharacterHeight(FontSize::Normal) + 1, GetString(STR_CONTENT_TOTAL_DOWNLOAD_SIZE, this->filesize_sum));
@@ -727,7 +727,7 @@ public:
if (this->selected == nullptr) return;
/* And fill the rest of the details when there's information to place there */
DrawStringMultiLine(hr.left, hr.right, hr.top + GetCharacterHeight(FontSize::Normal), hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + to_underlying(this->selected->state), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(hr.left, hr.right, hr.top + GetCharacterHeight(FontSize::Normal), hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + to_underlying(this->selected->state), TextColour::FromString, SA_CENTER);
/* Also show the total download size, so keep some space from the bottom */
tr.bottom -= GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_wide;
+3 -3
View File
@@ -75,9 +75,9 @@ bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_na
bool NetworkCanJoinCompany(CompanyID company_id);
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, std::string_view string);
void NetworkServerSendRcon(ClientID client_id, ExtendedTextColour colour_code, std::string_view string);
void NetworkServerSendChat(NetworkAction action, NetworkChatDestinationType type, int dest, std::string_view msg, ClientID from_id, int64_t data = 0, bool from_admin = false);
void NetworkServerSendExternalChat(std::string_view source, TextColour colour, std::string_view user, std::string_view msg);
void NetworkServerSendExternalChat(std::string_view source, ExtendedTextColour colour, std::string_view user, std::string_view msg);
void NetworkServerKickClient(ClientID client_id, std::string_view reason);
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, std::string_view reason);
@@ -85,7 +85,7 @@ uint NetworkServerKickOrBanIP(std::string_view ip, bool ban, std::string_view re
void NetworkInitChatMessage();
void NetworkReInitChatBoxSize();
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message);
void CDECL NetworkAddChatMessage(ExtendedTextColour colour, uint duration, const std::string &message);
void NetworkUndrawChatMessage();
void NetworkAfterNewGRFScan();
+22 -22
View File
@@ -375,7 +375,7 @@ protected:
info = info.Shrink(WidgetDimensions::scaled.framerect);
name = name.Shrink(WidgetDimensions::scaled.framerect);
DrawString(name.left, name.right, y + text_y_offset, cur_item->info.server_name, TC_BLACK);
DrawString(name.left, name.right, y + text_y_offset, cur_item->info.server_name, TextColour::Black);
/* only draw details if the server is online */
if (cur_item->status == NGLS_ONLINE) {
@@ -383,7 +383,7 @@ protected:
Rect clients = nwid->GetCurrentRect();
DrawString(clients.left, clients.right, y + text_y_offset,
GetString(STR_NETWORK_SERVER_LIST_GENERAL_ONLINE, cur_item->info.clients_on, cur_item->info.clients_max, cur_item->info.companies_on, cur_item->info.companies_max),
TC_FROMSTRING, SA_HOR_CENTER);
TextColour::FromString, SA_HOR_CENTER);
}
if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_MAPSIZE); nwid->current_x != 0) {
@@ -391,7 +391,7 @@ protected:
Rect mapsize = nwid->GetCurrentRect();
DrawString(mapsize.left, mapsize.right, y + text_y_offset,
GetString(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT, cur_item->info.map_width, cur_item->info.map_height),
TC_FROMSTRING, SA_HOR_CENTER);
TextColour::FromString, SA_HOR_CENTER);
}
if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_DATE); nwid->current_x != 0) {
@@ -400,7 +400,7 @@ protected:
TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(cur_item->info.calendar_date);
DrawString(date.left, date.right, y + text_y_offset,
GetString(STR_JUST_INT, ymd.year),
TC_BLACK, SA_HOR_CENTER);
TextColour::Black, SA_HOR_CENTER);
}
if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_YEARS); nwid->current_x != 0) {
@@ -409,7 +409,7 @@ protected:
const auto play_time = cur_item->info.ticks_playing / Ticks::TICKS_PER_SECOND;
DrawString(years.left, years.right, y + text_y_offset,
GetString(STR_NETWORK_SERVER_LIST_PLAY_TIME_SHORT, play_time / 60 / 60, (play_time / 60) % 60),
TC_BLACK, SA_HOR_CENTER);
TextColour::Black, SA_HOR_CENTER);
}
/* Set top and bottom of info rect to current row. */
@@ -648,12 +648,12 @@ public:
/* Draw the right menu */
/* Create the nice darker rectangle at the details top */
GfxFillRect(r.WithHeight(header_height).Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(Colours::LightBlue, Shade::Normal));
hr.top = DrawStringMultiLine(hr, header_msg, TC_FROMSTRING, SA_HOR_CENTER);
hr.top = DrawStringMultiLine(hr, header_msg, TextColour::FromString, SA_HOR_CENTER);
if (sel == nullptr) return;
hr.top = DrawStringMultiLine(hr, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
hr.top = DrawStringMultiLine(hr, sel->info.server_name, TextColour::Orange, SA_HOR_CENTER); // game name
if (sel->status != NGLS_ONLINE) {
tr.top = DrawStringMultiLine(tr, header_msg, TC_FROMSTRING, SA_HOR_CENTER);
tr.top = DrawStringMultiLine(tr, header_msg, TextColour::FromString, SA_HOR_CENTER);
} else { // show game info
tr.top = DrawStringMultiLine(tr, GetString(STR_NETWORK_SERVER_LIST_CLIENTS, sel->info.clients_on, sel->info.clients_max, sel->info.companies_on, sel->info.companies_max));
@@ -680,12 +680,12 @@ public:
tr.top += WidgetDimensions::scaled.vsep_wide;
if (!sel->info.compatible) {
DrawStringMultiLine(tr, sel->info.version_compatible ? STR_NETWORK_SERVER_LIST_GRF_MISMATCH : STR_NETWORK_SERVER_LIST_VERSION_MISMATCH, TC_FROMSTRING, SA_HOR_CENTER); // server mismatch
DrawStringMultiLine(tr, sel->info.version_compatible ? STR_NETWORK_SERVER_LIST_GRF_MISMATCH : STR_NETWORK_SERVER_LIST_VERSION_MISMATCH, TextColour::FromString, SA_HOR_CENTER); // server mismatch
} else if (sel->info.clients_on == sel->info.clients_max) {
/* Show: server full, when clients_on == max_clients */
DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_SERVER_FULL, TC_FROMSTRING, SA_HOR_CENTER); // server full
DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_SERVER_FULL, TextColour::FromString, SA_HOR_CENTER); // server full
} else if (sel->info.use_password) {
DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_PASSWORD, TC_FROMSTRING, SA_HOR_CENTER); // password warning
DrawStringMultiLine(tr, STR_NETWORK_SERVER_LIST_PASSWORD, TextColour::FromString, SA_HOR_CENTER); // password warning
}
}
}
@@ -1028,7 +1028,7 @@ struct NetworkStartServerWindow : public Window {
switch (widget) {
case WID_NSS_SETPWD:
/* If password is set, draw red '*' next to 'Set password' button. */
if (!_settings_client.network.server_password.empty()) DrawString(r.right + WidgetDimensions::scaled.framerect.left, this->width - WidgetDimensions::scaled.framerect.right, r.top, "*", TC_RED);
if (!_settings_client.network.server_password.empty()) DrawString(r.right + WidgetDimensions::scaled.framerect.left, this->width - WidgetDimensions::scaled.framerect.right, r.top, "*", TextColour::Red);
}
}
@@ -1524,11 +1524,11 @@ public:
Rect tr = r.CentreToHeight(GetCharacterHeight(FontSize::Normal)).Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl);
if (this->company_id == COMPANY_SPECTATOR) {
DrawString(tr, STR_NETWORK_CLIENT_LIST_SPECTATORS, TC_SILVER);
DrawString(tr, STR_NETWORK_CLIENT_LIST_SPECTATORS, TextColour::Silver);
} else if (this->company_id == COMPANY_NEW_COMPANY) {
DrawString(tr, STR_NETWORK_CLIENT_LIST_NEW_COMPANY, TC_WHITE);
DrawString(tr, STR_NETWORK_CLIENT_LIST_NEW_COMPANY, TextColour::White);
} else {
DrawString(tr, GetString(STR_COMPANY_NAME, this->company_id, this->company_id), TC_SILVER);
DrawString(tr, GetString(STR_COMPANY_NAME, this->company_id, this->company_id), TextColour::Silver);
}
};
@@ -1568,7 +1568,7 @@ public:
tr = tr.Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl);
}
DrawString(tr, GetString(STR_JUST_RAW_STRING, ci->client_name), TC_BLACK);
DrawString(tr, GetString(STR_JUST_RAW_STRING, ci->client_name), TextColour::Black);
}
std::optional<EncodedString> GetTooltip(Rect r, const Point &pt) const override
@@ -2124,21 +2124,21 @@ struct NetworkJoinStatusWindow : Window {
break;
}
DrawFrameRect(ir.WithWidth(ir.Width() * progress / 100, _current_text_dir == TD_RTL), Colours::Mauve, {});
DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), STR_NETWORK_CONNECTING_1 + to_underlying(_network_join_status), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), STR_NETWORK_CONNECTING_1 + to_underlying(_network_join_status), TextColour::FromString, SA_HOR_CENTER);
break;
}
case WID_NJS_PROGRESS_TEXT:
switch (_network_join_status) {
case NetworkJoinStatus::Waiting:
DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_WAITING, _network_join_waiting), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_WAITING, _network_join_waiting), TextColour::FromString, SA_CENTER);
break;
case NetworkJoinStatus::Downloading:
if (_network_join_bytes_total == 0) {
DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_DOWNLOADING_1, _network_join_bytes), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_DOWNLOADING_1, _network_join_bytes), TextColour::FromString, SA_CENTER);
} else {
DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_DOWNLOADING_2, _network_join_bytes, _network_join_bytes_total), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, GetString(STR_NETWORK_CONNECTING_DOWNLOADING_2, _network_join_bytes, _network_join_bytes_total), TextColour::FromString, SA_CENTER);
}
break;
@@ -2276,7 +2276,7 @@ struct NetworkAskRelayWindow : public Window {
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget == WID_NAR_TEXT) {
DrawStringMultiLine(r, GetString(STR_NETWORK_ASK_RELAY_TEXT, this->server_connection_string, this->relay_connection_string), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, GetString(STR_NETWORK_ASK_RELAY_TEXT, this->server_connection_string, this->relay_connection_string), TextColour::FromString, SA_CENTER);
}
}
@@ -2376,7 +2376,7 @@ struct NetworkAskSurveyWindow : public Window {
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget == WID_NAS_TEXT) {
DrawStringMultiLine(r, STR_NETWORK_ASK_SURVEY_TEXT, TC_BLACK, SA_CENTER);
DrawStringMultiLine(r, STR_NETWORK_ASK_SURVEY_TEXT, TextColour::Black, SA_CENTER);
}
}
+1 -1
View File
@@ -109,7 +109,7 @@ void NetworkSyncCommandQueue(NetworkClientSocket *cs);
void NetworkReplaceCommandClientId(CommandPacket &cp, ClientID client_id);
void ShowNetworkError(StringID error_string);
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, std::string_view name, std::string_view str = {}, StringParameter &&data = {});
void NetworkTextMessage(NetworkAction action, ExtendedTextColour colour, bool self_send, std::string_view name, std::string_view str = {}, StringParameter &&data = {});
uint NetworkCalculateLag(const NetworkClientSocket *cs);
StringID GetNetworkErrorMsg(NetworkErrorCode err);
bool NetworkMakeClientNameUnique(std::string &new_name);
+5 -5
View File
@@ -741,7 +741,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action,
* @param msg The actual message.
* @return The new state the network.
*/
NetworkRecvStatus ServerNetworkGameSocketHandler::SendExternalChat(std::string_view source, TextColour colour, std::string_view user, std::string_view msg)
NetworkRecvStatus ServerNetworkGameSocketHandler::SendExternalChat(std::string_view source, ExtendedTextColour colour, std::string_view user, std::string_view msg)
{
Debug(net, 9, "client[{}] SendExternalChat(): source={}", this->client_id, source);
@@ -750,7 +750,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendExternalChat(std::string_v
auto p = std::make_unique<Packet>(this, PacketGameType::ServerExternalChat);
p->Send_string(source);
p->Send_uint16(colour);
p->Send_uint16(colour.ToNetwork());
p->Send_string(user);
p->Send_string(msg);
@@ -1422,7 +1422,7 @@ void NetworkServerSendChat(NetworkAction action, NetworkChatDestinationType dest
* @param user Name of the user who sent the message.
* @param msg The actual message.
*/
void NetworkServerSendExternalChat(std::string_view source, TextColour colour, std::string_view user, std::string_view msg)
void NetworkServerSendExternalChat(std::string_view source, ExtendedTextColour colour, std::string_view user, std::string_view msg)
{
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
if (cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) cs->SendExternalChat(source, colour, user, msg);
@@ -2076,9 +2076,9 @@ void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
* @param colour_code The colour of the text.
* @param string The actual reply.
*/
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, std::string_view string)
void NetworkServerSendRcon(ClientID client_id, ExtendedTextColour colour_code, std::string_view string)
{
NetworkClientSocket::GetByClientID(client_id)->SendRConResult(colour_code, string);
NetworkClientSocket::GetByClientID(client_id)->SendRConResult(colour_code.ToNetwork(), string);
}
/**
+1 -1
View File
@@ -95,7 +95,7 @@ public:
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);
NetworkRecvStatus SendError(NetworkErrorCode error, std::string_view reason = {});
NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, std::string_view msg, int64_t data);
NetworkRecvStatus SendExternalChat(std::string_view source, TextColour colour, std::string_view user, std::string_view msg);
NetworkRecvStatus SendExternalChat(std::string_view source, ExtendedTextColour colour, std::string_view user, std::string_view msg);
NetworkRecvStatus SendJoin(ClientID client_id);
NetworkRecvStatus SendFrame();
NetworkRecvStatus SendSync();
+1 -1
View File
@@ -153,7 +153,7 @@ int DrawBadgeNameList(Rect r, std::span<const BadgeID> badges, GrfSpecFeature)
if (s.empty()) continue;
r.top = DrawStringMultiLine(r, GetString(STR_BADGE_NAME_LIST, class_badge->name, std::move(s)), TC_BLACK);
r.top = DrawStringMultiLine(r, GetString(STR_BADGE_NAME_LIST, class_badge->name, std::move(s)), TextColour::Black);
}
return r.top;
+3 -3
View File
@@ -393,7 +393,7 @@ struct NewGRFInspectWindow : Window {
offset -= this->vscroll->GetPosition();
if (offset < 0 || offset >= this->vscroll->GetCapacity()) return;
::DrawString(r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0), string, TC_BLACK);
::DrawString(r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0), string, TextColour::Black);
}
/**
@@ -942,9 +942,9 @@ struct SpriteAlignerWindow : Window {
for (auto it = first; it != last; ++it) {
const SpriteFile *file = GetOriginFile(*it);
if (file == nullptr) {
DrawString(ir, GetString(STR_JUST_COMMA, *it), *it == this->current_sprite ? TC_WHITE : (TC_GREY | TC_NO_SHADE), SA_RIGHT | SA_FORCE);
DrawString(ir, GetString(STR_JUST_COMMA, *it), *it == this->current_sprite ? TextColour::White : ExtendedTextColour{TextColour::Grey, ExtendedTextColourFlag::NoShade}, SA_RIGHT | SA_FORCE);
} else {
DrawString(ir, GetString(STR_SPRITE_ALIGNER_SPRITE, file->GetSimplifiedFilename(), GetSpriteLocalID(*it)), *it == this->current_sprite ? TC_WHITE : TC_BLACK);
DrawString(ir, GetString(STR_SPRITE_ALIGNER_SPRITE, file->GetSimplifiedFilename(), GetSpriteLocalID(*it)), *it == this->current_sprite ? TextColour::White : TextColour::Black);
}
ir.top += step_size;
}
+10 -10
View File
@@ -133,7 +133,7 @@ static void ShowNewGRFInfo(const GRFConfig &c, const Rect &r, bool show_params)
/* Draw GRF info if it exists */
if (auto desc = c.GetDescription(); desc.has_value() && !desc->empty()) {
tr.top = DrawStringMultiLine(tr, GetString(STR_JUST_RAW_STRING, std::move(*desc)), TC_BLACK);
tr.top = DrawStringMultiLine(tr, GetString(STR_JUST_RAW_STRING, std::move(*desc)), TextColour::Black);
} else {
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NO_INFO);
}
@@ -286,7 +286,7 @@ struct NewGRFParametersWindow : public Window {
const GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
auto desc = GetGRFStringFromGRFText(par_info.desc);
if (!desc.has_value()) return;
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect), *desc, TC_BLACK);
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect), *desc, TextColour::Black);
return;
} else if (widget != WID_NP_BACKGROUND) {
return;
@@ -314,7 +314,7 @@ struct NewGRFParametersWindow : public Window {
}
}
DrawString(tr.left, tr.right, ir.top + text_y_offset, this->GetSettingString(par_info, i, current_value), selected ? TC_WHITE : TC_LIGHT_BLUE);
DrawString(tr.left, tr.right, ir.top + text_y_offset, this->GetSettingString(par_info, i, current_value), selected ? TextColour::White : TextColour::LightBlue);
ir.top += this->line_height;
}
}
@@ -873,7 +873,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
DrawSprite(SPR_SQUARE, pal, square_left, tr.top + square_offset_y);
if (!c->errors.empty()) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, tr.top + warning_offset_y);
uint txtoffset = c->errors.empty() ? 0 : warning.width;
DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), tr.top + offset_y, std::move(text), h ? TC_WHITE : TC_ORANGE);
DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), tr.top + offset_y, std::move(text), h ? TextColour::White : TextColour::Orange);
tr.top += step_height;
}
i++;
@@ -899,7 +899,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
std::string text = c->GetName();
if (h) GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
DrawString(tr.left, tr.right, tr.top + offset_y, std::move(text), h ? TC_WHITE : TC_SILVER);
DrawString(tr.left, tr.right, tr.top + offset_y, std::move(text), h ? TextColour::White : TextColour::Silver);
tr.top += step_height;
}
break;
@@ -908,7 +908,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
case WID_NS_NEWGRF_INFO_TITLE: {
/* Create the nice darker rectangle at the details top. */
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(Colours::Mauve, Shade::Normal));
DrawString(r.left, r.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FontSize::Normal)), STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left, r.right, CentreBounds(r.top, r.bottom, GetCharacterHeight(FontSize::Normal)), STR_NEWGRF_SETTINGS_INFO_TITLE, TextColour::FromString, SA_HOR_CENTER);
break;
}
@@ -2074,7 +2074,7 @@ struct SavePresetWindow : public Window {
int row = static_cast<int>(std::distance(std::begin(this->presets), it));
if (row == this->selected) GfxFillRect(br.left, tr.top, br.right, tr.top + step_height - 1, PC_DARK_BLUE);
DrawString(tr.left, tr.right, tr.top + offset_y, *it, (row == this->selected) ? TC_WHITE : TC_SILVER);
DrawString(tr.left, tr.right, tr.top + offset_y, *it, (row == this->selected) ? TextColour::White : TextColour::Silver);
tr.top += step_height;
}
break;
@@ -2185,14 +2185,14 @@ struct ScanProgressWindow : public Window {
Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
uint percent = scanned * 100 / std::max(1U, _settings_client.gui.last_newgrf_count);
DrawFrameRect(ir.WithWidth(ir.Width() * percent / 100, _current_text_dir == TD_RTL), Colours::Mauve, {});
DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, percent), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)), GetString(STR_GENERATION_PROGRESS, percent), TextColour::FromString, SA_HOR_CENTER);
break;
}
case WID_SP_PROGRESS_TEXT:
DrawString(r.left, r.right, r.top, GetString(STR_NEWGRF_SCAN_STATUS, this->scanned, _settings_client.gui.last_newgrf_count), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left, r.right, r.top, GetString(STR_NEWGRF_SCAN_STATUS, this->scanned, _settings_client.gui.last_newgrf_count), TextColour::FromString, SA_HOR_CENTER);
DrawString(r.left, r.right, r.top + GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal, this->last_name, TC_BLACK, SA_HOR_CENTER);
DrawString(r.left, r.right, r.top + GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal, this->last_name, TextColour::Black, SA_HOR_CENTER);
break;
}
}
+14 -14
View File
@@ -111,7 +111,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_normal_news_widgets
NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
NWidget(WWT_CLOSEBOX, Colours::White, WID_N_CLOSEBOX),
NWidget(WWT_LABEL, Colours::Invalid, WID_N_DATE),
SetTextStyle(TC_BLACK, FontSize::Small),
SetTextStyle(TextColour::Black, FontSize::Small),
SetAlignment(SA_RIGHT | SA_TOP),
EndContainer(),
EndContainer(),
@@ -120,7 +120,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_normal_news_widgets
SetMinimalTextLines(8, 0, FontSize::Large),
SetMinimalSize(400, 0),
SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
SetTextStyle(TC_BLACK, FontSize::Large),
SetTextStyle(TextColour::Black, FontSize::Large),
EndContainer(),
EndContainer(),
EndContainer(),
@@ -152,7 +152,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_vehicle_news_widgets
SetMinimalSize(400, 0),
SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
SetStringTip(STR_EMPTY),
SetTextStyle(TC_BLACK, FontSize::Large),
SetTextStyle(TextColour::Black, FontSize::Large),
EndContainer(),
NWidget(WWT_PANEL, Colours::White, WID_N_VEH_BKGND), SetPadding(WidgetDimensions::unscaled.fullbevel),
NWidget(NWID_VERTICAL),
@@ -200,7 +200,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_company_news_widgets
SetMinimalTextLines(1, 0, FontSize::Large),
SetMinimalSize(400, 0),
SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_normal),
SetTextStyle(TC_BLACK, FontSize::Large),
SetTextStyle(TextColour::Black, FontSize::Large),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), SetPadding(2),
@@ -215,7 +215,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_company_news_widgets
SetFill(1, 1),
SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_wide),
SetMinimalSize(300, 0),
SetTextStyle(TC_BLACK, FontSize::Large),
SetTextStyle(TextColour::Black, FontSize::Large),
EndContainer(),
EndContainer(),
EndContainer(),
@@ -239,7 +239,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_thin_news_widgets =
NWidget(NWID_HORIZONTAL), SetPIPRatio(0, 1, 0),
NWidget(WWT_CLOSEBOX, Colours::White, WID_N_CLOSEBOX),
NWidget(WWT_LABEL, Colours::Invalid, WID_N_DATE),
SetTextStyle(TC_BLACK, FontSize::Small),
SetTextStyle(TextColour::Black, FontSize::Small),
SetAlignment(SA_RIGHT | SA_TOP),
EndContainer(),
EndContainer(),
@@ -248,7 +248,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_thin_news_widgets =
SetMinimalTextLines(3, 0, FontSize::Large),
SetMinimalSize(400, 0),
SetPadding(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.vsep_normal),
SetTextStyle(TC_BLACK, FontSize::Large),
SetTextStyle(TextColour::Black, FontSize::Large),
EndContainer(),
NWidget(NWID_VIEWPORT, Colours::Invalid, WID_N_VIEWPORT), SetMinimalSize(426, 70),
SetPadding(WidgetDimensions::unscaled.fullbevel),
@@ -290,7 +290,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_small_news_widgets =
NWidget(WWT_EMPTY, Colours::Invalid, WID_N_MESSAGE),
SetMinimalTextLines(2, 0),
SetMinimalSize(275, 0),
SetTextStyle(TC_WHITE, FontSize::Normal),
SetTextStyle(TextColour::White, FontSize::Normal),
EndContainer(),
EndContainer(),
};
@@ -515,7 +515,7 @@ struct NewsWindow : Window {
{
switch (widget) {
case WID_N_CAPTION:
DrawCaption(r, Colours::LightBlue, this->owner, TC_FROMSTRING, GetString(STR_NEWS_MESSAGE_CAPTION), SA_CENTER, FontSize::Normal);
DrawCaption(r, Colours::LightBlue, this->owner, TextColour::FromString, GetString(STR_NEWS_MESSAGE_CAPTION), SA_CENTER, FontSize::Normal);
break;
case WID_N_PANEL:
@@ -537,7 +537,7 @@ struct NewsWindow : Window {
}
case WID_N_MGR_NAME: {
const CompanyNewsInformation *cni = static_cast<const CompanyNewsInformation*>(this->ni->data.get());
DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, cni->president_name), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, GetString(STR_JUST_RAW_STRING, cni->president_name), TextColour::FromString, SA_CENTER);
break;
}
@@ -547,7 +547,7 @@ struct NewsWindow : Window {
case WID_N_VEH_NAME:
case WID_N_VEH_TITLE:
DrawStringMultiLine(r, this->GetNewVehicleMessageString(widget), TC_FROMSTRING, SA_CENTER);
DrawStringMultiLine(r, this->GetNewVehicleMessageString(widget), TextColour::FromString, SA_CENTER);
break;
case WID_N_VEH_SPR: {
@@ -560,7 +560,7 @@ struct NewsWindow : Window {
case WID_N_VEH_INFO: {
assert(std::holds_alternative<EngineID>(ni->ref1));
EngineID engine = std::get<EngineID>(this->ni->ref1);
DrawStringMultiLine(r, GetEngineInfoString(engine), TC_BLACK, SA_CENTER);
DrawStringMultiLine(r, GetEngineInfoString(engine), TextColour::Black, SA_CENTER);
break;
}
}
@@ -1257,9 +1257,9 @@ struct MessageHistoryWindow : Window {
auto [first, last] = this->vscroll->GetVisibleRangeIterators(_news);
for (auto ni = first; ni != last; ++ni) {
DrawString(date.left, date.right, y, GetString(STR_JUST_DATE_TINY, ni->date), TC_WHITE);
DrawString(date.left, date.right, y, GetString(STR_JUST_DATE_TINY, ni->date), TextColour::White);
DrawNewsString(news.left, news.right, y, TC_WHITE, *ni);
DrawNewsString(news.left, news.right, y, TextColour::White, *ni);
y += this->line_height;
}
}
+1 -1
View File
@@ -252,7 +252,7 @@ public:
str = GetGRFStringWithTextStack(spec->grf_prop.grffile, GRFSTR_MISC_GRF_TEXT + callback_res, regs100);
}
if (!str.empty()) {
tr.top = DrawStringMultiLine(tr, str, TC_ORANGE);
tr.top = DrawStringMultiLine(tr, str, TextColour::Orange);
}
}
}
+4 -4
View File
@@ -236,11 +236,11 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)GetCharacterHeight(FontSize::Normal) - (int)sprite_size.height) / 2);
}
TextColour colour = TC_BLACK;
ExtendedTextColour colour{TextColour::Black};
if (order->IsType(OT_IMPLICIT)) {
colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
colour = ExtendedTextColour{selected ? TextColour::Silver : TextColour::Grey, ExtendedTextColourFlag::NoShade};
} else if (selected) {
colour = TC_WHITE;
colour = TextColour::White;
}
DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, GetString(STR_ORDER_INDEX, order_index + 1), colour, SA_RIGHT | SA_FORCE);
@@ -1130,7 +1130,7 @@ public:
if (this->vscroll->IsVisible(i)) {
StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
DrawString(rtl ? ir.left : middle, rtl ? middle : ir.right, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
DrawString(rtl ? ir.left : middle, rtl ? middle : ir.right, y, str, (i == this->selected_order) ? TextColour::White : TextColour::Black);
}
}
+1 -1
View File
@@ -164,7 +164,7 @@ static const CTRunDelegateCallbacks _sprite_font_callback = {
}
CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, position - last), kCTFontAttributeName, font_handle);
CGColorRef colour = CGColorCreateGenericGray((uint8_t)font->colour / 255.0f, 1.0f); // We don't care about the real colours, just that they are different.
CGColorRef colour = CGColorCreateGenericGray(to_underlying(font->colour.colour) / 255.0f, 1.0f); // We don't care about the real colours, just that they are different.
CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, position - last), kCTForegroundColorAttributeName, colour);
CGColorRelease(colour);
+2 -2
View File
@@ -101,7 +101,7 @@ struct OskWindow : public Window {
if (widget < WID_OSK_LETTERS) return;
widget -= WID_OSK_LETTERS;
DrawCharCentered(_keyboard[this->shift][widget], r, TC_BLACK);
DrawCharCentered(_keyboard[this->shift][widget], r, TextColour::Black);
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
@@ -322,7 +322,7 @@ static std::unique_ptr<NWidgetBase> MakeSpacebarKeys()
static constexpr std::initializer_list<NWidgetPart> _nested_osk_widgets = {
NWidget(WWT_CAPTION, Colours::Grey, WID_OSK_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::Grey, WID_OSK_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_PANEL, Colours::Grey),
NWidget(WWT_EDITBOX, Colours::Grey, WID_OSK_TEXT), SetMinimalSize(252, 0), SetPadding(2, 2, 2, 2),
EndContainer(),
+3 -3
View File
@@ -360,8 +360,8 @@ void DoPaletteAnimations()
/**
* Determine a contrasty text colour for a coloured background.
* @param background Background colour.
* @param threshold Background colour brightness threshold below which the background is considered dark and TC_WHITE is returned, range: 0 - 255, default 128.
* @return TC_BLACK or TC_WHITE depending on what gives a better contrast.
* @param threshold Background colour brightness threshold below which the background is considered dark and TextColour::White is returned, range: 0 - 255, default 128.
* @return TextColour::Black or TextColour::White depending on what gives a better contrast.
*/
TextColour GetContrastColour(PixelColour background, uint8_t threshold)
{
@@ -370,7 +370,7 @@ TextColour GetContrastColour(PixelColour background, uint8_t threshold)
* 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 which defaults to 128 (50%) */
return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TextColour::White : TextColour::Black;
}
/**
+2 -2
View File
@@ -376,7 +376,7 @@ void PickerWindow::DrawWidget(const Rect &r, WidgetID widget) const
const int y_step = this->GetWidget<NWidgetResizeBase>(widget)->resize_y;
auto [first, last] = vscroll->GetVisibleRangeIterators(this->classes);
for (auto it = first; it != last; ++it) {
DrawString(ir, this->callbacks.GetClassName(*it), *it == selected ? TC_WHITE : TC_BLACK);
DrawString(ir, this->callbacks.GetClassName(*it), *it == selected ? TextColour::White : TextColour::Black);
ir.top += y_step;
}
break;
@@ -421,7 +421,7 @@ void PickerWindow::DrawWidget(const Rect &r, WidgetID widget) const
case WID_PW_TYPE_NAME: {
StringID str = this->callbacks.GetTypeName(this->callbacks.GetSelectedClass(), this->callbacks.GetSelectedType());
if (str != INVALID_STRING_ID) DrawString(r, str, TC_GOLD, SA_CENTER);
if (str != INVALID_STRING_ID) DrawString(r, str, TextColour::Gold, SA_CENTER);
break;
}
}
+2 -2
View File
@@ -904,7 +904,7 @@ struct BuildRailToolbarWindow : Window {
static constexpr std::initializer_list<NWidgetPart> _nested_build_rail_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::DarkGreen),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_RAT_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_RAT_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_STICKYBOX, Colours::DarkGreen),
EndContainer(),
NWidget(NWID_HORIZONTAL),
@@ -1729,7 +1729,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_signal_builder_widge
NWidget(WWT_IMGBTN, Colours::DarkGreen, WID_BS_CONVERT), SetSpriteTip(SPR_IMG_SIGNAL_CONVERT, STR_BUILD_SIGNAL_CONVERT_TOOLTIP), SetFill(0, 1),
NWidget(WWT_PANEL, Colours::DarkGreen), SetToolTip(STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP), SetFill(0, 1),
NWidget(NWID_VERTICAL), SetPadding(2), SetPIPRatio(1, 0, 1),
NWidget(WWT_LABEL, Colours::Invalid, WID_BS_DRAG_SIGNALS_DENSITY_LABEL), SetToolTip(STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP), SetTextStyle(TC_ORANGE), SetFill(1, 1),
NWidget(WWT_LABEL, Colours::Invalid, WID_BS_DRAG_SIGNALS_DENSITY_LABEL), SetToolTip(STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP), SetTextStyle(TextColour::Orange), SetFill(1, 1),
NWidget(NWID_HORIZONTAL), SetPIPRatio(1, 0, 1),
NWidget(WWT_PUSHARROWBTN, Colours::Grey, WID_BS_DRAG_SIGNALS_DENSITY_DECREASE), SetMinimalSize(9, 12), SetArrowWidgetTypeTip(ArrowWidgetType::Decrease, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_DECREASE_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, Colours::Grey, WID_BS_DRAG_SIGNALS_DENSITY_INCREASE), SetMinimalSize(9, 12), SetArrowWidgetTypeTip(ArrowWidgetType::Increase, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_INCREASE_TOOLTIP),
+4 -4
View File
@@ -958,7 +958,7 @@ struct BuildRoadToolbarWindow : Window {
static constexpr std::initializer_list<NWidgetPart> _nested_build_road_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::DarkGreen),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_ROT_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_STICKYBOX, Colours::DarkGreen),
EndContainer(),
NWidget(NWID_HORIZONTAL),
@@ -1006,7 +1006,7 @@ static WindowDesc _build_road_desc(
static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::DarkGreen),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_ROT_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_STICKYBOX, Colours::DarkGreen),
EndContainer(),
NWidget(NWID_HORIZONTAL),
@@ -1071,7 +1071,7 @@ Window *ShowBuildRoadToolbar(RoadType roadtype)
static constexpr std::initializer_list<NWidgetPart> _nested_build_road_scen_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::DarkGreen),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_ROT_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_STICKYBOX, Colours::DarkGreen),
EndContainer(),
NWidget(NWID_HORIZONTAL),
@@ -1111,7 +1111,7 @@ static WindowDesc _build_road_scen_desc(
static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_scen_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::DarkGreen),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::DarkGreen, WID_ROT_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_STICKYBOX, Colours::DarkGreen),
EndContainer(),
NWidget(NWID_HORIZONTAL),
+1 -1
View File
@@ -66,7 +66,7 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
}
}
DrawString(r.left, r.right, y, GetString(STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY, capacity), TC_BLUE);
DrawString(r.left, r.right, y, GetString(STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY, capacity), TextColour::Blue);
y += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal;
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
+1 -1
View File
@@ -47,7 +47,7 @@
if (ScriptGame::IsMultiplayer()) return;
if (number == NUMBER_ALL) return;
if (!IsOpen(window, number)) return;
if (colour != TC_INVALID && (::TextColour)colour >= ::TC_END) return;
if (colour != TC_INVALID && (::TextColour)colour >= ::TextColour::End) return;
number = Clamp<SQInteger>(number, 0, INT32_MAX);
+18 -18
View File
@@ -43,24 +43,24 @@ public:
*/
enum TextColour {
/* Note: these values represent part of the in-game TextColour enum */
TC_BLUE = ::TC_BLUE, ///< Blue colour.
TC_SILVER = ::TC_SILVER, ///< Silver colour.
TC_GOLD = ::TC_GOLD, ///< Gold colour.
TC_RED = ::TC_RED, ///< Red colour.
TC_PURPLE = ::TC_PURPLE, ///< Purple colour.
TC_LIGHT_BROWN = ::TC_LIGHT_BROWN, ///< Light brown colour.
TC_ORANGE = ::TC_ORANGE, ///< Orange colour.
TC_GREEN = ::TC_GREEN, ///< Green colour.
TC_YELLOW = ::TC_YELLOW, ///< Yellow colour.
TC_DARK_GREEN = ::TC_DARK_GREEN, ///< Dark green colour.
TC_CREAM = ::TC_CREAM, ///< Cream colour.
TC_BROWN = ::TC_BROWN, ///< Brown colour.
TC_WHITE = ::TC_WHITE, ///< White colour.
TC_LIGHT_BLUE = ::TC_LIGHT_BLUE, ///< Light blue colour.
TC_GREY = ::TC_GREY, ///< Grey colour.
TC_DARK_BLUE = ::TC_DARK_BLUE, ///< Dark blue colour.
TC_BLACK = ::TC_BLACK, ///< Black colour.
TC_INVALID = ::TC_INVALID, ///< Invalid colour.
TC_BLUE = to_underlying(::TextColour::Blue), ///< Blue colour.
TC_SILVER = to_underlying(::TextColour::Silver), ///< Silver colour.
TC_GOLD = to_underlying(::TextColour::Gold), ///< Gold colour.
TC_RED = to_underlying(::TextColour::Red), ///< Red colour.
TC_PURPLE = to_underlying(::TextColour::Purple), ///< Purple colour.
TC_LIGHT_BROWN = to_underlying(::TextColour::LightBrown), ///< Light brown colour.
TC_ORANGE = to_underlying(::TextColour::Orange), ///< Orange colour.
TC_GREEN = to_underlying(::TextColour::Green), ///< Green colour.
TC_YELLOW = to_underlying(::TextColour::Yellow), ///< Yellow colour.
TC_DARK_GREEN = to_underlying(::TextColour::DarkGreen), ///< Dark green colour.
TC_CREAM = to_underlying(::TextColour::Cream), ///< Cream colour.
TC_BROWN = to_underlying(::TextColour::Brown), ///< Brown colour.
TC_WHITE = to_underlying(::TextColour::White), ///< White colour.
TC_LIGHT_BLUE = to_underlying(::TextColour::LightBlue), ///< Light blue colour.
TC_GREY = to_underlying(::TextColour::Grey), ///< Grey colour.
TC_DARK_BLUE = to_underlying(::TextColour::DarkBlue), ///< Dark blue colour.
TC_BLACK = to_underlying(::TextColour::Black), ///< Black colour.
TC_INVALID = to_underlying(::TextColour::Invalid), ///< Invalid colour.
};
/**
+1 -1
View File
@@ -221,6 +221,6 @@ std::string ScriptConfigItem::GetString(int value) const
*/
TextColour ScriptConfigItem::GetColour() const
{
return this->description.empty() ? TC_ORANGE : TC_LIGHT_BLUE;
return this->description.empty() ? TextColour::Orange : TextColour::LightBlue;
}
+10 -10
View File
@@ -124,14 +124,14 @@ struct ScriptListWindow : public Window {
Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
/* First AI in the list is hardcoded to random */
if (this->vscroll->IsVisible(0)) {
DrawString(tr, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
DrawString(tr, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TextColour::White : TextColour::Orange);
tr.top += this->line_height;
}
int i = 0;
for (const auto &item : *this->info_list) {
i++;
if (this->vscroll->IsVisible(i)) {
DrawString(tr, this->show_all ? GetString(STR_AI_CONFIG_NAME_VERSION, item.second->GetName(), item.second->GetVersion()) : item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
DrawString(tr, this->show_all ? GetString(STR_AI_CONFIG_NAME_VERSION, item.second->GetName(), item.second->GetVersion()) : item.second->GetName(), (this->selected == i - 1) ? TextColour::White : TextColour::Orange);
tr.top += this->line_height;
}
}
@@ -155,7 +155,7 @@ struct ScriptListWindow : public Window {
DrawString(tr, GetString(STR_AI_LIST_URL, selected_info->GetURL()));
tr.top += GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal;
}
DrawStringMultiLine(tr, selected_info->GetDescription(), TC_WHITE);
DrawStringMultiLine(tr, selected_info->GetDescription(), TextColour::White);
}
break;
}
@@ -882,19 +882,19 @@ struct ScriptDebugWindow : public Window {
TextColour colour;
switch (line.type) {
case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK; break;
case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE; break;
case ScriptLogTypes::LOG_INFO: colour = TC_BLACK; break;
case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW; break;
case ScriptLogTypes::LOG_ERROR: colour = TC_RED; break;
default: colour = TC_BLACK; break;
case ScriptLogTypes::LOG_SQ_INFO: colour = TextColour::Black; break;
case ScriptLogTypes::LOG_SQ_ERROR: colour = TextColour::White; break;
case ScriptLogTypes::LOG_INFO: colour = TextColour::Black; break;
case ScriptLogTypes::LOG_WARNING: colour = TextColour::Yellow; break;
case ScriptLogTypes::LOG_ERROR: colour = TextColour::Red; break;
default: colour = TextColour::Black; break;
}
/* Check if the current line should be highlighted */
if (std::distance(std::begin(log), it) == this->highlight_row) {
fr.bottom = fr.top + this->resize.step_height - 1;
GfxFillRect(fr, PC_BLACK);
if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
if (colour == TextColour::Black) colour = TextColour::White; // Make black text readable by inverting it to white.
}
DrawString(fr, line.text, colour, SA_LEFT | SA_FORCE);
+2 -2
View File
@@ -282,7 +282,7 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
editable && value != (sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : min_val), editable && static_cast<uint32_t>(value) != max_val);
}
auto [param1, param2] = sd->GetValueParams(value);
DrawString(text_left, text_right, y + (BaseSettingEntry::line_height - GetCharacterHeight(FontSize::Normal)) / 2, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), highlight ? TC_WHITE : TC_LIGHT_BLUE);
DrawString(text_left, text_right, y + (BaseSettingEntry::line_height - GetCharacterHeight(FontSize::Normal)) / 2, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), highlight ? TextColour::White : TextColour::LightBlue);
}
/* == SettingsContainer methods == */
@@ -559,7 +559,7 @@ void SettingsPage::DrawSetting(GameSettings *, int left, int right, int y, bool)
{
bool rtl = _current_text_dir == TD_RTL;
DrawSprite((this->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? right - BaseSettingEntry::circle_size.width : left, y + (BaseSettingEntry::line_height - BaseSettingEntry::circle_size.height) / 2);
DrawString(rtl ? left : left + BaseSettingEntry::circle_size.width + WidgetDimensions::scaled.hsep_normal, rtl ? right - BaseSettingEntry::circle_size.width - WidgetDimensions::scaled.hsep_normal : right, y + (BaseSettingEntry::line_height - GetCharacterHeight(FontSize::Normal)) / 2, this->title, TC_ORANGE);
DrawString(rtl ? left : left + BaseSettingEntry::circle_size.width + WidgetDimensions::scaled.hsep_normal, rtl ? right - BaseSettingEntry::circle_size.width - WidgetDimensions::scaled.hsep_normal : right, y + (BaseSettingEntry::line_height - GetCharacterHeight(FontSize::Normal)) / 2, this->title, TextColour::Orange);
}
/**
+8 -8
View File
@@ -198,11 +198,11 @@ static constexpr Colours GAME_OPTIONS_BACKGROUND = Colours::Mauve;
/** Colour for buttons of game options. */
static constexpr Colours GAME_OPTIONS_BUTTON = Colours::Yellow;
/** Colour for frame text of game options. */
static constexpr TextColour GAME_OPTIONS_FRAME = TC_ORANGE;
static constexpr TextColour GAME_OPTIONS_FRAME = TextColour::Orange;
/** Colour for label text of game options. */
static constexpr TextColour GAME_OPTIONS_LABEL = TC_LIGHT_BLUE;
static constexpr TextColour GAME_OPTIONS_LABEL = TextColour::LightBlue;
/** Colour for selected text of game options. */
static constexpr TextColour GAME_OPTIONS_SELECTED = TC_WHITE;
static constexpr TextColour GAME_OPTIONS_SELECTED = TextColour::White;
static constexpr std::initializer_list<NWidgetPart> _nested_social_plugins_widgets = {
NWidget(NWID_HORIZONTAL),
@@ -693,7 +693,7 @@ struct GameOptionsWindow : Window {
break;
case WID_GO_GUI_SCALE:
DrawSliderWidget(r, GAME_OPTIONS_BACKGROUND, GAME_OPTIONS_BUTTON, TC_BLACK, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, SCALE_NMARKS, this->gui_scale, ScaleMarkFunc);
DrawSliderWidget(r, GAME_OPTIONS_BACKGROUND, GAME_OPTIONS_BUTTON, TextColour::Black, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, SCALE_NMARKS, this->gui_scale, ScaleMarkFunc);
break;
case WID_GO_VIDEO_DRIVER_INFO:
@@ -701,11 +701,11 @@ struct GameOptionsWindow : Window {
break;
case WID_GO_BASE_SFX_VOLUME:
DrawSliderWidget(r, GAME_OPTIONS_BACKGROUND, GAME_OPTIONS_BUTTON, TC_BLACK, 0, INT8_MAX, VOLUME_NMARKS, _settings_client.music.effect_vol, VolumeMarkFunc);
DrawSliderWidget(r, GAME_OPTIONS_BACKGROUND, GAME_OPTIONS_BUTTON, TextColour::Black, 0, INT8_MAX, VOLUME_NMARKS, _settings_client.music.effect_vol, VolumeMarkFunc);
break;
case WID_GO_BASE_MUSIC_VOLUME:
DrawSliderWidget(r, GAME_OPTIONS_BACKGROUND, GAME_OPTIONS_BUTTON, TC_BLACK, 0, INT8_MAX, VOLUME_NMARKS, _settings_client.music.music_vol, VolumeMarkFunc);
DrawSliderWidget(r, GAME_OPTIONS_BACKGROUND, GAME_OPTIONS_BUTTON, TextColour::Black, 0, INT8_MAX, VOLUME_NMARKS, _settings_client.music.music_vol, VolumeMarkFunc);
break;
case WID_GO_OPTIONSPANEL: {
@@ -746,7 +746,7 @@ struct GameOptionsWindow : Window {
if (FillDrawPixelInfo(&tmp_dpi, r)) {
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
int scrolls_pos = this->vscroll_description->GetPosition() * GetCharacterHeight(FontSize::Normal);
DrawStringMultiLine(0, r.Width() - 1, -scrolls_pos, r.Height() - 1, sd->GetHelp(), TC_WHITE);
DrawStringMultiLine(0, r.Width() - 1, -scrolls_pos, r.Height() - 1, sd->GetHelp(), TextColour::White);
}
}
break;
@@ -926,7 +926,7 @@ struct GameOptionsWindow : Window {
if (this->warn_missing != WHR_NONE) {
DrawStringMultiLineWithClipping(panel.WithHeight(this->warn_lines * GetCharacterHeight(FontSize::Normal)),
GetString(warn_str, _game_settings_restrict_dropdown[this->filter.min_cat]),
TC_BLACK, SA_CENTER);
TextColour::Black, SA_CENTER);
}
}
+2 -2
View File
@@ -216,7 +216,7 @@ struct SignListWindow : Window, SignList {
if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, tr.top + sprite_offset_y);
DrawString(tr.left, tr.right, tr.top + text_offset_y, GetString(STR_SIGN_NAME, si->index), TC_YELLOW);
DrawString(tr.left, tr.right, tr.top + text_offset_y, GetString(STR_SIGN_NAME, si->index), TextColour::Yellow);
tr.top += this->resize.step_height;
}
break;
@@ -593,7 +593,7 @@ struct SignWindow : Window, SignList {
static constexpr std::initializer_list<NWidgetPart> _nested_query_sign_edit_widgets = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, Colours::Grey),
NWidget(WWT_CAPTION, Colours::Grey, WID_QES_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_CAPTION, Colours::Grey, WID_QES_CAPTION), SetTextStyle(TextColour::White),
NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_QES_LOCATION), SetAspect(WidgetDimensions::ASPECT_LOCATION), SetSpriteTip(SPR_GOTO_LOCATION, STR_EDIT_SIGN_LOCATION_TOOLTIP),
EndContainer(),
NWidget(WWT_PANEL, Colours::Grey),
+3 -3
View File
@@ -1043,7 +1043,7 @@ protected:
y < dpi->top + dpi->height) {
/* And draw it. */
DrawString(x, x + legend_text_width, y, tbl.legend, TC_WHITE, SA_LEFT, false, FontSize::Small);
DrawString(x, x + legend_text_width, y, tbl.legend, TextColour::White, SA_LEFT, false, FontSize::Small);
}
}
}
@@ -1674,9 +1674,9 @@ public:
if (!tbl->show_on_map) {
/* Simply draw the string, not the black border of the legend colour.
* This will enforce the idea of the disabled item */
DrawString(text, GetStringWithArgs(string, params), TC_GREY);
DrawString(text, GetStringWithArgs(string, params), TextColour::Grey);
} else {
DrawString(text, GetStringWithArgs(string, params), TC_BLACK);
DrawString(text, GetStringWithArgs(string, params), TextColour::Black);
GfxFillRect(icon, PC_BLACK); // Outer border of the legend colour
}
break;
+2 -2
View File
@@ -778,7 +778,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_company_stations_wid
NWidget(WWT_TEXTBTN, Colours::Grey, WID_STL_BUS), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_BUS, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP), SetFill(0, 1),
NWidget(WWT_TEXTBTN, Colours::Grey, WID_STL_SHIP), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_SHIP, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP), SetFill(0, 1),
NWidget(WWT_TEXTBTN, Colours::Grey, WID_STL_AIRPLANE), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_PLANE, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP), SetFill(0, 1),
NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_STL_FACILALL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_FACILITIES_TOOLTIP), SetTextStyle(TC_BLACK, FontSize::Small), SetFill(0, 1),
NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_STL_FACILALL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_FACILITIES_TOOLTIP), SetTextStyle(TextColour::Black, FontSize::Small), SetFill(0, 1),
NWidget(WWT_PANEL, Colours::Grey), SetMinimalSize(5, 0), SetFill(0, 1), EndContainer(),
NWidget(WWT_DROPDOWN, Colours::Grey, WID_STL_CARGODROPDOWN), SetFill(1, 0), SetToolTip(STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP),
NWidget(WWT_PANEL, Colours::Grey), SetResize(1, 0), SetFill(1, 1), EndContainer(),
@@ -1870,7 +1870,7 @@ struct StationViewWindow : public Window {
}
}
}
if (!sym.empty()) DrawString(shrink.left, shrink.right, y + text_y_offset, sym, TC_YELLOW);
if (!sym.empty()) DrawString(shrink.left, shrink.right, y + text_y_offset, sym, TextColour::Yellow);
}
this->SetDisplayedRow(cd);
}
+10 -10
View File
@@ -48,7 +48,7 @@ static bool DrawScrollingStatusText(const NewsItem &ni, int scroll_pos, int left
int pos = (_current_text_dir == TD_RTL) ? (scroll_pos - width) : (right - scroll_pos - left);
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
DrawString(pos, INT16_MAX, 0, message, TC_LIGHT_BLUE, SA_LEFT | SA_FORCE);
DrawString(pos, INT16_MAX, 0, message, TextColour::LightBlue, SA_LEFT | SA_FORCE);
return (_current_text_dir == TD_RTL) ? (pos < right - left) : (pos + width > 0);
}
@@ -110,19 +110,19 @@ struct StatusBarWindow : Window {
switch (widget) {
case WID_S_LEFT:
/* Draw the date */
DrawString(tr, GetString(STR_JUST_DATE_LONG, TimerGameCalendar::date), TC_WHITE, SA_HOR_CENTER);
DrawString(tr, GetString(STR_JUST_DATE_LONG, TimerGameCalendar::date), TextColour::White, SA_HOR_CENTER);
break;
case WID_S_RIGHT: {
if (_local_company == COMPANY_SPECTATOR) {
DrawString(tr, STR_STATUSBAR_SPECTATOR, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(tr, STR_STATUSBAR_SPECTATOR, TextColour::FromString, SA_HOR_CENTER);
} else if (_settings_game.difficulty.infinite_money) {
DrawString(tr, STR_STATUSBAR_INFINITE_MONEY, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(tr, STR_STATUSBAR_INFINITE_MONEY, TextColour::FromString, SA_HOR_CENTER);
} else {
/* Draw company money, if any */
const Company *c = Company::GetIfValid(_local_company);
if (c != nullptr) {
DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, c->money), TC_WHITE, SA_HOR_CENTER);
DrawString(tr, GetString(STR_JUST_CURRENCY_LONG, c->money), TextColour::White, SA_HOR_CENTER);
}
}
break;
@@ -131,25 +131,25 @@ struct StatusBarWindow : Window {
case WID_S_MIDDLE:
/* Draw status bar */
if (this->saving) { // true when saving is active
DrawString(tr, STR_STATUSBAR_SAVING_GAME, TC_FROMSTRING, SA_HOR_CENTER | SA_VERT_CENTER);
DrawString(tr, STR_STATUSBAR_SAVING_GAME, TextColour::FromString, SA_HOR_CENTER | SA_VERT_CENTER);
} else if (_do_autosave) {
DrawString(tr, STR_STATUSBAR_AUTOSAVE, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(tr, STR_STATUSBAR_AUTOSAVE, TextColour::FromString, SA_HOR_CENTER);
} else if (_pause_mode.Any()) {
StringID msg = _pause_mode.Test(PauseMode::LinkGraph) ? STR_STATUSBAR_PAUSED_LINK_GRAPH : STR_STATUSBAR_PAUSED;
DrawString(tr, msg, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(tr, msg, TextColour::FromString, SA_HOR_CENTER);
} else if (this->ticker_scroll < TICKER_STOP && GetStatusbarNews() != nullptr && !GetStatusbarNews()->headline.empty()) {
/* Draw the scrolling news text */
if (!DrawScrollingStatusText(*GetStatusbarNews(), ScaleGUITrad(this->ticker_scroll), tr.left, tr.right, tr.top, tr.bottom)) {
InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED);
if (Company::IsValidID(_local_company)) {
/* This is the default text */
DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TextColour::FromString, SA_HOR_CENTER);
}
}
} else {
if (Company::IsValidID(_local_company)) {
/* This is the default text */
DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TC_FROMSTRING, SA_HOR_CENTER);
DrawString(tr, GetString(STR_STATUSBAR_COMPANY_NAME, _local_company), TextColour::FromString, SA_HOR_CENTER);
}
}
+5 -5
View File
@@ -522,7 +522,7 @@ protected:
uint text_top = y_offset + (element_height - line_height) / 2;
DrawSprite(action_sprite, PAL_NONE, 0, sprite_top);
DrawString(sprite_dim.width + WidgetDimensions::scaled.frametext.left, width, text_top, text, TC_BLACK);
DrawString(sprite_dim.width + WidgetDimensions::scaled.frametext.left, width, text_top, text, TextColour::Black);
y_offset += element_height;
}
@@ -697,13 +697,13 @@ public:
/* Date */
if (page->date != CalendarTime::INVALID_DATE) {
DrawString(0, fr.right, y_offset, GetString(STR_JUST_DATE_LONG, page->date), TC_BLACK);
DrawString(0, fr.right, y_offset, GetString(STR_JUST_DATE_LONG, page->date), TextColour::Black);
}
y_offset += line_height;
/* Title */
y_offset = DrawStringMultiLine(0, fr.right, y_offset, fr.bottom,
GetString(STR_STORY_BOOK_TITLE, !page->title.empty() ? page->title.GetDecodedString() : this->selected_generic_title), TC_BLACK, SA_TOP | SA_HOR_CENTER);
GetString(STR_STORY_BOOK_TITLE, !page->title.empty() ? page->title.GetDecodedString() : this->selected_generic_title), TextColour::Black, SA_TOP | SA_HOR_CENTER);
/* Page elements */
this->EnsureStoryPageElementLayout();
@@ -716,7 +716,7 @@ public:
switch (ce.pe->type) {
case SPET_TEXT:
DrawStringMultiLineWithClipping(ce.bounds.left, ce.bounds.right, ce.bounds.top - scrollpos, ce.bounds.bottom - scrollpos,
ce.pe->text.GetDecodedString(), TC_BLACK, SA_TOP | SA_LEFT);
ce.pe->text.GetDecodedString(), TextColour::Black, SA_TOP | SA_LEFT);
break;
case SPET_GOAL: {
@@ -741,7 +741,7 @@ public:
DrawFrameRect(ce.bounds.left, ce.bounds.top - scrollpos, ce.bounds.right, ce.bounds.bottom - scrollpos - 1, bgcolour, frame);
DrawString(ce.bounds.left + WidgetDimensions::scaled.bevel.left, ce.bounds.right - WidgetDimensions::scaled.bevel.right, ce.bounds.top + tmargin - scrollpos,
ce.pe->text.GetDecodedString(), TC_WHITE, SA_CENTER);
ce.pe->text.GetDecodedString(), TextColour::White, SA_CENTER);
break;
}
+17 -17
View File
@@ -9,21 +9,21 @@
/** Colour mapping for #TextColour. */
static constexpr PixelColour _string_colourmap[17] = {
PixelColour{150}, // TC_BLUE
PixelColour{ 12}, // TC_SILVER
PixelColour{189}, // TC_GOLD
PixelColour{184}, // TC_RED
PixelColour{174}, // TC_PURPLE
PixelColour{ 30}, // TC_LIGHT_BROWN
PixelColour{195}, // TC_ORANGE
PixelColour{209}, // TC_GREEN
PixelColour{ 68}, // TC_YELLOW
PixelColour{ 95}, // TC_DARK_GREEN
PixelColour{ 79}, // TC_CREAM
PixelColour{116}, // TC_BROWN
PixelColour{ 15}, // TC_WHITE
PixelColour{152}, // TC_LIGHT_BLUE
PixelColour{ 6}, // TC_GREY
PixelColour{133}, // TC_DARK_BLUE
PixelColour{ 1}, // TC_BLACK
PixelColour{150}, // TextColour::Blue
PixelColour{ 12}, // TextColour::Silver
PixelColour{189}, // TextColour::Gold
PixelColour{184}, // TextColour::Red
PixelColour{174}, // TextColour::Purple
PixelColour{ 30}, // TextColour::LightBrown
PixelColour{195}, // TextColour::Orange
PixelColour{209}, // TextColour::Green
PixelColour{ 68}, // TextColour::Yellow
PixelColour{ 95}, // TextColour::DarkGreen
PixelColour{ 79}, // TextColour::Cream
PixelColour{116}, // TextColour::Brown
PixelColour{ 15}, // TextColour::White
PixelColour{152}, // TextColour::LightBlue
PixelColour{ 6}, // TextColour::Grey
PixelColour{133}, // TextColour::DarkBlue
PixelColour{ 1}, // TextColour::Black
};
+1 -1
View File
@@ -495,7 +495,7 @@ void TextfileWindow::AfterLoadMarkdown()
/* All lines beginning with # are headings. */
if (!line.text.empty() && line.text[0] == '#') {
this->jumplist.push_back(line_index);
this->lines[line_index].colour = TC_GOLD;
this->lines[line_index].colour = TextColour::Gold;
this->link_anchors.emplace_back(line_index, 0, 0, MakeAnchorSlug(line.text));
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ protected:
int num_lines = 1; ///< Number of visual lines for this line.
int wrapped_width = 0;
int max_width = -1;
TextColour colour = TC_WHITE; ///< Colour to render text line in.
TextColour colour = TextColour::White; ///< Colour to render text line in.
std::string text{}; ///< Contents of the line.
Line(std::string_view text) : text(text) {}
+22 -15
View File
@@ -228,14 +228,14 @@ struct TimetableWindow : Window {
/* A five-digit number would fit a timetable lasting 2.7 real-world hours, which should be plenty. */
uint64_t max_digits = GetParamMaxDigits(4, FontSize::Small);
size.width = std::max(
GetStringBoundingBox(GetString(STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, TC_BLACK, max_digits)).width,
GetStringBoundingBox(GetString(STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE, TC_BLACK, max_digits)).width)
GetStringBoundingBox(GetString(STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, TextColour::Black, max_digits)).width,
GetStringBoundingBox(GetString(STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE, TextColour::Black, max_digits)).width)
+ WidgetDimensions::scaled.hsep_wide + padding.width;
} else {
uint64_t max_value = GetParamMaxValue(TimerGameEconomy::DateAtStartOfYear(EconomyTime::MAX_YEAR).base(), 0, FontSize::Small);
size.width = std::max(
GetStringBoundingBox(GetString(STR_TIMETABLE_ARRIVAL_DATE, TC_BLACK, max_value)).width,
GetStringBoundingBox(GetString(STR_TIMETABLE_DEPARTURE_DATE, TC_BLACK, max_value)).width)
GetStringBoundingBox(GetString(STR_TIMETABLE_ARRIVAL_DATE, TextColour::Black, max_value)).width,
GetStringBoundingBox(GetString(STR_TIMETABLE_DEPARTURE_DATE, TextColour::Black, max_value)).width)
+ WidgetDimensions::scaled.hsep_wide + padding.width;
}
[[fallthrough]];
@@ -387,16 +387,23 @@ struct TimetableWindow : Window {
}
}
std::string GetTimetableTravelString(const Order &order, int i, TextColour &colour) const
/**
* Get the time table travel string
* @param order The order.
* @param i The index of the currently requested order.
* @param[out] colour The text colour.
* @return The status as string.
*/
std::string GetTimetableTravelString(const Order &order, int i, ExtendedTextColour &colour) const
{
colour = (i == this->sel_index) ? TC_WHITE : TC_BLACK;
colour = (i == this->sel_index) ? TextColour::White : TextColour::Black;
if (order.IsType(OT_CONDITIONAL)) {
return GetString(STR_TIMETABLE_NO_TRAVEL);
}
if (order.IsType(OT_IMPLICIT)) {
colour = ((i == this->sel_index) ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
colour = ExtendedTextColour{(i == this->sel_index) ? TextColour::Silver : TextColour::Grey, ExtendedTextColourFlag::NoShade};
return GetString(STR_TIMETABLE_NOT_TIMETABLEABLE);
}
@@ -447,7 +454,7 @@ struct TimetableWindow : Window {
if (v->orders->GetNext(order_id) == 0) final_order = true;
order_id = v->orders->GetNext(order_id);
} else {
TextColour colour;
ExtendedTextColour colour;
std::string string = GetTimetableTravelString(orders[order_id], i, colour);
DrawString(rtl ? tr.left : middle, rtl ? middle : tr.right, tr.top, string, colour);
@@ -488,8 +495,8 @@ struct TimetableWindow : Window {
/* Don't draw anything if it extends past the end of the window. */
if (!this->vscroll->IsVisible(i)) break;
/* TC_INVALID will skip the colour change. */
TextColour tc = show_late ? TC_RED : TC_INVALID;
/* TextColour::Invalid will skip the colour change. */
TextColour tc = show_late ? TextColour::Red : TextColour::Invalid;
if (i % 2 == 0) {
/* Draw an arrival time. */
if (arr_dep[i / 2].arrival != Ticks::INVALID_TICKS) {
@@ -498,7 +505,7 @@ struct TimetableWindow : Window {
if (this->show_expected && i / 2 == early_id) {
/* Show expected arrival. */
this_offset = 0;
tc = TC_GREEN;
tc = TextColour::Green;
} else {
/* Show scheduled arrival. */
this_offset = offset;
@@ -509,12 +516,12 @@ struct TimetableWindow : Window {
/* Display seconds from now. */
DrawString(tr,
GetString(STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, tc, (arr_dep[i / 2].arrival + offset) / Ticks::TICKS_PER_SECOND),
i == selected ? TC_WHITE : TC_BLACK);
i == selected ? TextColour::White : TextColour::Black);
} else {
/* Show a date. */
DrawString(tr,
GetString(STR_TIMETABLE_ARRIVAL_DATE, tc, TimerGameEconomy::date + (arr_dep[i / 2].arrival + this_offset) / Ticks::DAY_TICKS),
i == selected ? TC_WHITE : TC_BLACK);
i == selected ? TextColour::White : TextColour::Black);
}
}
} else {
@@ -524,12 +531,12 @@ struct TimetableWindow : Window {
/* Display seconds from now. */
DrawString(tr,
GetString(STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE, tc, (arr_dep[i / 2].departure + offset) / Ticks::TICKS_PER_SECOND),
i == selected ? TC_WHITE : TC_BLACK);
i == selected ? TextColour::White : TextColour::Black);
} else {
/* Show a date. */
DrawString(tr,
GetString(STR_TIMETABLE_DEPARTURE_DATE, tc, TimerGameEconomy::date + (arr_dep[i / 2].departure + offset) / Ticks::DAY_TICKS),
i == selected ? TC_WHITE : TC_BLACK);
i == selected ? TextColour::White : TextColour::Black);
}
}
}
+4 -4
View File
@@ -2394,10 +2394,10 @@ struct ScenarioEditorToolbarWindow : Window {
case WID_TE_SPACER: {
int height = r.Height();
if (height > 2 * GetCharacterHeight(FontSize::Normal)) {
DrawString(r.left, r.right, height / 2 - GetCharacterHeight(FontSize::Normal), STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left, r.right, height / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left, r.right, height / 2 - GetCharacterHeight(FontSize::Normal), STR_SCENEDIT_TOOLBAR_OPENTTD, TextColour::FromString, SA_HOR_CENTER);
DrawString(r.left, r.right, height / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TextColour::FromString, SA_HOR_CENTER);
} else {
DrawString(r.left, r.right, (height - GetCharacterHeight(FontSize::Normal)) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
DrawString(r.left, r.right, (height - GetCharacterHeight(FontSize::Normal)) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TextColour::FromString, SA_HOR_CENTER);
}
break;
}
@@ -2567,7 +2567,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_toolb_scen_inner_wid
NWidget(WWT_PANEL, Colours::Grey, WID_TE_DATE_PANEL),
NWidget(NWID_HORIZONTAL), SetPIP(2, 2, 2), SetPadding(1),
NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_DATE_BACKWARD), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetFill(0, 1),
NWidget(WWT_TEXT, Colours::Invalid, WID_TE_DATE), SetToolTip(STR_SCENEDIT_TOOLBAR_SET_DATE_TOOLTIP), SetTextStyle(TC_WHITE), SetAlignment(SA_CENTER), SetFill(0, 1),
NWidget(WWT_TEXT, Colours::Invalid, WID_TE_DATE), SetToolTip(STR_SCENEDIT_TOOLBAR_SET_DATE_TOOLTIP), SetTextStyle(TextColour::White), SetAlignment(SA_CENTER), SetFill(0, 1),
NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_DATE_FORWARD), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetFill(0, 1),
EndContainer(),
EndContainer(),
+5 -5
View File
@@ -214,9 +214,9 @@ public:
if (!this->enabled_actions.Test(i)) continue;
/* Set colour of action based on ability to execute and if selected. */
TextColour action_colour = TC_GREY | TC_NO_SHADE;
if (this->available_actions.Test(i)) action_colour = TC_ORANGE;
if (this->sel_action == i) action_colour = TC_WHITE;
ExtendedTextColour action_colour{TextColour::Grey, ExtendedTextColourFlag::NoShade};
if (this->available_actions.Test(i)) action_colour = TextColour::Orange;
if (this->sel_action == i) action_colour = TextColour::White;
DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + to_underlying(i), action_colour);
r.top += GetCharacterHeight(FontSize::Normal);
@@ -240,7 +240,7 @@ public:
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect),
GetString(this->action_tooltips[to_underlying(this->sel_action)], action_cost),
affordable ? TC_YELLOW : TC_RED);
affordable ? TextColour::Yellow : TextColour::Red);
}
break;
}
@@ -469,7 +469,7 @@ public:
}
if (!this->town->text.empty()) {
tr.top = DrawStringMultiLine(tr, this->town->text.GetDecodedString(), TC_BLACK);
tr.top = DrawStringMultiLine(tr, this->town->text.GetDecodedString(), TextColour::Black);
}
}
+2 -2
View File
@@ -224,7 +224,7 @@ static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int rig
} else {
str = GetString(STR_VEHICLE_DETAILS_CARGO_FROM, item->cargo, item->amount, item->source);
}
DrawString(left, right, y, str, TC_LIGHT_BLUE);
DrawString(left, right, y, str, TextColour::LightBlue);
}
/**
@@ -413,7 +413,7 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t v
if (i < _cargo_summary.size()) {
TrainDetailsCargoTab(&_cargo_summary[i], dr.left, dr.right, py);
} else {
DrawString(dr.left, dr.right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
DrawString(dr.left, dr.right, py, STR_QUANTITY_N_A, TextColour::LightBlue);
}
break;
+23 -17
View File
@@ -739,7 +739,7 @@ static void DrawVehicleRefitWindow(const RefitOptions &refits, const RefitOption
}
}
TextColour colour = (sel != nullptr && sel->cargo == refit.cargo && sel->subtype == refit.subtype) ? TC_WHITE : TC_BLACK;
TextColour colour = (sel != nullptr && sel->cargo == refit.cargo && sel->subtype == refit.subtype) ? TextColour::White : TextColour::Black;
/* Get the cargo name. */
DrawString(tr, GetString(STR_JUST_STRING_STRING, CargoSpec::Get(refit.cargo)->name, refit.string), colour);
@@ -1686,10 +1686,10 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y, uin
VehicleOrderID oid = start;
do {
if (oid == v->cur_real_order_index) DrawString(left, right, y, rtl ? STR_JUST_LEFT_ARROW : STR_JUST_RIGHT_ARROW, TC_BLACK, SA_LEFT, false, FontSize::Small);
if (oid == v->cur_real_order_index) DrawString(left, right, y, rtl ? STR_JUST_LEFT_ARROW : STR_JUST_RIGHT_ARROW, TextColour::Black, SA_LEFT, false, FontSize::Small);
if (orders[oid].IsType(OT_GOTO_STATION)) {
DrawString(left + l_offset, right - r_offset, y, GetString(STR_STATION_NAME, orders[oid].GetDestination()), TC_BLACK, SA_LEFT, false, FontSize::Small);
DrawString(left + l_offset, right - r_offset, y, GetString(STR_STATION_NAME, orders[oid].GetDestination()), TextColour::Black, SA_LEFT, false, FontSize::Small);
y += GetCharacterHeight(FontSize::Small);
if (++i == 4) break;
@@ -1718,7 +1718,7 @@ static void DrawSmallOrderList(const OrderList *orderlist, int left, int right,
for (const Order &order : orderlist->GetOrders()) {
if (order.IsType(OT_GOTO_STATION)) {
DrawString(left + l_offset, right - r_offset, y, GetString(STR_STATION_NAME, order.GetDestination()), TC_BLACK, SA_LEFT, false, FontSize::Small);
DrawString(left + l_offset, right - r_offset, y, GetString(STR_STATION_NAME, order.GetDestination()), TextColour::Black, SA_LEFT, false, FontSize::Small);
y += GetCharacterHeight(FontSize::Small);
if (++i == 4) break;
@@ -1833,31 +1833,31 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
/* The vehicle got a name so we will print it and the cargoes */
DrawString(tr.left, tr.right, ir.top,
GetString(STR_VEHICLE_LIST_NAME_AND_CARGO, STR_VEHICLE_NAME, v->index, STR_VEHICLE_LIST_CARGO, vehicle_cargoes),
TC_BLACK, SA_LEFT, false, FontSize::Small);
TextColour::Black, SA_LEFT, false, FontSize::Small);
} else if (v->group_id != DEFAULT_GROUP) {
/* The vehicle has no name, but is member of a group, so print group name and the cargoes */
DrawString(tr.left, tr.right, ir.top,
GetString(STR_VEHICLE_LIST_NAME_AND_CARGO, STR_GROUP_NAME, v->group_id, STR_VEHICLE_LIST_CARGO, vehicle_cargoes),
TC_BLACK, SA_LEFT, false, FontSize::Small);
TextColour::Black, SA_LEFT, false, FontSize::Small);
} else {
/* The vehicle has no name, and is not a member of a group, so just print the cargoes */
DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_LIST_CARGO, vehicle_cargoes), TC_BLACK, SA_LEFT, false, FontSize::Small);
DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_LIST_CARGO, vehicle_cargoes), TextColour::Black, SA_LEFT, false, FontSize::Small);
}
} else if (!v->name.empty()) {
/* The vehicle got a name so we will print it */
DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_NAME, v->index), TC_BLACK, SA_LEFT, false, FontSize::Small);
DrawString(tr.left, tr.right, ir.top, GetString(STR_VEHICLE_NAME, v->index), TextColour::Black, SA_LEFT, false, FontSize::Small);
} else if (v->group_id != DEFAULT_GROUP) {
/* The vehicle has no name, but is member of a group, so print group name */
DrawString(tr.left, tr.right, ir.top, GetString(STR_GROUP_NAME, v->group_id), TC_BLACK, SA_LEFT, false, FontSize::Small);
DrawString(tr.left, tr.right, ir.top, GetString(STR_GROUP_NAME, v->group_id), TextColour::Black, SA_LEFT, false, FontSize::Small);
}
if (show_orderlist) DrawSmallOrderList(v, olr.left, olr.right, ir.top + GetCharacterHeight(FontSize::Small), this->order_arrow_width, v->cur_real_order_index);
TextColour tc;
if (v->IsChainInDepot()) {
tc = TC_BLUE;
tc = TextColour::Blue;
} else {
tc = (v->age > v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) ? TC_RED : TC_BLACK;
tc = (v->age > v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) ? TextColour::Red : TextColour::Black;
}
DrawString(ir.left, ir.right, ir.top + WidgetDimensions::scaled.framerect.top, GetString(STR_JUST_COMMA, v->unitnumber), tc);
@@ -1874,7 +1874,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
if (show_orderlist) DrawSmallOrderList(vehgroup.vehicles_begin[0]->orders, olr.left, olr.right, ir.top + GetCharacterHeight(FontSize::Small), this->order_arrow_width);
DrawString(ir.left, ir.right, ir.top + WidgetDimensions::scaled.framerect.top, GetString(STR_JUST_COMMA, vehgroup.NumVehicles()), TC_BLACK);
DrawString(ir.left, ir.right, ir.top + WidgetDimensions::scaled.framerect.top, GetString(STR_JUST_COMMA, vehgroup.NumVehicles()), TextColour::Black);
break;
default:
@@ -3180,9 +3180,15 @@ public:
return GetString(STR_VEHICLE_VIEW_CAPTION, v->index);
}
std::string GetVehicleStatusString(const Vehicle *v, TextColour &text_colour) const
/**
* Get the status of the vehicle.
* @param v The vehicle to check.
* @param[out] text_colour The text colour.
* @return The status as string.
*/
std::string GetVehicleStatusString(const Vehicle *v, ExtendedTextColour &text_colour) const
{
text_colour = TC_BLACK;
text_colour = TextColour::Black;
if (v->vehstatus.Test(VehState::Crashed)) return GetString(STR_VEHICLE_STATUS_CRASHED);
@@ -3204,9 +3210,9 @@ public:
/* Vehicle is in a "normal" state, show current order. */
if (mouse_over_start_stop) {
if (v->vehstatus.Test(VehState::Stopped)) {
text_colour = TC_RED | TC_FORCED;
text_colour = ExtendedTextColour{TextColour::Red, ExtendedTextColourFlag::Forced};
} else if (v->type == VehicleType::Train && Train::From(v)->flags.Test(VehicleRailFlag::Stuck) && !v->current_order.IsType(OT_LOADING)) {
text_colour = TC_ORANGE | TC_FORCED;
text_colour = ExtendedTextColour{TextColour::Orange, ExtendedTextColourFlag::Forced};
}
}
@@ -3274,7 +3280,7 @@ public:
tr = tr.Indent(icon_width + WidgetDimensions::scaled.imgbtn.Horizontal(), rtl);
TextColour text_colour = TC_FROMSTRING;
ExtendedTextColour text_colour{TextColour::FromString};
std::string str = GetVehicleStatusString(v, text_colour);
DrawString(tr.left, tr.right, CentreBounds(tr.top, tr.bottom, GetCharacterHeight(FontSize::Normal)), str, text_colour, SA_HOR_CENTER);
}
+4 -4
View File
@@ -1780,16 +1780,16 @@ static void ViewportDrawStrings(ZoomLevel zoom, const StringSpriteToDrawVector *
int y = UnScaleByZoom(ss.y, zoom);
int h = WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(small ? FontSize::Small : FontSize::Normal) + WidgetDimensions::scaled.fullbevel.bottom;
TextColour colour = TC_WHITE;
ExtendedTextColour colour{TextColour::White};
if (ss.flags.Test(ViewportStringFlag::ColourRect)) {
if (ss.colour != Colours::Invalid) DrawFrameRect(x, y, x + w - 1, y + h - 1, ss.colour, {});
colour = TC_BLACK;
colour = TextColour::Black;
} else if (ss.flags.Test(ViewportStringFlag::TransparentRect)) {
DrawFrameRect(x, y, x + w - 1, y + h - 1, ss.colour, FrameFlag::Transparent);
}
if (ss.flags.Test(ViewportStringFlag::TextColour)) {
if (ss.colour != Colours::Invalid) colour = GetColourGradient(ss.colour, Shade::Lighter).ToTextColour();
if (ss.colour != Colours::Invalid) colour = ExtendedTextColour{GetColourGradient(ss.colour, Shade::Lighter)};
}
int left = x + WidgetDimensions::scaled.fullbevel.left;
@@ -1800,7 +1800,7 @@ static void ViewportDrawStrings(ZoomLevel zoom, const StringSpriteToDrawVector *
if (small && ss.flags.Test(ViewportStringFlag::Shadow)) {
/* Shadow needs to be shifted 1 pixel. */
shadow_offset = WidgetDimensions::scaled.fullbevel.top;
DrawString(left + shadow_offset, right + shadow_offset, top, ss.string, TC_BLACK, SA_HOR_CENTER, false, FontSize::Small);
DrawString(left + shadow_offset, right + shadow_offset, top, ss.string, TextColour::Black, SA_HOR_CENTER, false, FontSize::Small);
}
DrawString(left, right, top - shadow_offset, ss.string, colour, SA_HOR_CENTER, false, small ? FontSize::Small : FontSize::Normal);
+4 -4
View File
@@ -722,7 +722,7 @@ static inline void DrawCloseBox(const Rect &r, Colours colour)
d.width -= offset.x;
d.height -= offset.y;
int s = ScaleSpriteTrad(1); // Offset to account for shadow of SPR_CLOSEBOX.
DrawSprite(SPR_CLOSEBOX, (colour != Colours::White ? TC_BLACK : TC_SILVER) | (1U << PALETTE_TEXT_RECOLOUR), CentreBounds(r.left, r.right, d.width - s) - offset.x, CentreBounds(r.top, r.bottom, d.height - s) - offset.y);
DrawSprite(SPR_CLOSEBOX, to_underlying(colour != Colours::White ? TextColour::Black : TextColour::Silver) | (1U << PALETTE_TEXT_RECOLOUR), CentreBounds(r.left, r.right, d.width - s) - offset.x, CentreBounds(r.top, r.bottom, d.height - s) - offset.y);
}
/**
@@ -773,7 +773,7 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke
DrawFrameRect(text, colour, clicked_button ? FrameFlag::Lowered : FrameFlags{});
if (!str.empty()) {
text = text.CentreToHeight(GetCharacterHeight(FontSize::Normal)).Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero);
DrawString(text, str, TC_BLACK, align);
DrawString(text, str, TextColour::Black, align);
}
Rect button = r.WithWidth(NWidgetLeaf::dropdown_dimension.width, !rtl);
@@ -800,7 +800,7 @@ void Window::DrawWidgets() const
Rect outer = widget->GetCurrentRect();
Rect inner = outer.Shrink(WidgetDimensions::scaled.bevel).Expand(1);
PixelColour colour = _string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE];
PixelColour colour = _string_colourmap[to_underlying(_window_highlight_colour ? widget->GetHighlightColour() : TextColour::White)];
GfxFillRect(outer.left, outer.top, inner.left, inner.bottom, colour);
GfxFillRect(inner.left + 1, outer.top, inner.right - 1, inner.top, colour);
@@ -1175,7 +1175,7 @@ NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fil
this->colour = colour;
this->widget_data = widget_data;
this->SetToolTip(tool_tip);
this->text_colour = tp == WWT_CAPTION ? TC_WHITE : TC_BLACK;
this->text_colour = tp == WWT_CAPTION ? TextColour::White : TextColour::Black;
}
/**
+2 -2
View File
@@ -195,7 +195,7 @@ public:
* Get the colour of the highlighted text.
* @return The highlight colour.
*/
virtual TextColour GetHighlightColour() const { return TC_INVALID; }
virtual TextColour GetHighlightColour() const { return TextColour::Invalid; }
/**
* Highlight the widget or not.
@@ -439,7 +439,7 @@ protected:
inline void NWidgetCore::SetHighlighted(TextColour highlight_colour)
{
highlight_colour != TC_INVALID ? this->disp_flags.Set(NWidgetDisplayFlag::Highlight) : this->disp_flags.Reset(NWidgetDisplayFlag::Highlight);
highlight_colour != TextColour::Invalid ? this->disp_flags.Set(NWidgetDisplayFlag::Highlight) : this->disp_flags.Reset(NWidgetDisplayFlag::Highlight);
this->highlight_colour = highlight_colour;
}
+4 -4
View File
@@ -236,7 +236,7 @@ void Window::DisableAllWidgetHighlight()
for (auto &pair : this->widget_lookup) {
NWidgetBase *nwid = pair.second;
if (nwid->IsHighlighted()) {
nwid->SetHighlighted(TC_INVALID);
nwid->SetHighlighted(TextColour::Invalid);
nwid->SetDirty(this);
}
}
@@ -247,7 +247,7 @@ void Window::DisableAllWidgetHighlight()
/**
* Sets the highlighted status of a widget.
* @param widget_index index of this widget in the window
* @param highlighted_colour Colour of highlight, or TC_INVALID to disable.
* @param highlighted_colour Colour of highlight, or TextColour::Invalid to disable.
*/
void Window::SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour)
{
@@ -257,7 +257,7 @@ void Window::SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_co
nwid->SetHighlighted(highlighted_colour);
nwid->SetDirty(this);
if (highlighted_colour != TC_INVALID) {
if (highlighted_colour != TextColour::Invalid) {
/* If we set a highlight, the window has a highlight */
this->flags.Set(WindowFlag::Highlighted);
} else {
@@ -759,7 +759,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
/* Check if the widget is highlighted; if so, disable highlight and dispatch an event to the GameScript */
if (w->IsWidgetHighlighted(widget_index)) {
w->SetWidgetHighlight(widget_index, TC_INVALID);
w->SetWidgetHighlight(widget_index, TextColour::Invalid);
Game::NewEvent(new ScriptEventWindowWidgetClick((ScriptWindow::WindowClass)w->window_class, w->window_number, widget_index));
}