MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / OnDropdownClose

Method OnDropdownClose

src/window.cpp:286–308  ·  view source on GitHub ↗

* A dropdown window associated to this window has been closed. * @param pt the point inside the window the mouse resides on after closure. * @param widget the widget (button) that the dropdown is associated with. * @param index the element in the dropdown that is selected. * @param instant_close whether the dropdown was configured to close on mouse up. */

Source from the content-addressed store, hash-verified

284 * @param instant_close whether the dropdown was configured to close on mouse up.
285 */
286void Window::OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close)
287{
288 if (widget < 0) return;
289
290 /* Many dropdown selections depend on the position of the main toolbar,
291 * so if it doesn't exist (e.g. the end screen has appeared), just skip the instant close behaviour. */
292 if (instant_close && FindWindowById(WC_MAIN_TOOLBAR, 0) != nullptr) {
293 /* Send event for selected option if we're still
294 * on the parent button of the dropdown (behaviour of the dropdowns in the main toolbar). */
295 if (GetWidgetFromPos(this, pt.x, pt.y) == widget) {
296 this->OnDropdownSelect(widget, index, click_result);
297 }
298 }
299
300 /* Raise the dropdown button */
301 NWidgetCore *nwi2 = this->GetWidget<NWidgetCore>(widget);
302 if ((nwi2->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
303 nwi2->disp_flags.Reset(NWidgetDisplayFlag::DropdownActive);
304 } else {
305 this->RaiseWidget(widget);
306 }
307 this->SetWidgetDirty(widget);
308}
309
310/**
311 * Return the Scrollbar to a widget index.

Callers 1

CloseMethod · 0.45

Calls 6

OnDropdownSelectMethod · 0.95
RaiseWidgetMethod · 0.95
SetWidgetDirtyMethod · 0.95
FindWindowByIdFunction · 0.85
GetWidgetFromPosFunction · 0.85
ResetMethod · 0.45

Tested by

no test coverage detected