/** * @brief Set the focus to the next action node * @note Action nodes are nodes with click defined * @sa Key_Event * @sa UI_FocusExecuteActionNode */ static bool UI_FocusNextActionNode (void) { #if 0 /**< @todo need a cleanup */ static int i = UI_MAX_WINDOWSTACK + 1; /* to cycle between all windows */ if (IN_GetMouseSpace() != MS_UI) return false; if (UI_GetMouseCapture()) return false; if (i >= ui_global.windowStackPos) i = UI_GetLastFullScreenWindow(); assert(i >= 0); if (focusNode) { uiNode_t* node = UI_GetNextActionNode(focusNode); if (node) return UI_FocusSetNode(node); } while (i < ui_global.windowStackPos) { uiNode_t* window; window = ui_global.windowStack[i++]; if (UI_FocusSetNode(UI_GetNextActionNode(window->firstChild))) return true; } i = UI_GetLastFullScreenWindow(); /* no node to focus */ UI_RemoveFocus(); #endif return false; }
/** * @brief Called by the client when the user type a key * @param[in] key key code, either K_ value or lowercase ascii * @param[in] unicode translated meaning of keypress in unicode * @return true, if we used the event * @todo think about what we should do when the mouse is captured */ bool UI_KeyPressed (unsigned int key, unsigned short unicode) { int windowId; int lastWindowId; if (UI_DNDIsDragging()) { if (key == K_ESCAPE) UI_DNDAbort(); return false; } if (key == K_ESCAPE && CL_BattlescapeRunning() && selActor && CL_ActorFireModeActivated(selActor->actorMode)) { /* Cancel firing with Escape, needed for Android, where right mouse click is bound to multitouch, which is non-obvious */ CL_ActorSetMode(selActor, M_MOVE); return true; } /* translate event into the node with focus */ if (focusNode && UI_Node_KeyPressed(focusNode, key, unicode)) { return true; } /* else use common behaviour */ switch (key) { case K_TAB: if (UI_FocusNextActionNode()) return true; break; case K_ENTER: case K_KP_ENTER: if (UI_FocusExecuteActionNode()) return true; break; case K_ESCAPE: if (UI_GetMouseCapture() != nullptr) { UI_MouseRelease(); return true; } UI_PopWindowWithEscKey(); return true; } lastWindowId = UI_GetLastFullScreenWindow(); if (lastWindowId < 0) return false; /* check "active" window from top to down */ for (windowId = ui_global.windowStackPos - 1; windowId >= lastWindowId; windowId--) { const uiNode_t* window = ui_global.windowStack[windowId]; if (!window) return false; if (UI_KeyPressedInWindow(key, window)) return true; if (UI_WindowIsModal(window)) break; } return false; }
/** * @brief Called by the client when the user type a key * @param[in] key key code, either K_ value or lowercase ascii * @param[in] unicode translated meaning of keypress in unicode * @return true, if we used the event * @todo think about what we should do when the mouse is captured */ bool UI_KeyPressed (unsigned int key, unsigned short unicode) { int windowId; int lastWindowId; if (UI_DNDIsDragging()) { if (key == K_ESCAPE) UI_DNDAbort(); return false; } /* translate event into the node with focus */ if (focusNode && UI_Node_KeyPressed(focusNode, key, unicode)) { return true; } /* else use common behaviour */ switch (key) { case K_TAB: if (UI_FocusNextActionNode()) return true; break; case K_ENTER: case K_KP_ENTER: if (UI_FocusExecuteActionNode()) return true; break; case K_ESCAPE: if (UI_GetMouseCapture() != NULL) { UI_MouseRelease(); return true; } UI_PopWindowWithEscKey(); return true; } lastWindowId = UI_GetLastFullScreenWindow(); if (lastWindowId < 0) return false; /* check "active" window from top to down */ for (windowId = ui_global.windowStackPos - 1; windowId >= lastWindowId; windowId--) { const uiNode_t *window = ui_global.windowStack[windowId]; if (!window) return false; if (UI_KeyPressedInWindow(key, window)) return true; if (UI_WindowIsModal(window)) break; } return false; }