Refactor Dark/ExtraDark into its own structure

This commit is contained in:
Gymnasiast 2022-10-12 18:27:05 +02:00
parent 19cb2271ff
commit 9ca9412205
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
11 changed files with 55 additions and 40 deletions

View File

@ -295,13 +295,14 @@ public:
// It needs a {BLACK} token in the string to work properly.
colour_t colour = COLOUR_BLACK;
FontSpriteBase fontSpriteBase = FontSpriteBase::MEDIUM;
auto darkness = TextDarkness::Regular;
if (researchItem.IsAlwaysResearched())
{
if (_selectedResearchItem == &researchItem && dragItem == nullptr)
fontSpriteBase = FontSpriteBase::MEDIUM_EXTRA_DARK;
darkness = TextDarkness::ExtraDark;
else
fontSpriteBase = FontSpriteBase::MEDIUM_DARK;
darkness = TextDarkness::Dark;
colour = colours[1] | COLOUR_FLAG_INSET;
}
@ -318,21 +319,21 @@ public:
ft.Add<StringId>(rideTypeName);
DrawTextEllipsised(
&dpi, { 1, itemY }, columnSplitOffset - 11, STR_INVENTIONS_LIST_RIDE_AND_VEHICLE_NAME, ft,
{ colour, fontSpriteBase });
{ colour, fontSpriteBase, darkness });
// Draw vehicle name
ft = Formatter();
ft.Add<StringId>(itemNameId);
DrawTextEllipsised(
&dpi, { columnSplitOffset + 1, itemY }, columnSplitOffset - 11, STR_BLACK_STRING, ft,
{ colour, fontSpriteBase });
{ colour, fontSpriteBase, darkness });
}
else
{
// Scenery group, flat ride or shop
auto ft = Formatter();
ft.Add<StringId>(itemNameId);
DrawTextEllipsised(&dpi, { 1, itemY }, boxWidth, STR_BLACK_STRING, ft, { colour, fontSpriteBase });
DrawTextEllipsised(&dpi, { 1, itemY }, boxWidth, STR_BLACK_STRING, ft, { colour, fontSpriteBase, darkness });
}
}
}

View File

@ -721,15 +721,14 @@ public:
if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) && (*listItem.flags & ObjectSelectionFlags::Selected))
{
screenCoords.x = 2;
FontSpriteBase fontSpriteBase = highlighted ? FontSpriteBase::MEDIUM_EXTRA_DARK
: FontSpriteBase::MEDIUM_DARK;
auto darkness = highlighted ? TextDarkness::ExtraDark : TextDarkness::Dark;
colour_t colour2 = NOT_TRANSLUCENT(colours[1]);
if (*listItem.flags & (ObjectSelectionFlags::InUse | ObjectSelectionFlags::AlwaysRequired))
colour2 |= COLOUR_FLAG_INSET;
gfx_draw_string(
&dpi, screenCoords, static_cast<const char*>(CheckBoxMarkString),
{ static_cast<colour_t>(colour2), fontSpriteBase });
{ static_cast<colour_t>(colour2), FontSpriteBase::MEDIUM, darkness });
}
screenCoords.x = gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER ? 0 : 15;
@ -738,11 +737,11 @@ public:
auto buffer = strchr(bufferWithColour, '\0');
colour_t colour = COLOUR_BLACK;
FontSpriteBase fontSpriteBase = FontSpriteBase::MEDIUM;
auto darkness = TextDarkness::Regular;
if (*listItem.flags & ObjectSelectionFlags::Flag6)
{
colour = colours[1] & 0x7F;
fontSpriteBase = FontSpriteBase::MEDIUM_DARK;
darkness = TextDarkness::Dark;
}
int32_t width_limit = widgets[WIDX_LIST].width() - screenCoords.x;
@ -755,7 +754,8 @@ public:
safe_strcpy(buffer, language_get_string(rideTypeStringId), 256 - (buffer - bufferWithColour));
auto ft = Formatter();
ft.Add<const char*>(gCommonStringFormatBuffer);
DrawTextEllipsised(&dpi, screenCoords, width_limit - 15, STR_STRING, ft, { colour, fontSpriteBase });
DrawTextEllipsised(
&dpi, screenCoords, width_limit - 15, STR_STRING, ft, { colour, FontSpriteBase::MEDIUM, darkness });
screenCoords.x = widgets[WIDX_LIST_SORT_RIDE].left - widgets[WIDX_LIST].left;
}
@ -770,7 +770,8 @@ public:
}
auto ft = Formatter();
ft.Add<const char*>(gCommonStringFormatBuffer);
DrawTextEllipsised(&dpi, screenCoords, width_limit, STR_STRING, ft, { colour, fontSpriteBase });
DrawTextEllipsised(
&dpi, screenCoords, width_limit, STR_STRING, ft, { colour, FontSpriteBase::MEDIUM, darkness });
}
screenCoords.y += SCROLLABLE_ROW_HEIGHT;
}

