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

Method OnHotkey

src/window.cpp:572–590  ·  view source on GitHub ↗

* A hotkey has been pressed. * @param hotkey Hotkey index, by default a widget index of a button or editbox. * @return #ES_HANDLED if the key press has been handled, and the hotkey is not unavailable for some reason. */

Source from the content-addressed store, hash-verified

570 * @return #ES_HANDLED if the key press has been handled, and the hotkey is not unavailable for some reason.
571 */
572EventState Window::OnHotkey(int hotkey)
573{
574 if (hotkey < 0) return ES_NOT_HANDLED;
575
576 NWidgetCore *nw = this->GetWidget<NWidgetCore>(hotkey);
577 if (nw == nullptr || nw->IsDisabled()) return ES_NOT_HANDLED;
578
579 if (nw->type == WWT_EDITBOX) {
580 if (this->IsShaded()) return ES_NOT_HANDLED;
581
582 /* Focus editbox */
583 this->SetFocusedWidget(hotkey);
584 SetFocusedWindow(this);
585 } else {
586 /* Click button */
587 this->OnClick(Point(), hotkey, 1);
588 }
589 return ES_HANDLED;
590}
591
592/**
593 * Do all things to make a button look clicked and mark it to be

Calls 5

IsShadedMethod · 0.95
SetFocusedWidgetMethod · 0.95
OnClickMethod · 0.95
SetFocusedWindowFunction · 0.85
IsDisabledMethod · 0.80

Tested by

no test coverage detected