/** * @brief Release all captured input (keyboard or mouse) */ void UI_ReleaseInput (void) { UI_RemoveFocus(); UI_MouseRelease(); if (UI_DNDIsDragging()) UI_DNDAbort(); }
void uiContainerNode::onMouseDown (uiNode_t *node, int x, int y, int button) { switch (button) { case K_MOUSE1: { /* start drag and drop */ int fromX, fromY; dragInfoIC = UI_ContainerNodeGetItemAtPosition(node, x, y, &fromX, &fromY); if (dragInfoIC) { dragInfoFromX = fromX; dragInfoFromY = fromY; oldMouseX = x; oldMouseY = y; UI_SetMouseCapture(node); EXTRADATA(node).lastSelectedId = dragInfoIC->item.item->idx; if (EXTRADATA(node).onSelect) { UI_ExecuteEventActions(node, EXTRADATA(node).onSelect); } } break; } case K_MOUSE2: if (UI_DNDIsDragging()) { UI_DNDAbort(); } else { /* auto place */ UI_ContainerNodeAutoPlace(node, x, y); } break; default: break; } }
/** * @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; }
/** * @brief Drop the object at the current position * @sa UI_DNDStartDrag * @sa UI_DNDAbort */ void UI_DNDDrop (void) { bool result = false; assert(UI_DNDIsDragging()); assert(objectType != DND_NOTHING); assert(sourceNode != nullptr); if (!positionAcceptDND) { UI_DNDAbort(); return; } if (targetNode) { result = UI_Node_DndDrop(targetNode, mousePosX, mousePosY); } UI_Node_DndFinished(sourceNode, result); UI_PlaySound("item-drop"); UI_DNDCleanup(); UI_InvalidateMouse(); }