From 760cd803c5e0cff046e7a34e158d8889c2335130 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 14 Jun 2026 20:39:03 +0200 Subject: [PATCH] Codechange: make TooltipCloseCondition scoped --- src/depot_gui.cpp | 4 ++-- src/misc_gui.cpp | 8 ++++---- src/viewport.cpp | 2 +- src/window.cpp | 8 ++++---- src/window_gui.h | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 34945184a1..a0e3a4b3b7 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -917,9 +917,9 @@ struct DepotWindow : Window { /* Show tooltip window */ if (whole_chain) { - GuiShowTooltips(this, GetEncodedString(STR_DEPOT_VEHICLE_TOOLTIP_CHAIN, num, details), TCC_RIGHT_CLICK); + GuiShowTooltips(this, GetEncodedString(STR_DEPOT_VEHICLE_TOOLTIP_CHAIN, num, details), TooltipCloseCondition::RightClick); } else { - GuiShowTooltips(this, GetEncodedString(STR_DEPOT_VEHICLE_TOOLTIP, v->engine_type, details), TCC_RIGHT_CLICK); + GuiShowTooltips(this, GetEncodedString(STR_DEPOT_VEHICLE_TOOLTIP, v->engine_type, details), TooltipCloseCondition::RightClick); } return true; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 4d5a64e586..5579907224 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -668,11 +668,11 @@ struct TooltipsWindow : public Window /* We can show tooltips while dragging tools. These are shown as long as * we are dragging the tool. Normal tooltips work with hover or rmb. */ switch (this->close_cond) { - case TCC_RIGHT_CLICK: if (!_right_button_down) this->Close(); break; - case TCC_HOVER: if (!_mouse_hovering) this->Close(); break; - case TCC_NONE: break; + case TooltipCloseCondition::RightClick: if (!_right_button_down) this->Close(); break; + case TooltipCloseCondition::Hover: if (!_mouse_hovering) this->Close(); break; + case TooltipCloseCondition::None: break; - case TCC_EXIT_VIEWPORT: { + case TooltipCloseCondition::ExitViewport: { Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); if (w == nullptr || IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y) == nullptr) this->Close(); break; diff --git a/src/viewport.cpp b/src/viewport.cpp index a855d8f44d..5e296497c7 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2789,7 +2789,7 @@ void UpdateTileSelection() static inline void ShowMeasurementTooltips(EncodedString &&text) { if (!_settings_client.gui.measure_tooltip) return; - GuiShowTooltips(_thd.GetCallbackWnd(), std::move(text), TCC_EXIT_VIEWPORT); + GuiShowTooltips(_thd.GetCallbackWnd(), std::move(text), TooltipCloseCondition::ExitViewport); } static void HideMeasurementTooltips() diff --git a/src/window.cpp b/src/window.cpp index f7c942e5d0..97391e47f6 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -782,8 +782,8 @@ static void DispatchRightClickEvent(Window *w, int x, int y) } else if (_settings_client.gui.right_click_wnd_close == RightClickClose::YesExceptSticky && !w->flags.Test(WindowFlag::Sticky) && !w->window_desc.flags.Test(WindowDefaultFlag::NoClose)) { /* 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) { - GuiShowTooltips(w, GetEncodedString(wid->GetToolTip()), TCC_RIGHT_CLICK); + } else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->GetIndex(), TooltipCloseCondition::RightClick) && wid->GetToolTip() != STR_NULL) { + GuiShowTooltips(w, GetEncodedString(wid->GetToolTip()), TooltipCloseCondition::RightClick); } } @@ -803,8 +803,8 @@ static void DispatchHoverEvent(Window *w, int x, int y) Point pt = { x, y }; /* Show the tooltip if there is any */ - if (!w->OnTooltip(pt, wid->GetIndex(), TCC_HOVER) && wid->GetToolTip() != STR_NULL) { - GuiShowTooltips(w, GetEncodedString(wid->GetToolTip()), TCC_HOVER); + if (!w->OnTooltip(pt, wid->GetIndex(), TooltipCloseCondition::Hover) && wid->GetToolTip() != STR_NULL) { + GuiShowTooltips(w, GetEncodedString(wid->GetToolTip()), TooltipCloseCondition::Hover); return; } diff --git a/src/window_gui.h b/src/window_gui.h index 7a9d4b6161..fc7db8ceb3 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -259,12 +259,12 @@ struct ViewportData : Viewport { struct QueryString; -/* misc_gui.cpp */ -enum TooltipCloseCondition : uint8_t { - TCC_RIGHT_CLICK, - TCC_HOVER, - TCC_NONE, - TCC_EXIT_VIEWPORT, +/* Automatic closing conditions for tooltips. */ +enum class TooltipCloseCondition : uint8_t { + RightClick, ///< Close the tooltip when releasing the right mouse button. + Hover, ///< Close the tooltip when stopping to hovering, i.e. moving the mouse. + None, ///< Do not automatically close the tooltip. + ExitViewport, ///< Close the tooltip when leaving the viewport. }; /**