mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-17 20:13:07 +01:00
Use FlagHolder in ColourWithFlags
This commit is contained in:
@@ -298,7 +298,7 @@ void InGameConsole::Draw(RenderTarget& rt) const
|
||||
return;
|
||||
|
||||
// Set font
|
||||
ColourWithFlags textColour = { ThemeGetColour(WindowClass::console, 1).colour, 0 };
|
||||
ColourWithFlags textColour = { ThemeGetColour(WindowClass::console, 1).colour, {} };
|
||||
const FontStyle style = InGameConsoleGetFontStyle();
|
||||
const int32_t lineHeight = InGameConsoleGetLineHeight();
|
||||
const int32_t maxLines = GetNumVisibleLines();
|
||||
@@ -306,7 +306,7 @@ void InGameConsole::Draw(RenderTarget& rt) const
|
||||
// TTF looks far better without the outlines
|
||||
if (!LocalisationService_UseTrueTypeFont())
|
||||
{
|
||||
textColour.setFlag(ColourFlag::withOutline, true);
|
||||
textColour.flags.set(ColourFlag::withOutline, true);
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace OpenRCT2::Ui
|
||||
}
|
||||
static constexpr ColourWithFlags translucent(colour_t colour)
|
||||
{
|
||||
return ColourWithFlags{ colour, EnumToFlag(ColourFlag::translucent) };
|
||||
return ColourWithFlags{ colour, { ColourFlag::translucent } };
|
||||
}
|
||||
|
||||
static constexpr WindowThemeDesc kWindowThemeDescriptors[] =
|
||||
@@ -322,7 +322,7 @@ namespace OpenRCT2::Ui
|
||||
for (uint8_t i = 0; i < wtDesc->windowColours.numColours; i++)
|
||||
{
|
||||
json_t jsonEntry = { { "colour", Colour::ToString(Theme.Colours[i].colour) },
|
||||
{ "translucent", Theme.Colours[i].hasFlag(ColourFlag::translucent) } };
|
||||
{ "translucent", Theme.Colours[i].flags.has(ColourFlag::translucent) } };
|
||||
|
||||
jsonColours.emplace_back(jsonEntry);
|
||||
}
|
||||
@@ -364,7 +364,8 @@ namespace OpenRCT2::Ui
|
||||
auto colourObject = Json::AsObject(jsonColours[i]);
|
||||
auto colour = Colour::FromString(Json::GetString(colourObject["colour"]), COLOUR_BLACK);
|
||||
auto isTranslucent = Json::GetBoolean(colourObject["translucent"], false);
|
||||
uint8_t flags = isTranslucent ? EnumToFlag(ColourFlag::translucent) : 0;
|
||||
ColourFlags flags{};
|
||||
flags.set(ColourFlag::translucent, isTranslucent);
|
||||
|
||||
result.Theme.Colours[i] = { colour, flags };
|
||||
}
|
||||
|
||||
@@ -357,9 +357,9 @@ namespace OpenRCT2::Ui
|
||||
return;
|
||||
|
||||
auto colour = w.colours[widget.colour];
|
||||
colour.setFlag(ColourFlag::translucent, false);
|
||||
colour.flags.set(ColourFlag::translucent, false);
|
||||
if (widgetIsDisabled(w, widgetIndex))
|
||||
colour.setFlag(ColourFlag::inset, true);
|
||||
colour.flags.set(ColourFlag::inset, true);
|
||||
|
||||
// Resolve the absolute ltrb
|
||||
auto topLeft = w.windowPos + ScreenCoordsXY{ widget.left, 0 };
|
||||
@@ -403,7 +403,7 @@ namespace OpenRCT2::Ui
|
||||
|
||||
auto colour = w.colours[widget.colour];
|
||||
if (widgetIsDisabled(w, widgetIndex))
|
||||
colour.setFlag(ColourFlag::inset, true);
|
||||
colour.flags.set(ColourFlag::inset, true);
|
||||
|
||||
// Resolve the absolute ltrb
|
||||
int32_t l = w.windowPos.x + widget.left;
|
||||
@@ -492,7 +492,7 @@ namespace OpenRCT2::Ui
|
||||
{
|
||||
auto colour = w.colours[widget.colour].withFlag(ColourFlag::translucent, false);
|
||||
if (widgetIsDisabled(w, widgetIndex))
|
||||
colour.setFlag(ColourFlag::inset, true);
|
||||
colour.flags.set(ColourFlag::inset, true);
|
||||
|
||||
utf8 buffer[512] = { 0 };
|
||||
OpenRCT2::FormatStringLegacy(buffer, sizeof(buffer), stringId, rawFt.Data());
|
||||
@@ -624,7 +624,7 @@ namespace OpenRCT2::Ui
|
||||
topLeft = w.windowPos + ScreenCoordsXY{ widget.midX() - 1, std::max<int32_t>(widget.top, widget.midY() - 5) };
|
||||
|
||||
if (widgetIsDisabled(w, widgetIndex))
|
||||
colour.setFlag(ColourFlag::inset, true);
|
||||
colour.flags.set(ColourFlag::inset, true);
|
||||
|
||||
DrawText(rt, topLeft, { colour, TextAlignment::centre }, widget.string);
|
||||
}
|
||||
@@ -652,7 +652,7 @@ namespace OpenRCT2::Ui
|
||||
|
||||
if (widgetIsDisabled(w, widgetIndex))
|
||||
{
|
||||
colour.setFlag(ColourFlag::inset, true);
|
||||
colour.flags.set(ColourFlag::inset, true);
|
||||
}
|
||||
|
||||
// fill it when checkbox is pressed
|
||||
@@ -762,7 +762,7 @@ namespace OpenRCT2::Ui
|
||||
static void WidgetHScrollbarDraw(
|
||||
RenderTarget& rt, const ScrollArea& scroll, int32_t l, int32_t t, int32_t r, int32_t b, ColourWithFlags colour)
|
||||
{
|
||||
colour.setFlag(ColourFlag::translucent, false);
|
||||
colour.flags.set(ColourFlag::translucent, false);
|
||||
|
||||
// Trough
|
||||
Rectangle::fill(rt, { { l + kScrollBarWidth, t }, { r - kScrollBarWidth, b } }, ColourMapA[colour.colour].lighter);
|
||||
@@ -809,7 +809,7 @@ namespace OpenRCT2::Ui
|
||||
static void WidgetVScrollbarDraw(
|
||||
RenderTarget& rt, const ScrollArea& scroll, int32_t l, int32_t t, int32_t r, int32_t b, ColourWithFlags colour)
|
||||
{
|
||||
colour.setFlag(ColourFlag::translucent, false);
|
||||
colour.flags.set(ColourFlag::translucent, false);
|
||||
|
||||
// Trough
|
||||
Rectangle::fill(rt, { { l, t + kScrollBarWidth }, { r, b - kScrollBarWidth } }, ColourMapA[colour.colour].lighter);
|
||||
|
||||
@@ -318,9 +318,9 @@ namespace OpenRCT2::Ui::Windows
|
||||
if (w.type() == DukValue::Type::NUMBER)
|
||||
{
|
||||
colour_t colour = w.as_uint() & ~kLegacyColourFlagTranslucent;
|
||||
auto isTranslucent = (w.as_uint() & kLegacyColourFlagTranslucent);
|
||||
bool isTranslucent = (w.as_uint() & kLegacyColourFlagTranslucent);
|
||||
c.colour = std::clamp<colour_t>(colour, COLOUR_BLACK, COLOUR_COUNT - 1);
|
||||
c.flags = (isTranslucent ? EnumToFlag(ColourFlag::translucent) : 0);
|
||||
c.flags.set(ColourFlag::translucent, isTranslucent);
|
||||
}
|
||||
return c;
|
||||
});
|
||||
@@ -488,7 +488,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
void onPrepareDraw() override
|
||||
{
|
||||
auto& closeButton = widgets[WIDX_CLOSE];
|
||||
bool translucent = colours[closeButton.colour].hasFlag(ColourFlag::translucent);
|
||||
bool translucent = colours[closeButton.colour].flags.has(ColourFlag::translucent);
|
||||
if (Config::Get().interface.enlargedUi)
|
||||
closeButton.string = !translucent ? kCloseBoxStringBlackLarge : kCloseBoxStringWhiteLarge;
|
||||
else
|
||||
|
||||
@@ -238,7 +238,7 @@ namespace OpenRCT2::Scripting
|
||||
for (auto c : w->colours)
|
||||
{
|
||||
auto colour = c.colour;
|
||||
if (c.hasFlag(ColourFlag::translucent))
|
||||
if (c.flags.has(ColourFlag::translucent))
|
||||
colour |= kLegacyColourFlagTranslucent;
|
||||
result.push_back(colour);
|
||||
}
|
||||
@@ -256,9 +256,9 @@ namespace OpenRCT2::Scripting
|
||||
if (i < colours.size())
|
||||
{
|
||||
colour_t colour = colours[i] & ~kLegacyColourFlagTranslucent;
|
||||
auto isTranslucent = (colours[i] & kLegacyColourFlagTranslucent);
|
||||
bool isTranslucent = (colours[i] & kLegacyColourFlagTranslucent);
|
||||
c.colour = std::clamp<colour_t>(colour, COLOUR_BLACK, COLOUR_COUNT - 1);
|
||||
c.flags = (isTranslucent ? EnumToFlag(ColourFlag::translucent) : 0);
|
||||
c.flags.set(ColourFlag::translucent, isTranslucent);
|
||||
}
|
||||
w->colours[i] = c;
|
||||
}
|
||||
|
||||
@@ -608,7 +608,7 @@ static StringId window_cheats_page_titles[] = {
|
||||
ft.Add<money64>(_moneySpinnerValue);
|
||||
if (isWidgetDisabled(WIDX_MONEY_SPINNER))
|
||||
{
|
||||
colour.setFlag(ColourFlag::inset, true);
|
||||
colour.flags.set(ColourFlag::inset, true);
|
||||
}
|
||||
|
||||
auto& widget = widgets[WIDX_MONEY_SPINNER];
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
if (highlighted)
|
||||
colour.colour = COLOUR_WHITE;
|
||||
if (item.isDisabled())
|
||||
colour = { background, EnumToFlag(ColourFlag::inset) };
|
||||
colour = { background, { ColourFlag::inset } };
|
||||
|
||||
auto yOffset = GetAdditionalRowPadding();
|
||||
Formatter ft;
|
||||
@@ -125,7 +125,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
const auto rightBottom = leftTop + ScreenCoordsXY{ ItemWidth - 4, 0 };
|
||||
const auto shadowOffset = ScreenCoordsXY{ 0, 1 };
|
||||
|
||||
if (colours[0].hasFlag(ColourFlag::translucent))
|
||||
if (colours[0].flags.has(ColourFlag::translucent))
|
||||
{
|
||||
TranslucentWindowPalette palette = kTranslucentWindowPalettes[colours[0].colour];
|
||||
Rectangle::filter(rt, { leftTop, rightBottom }, palette.highlight);
|
||||
@@ -231,7 +231,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
UpdateSizeAndPosition(screenPos, extraY);
|
||||
|
||||
if (colour.hasFlag(ColourFlag::translucent))
|
||||
if (colour.flags.has(ColourFlag::translucent))
|
||||
flags |= WindowFlag::transparent;
|
||||
colours[0] = colour;
|
||||
}
|
||||
@@ -264,7 +264,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
UpdateSizeAndPosition(screenPos, extraY);
|
||||
|
||||
if (colour.hasFlag(ColourFlag::translucent))
|
||||
if (colour.flags.has(ColourFlag::translucent))
|
||||
flags |= WindowFlag::transparent;
|
||||
colours[0] = colour;
|
||||
}
|
||||
|
||||
@@ -764,7 +764,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
auto darkness = highlighted ? TextDarkness::extraDark : TextDarkness::dark;
|
||||
auto colour2 = colours[1].withFlag(ColourFlag::translucent, false);
|
||||
if (*listItem.flags & (ObjectSelectionFlags::InUse | ObjectSelectionFlags::AlwaysRequired))
|
||||
colour2.setFlag(ColourFlag::inset, true);
|
||||
colour2.flags.set(ColourFlag::inset, true);
|
||||
|
||||
DrawText(rt, screenCoords, { colour2, FontStyle::medium, darkness }, kCheckMarkString);
|
||||
}
|
||||
|
||||
@@ -702,7 +702,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
else
|
||||
{
|
||||
auto colour = ThemeGetColour(wc, _buttonIndex);
|
||||
colour.setFlag(ColourFlag::translucent, !colour.hasFlag(ColourFlag::translucent));
|
||||
colour.flags.flip(ColourFlag::translucent);
|
||||
ThemeSetColour(wc, _buttonIndex, colour);
|
||||
ColourSchemeUpdateAll();
|
||||
|
||||
@@ -721,7 +721,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
if (_selectedTab == WINDOW_THEMES_TAB_SETTINGS || _selectedTab == WINDOW_THEMES_TAB_FEATURES)
|
||||
return;
|
||||
|
||||
if (!colours[1].hasFlag(ColourFlag::translucent))
|
||||
if (!colours[1].flags.has(ColourFlag::translucent))
|
||||
// Rectangle::fill(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1,
|
||||
// ColourMapA[colours[1].colour].mid_light);
|
||||
GfxClear(rt, ColourMapA[colours[1].colour].mid_light);
|
||||
@@ -759,7 +759,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
screenCoords.y + _max_row_height - colorOffset + 1 };
|
||||
auto yPixelOffset = ScreenCoordsXY{ 0, 1 };
|
||||
|
||||
if (colour.hasFlag(ColourFlag::translucent))
|
||||
if (colour.flags.has(ColourFlag::translucent))
|
||||
{
|
||||
TranslucentWindowPalette windowPalette = kTranslucentWindowPalettes[colour.colour];
|
||||
|
||||
@@ -799,7 +799,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
Rectangle::fillInset(
|
||||
rt, { topLeft, bottomRight }, colours[1], Rectangle::BorderStyle::inset,
|
||||
Rectangle::FillBrightness::dark, Rectangle::FillMode::dontLightenWhenInset);
|
||||
if (colour.hasFlag(ColourFlag::translucent))
|
||||
if (colour.flags.has(ColourFlag::translucent))
|
||||
{
|
||||
DrawText(
|
||||
rt, topLeft, { colours[1].colour, FontStyle::medium, TextDarkness::dark }, kCheckMarkString);
|
||||
|
||||
@@ -754,11 +754,11 @@ static void TTFProcessInitialColour(ColourWithFlags colour, TextDrawInfo* info)
|
||||
if (colour.colour != kTextColour254 && colour.colour != kTextColour255)
|
||||
{
|
||||
info->flags &= ~(TEXT_DRAW_FLAG_INSET | TEXT_DRAW_FLAG_OUTLINE);
|
||||
if (colour.hasFlag(ColourFlag::withOutline))
|
||||
if (colour.flags.has(ColourFlag::withOutline))
|
||||
{
|
||||
info->flags |= TEXT_DRAW_FLAG_OUTLINE;
|
||||
}
|
||||
if (!colour.hasFlag(ColourFlag::inset))
|
||||
if (!colour.flags.has(ColourFlag::inset))
|
||||
{
|
||||
uint16_t flags = info->flags;
|
||||
ColourCharacterWindow(colour.colour, &flags, reinterpret_cast<uint8_t*>(&info->palette));
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRCT2::Drawing::Rectangle
|
||||
const auto leftBottom = ScreenCoordsXY{ rect.GetLeft(), rect.GetBottom() };
|
||||
const auto rightTop = ScreenCoordsXY{ rect.GetRight(), rect.GetTop() };
|
||||
const auto rightBottom = ScreenCoordsXY{ rect.GetRight(), rect.GetBottom() };
|
||||
if (colour.hasFlag(ColourFlag::translucent))
|
||||
if (colour.flags.has(ColourFlag::translucent))
|
||||
{
|
||||
auto palette = kTranslucentWindowPalettes[colour.colour];
|
||||
|
||||
|
||||
@@ -211,23 +211,10 @@ BlendColourMapType* GetBlendColourMap()
|
||||
}
|
||||
#endif
|
||||
|
||||
bool ColourWithFlags::hasFlag(ColourFlag flag) const
|
||||
{
|
||||
return flags & EnumToFlag(flag);
|
||||
}
|
||||
|
||||
void ColourWithFlags::setFlag(ColourFlag flag, bool on)
|
||||
{
|
||||
if (on)
|
||||
flags |= EnumToFlag(flag);
|
||||
else
|
||||
flags &= ~EnumToFlag(flag);
|
||||
}
|
||||
|
||||
ColourWithFlags ColourWithFlags::withFlag(ColourFlag flag, bool on) const
|
||||
{
|
||||
struct ColourWithFlags result = *this;
|
||||
result.setFlag(flag, on);
|
||||
result.flags.set(flag, on);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -236,11 +223,11 @@ ColourWithFlags ColourWithFlags::fromLegacy(uint8_t legacy)
|
||||
ColourWithFlags result{};
|
||||
result.colour = legacy & kLegacyColourMaskBase;
|
||||
if (legacy & kLegacyColourFlagTranslucent)
|
||||
result.flags |= EnumToFlag(ColourFlag::translucent);
|
||||
result.flags.set(ColourFlag::translucent);
|
||||
if (legacy & kLegacyColourFlagInset)
|
||||
result.flags |= EnumToFlag(ColourFlag::inset);
|
||||
result.flags.set(ColourFlag::inset);
|
||||
if (legacy & kLegacyColourFlagOutline)
|
||||
result.flags |= EnumToFlag(ColourFlag::withOutline);
|
||||
result.flags.set(ColourFlag::withOutline);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -248,6 +235,6 @@ ColourWithFlags ColourWithFlags::fromLegacy(uint8_t legacy)
|
||||
ColourWithFlags& ColourWithFlags::operator=(colour_t rhs)
|
||||
{
|
||||
colour = rhs;
|
||||
flags = 0;
|
||||
flags = {};
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../core/FlagHolder.hpp"
|
||||
#include "../core/StringTypes.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -221,15 +222,12 @@ enum class ColourFlag : uint8_t
|
||||
inset,
|
||||
withOutline,
|
||||
};
|
||||
using ColourFlags = FlagHolder<uint8_t, ColourFlag>;
|
||||
|
||||
struct ColourWithFlags
|
||||
{
|
||||
colour_t colour{};
|
||||
uint8_t flags{};
|
||||
|
||||
bool hasFlag(ColourFlag flag) const;
|
||||
|
||||
void setFlag(ColourFlag flag, bool on);
|
||||
ColourFlags flags{};
|
||||
|
||||
ColourWithFlags withFlag(ColourFlag flag, bool on) const;
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace OpenRCT2
|
||||
auto& closeButton = widgets[2];
|
||||
if (closeButton.type == WidgetType::closeBox || closeButton.type == WidgetType::empty)
|
||||
{
|
||||
bool translucent = colours[closeButton.colour].hasFlag(ColourFlag::translucent);
|
||||
bool translucent = colours[closeButton.colour].flags.has(ColourFlag::translucent);
|
||||
repositionCloseButton(closeButton, width, translucent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user