about summary refs log tree commit diff
path: root/src/game/client/lineinput.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/client/lineinput.cpp')
-rw-r--r--src/game/client/lineinput.cpp107
1 files changed, 56 insertions, 51 deletions
diff --git a/src/game/client/lineinput.cpp b/src/game/client/lineinput.cpp
index f8c9d7e7..f1159caf 100644
--- a/src/game/client/lineinput.cpp
+++ b/src/game/client/lineinput.cpp
@@ -1,85 +1,90 @@
-#include <engine/e_client_interface.h>
-#include <string.h> // strlen
-#include "lineinput.hpp"
+#include <engine/keys.h>
+#include "lineinput.h"
 
-LINEINPUT::LINEINPUT()
+CLineInput::CLineInput()
 {
-	clear();
+	Clear();
 }
 
-void LINEINPUT::clear()
+void CLineInput::Clear()
 {
-	mem_zero(str, sizeof(str));
-	len = 0;
-	cursor_pos = 0;
+	mem_zero(m_Str, sizeof(m_Str));
+	m_Len = 0;
+	m_CursorPos = 0;
 }
 
-void LINEINPUT::set(const char *string)
+void CLineInput::Set(const char *pString)
 {
-	str_copy(str, string, sizeof(str));
-	len = strlen(str);
-	cursor_pos = len;
+	str_copy(m_Str, pString, sizeof(m_Str));
+	m_Len = str_length(m_Str);
+	m_CursorPos = m_Len;
 }
 
-void LINEINPUT::manipulate(INPUT_EVENT e, char *str, int str_max_size, int *str_len_ptr, int *cursor_pos_ptr)
+bool CLineInput::Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int *pStrLenPtr, int *pCursorPosPtr)
 {
-	int cursor_pos = *cursor_pos_ptr;
-	int len = *str_len_ptr;
+	int CursorPos = *pCursorPosPtr;
+	int Len = *pStrLenPtr;
+	bool Changes = false;
 	
-	if(cursor_pos > len)
-		cursor_pos = len;
+	if(CursorPos > Len)
+		CursorPos = Len;
 	
-	int code = e.unicode;
-	int k = e.key;
+	int Code = e.m_Unicode;
+	int k = e.m_Key;
 	
 	// 127 is produced on Mac OS X and corresponds to the delete key
-	if (!(code >= 0 && code < 32) && code != 127)
+	if (!(Code >= 0 && Code < 32) && Code != 127)
 	{
-		char tmp[8];
-		int charsize = str_utf8_encode(tmp, code);
+		char Tmp[8];
+		int CharSize = str_utf8_encode(Tmp, Code);
 		
-		if (len < str_max_size - charsize && cursor_pos < str_max_size - charsize)
+		if (Len < StrMaxSize - CharSize && CursorPos < StrMaxSize - CharSize)
 		{
-			memmove(str + cursor_pos + charsize, str + cursor_pos, len - cursor_pos + charsize);
-			for(int i = 0; i < charsize; i++)
-				str[cursor_pos+i] = tmp[i];
-			cursor_pos += charsize;
-			len += charsize;
+			mem_move(pStr + CursorPos + CharSize, pStr + CursorPos, Len - CursorPos + CharSize);
+			for(int i = 0; i < CharSize; i++)
+				pStr[CursorPos+i] = Tmp[i];
+			CursorPos += CharSize;
+			Len += CharSize;
+			Changes = true;
 		}
 	}
 	
-	if(e.flags&INPFLAG_PRESS)
+	if(e.m_Flags&IInput::FLAG_PRESS)
 	{
-		if (k == KEY_BACKSPACE && cursor_pos > 0)
+		if (k == KEY_BACKSPACE && CursorPos > 0)
 		{
-			int new_cursor_pos = str_utf8_rewind(str, cursor_pos);
-			int charsize = cursor_pos-new_cursor_pos;
-			memmove(str+new_cursor_pos, str+cursor_pos, len - charsize + 1); // +1 == null term
-			cursor_pos = new_cursor_pos;
-			len -= charsize;
+			int NewCursorPos = str_utf8_rewind(pStr, CursorPos);
+			int CharSize = CursorPos-NewCursorPos;
+			mem_move(pStr+NewCursorPos, pStr+CursorPos, Len - NewCursorPos - CharSize + 1); // +1 == null term
+			CursorPos = NewCursorPos;
+			Len -= CharSize;
+			Changes = true;
 		}
-		else if (k == KEY_DELETE && cursor_pos < len)
+		else if (k == KEY_DELETE && CursorPos < Len)
 		{
-			int p = str_utf8_forward(str, cursor_pos);
-			int charsize = p-cursor_pos;
-			memmove(str + cursor_pos, str + cursor_pos + charsize, len - cursor_pos - charsize + 1); // +1 == null term
-			len -= charsize;
+			int p = str_utf8_forward(pStr, CursorPos);
+			int CharSize = p-CursorPos;
+			mem_move(pStr + CursorPos, pStr + CursorPos + CharSize, Len - CursorPos - CharSize + 1); // +1 == null term
+			Len -= CharSize;
+			Changes = true;
 		}
-		else if (k == KEY_LEFT && cursor_pos > 0)
-			cursor_pos = str_utf8_rewind(str, cursor_pos);
-		else if (k == KEY_RIGHT && cursor_pos < len)
-			cursor_pos = str_utf8_forward(str, cursor_pos);
+		else if (k == KEY_LEFT && CursorPos > 0)
+			CursorPos = str_utf8_rewind(pStr, CursorPos);
+		else if (k == KEY_RIGHT && CursorPos < Len)
+			CursorPos = str_utf8_forward(pStr, CursorPos);
 		else if (k == KEY_HOME)
-			cursor_pos = 0;
+			CursorPos = 0;
 		else if (k == KEY_END)
-			cursor_pos = len;
+			CursorPos = Len;
 	}
 	
-	*cursor_pos_ptr = cursor_pos;
-	*str_len_ptr = len;
+	*pCursorPosPtr = CursorPos;
+	*pStrLenPtr = Len;
+
+	return Changes;
 }
 
-void LINEINPUT::process_input(INPUT_EVENT e)
+void CLineInput::ProcessInput(IInput::CEvent e)
 {
-	manipulate(e, str, sizeof(str), &len, &cursor_pos);
+	Manipulate(e, m_Str, sizeof(m_Str), &m_Len, &m_CursorPos);
 }