/** * @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 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; }