Beispiel #1
0
/**
 * @brief Called when we press a key when the node got the focus
 * @return True, if we use the event
 */
static qboolean UI_TextEntryNodeKeyPressed (uiNode_t *node, unsigned int key, unsigned short unicode)
{
    switch (key) {
    /* remove the last char */
    case K_BACKSPACE:
        UI_TextEntryNodeEdit(node, K_BACKSPACE);
        return qtrue;
    /* cancel the edition */
    case K_ESCAPE:
        isAborted = qtrue;
        UI_RemoveFocus();
        return qtrue;
    /* validate the edition */
    case K_ENTER:
    case K_KP_ENTER:
        UI_TextEntryNodeValidateEdition(node);
        UI_RemoveFocus();
        return qtrue;
    }

    /* non printable */
    if (unicode < 32 || (unicode >= 127 && unicode < 192))
        return qfalse;

    /* add a char */
    UI_TextEntryNodeEdit(node, unicode);
    return qtrue;
}
/**
 * @brief Called when the node got the focus
 */
void uiTextEntryNode::onFocusGained (uiNode_t* node)
{
	assert(editedCvar == nullptr);
	/* skip '*cvar ' */
	const char* cvarRef = "*cvar:";
	editedCvar = Cvar_Get(&((const char*)node->text)[strlen(cvarRef)]);
	assert(editedCvar);
	Q_strncpyz(cvarValueBackup, editedCvar->string, sizeof(cvarValueBackup));
	isAborted = false;
	EXTRADATA(node).cursorPosition = UTF8_strlen(editedCvar->string);

#if SDL_VERSION_ATLEAST(2,0,0)
	SDL_StartTextInput();
	vec2_t pos;
	UI_GetNodeAbsPos(node, pos);
	SDL_Rect r = {static_cast<int>(pos[0]), static_cast<int>(pos[1]), static_cast<int>(node->box.size[0]), static_cast<int>(node->box.size[1])};
	SDL_SetTextInputRect(&r);
#else
#ifdef ANDROID
	char buf[MAX_CVAR_EDITING_LENGTH];
	Q_strncpyz(buf, editedCvar->string, sizeof(buf));
	SDL_ANDROID_GetScreenKeyboardTextInput(buf, sizeof(buf));
	Cvar_ForceSet(editedCvar->name, buf);
	UI_TextEntryNodeValidateEdition(node);
	UI_RemoveFocus();
#endif
#endif
}
Beispiel #3
0
/**
 * @brief Called when the node lost the focus
 */
static void UI_TextEntryFocusLost (uiNode_t *node)
{
    /* already aborted/changed with the keyboard */
    if (editedCvar == NULL)
        return;

    /* release the keyboard */
    if (isAborted || EXTRADATA(node).clickOutAbort) {
        UI_TextEntryNodeAbortEdition(node);
    } else {
        UI_TextEntryNodeValidateEdition(node);
    }
}
/**
 * @brief Called when we press a key when the node got the focus
 * @return True, if we use the event
 */
bool uiTextEntryNode::onKeyPressed (uiNode_t* node, unsigned int key, unsigned short unicode)
{
	switch (key) {
	/* remove the last char. */
	case K_BACKSPACE:
		UI_TextEntryNodeEdit(node, K_BACKSPACE);
		return true;
	/* cancel the edition */
	case K_ESCAPE:
		isAborted = true;
		UI_RemoveFocus();
		return true;
	/* validate the edition */
	case K_ENTER:
	case K_KP_ENTER:
		UI_TextEntryNodeValidateEdition(node);
		UI_RemoveFocus();
		return true;
	case K_LEFTARROW:
	case K_KP_LEFTARROW:
		if (EXTRADATA(node).cursorPosition > 0)
			EXTRADATA(node).cursorPosition--;
		return true;
	case K_RIGHTARROW:
	case K_KP_RIGHTARROW:
		if (EXTRADATA(node).cursorPosition < UTF8_strlen(editedCvar->string))
			EXTRADATA(node).cursorPosition++;
		return true;
	case K_HOME:
	case K_KP_HOME:
		EXTRADATA(node).cursorPosition = 0;
		return true;
	case K_END:
	case K_KP_END:
		EXTRADATA(node).cursorPosition = UTF8_strlen(editedCvar->string);
		return true;
	case K_DEL:
	case K_KP_DEL:
		UI_TextEntryNodeEdit(node, K_DEL);
		return true;
	}

	/* non printable */
	if (unicode < 32 || (unicode >= 127 && unicode < 192))
		return false;

	/* add a char. */
	UI_TextEntryNodeEdit(node, unicode);
	return true;
}
/**
 * @brief Called when the node lost the focus
 */
void uiTextEntryNode::onFocusLost (uiNode_t* node)
{
	/* already aborted/changed with the keyboard */
	if (editedCvar == nullptr)
		return;

	/* release the keyboard */
	if (isAborted || EXTRADATA(node).clickOutAbort) {
		UI_TextEntryNodeAbortEdition(node);
	} else {
		UI_TextEntryNodeValidateEdition(node);
	}
#if SDL_VERSION_ATLEAST(2,0,0)
	SDL_StopTextInput();
#endif
}