View File

@ -1084,11 +1084,10 @@ static void WindowEditorObjectiveOptionsRidesScrollpaint(rct_window* w, rct_draw
{
if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE)
{
FontSpriteBase fontSpriteBase = stringId == STR_WINDOW_COLOUR_2_STRINGID ? FontSpriteBase::MEDIUM_EXTRA_DARK
: FontSpriteBase::MEDIUM_DARK;
auto darkness = stringId == STR_WINDOW_COLOUR_2_STRINGID ? TextDarkness::ExtraDark : TextDarkness::Dark;
gfx_draw_string(
dpi, { 2, y }, static_cast<const char*>(CheckBoxMarkString),
{ static_cast<colour_t>(w->colours[1] & 0x7F), fontSpriteBase });
{ static_cast<colour_t>(w->colours[1] & 0x7F), FontSpriteBase::MEDIUM, darkness });
}
// Ride name

View File

@ -613,10 +613,12 @@ static void WindowScenarioselectScrollpaint(rct_window* w, rct_drawpixelinfo* dp
ft.Add<StringId>(STR_STRING);
ft.Add<char*>(buffer);
colour_t colour = isDisabled ? w->colours[1] | COLOUR_FLAG_INSET : COLOUR_BLACK;
FontSpriteBase fontSpriteBase = isDisabled ? FontSpriteBase::MEDIUM_DARK : FontSpriteBase::MEDIUM;
auto darkness = isDisabled ? TextDarkness::Dark : TextDarkness::Regular;
const auto scrollCentre = window_scenarioselect_widgets[WIDX_SCENARIOLIST].width() / 2;
DrawTextBasic(dpi, { scrollCentre, y + 1 }, format, ft, { colour, fontSpriteBase, TextAlignment::CENTRE });
DrawTextBasic(
dpi, { scrollCentre, y + 1 }, format, ft,
{ colour, FontSpriteBase::MEDIUM, TextAlignment::CENTRE, darkness });
// Check if scenario is completed
if (isCompleted)

View File

@ -823,7 +823,7 @@ public:
{
gfx_draw_string(
&dpi, topLeft, static_cast<const char*>(CheckBoxMarkString),
{ static_cast<colour_t>(colours[1] & 0x7F), FontSpriteBase::MEDIUM_DARK });
{ static_cast<colour_t>(colours[1] & 0x7F), FontSpriteBase::MEDIUM, TextDarkness::Dark });
}
}
}

View File

