/* ================== MField_CharEvent ================== */ void MField_CharEvent( mfield_t *edit, int ch ) { int i; if ( ch == 'v' - 'a' + 1 ) { // ctrl-v is paste MField_Paste( edit ); return; } if ( ch == 'c' - 'a' + 1 ) { // ctrl-c clears the field MField_Clear( edit ); return; } if ( ch == 'h' - 'a' + 1 ) { // ctrl-h is backspace if ( edit->cursor > 0 ) { for ( i = edit->cursor; i < edit->len+1; i++ ) { edit->buffer[i-1] = edit->buffer[i]; } edit->cursor--; if ( edit->cursor < edit->scroll ) { edit->scroll--; } edit->len--; } return; } if ( ch == 'a' - 'a' + 1 ) { // ctrl-a is home edit->cursor = 0; edit->scroll = 0; return; } if ( ch == 'e' - 'a' + 1 ) { // ctrl-e is end edit->cursor = edit->len; edit->scroll = edit->cursor - edit->widthInChars + 1; if (edit->scroll < 0) edit->scroll = 0; return; } // // ignore any other non printable chars // if ( ch < 32 ) { return; } if ( trap_Key_GetOverstrikeMode() ) { if ((edit->cursor == MAX_EDIT_LINE - 1) || (edit->maxchars && edit->cursor >= edit->maxchars)) return; } else { // insert mode if (( edit->len == MAX_EDIT_LINE - 1 ) || (edit->maxchars && edit->len >= edit->maxchars)) return; for ( i = edit->len + 1; i >= edit->cursor; i-- ) { edit->buffer[i+1] = edit->buffer[i]; } edit->len++; } edit->buffer[edit->cursor] = ch; if (!edit->maxchars || edit->cursor < edit->maxchars-1) edit->cursor++; if ( edit->cursor >= edit->widthInChars ) { edit->scroll++; } if ( edit->cursor == edit->len + 1) { edit->buffer[edit->cursor] = 0; edit->len++; } }
/* ================== MField_CharEvent ================== */ void MField_CharEvent( mfield_t *edit, int ch ) { int len; if ( ch == 'v' - 'a' + 1 ) { // ctrl-v is paste MField_Paste( edit ); return; } if ( ch == 'c' - 'a' + 1 ) { // ctrl-c clears the field MField_Clear( edit ); return; } len = strlen( edit->buffer ); if ( ch == 'h' - 'a' + 1 ) { // ctrl-h is backspace if ( edit->cursor > 0 ) { memmove( edit->buffer + edit->cursor - 1, edit->buffer + edit->cursor, len + 1 - edit->cursor ); edit->cursor--; if ( edit->cursor < edit->scroll ) { edit->scroll--; } } return; } if ( ch == 'a' - 'a' + 1 ) { // ctrl-a is home edit->cursor = 0; edit->scroll = 0; return; } if ( ch == 'e' - 'a' + 1 ) { // ctrl-e is end edit->cursor = len; edit->scroll = edit->cursor - edit->widthInChars + 1; if (edit->scroll < 0) edit->scroll = 0; return; } // // ignore any other non printable chars // if ( ch < 32 ) { return; } if ( !trap_Key_GetOverstrikeMode() ) { if ((edit->cursor == MAX_EDIT_LINE - 1) || (edit->maxchars && edit->cursor >= edit->maxchars)) return; } else { // insert mode if (( len == MAX_EDIT_LINE - 1 ) || (edit->maxchars && len >= edit->maxchars)) return; memmove( edit->buffer + edit->cursor + 1, edit->buffer + edit->cursor, len + 1 - edit->cursor ); } edit->buffer[edit->cursor] = ch; if (!edit->maxchars || edit->cursor < edit->maxchars-1) edit->cursor++; if ( edit->cursor >= edit->widthInChars ) { edit->scroll++; } if ( edit->cursor == len + 1) { edit->buffer[edit->cursor] = 0; } }
/* ================= MField_KeyDownEvent Performs the basic line editing functions for the console, in-game talk, and menu fields Key events are used for non-printable characters, others are gotten from char events. ================= */ void MField_KeyDownEvent( mfield_t *edit, int key ) { // shift-insert is paste if ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && trap_Key_IsDown( K_SHIFT ) ) { MField_Paste( edit ); return; } if ( key == K_DEL || key == K_KP_DEL ) { int i; if ( edit->cursor < edit->len ) { for ( i = edit->cursor; i < edit->len; i++ ) { edit->buffer[i] = edit->buffer[i+1]; } edit->len--; } return; } if ( key == K_RIGHTARROW || key == K_KP_RIGHTARROW ) { if ( edit->cursor < edit->len ) { edit->cursor++; } if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= edit->len ) { edit->scroll++; } return; } if ( key == K_LEFTARROW || key == K_KP_LEFTARROW ) { if ( edit->cursor > 0 ) { edit->cursor--; } if ( edit->cursor < edit->scroll ) { edit->scroll--; } return; } if ( key == K_HOME || key == K_KP_HOME || ( tolower(key) == 'a' && trap_Key_IsDown( K_CTRL ) ) ) { edit->cursor = 0; edit->scroll = 0; return; } if ( key == K_END || key == K_KP_END || ( tolower(key) == 'e' && trap_Key_IsDown( K_CTRL ) ) ) { edit->cursor = edit->len; edit->scroll = edit->len - edit->widthInChars + 1; if (edit->scroll < 0) edit->scroll = 0; return; } if ( key == K_INS || key == K_KP_INS ) { trap_Key_SetOverstrikeMode( !trap_Key_GetOverstrikeMode() ); return; } }
/* ================= MField_KeyDownEvent Performs the basic line editing functions for the console, in-game talk, and menu fields Key events are used for non-printable characters, others are gotten from char events. ================= */ void MField_KeyDownEvent( mfield_t *edit, int key ) { int len; // shift-insert is paste if ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && Key_IsDown( K_SHIFT ) ) { MField_Paste( edit ); return; } len = strlen( edit->buffer ); if ( key == K_DEL || key == K_KP_DEL ) { if ( edit->cursor < len ) { memmove( edit->buffer + edit->cursor, edit->buffer + edit->cursor + 1, len - edit->cursor ); } return; } if ( key == K_RIGHTARROW || key == K_KP_RIGHTARROW ) { if ( edit->cursor < len ) { edit->cursor++; } if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len ) { edit->scroll++; } return; } if ( key == K_LEFTARROW || key == K_KP_LEFTARROW ) { if ( edit->cursor > 0 ) { edit->cursor--; } if ( edit->cursor < edit->scroll ) { edit->scroll--; } return; } if ( key == K_HOME || key == K_KP_HOME || ( tolower(key) == 'a' && Key_IsDown( K_CTRL ) ) ) { edit->cursor = 0; edit->scroll = 0; return; } if ( key == K_END || key == K_KP_END || ( tolower(key) == 'e' && Key_IsDown( K_CTRL ) ) ) { edit->cursor = len; edit->scroll = len - edit->widthInChars + 1; if (edit->scroll < 0) edit->scroll = 0; return; } if ( key == K_INS || key == K_KP_INS ) { Key_SetOverstrikeMode( !Key_GetOverstrikeMode() ); return; } }