diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 944ad703b9..5192bd8741 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -817,19 +817,19 @@ static const WindowDesc _tool_tips_desc( /** Window for displaying a tooltip. */ struct TooltipsWindow : public Window { - StringID string_id; ///< String to display as tooltip. - byte paramcount; ///< Number of string parameters in #string_id. - uint64 params[5]; ///< The string parameters. - bool use_left_mouse_button; ///< Wait for left mouse button to close window (else, wait for right button). + StringID string_id; ///< String to display as tooltip. + byte paramcount; ///< Number of string parameters in #string_id. + uint64 params[5]; ///< The string parameters. + TooltipCloseCondition close_cond; ///< Condition for closing the window. - TooltipsWindow(StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button) : Window() + TooltipsWindow(StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip) : Window() { this->string_id = str; assert_compile(sizeof(this->params[0]) == sizeof(params[0])); assert(paramcount <= lengthof(this->params)); memcpy(this->params, params, sizeof(this->params[0]) * paramcount); this->paramcount = paramcount; - this->use_left_mouse_button = use_left_mouse_button; + this->close_cond = close_tooltip; this->InitNested(&_tool_tips_desc); @@ -891,7 +891,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 rmb */ - if (this->use_left_mouse_button ? !_left_button_down : !_right_button_down) delete this; + switch (this->close_cond) { + case TCC_RIGHT_CLICK: if (!_right_button_down) delete this; break; + case TCC_LEFT_CLICK: if (!_left_button_down) delete this; break; + case TCC_HOVER: if (!_mouse_hovering) delete this; break; + } } }; @@ -901,13 +905,13 @@ struct TooltipsWindow : public Window * @param params (optional) up to 5 pieces of additional information that may be added to a tooltip * @param use_left_mouse_button close the tooltip when the left (true) or right (false) mousebutton is released */ -void GuiShowTooltips(StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button) +void GuiShowTooltips(StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip) { DeleteWindowById(WC_TOOLTIPS, 0); if (str == STR_NULL) return; - new TooltipsWindow(str, paramcount, params, use_left_mouse_button); + new TooltipsWindow(str, paramcount, params, close_tooltip); } /* Delete a character at the caret position in a text buf. diff --git a/src/viewport.cpp b/src/viewport.cpp index a3e2e6fe86..5852881f3d 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2039,7 +2039,7 @@ void UpdateTileSelection() static inline void ShowMeasurementTooltips(StringID str, uint paramcount, const uint64 params[]) { if (!_settings_client.gui.measure_tooltip) return; - GuiShowTooltips(str, paramcount, params, true); + GuiShowTooltips(str, paramcount, params, TCC_LEFT_CLICK); } /** highlighting tiles while only going over them with the mouse */ diff --git a/src/window_gui.h b/src/window_gui.h index 7fc0ebe720..6a882647bb 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -894,7 +894,13 @@ Wcls *AllocateWindowDescFront(const WindowDesc *desc, int window_number) void RelocateAllWindows(int neww, int newh); /* misc_gui.cpp */ -void GuiShowTooltips(StringID str, uint paramcount = 0, const uint64 params[] = NULL, bool use_left_mouse_button = false); +enum TooltipCloseCondition { + TCC_RIGHT_CLICK, + TCC_LEFT_CLICK, + TCC_HOVER, +}; + +void GuiShowTooltips(StringID str, uint paramcount = 0, const uint64 params[] = NULL, TooltipCloseCondition close_tooltip = TCC_RIGHT_CLICK); /* widget.cpp */ int GetWidgetFromPos(const Window *w, int x, int y);