From dfe499248f1b1236487156b28e4a535d7963fe35 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Wed, 27 Aug 2008 15:48:50 +0000 Subject: major commit. game client restructure. not complete, loads of stuff not working, but the structure is there --- src/game/client/lineinput.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/game/client/lineinput.cpp (limited to 'src/game/client/lineinput.cpp') diff --git a/src/game/client/lineinput.cpp b/src/game/client/lineinput.cpp new file mode 100644 index 00000000..7a02d1f9 --- /dev/null +++ b/src/game/client/lineinput.cpp @@ -0,0 +1,65 @@ +#include +#include // strlen +#include "lineinput.hpp" + +LINEINPUT::LINEINPUT() +{ + clear(); +} + +void LINEINPUT::clear() +{ + mem_zero(str, sizeof(str)); + len = 0; + cursor_pos = 0; +} + +void LINEINPUT::set(const char *string) +{ + str_copy(str, string, sizeof(str)); + len = strlen(str); + cursor_pos = len; +} + +void LINEINPUT::process_input(INPUT_EVENT e) +{ + if(cursor_pos > len) + cursor_pos = len; + + char c = e.ch; + int k = e.key; + + if (!(c >= 0 && c < 32)) + { + if (len < sizeof(str) - 1 && cursor_pos < sizeof(str) - 1) + { + memmove(str + cursor_pos + 1, str + cursor_pos, len - cursor_pos + 1); + str[cursor_pos] = c; + cursor_pos++; + len++; + } + } + + if(e.flags&INPFLAG_PRESS) + { + if (k == KEY_BACKSPACE && cursor_pos > 0) + { + memmove(str + cursor_pos - 1, str + cursor_pos, len - cursor_pos + 1); + cursor_pos--; + len--; + } + else if (k == KEY_DEL && cursor_pos < len) + { + memmove(str + cursor_pos, str + cursor_pos + 1, len - cursor_pos); + len--; + } + else if (k == KEY_LEFT && cursor_pos > 0) + cursor_pos--; + else if (k == KEY_RIGHT && cursor_pos < len) + cursor_pos++; + else if (k == KEY_HOME) + cursor_pos = 0; + else if (k == KEY_END) + cursor_pos = len; + } +} -- cgit 1.4.1