MCPcopy Create free account
hub / github.com/JACoders/OpenJK / Item_TextField_HandleKey

Function Item_TextField_HandleKey

code/ui/ui_shared.cpp:9745–9922  ·  view source on GitHub ↗

================= Item_TextField_HandleKey ================= */

Source from the content-addressed store, hash-verified

9743=================
9744*/
9745qboolean Item_TextField_HandleKey(itemDef_t *item, int key)
9746{
9747 char buff[1024];
9748 int len;
9749 itemDef_t *newItem = NULL;
9750 editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData;
9751
9752 if (item->cvar)
9753 {
9754
9755 memset(buff, 0, sizeof(buff));
9756 DC->getCVarString(item->cvar, buff, sizeof(buff));
9757 len = strlen(buff);
9758 if (editPtr->maxChars && len > editPtr->maxChars)
9759 {
9760 len = editPtr->maxChars;
9761 }
9762
9763 if ( key & K_CHAR_FLAG )
9764 {
9765 key &= ~K_CHAR_FLAG;
9766
9767
9768 if (key == 'h' - 'a' + 1 )
9769 { // ctrl-h is backspace
9770 if ( item->cursorPos > 0 )
9771 {
9772 memmove( &buff[item->cursorPos - 1], &buff[item->cursorPos], len + 1 - item->cursorPos);
9773 item->cursorPos--;
9774 if (item->cursorPos < editPtr->paintOffset)
9775 {
9776 editPtr->paintOffset--;
9777 }
9778 }
9779 DC->setCVar(item->cvar, buff);
9780 return qtrue;
9781 }
9782
9783 //
9784 // ignore any non printable chars
9785 //
9786 if ( key < 32 || !item->cvar)
9787 {
9788 return qtrue;
9789 }
9790
9791 if (item->type == ITEM_TYPE_NUMERICFIELD)
9792 {
9793 if (key < '0' || key > '9')
9794 {
9795 return qfalse;
9796 }
9797 }
9798
9799 if (!DC->getOverstrikeMode())
9800 {
9801 if (( len == MAX_EDITFIELD - 1 ) || (editPtr->maxChars && len >= editPtr->maxChars))
9802 {

Callers 1

Menu_HandleKeyFunction · 0.70

Calls 2

Menu_SetNextCursorItemFunction · 0.70
Menu_SetPrevCursorItemFunction · 0.70

Tested by

no test coverage detected