1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 08:52:40 +01:00

Codechange: Add HasFlag() to test if a value is present in a bitset enum type. (#12959)

This simplifies tests for `(x & y) != y` with enum classes by reducing repetition, similar to HasBit(), and also makes the intent of the expression clearer.
This commit is contained in:
Peter Nelson
2024-09-22 14:51:37 +01:00
committed by GitHub
parent d450d4743e
commit 376e882a14
8 changed files with 37 additions and 25 deletions

View File

@@ -932,8 +932,8 @@ void NWidgetBase::ApplyAspectRatio()
uint x = this->smallest_x;
uint y = this->smallest_y;
if ((this->aspect_flags & AspectFlags::ResizeX) == AspectFlags::ResizeX) x = std::max(this->smallest_x, static_cast<uint>(this->smallest_y * std::abs(this->aspect_ratio)));
if ((this->aspect_flags & AspectFlags::ResizeY) == AspectFlags::ResizeY) y = std::max(this->smallest_y, static_cast<uint>(this->smallest_x / std::abs(this->aspect_ratio)));
if (HasFlag(this->aspect_flags, AspectFlags::ResizeX)) x = std::max(this->smallest_x, static_cast<uint>(this->smallest_y * std::abs(this->aspect_ratio)));
if (HasFlag(this->aspect_flags, AspectFlags::ResizeY)) y = std::max(this->smallest_y, static_cast<uint>(this->smallest_x / std::abs(this->aspect_ratio)));
this->smallest_x = x;
this->smallest_y = y;