示例#1
0
/**
 * @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;
}
示例#2
0
/**
 * @brief Return the first visible node at a position
 */
uiNode_t *UI_GetNodeAtPosition (int x, int y)
{
	int pos;

	/* find the first window under the mouse */
	for (pos = ui_global.windowStackPos - 1; pos >= 0; pos--) {
		uiNode_t *window = ui_global.windowStack[pos];
		uiNode_t *find;

		/* update the layout */
		UI_Validate(window);

		find = UI_GetNodeInTreeAtPosition(window, x, y);
		if (find)
			return find;

		/* we must not search anymore */
		if (UI_WindowIsDropDown(window))
			break;
		if (UI_WindowIsModal(window))
			break;
		if (UI_WindowIsFullScreen(window))
			break;
	}

	return NULL;
}
示例#3
0
/**
 * @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;
}