summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/cl_keys.c90
1 files changed, 39 insertions, 51 deletions
diff --git a/src/client/cl_keys.c b/src/client/cl_keys.c
index b283ffbc..950cb5b1 100644
--- a/src/client/cl_keys.c
+++ b/src/client/cl_keys.c
@@ -307,7 +307,7 @@ EDIT FIELDS
Field_Draw
Handles horizontal scrolling and cursor blinking
-x, y, amd width are in pixels
+x, y, and width are in pixels
===================
*/
void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, qboolean showCursor ) {
@@ -318,8 +318,8 @@ void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, q
char str[MAX_STRING_CHARS];
int i;
- drawLen = edit->widthInChars;
- len = strlen( edit->buffer ) + 1;
+ drawLen = edit->widthInChars - 1; // - 1 so there is always a space for the cursor
+ len = strlen( edit->buffer );
// guarantee that cursor will be visible
if ( len <= drawLen ) {
@@ -332,14 +332,6 @@ void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, q
}
}
prestep = edit->scroll;
-
-/*
- if ( edit->cursor < len - drawLen ) {
- prestep = edit->cursor; // cursor at start
- } else {
- prestep = len - drawLen;
- }
-*/
}
if ( prestep + drawLen > len ) {
@@ -380,7 +372,7 @@ void Field_VariableSizeDraw( field_t *edit, int x, int y, int width, int size, q
cursorChar = 10;
}
- i = drawLen - ( Q_PrintStrlen( str ) + 1 );
+ i = drawLen - Q_PrintStrlen( str );
if ( size == SMALLCHAR_WIDTH ) {
SCR_DrawSmallChar( x + ( edit->cursor - prestep - i ) * size, y, cursorChar );
@@ -445,54 +437,50 @@ void Field_KeyDownEvent( field_t *edit, int key ) {
return;
}
+ key = tolower( key );
len = strlen( edit->buffer );
- if ( key == K_DEL ) {
- if ( edit->cursor < len ) {
- memmove( edit->buffer + edit->cursor,
- edit->buffer + edit->cursor + 1, len - edit->cursor );
- }
- return;
- }
+ switch ( key ) {
+ case K_DEL:
+ if ( edit->cursor < len ) {
+ memmove( edit->buffer + edit->cursor,
+ edit->buffer + edit->cursor + 1, len - edit->cursor );
+ }
+ break;
- if ( key == K_RIGHTARROW )
- {
- if ( edit->cursor < len ) {
- edit->cursor++;
- }
+ case K_RIGHTARROW:
+ if ( edit->cursor < len ) {
+ edit->cursor++;
+ }
+ break;
- if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len )
- {
- edit->scroll++;
- }
- return;
- }
+ case K_LEFTARROW:
+ if ( edit->cursor > 0 ) {
+ edit->cursor--;
+ }
+ break;
- if ( key == K_LEFTARROW )
- {
- if ( edit->cursor > 0 ) {
- edit->cursor--;
- }
- if ( edit->cursor < edit->scroll )
- {
- edit->scroll--;
- }
- return;
- }
+ case K_HOME:
+ edit->cursor = 0;
+ break;
- if ( key == K_HOME || ( tolower(key) == 'a' && keys[K_CTRL].down ) ) {
- edit->cursor = 0;
- return;
- }
+ case K_END:
+ edit->cursor = len;
+ break;
- if ( key == K_END || ( tolower(key) == 'e' && keys[K_CTRL].down ) ) {
- edit->cursor = len;
- return;
+ case K_INS:
+ key_overstrikeMode = !key_overstrikeMode;
+ break;
+
+ default:
+ break;
}
- if ( key == K_INS ) {
- key_overstrikeMode = !key_overstrikeMode;
- return;
+ // Change scroll if cursor is no longer visible
+ if ( edit->cursor < edit->scroll ) {
+ edit->scroll = edit->cursor;
+ } else if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len ) {
+ edit->scroll = edit->cursor - edit->widthInChars + 1;
}
}