1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-22 19:54:06 +01:00

Codechange: Use EnumBitSet for WindowFlags.

This commit is contained in:
Peter Nelson
2025-01-29 23:36:47 +00:00
committed by Peter Nelson
parent 248f369e86
commit efb05396a7
21 changed files with 81 additions and 80 deletions

View File

@@ -191,7 +191,7 @@ void WindowDesc::SaveToConfig()
void Window::ApplyDefaults()
{
if (this->nested_root != nullptr && this->nested_root->GetWidgetOfType(WWT_STICKYBOX) != nullptr) {
if (this->window_desc.pref_sticky) this->flags |= WF_STICKY;
if (this->window_desc.pref_sticky) this->flags.Set(WindowFlag::Sticky);
} else {
/* There is no stickybox; clear the preference in case someone tried to be funny */
this->window_desc.pref_sticky = false;
@@ -228,7 +228,7 @@ void Window::DisableAllWidgetHighlight()
}
}
CLRBITS(this->flags, WF_HIGHLIGHTED);
this->flags.Reset(WindowFlag::Highlighted);
}
/**
@@ -246,7 +246,7 @@ void Window::SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_co
if (highlighted_colour != TC_INVALID) {
/* If we set a highlight, the window has a highlight */
this->flags |= WF_HIGHLIGHTED;
this->flags.Set(WindowFlag::Highlighted);
} else {
/* If we disable a highlight, check all widgets if anyone still has a highlight */
bool valid = false;
@@ -257,7 +257,7 @@ void Window::SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_co
valid = true;
}
/* If nobody has a highlight, disable the flag on the window */
if (!valid) CLRBITS(this->flags, WF_HIGHLIGHTED);
if (!valid) this->flags.Reset(WindowFlag::Highlighted);
}
}
@@ -708,9 +708,9 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
return;
case WWT_STICKYBOX:
w->flags ^= WF_STICKY;
w->flags.Flip(WindowFlag::Sticky);
nw->SetDirty(w);
if (_ctrl_pressed) w->window_desc.pref_sticky = (w->flags & WF_STICKY) != 0;
if (_ctrl_pressed) w->window_desc.pref_sticky = w->flags.Test(WindowFlag::Sticky);
return;
default:
@@ -750,7 +750,7 @@ static void DispatchRightClickEvent(Window *w, int x, int y)
/* Right-click close is enabled and there is a closebox. */
if (_settings_client.gui.right_click_wnd_close == RCC_YES && (w->window_desc.flags & WDF_NO_CLOSE) == 0) {
w->Close();
} else if (_settings_client.gui.right_click_wnd_close == RCC_YES_EXCEPT_STICKY && (w->flags & WF_STICKY) == 0 && (w->window_desc.flags & WDF_NO_CLOSE) == 0) {
} else if (_settings_client.gui.right_click_wnd_close == RCC_YES_EXCEPT_STICKY && !w->flags.Test(WindowFlag::Sticky) && (w->window_desc.flags & WDF_NO_CLOSE) == 0) {
/* Right-click close is enabled, but excluding sticky windows. */
w->Close();
} else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->GetIndex(), TCC_RIGHT_CLICK) && wid->GetToolTip() != STR_NULL) {
@@ -1137,7 +1137,7 @@ Window *GetMainWindow()
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
{
Window *w = FindWindowById(cls, number);
if (w != nullptr && (force || (w->flags & WF_STICKY) == 0)) {
if (w != nullptr && (force || !w->flags.Test(WindowFlag::Sticky))) {
w->Close(data);
}
}
@@ -1363,7 +1363,7 @@ void Window::InitializeData(WindowNumber window_number)
/* Set up window properties; some of them are needed to set up smallest size below */
this->window_class = this->window_desc.cls;
this->SetWhiteBorder();
if (this->window_desc.default_pos == WDP_CENTER) this->flags |= WF_CENTERED;
if (this->window_desc.default_pos == WDP_CENTER) this->flags.Set(WindowFlag::Centred);
this->owner = INVALID_OWNER;
this->nested_focus = nullptr;
this->window_number = window_number;
@@ -1848,8 +1848,8 @@ static void DecreaseWindowCounters()
}
for (Window *w : Window::Iterate()) {
if ((w->flags & WF_TIMEOUT) && --w->timeout_timer == 0) {
CLRBITS(w->flags, WF_TIMEOUT);
if (w->flags.Test(WindowFlag::Timeout) && --w->timeout_timer == 0) {
w->flags.Reset(WindowFlag::Timeout);
w->OnTimeout();
w->RaiseButtons(true);
@@ -2089,10 +2089,10 @@ static EventState HandleWindowDragging()
/* Otherwise find the window... */
for (Window *w : Window::Iterate()) {
if (w->flags & WF_DRAGGING) {
if (w->flags.Test(WindowFlag::Dragging)) {
/* Stop the dragging if the left mouse button was released */
if (!_left_button_down) {
w->flags &= ~WF_DRAGGING;
w->flags.Reset(WindowFlag::Dragging);
break;
}
@@ -2181,10 +2181,11 @@ static EventState HandleWindowDragging()
w->SetDirty();
return ES_HANDLED;
} else if (w->flags & WF_SIZING) {
} else if (w->flags.Test(WindowFlag::SizingLeft) || w->flags.Test(WindowFlag::SizingRight)) {
/* Stop the sizing if the left mouse button was released */
if (!_left_button_down) {
w->flags &= ~WF_SIZING;
w->flags.Reset(WindowFlag::SizingLeft);
w->flags.Reset(WindowFlag::SizingRight);
w->SetDirty();
break;
}
@@ -2193,7 +2194,7 @@ static EventState HandleWindowDragging()
* If resizing the left edge of the window, moving to the left makes the window bigger not smaller.
*/
int x, y = _cursor.pos.y - _drag_delta.y;
if (w->flags & WF_SIZING_LEFT) {
if (w->flags.Test(WindowFlag::SizingLeft)) {
x = _drag_delta.x - _cursor.pos.x;
} else {
x = _cursor.pos.x - _drag_delta.x;
@@ -2227,7 +2228,7 @@ static EventState HandleWindowDragging()
/* Now find the new cursor pos.. this is NOT _cursor, because we move in steps. */
_drag_delta.y += y;
if ((w->flags & WF_SIZING_LEFT) && x != 0) {
if (w->flags.Test(WindowFlag::SizingLeft) && x != 0) {
_drag_delta.x -= x; // x > 0 -> window gets longer -> left-edge moves to left -> subtract x to get new position.
w->SetDirty();
w->left -= x; // If dragging left edge, move left window edge in opposite direction by the same amount.
@@ -2252,8 +2253,8 @@ static EventState HandleWindowDragging()
*/
static void StartWindowDrag(Window *w)
{
w->flags |= WF_DRAGGING;
w->flags &= ~WF_CENTERED;
w->flags.Set(WindowFlag::Dragging);
w->flags.Reset(WindowFlag::Centred);
_dragging_window = true;
_drag_delta.x = w->left - _cursor.pos.x;
@@ -2269,8 +2270,8 @@ static void StartWindowDrag(Window *w)
*/
static void StartWindowSizing(Window *w, bool to_left)
{
w->flags |= to_left ? WF_SIZING_LEFT : WF_SIZING_RIGHT;
w->flags &= ~WF_CENTERED;
w->flags.Set(to_left ? WindowFlag::SizingLeft : WindowFlag::SizingRight);
w->flags.Reset(WindowFlag::Centred);
_dragging_window = true;
_drag_delta.x = _cursor.pos.x;
@@ -2677,7 +2678,7 @@ static void HandleAutoscroll()
int x = _cursor.pos.x;
int y = _cursor.pos.y;
Window *w = FindWindowFromPt(x, y);
if (w == nullptr || w->flags & WF_DISABLE_VP_SCROLL) return;
if (w == nullptr || w->flags.Test(WindowFlag::DisableVpScroll)) return;
if (_settings_client.gui.auto_scrolling != VA_EVERY_VIEWPORT && w->window_class != WC_MAIN_WINDOW) return;
Viewport *vp = IsPtInWindowViewport(w, x, y);
@@ -2815,7 +2816,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
}
if (vp != nullptr) {
if (scrollwheel_scrolling && !(w->flags & WF_DISABLE_VP_SCROLL)) {
if (scrollwheel_scrolling && !w->flags.Test(WindowFlag::DisableVpScroll)) {
_scrolling_viewport = true;
_cursor.fix_at = true;
return;
@@ -2825,7 +2826,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
case MC_DOUBLE_LEFT:
case MC_LEFT:
if (HandleViewportClicked(vp, x, y)) return;
if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
if (!w->flags.Test(WindowFlag::DisableVpScroll) &&
_settings_client.gui.scroll_mode == VSM_MAP_LMB) {
_scrolling_viewport = true;
_cursor.fix_at = false;
@@ -2834,7 +2835,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
break;
case MC_RIGHT:
if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
if (!w->flags.Test(WindowFlag::DisableVpScroll) &&
_settings_client.gui.scroll_mode != VSM_MAP_LMB) {
_scrolling_viewport = true;
_cursor.fix_at = (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED ||
@@ -2970,7 +2971,7 @@ static void CheckSoftLimit()
uint deletable_count = 0;
Window *last_deletable = nullptr;
for (Window *w : Window::IterateFromFront()) {
if (w->window_class == WC_MAIN_WINDOW || IsVitalWindow(w) || (w->flags & WF_STICKY)) continue;
if (w->window_class == WC_MAIN_WINDOW || IsVitalWindow(w) || w->flags.Test(WindowFlag::Sticky)) continue;
last_deletable = w;
deletable_count++;
@@ -3040,8 +3041,8 @@ static IntervalTimer<TimerWindow> white_border_interval(std::chrono::millisecond
if (_network_dedicated) return;
for (Window *w : Window::Iterate()) {
if ((w->flags & WF_WHITE_BORDER) && --w->white_border_timer == 0) {
CLRBITS(w->flags, WF_WHITE_BORDER);
if (w->flags.Test(WindowFlag::WhiteBorder) && --w->white_border_timer == 0) {
w->flags.Reset(WindowFlag::WhiteBorder);
w->SetDirty();
}
}
@@ -3180,7 +3181,7 @@ void Window::ProcessScheduledInvalidations()
*/
void Window::ProcessHighlightedInvalidations()
{
if ((this->flags & WF_HIGHLIGHTED) == 0) return;
if (!this->flags.Test(WindowFlag::Highlighted)) return;
for (const auto &pair : this->widget_lookup) {
if (pair.second->IsHighlighted()) pair.second->SetDirty(this);
@@ -3260,7 +3261,7 @@ void CloseNonVitalWindows()
/* Note: the container remains stable, even when deleting windows. */
for (Window *w : Window::Iterate()) {
if ((w->window_desc.flags & WDF_NO_CLOSE) == 0 &&
(w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
!w->flags.Test(WindowFlag::Sticky)) { // do not delete windows which are 'pinned'
w->Close();
}
@@ -3494,7 +3495,7 @@ void RelocateAllWindows(int neww, int newh)
continue;
default: {
if (w->flags & WF_CENTERED) {
if (w->flags.Test(WindowFlag::Centred)) {
top = (newh - w->height) >> 1;
left = (neww - w->width) >> 1;
break;