mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
Codechange: Use EnumBitSet for ViewportStringFlags.
This commit is contained in:
parent
05ac1dd888
commit
4b573b2703
@ -122,7 +122,7 @@ void DrawTextEffects(DrawPixelInfo *dpi)
|
||||
if (IsTransparencySet(TO_TEXT)) return;
|
||||
|
||||
ViewportStringFlags flags{};
|
||||
if (dpi->zoom >= ZOOM_LVL_TEXT_EFFECT) flags |= ViewportStringFlags::Small;
|
||||
if (dpi->zoom >= ZOOM_LVL_TEXT_EFFECT) flags.Set(ViewportStringFlag::Small);
|
||||
|
||||
for (const TextEffect &te : _text_effects) {
|
||||
if (te.string_id == INVALID_STRING_ID) continue;
|
||||
|
@ -1324,7 +1324,7 @@ std::string *ViewportAddString(const DrawPixelInfo *dpi, const ViewportSign *sig
|
||||
int right = left + dpi->width;
|
||||
int bottom = top + dpi->height;
|
||||
|
||||
bool small = HasFlag(flags, ViewportStringFlags::Small);
|
||||
bool small = flags.Test(ViewportStringFlag::Small);
|
||||
int sign_height = ScaleByZoom(WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(small ? FS_SMALL : FS_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom, dpi->zoom);
|
||||
int sign_half_width = ScaleByZoom((small ? sign->width_small : sign->width_normal) / 2, dpi->zoom);
|
||||
|
||||
@ -1362,7 +1362,7 @@ static Rect ExpandRectWithViewportSignMargins(Rect r, ZoomLevel zoom)
|
||||
static void ViewportAddTownStrings(DrawPixelInfo *dpi, const std::vector<const Town *> &towns, bool small)
|
||||
{
|
||||
ViewportStringFlags flags{};
|
||||
if (small) flags = ViewportStringFlags::Small | ViewportStringFlags::Shadow;
|
||||
if (small) flags.Set(ViewportStringFlag::Small).Set(ViewportStringFlag::Shadow);
|
||||
|
||||
StringID stringid = !small && _settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_TOWN_NAME;
|
||||
for (const Town *t : towns) {
|
||||
@ -1384,11 +1384,11 @@ static void ViewportAddTownStrings(DrawPixelInfo *dpi, const std::vector<const T
|
||||
static void ViewportAddSignStrings(DrawPixelInfo *dpi, const std::vector<const Sign *> &signs, bool small)
|
||||
{
|
||||
ViewportStringFlags flags{};
|
||||
if (small) flags = ViewportStringFlags::Small;
|
||||
if (small) flags.Set(ViewportStringFlag::Small);
|
||||
|
||||
/* Signs placed by a game script don't have a frame. */
|
||||
ViewportStringFlags deity_flags{flags};
|
||||
flags |= IsTransparencySet(TO_SIGNS) ? ViewportStringFlags::TransparentRect : ViewportStringFlags::ColourRect;
|
||||
flags.Set(IsTransparencySet(TO_SIGNS) ? ViewportStringFlag::TransparentRect : ViewportStringFlag::ColourRect);
|
||||
|
||||
for (const Sign *si : signs) {
|
||||
std::string *str = ViewportAddString(dpi, &si->sign, (si->owner == OWNER_DEITY) ? deity_flags : flags,
|
||||
@ -1409,8 +1409,8 @@ static void ViewportAddSignStrings(DrawPixelInfo *dpi, const std::vector<const S
|
||||
static void ViewportAddStationStrings(DrawPixelInfo *dpi, const std::vector<const BaseStation *> &stations, bool small)
|
||||
{
|
||||
/* Transparent station signs have colour text instead of a colour panel. */
|
||||
ViewportStringFlags flags{IsTransparencySet(TO_SIGNS) ? ViewportStringFlags::TextColour : ViewportStringFlags::ColourRect};
|
||||
if (small) flags = ViewportStringFlags::Small;
|
||||
ViewportStringFlags flags{IsTransparencySet(TO_SIGNS) ? ViewportStringFlag::TextColour : ViewportStringFlag::ColourRect};
|
||||
if (small) flags.Set(ViewportStringFlag::Small);
|
||||
|
||||
for (const BaseStation *st : stations) {
|
||||
std::string *str = ViewportAddString(dpi, &st->sign, flags, (st->owner == OWNER_NONE || !st->IsInUse()) ? COLOUR_GREY : _company_colours[st->owner]);
|
||||
@ -1764,21 +1764,21 @@ static void ViewportDrawDirtyBlocks()
|
||||
static void ViewportDrawStrings(ZoomLevel zoom, const StringSpriteToDrawVector *sstdv)
|
||||
{
|
||||
for (const StringSpriteToDraw &ss : *sstdv) {
|
||||
bool small = HasFlag(ss.flags, ViewportStringFlags::Small);
|
||||
bool small = ss.flags.Test(ViewportStringFlag::Small);
|
||||
int w = ss.width;
|
||||
int x = UnScaleByZoom(ss.x, zoom);
|
||||
int y = UnScaleByZoom(ss.y, zoom);
|
||||
int h = WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(small ? FS_SMALL : FS_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom;
|
||||
|
||||
TextColour colour = TC_WHITE;
|
||||
if (HasFlag(ss.flags, ViewportStringFlags::ColourRect)) {
|
||||
if (ss.flags.Test(ViewportStringFlag::ColourRect)) {
|
||||
if (ss.colour != INVALID_COLOUR) DrawFrameRect(x, y, x + w - 1, y + h - 1, ss.colour, FR_NONE);
|
||||
colour = TC_BLACK;
|
||||
} else if (HasFlag(ss.flags, ViewportStringFlags::TransparentRect)) {
|
||||
} else if (ss.flags.Test(ViewportStringFlag::TransparentRect)) {
|
||||
DrawFrameRect(x, y, x + w - 1, y + h - 1, ss.colour, FR_TRANSPARENT);
|
||||
}
|
||||
|
||||
if (HasFlag(ss.flags, ViewportStringFlags::TextColour)) {
|
||||
if (ss.flags.Test(ViewportStringFlag::TextColour)) {
|
||||
if (ss.colour != INVALID_COLOUR) colour = static_cast<TextColour>(GetColourGradient(ss.colour, SHADE_LIGHTER) | TC_IS_PALETTE_COLOUR);
|
||||
}
|
||||
|
||||
@ -1787,7 +1787,7 @@ static void ViewportDrawStrings(ZoomLevel zoom, const StringSpriteToDrawVector *
|
||||
int top = y + WidgetDimensions::scaled.fullbevel.top;
|
||||
|
||||
int shadow_offset = 0;
|
||||
if (small && HasFlag(ss.flags, ViewportStringFlags::Shadow)) {
|
||||
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, FS_SMALL);
|
||||
|
@ -18,14 +18,14 @@
|
||||
class LinkGraphOverlay;
|
||||
|
||||
/** Flags to control how Viewport Strings are rendered. */
|
||||
enum class ViewportStringFlags : uint8_t {
|
||||
Small = (1U << 0), ///< Draw using the small font.
|
||||
Shadow = (1U << 1), ///< Draw an extra text shadow. Should only be used with ViewportStringFlags::Small, as normal font already has a shadow.
|
||||
ColourRect = (1U << 2), ///< Draw a colour rect around the sign.
|
||||
TransparentRect = (1U << 3), ///< Draw a transparent rect around the sign.
|
||||
TextColour = (1U << 4), ///< Draw text in colour.
|
||||
enum class ViewportStringFlag : uint8_t {
|
||||
Small, ///< Draw using the small font.
|
||||
Shadow, ///< Draw an extra text shadow. Should only be used with ViewportStringFlag::Small, as normal font already has a shadow.
|
||||
ColourRect, ///< Draw a colour rect around the sign.
|
||||
TransparentRect, ///< Draw a transparent rect around the sign.
|
||||
TextColour, ///< Draw text in colour.
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(ViewportStringFlags)
|
||||
using ViewportStringFlags = EnumBitSet<ViewportStringFlag, uint8_t>;
|
||||
|
||||
/**
|
||||
* Data structure for viewport, display of a part of the world
|
||||
|
Loading…
Reference in New Issue
Block a user