@ -917,17 +917,7 @@ static void ttf_process_initial_colour(int32_t colour, text_draw_info* info)
{
if (colour != TEXT_COLOUR_254 && colour != TEXT_COLOUR_255)
{
info->flags &= ~(TEXT_DRAW_FLAG_INSET | TEXT_DRAW_FLAG_OUTLINE | TEXT_DRAW_FLAG_DARK | TEXT_DRAW_FLAG_EXTRA_DARK);
if (info->font_sprite_base == FontSpriteBase::MEDIUM_DARK
|| info->font_sprite_base == FontSpriteBase::MEDIUM_EXTRA_DARK)
{
info->flags |= TEXT_DRAW_FLAG_DARK;
if (info->font_sprite_base == FontSpriteBase::MEDIUM_EXTRA_DARK)
{
info->flags |= TEXT_DRAW_FLAG_EXTRA_DARK;
}
info->font_sprite_base = FontSpriteBase::MEDIUM;
}
info->flags &= ~(TEXT_DRAW_FLAG_INSET | TEXT_DRAW_FLAG_OUTLINE);
if (colour & COLOUR_FLAG_OUTLINE)
{
info->flags |= TEXT_DRAW_FLAG_OUTLINE;
@ -980,7 +970,7 @@ static void ttf_process_initial_colour(int32_t colour, text_draw_info* info)
void ttf_draw_string(
rct_drawpixelinfo* dpi, const_utf8string text, int32_t colour, const ScreenCoordsXY& coords, bool noFormatting,
FontSpriteBase fontSpriteBase)
FontSpriteBase fontSpriteBase, TextDarkness darkness)
{
if (text == nullptr)
return;
@ -1003,6 +993,15 @@ void ttf_draw_string(
info.flags |= TEXT_DRAW_FLAG_NO_FORMATTING;
}
if (darkness == TextDarkness::Dark)
{
info.flags |= TEXT_DRAW_FLAG_DARK;
}
else if (darkness == TextDarkness::ExtraDark)
{
info.flags |= (TEXT_DRAW_FLAG_DARK | TEXT_DRAW_FLAG_EXTRA_DARK);
}
std::memcpy(info.palette, gTextPalette, sizeof(info.palette));
ttf_process_initial_colour(colour, &info);
ttf_process_string(dpi, text, &info);

View File

@ -562,7 +562,7 @@ int32_t gfx_clip_string(char* buffer, int32_t width, FontSpriteBase fontSpriteBa
void shorten_path(utf8* buffer, size_t bufferSize, const utf8* path, int32_t availableWidth, FontSpriteBase fontSpriteBase);
void ttf_draw_string(
rct_drawpixelinfo* dpi, const_utf8string text, int32_t colour, const ScreenCoordsXY& coords, bool noFormatting,
FontSpriteBase fontSpriteBase);
FontSpriteBase fontSpriteBase, TextDarkness darkness);
// scrolling text
void scrolling_text_initialise_bitmaps();

View File

@ -298,11 +298,6 @@ int32_t font_sprite_get_codepoint_offset(int32_t codepoint)
int32_t font_sprite_get_codepoint_width(FontSpriteBase fontSpriteBase, int32_t codepoint)
{
if (fontSpriteBase == FontSpriteBase::MEDIUM_DARK || fontSpriteBase == FontSpriteBase::MEDIUM_EXTRA_DARK)
{
fontSpriteBase = FontSpriteBase::MEDIUM;
}
int32_t glyphIndex = font_sprite_get_codepoint_offset(codepoint);
int32_t baseFontIndex = font_get_font_index_from_sprite_base(fontSpriteBase);
if (glyphIndex >= FONT_SPRITE_GLYPH_COUNT)

View File

@ -25,9 +25,6 @@ enum
enum class FontSpriteBase : int16_t
{
MEDIUM_EXTRA_DARK = -2,
MEDIUM_DARK = -1,
TINY = FONT_SIZE_TINY * FONT_SPRITE_GLYPH_COUNT,
SMALL = FONT_SIZE_SMALL * FONT_SPRITE_GLYPH_COUNT,
MEDIUM = FONT_SIZE_MEDIUM * FONT_SPRITE_GLYPH_COUNT,

View File

@ -100,7 +100,7 @@ static void DrawText(
break;
}
ttf_draw_string(dpi, text, paint.Colour, alignedCoords, noFormatting, paint.SpriteBase);
ttf_draw_string(dpi, text, paint.Colour, alignedCoords, noFormatting, paint.SpriteBase, paint.Darkness);
if (paint.UnderlineText == TextUnderline::On)
{

View File

@ -30,12 +30,20 @@ enum class TextUnderline
On,
};
enum class TextDarkness
{
Regular = 0,
Dark = 1,
ExtraDark = 2,
};
struct TextPaint
{
colour_t Colour = COLOUR_BLACK;
FontSpriteBase SpriteBase = FontSpriteBase::MEDIUM;
TextUnderline UnderlineText = TextUnderline::Off;
TextAlignment Alignment = TextAlignment::LEFT;
TextDarkness Darkness = TextDarkness::Regular;
TextPaint() = default;
TextPaint(colour_t colour)
@ -99,6 +107,12 @@ struct TextPaint
, Alignment(alignment)
{
}
TextPaint(colour_t colour, FontSpriteBase spriteBase, TextDarkness darkness)
: Colour(colour)
, SpriteBase(spriteBase)
, Darkness(darkness)
{
}
TextPaint(colour_t colour, TextUnderline underlineText, TextAlignment alignment)
: Colour(colour)
, UnderlineText(underlineText)
@ -119,6 +133,13 @@ struct TextPaint
, Alignment(alignment)
{
}
TextPaint(colour_t colour, FontSpriteBase spriteBase, TextAlignment alignment, TextDarkness darkness)
: Colour(colour)
, SpriteBase(spriteBase)
, Alignment(alignment)
, Darkness(darkness)
{
}
};
void DrawTextBasic(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, StringId format);