[iortcw] 280/497: All: Add arrow key support for win32 console

Simon McVittie smcv at debian.org
Fri Sep 8 10:37:07 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.42d
in repository iortcw.

commit 003495132477f9bb1f89ca9b4e026cdc985be82b
Author: M4N4T4RMS at gmail.com <M4N4T4RMS at gmail.com@e65d2741-a53d-b2dc-ae96-bb75fa5e4c4a>
Date:   Tue Jan 27 20:39:02 2015 +0000

    All: Add arrow key support for win32 console
---
 MP/code/sys/con_win32.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-----
 SP/code/sys/con_win32.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 126 insertions(+), 14 deletions(-)

diff --git a/MP/code/sys/con_win32.c b/MP/code/sys/con_win32.c
index 454012e..e273ff0 100644
--- a/MP/code/sys/con_win32.c
+++ b/MP/code/sys/con_win32.c
@@ -44,6 +44,7 @@ static int qconsole_history_oldest = 0;
 static char qconsole_line[ MAX_EDIT_LINE ];
 static int qconsole_linelen = 0;
 static qboolean qconsole_drawinput = qtrue;
+static int qconsole_cursor;
 
 static HANDLE qconsole_hout;
 static HANDLE qconsole_hin;
@@ -139,6 +140,7 @@ static void CON_HistPrev( void )
 	Q_strncpyz( qconsole_line, qconsole_history[ qconsole_history_pos ], 
 		sizeof( qconsole_line ) );
 	qconsole_linelen = strlen( qconsole_line );
+	qconsole_cursor = qconsole_linelen;
 }
 
 /*
@@ -163,6 +165,7 @@ static void CON_HistNext( void )
 		qconsole_history_pos = pos;
 		qconsole_line[ 0 ] = '\0';
 		qconsole_linelen = 0;
+		qconsole_cursor = qconsole_linelen;
 		return;
 	}
 
@@ -170,6 +173,7 @@ static void CON_HistNext( void )
 	Q_strncpyz( qconsole_line, qconsole_history[ qconsole_history_pos ],
 		sizeof( qconsole_line ) );
 	qconsole_linelen = strlen( qconsole_line );
+	qconsole_cursor = qconsole_linelen;
 }
 
 
@@ -233,7 +237,11 @@ static void CON_Show( void )
 
 	// set curor position
 	cursorPos.Y = binfo.dwCursorPosition.Y;
-	cursorPos.X = qconsole_linelen > binfo.srWindow.Right ? binfo.srWindow.Right : qconsole_linelen;
+	cursorPos.X = qconsole_cursor < qconsole_linelen
+					? qconsole_cursor
+					: qconsole_linelen > binfo.srWindow.Right
+						? binfo.srWindow.Right
+						: qconsole_linelen;
 
 	SetConsoleCursorPosition( qconsole_hout, cursorPos );
 }
@@ -358,6 +366,7 @@ char *CON_Input( void )
 		if( key == VK_RETURN )
 		{
 			newlinepos = i;
+			qconsole_cursor = 0;
 			break;
 		}
 		else if( key == VK_UP )
@@ -370,6 +379,34 @@ char *CON_Input( void )
 			CON_HistNext();
 			break;
 		}
+		else if( key == VK_LEFT )
+		{
+			qconsole_cursor--;
+			if ( qconsole_cursor < 0 )
+			{
+				qconsole_cursor = 0;
+			}
+			break;
+		}
+		else if( key == VK_RIGHT )
+		{
+			qconsole_cursor++;
+			if ( qconsole_cursor > qconsole_linelen )
+			{
+				qconsole_cursor = qconsole_linelen;
+			}
+			break;
+		}
+		else if( key == VK_HOME )
+		{
+			qconsole_cursor = 0;
+			break;
+		}
+		else if( key == VK_END )
+		{
+			qconsole_cursor = qconsole_linelen;
+			break;
+		}
 		else if( key == VK_TAB )
 		{
 			field_t f;
@@ -380,6 +417,7 @@ char *CON_Input( void )
 			Q_strncpyz( qconsole_line, f.buffer,
 				sizeof( qconsole_line ) );
 			qconsole_linelen = strlen( qconsole_line );
+			qconsole_cursor = qconsole_linelen;
 			break;
 		}
 
@@ -389,15 +427,33 @@ char *CON_Input( void )
 
 			if( key == VK_BACK )
 			{
-				int pos = ( qconsole_linelen > 0 ) ?
-					qconsole_linelen - 1 : 0; 
-
-				qconsole_line[ pos ] = '\0';
-				qconsole_linelen = pos;
+				if ( qconsole_cursor > 0 )
+				{
+					int newlen = ( qconsole_linelen > 0 ) ? qconsole_linelen - 1 : 0;
+					if ( qconsole_cursor < qconsole_linelen )
+					{
+						memmove( qconsole_line + qconsole_cursor - 1,
+									qconsole_line + qconsole_cursor,
+									qconsole_linelen - qconsole_cursor );
+					}
+
+					qconsole_line[ newlen ] = '\0';
+					qconsole_linelen = newlen;
+					qconsole_cursor--;
+				}
 			}
 			else if( c )
 			{
-				qconsole_line[ qconsole_linelen++ ] = c;
+				if ( qconsole_linelen > qconsole_cursor )
+				{
+					memmove( qconsole_line + qconsole_cursor + 1,
+								qconsole_line + qconsole_cursor,
+								qconsole_linelen - qconsole_cursor );
+				}
+
+				qconsole_line[ qconsole_cursor++ ] = c;
+
+				qconsole_linelen++;
 				qconsole_line[ qconsole_linelen ] = '\0'; 
 			}
 		}
diff --git a/SP/code/sys/con_win32.c b/SP/code/sys/con_win32.c
index 454012e..e273ff0 100644
--- a/SP/code/sys/con_win32.c
+++ b/SP/code/sys/con_win32.c
@@ -44,6 +44,7 @@ static int qconsole_history_oldest = 0;
 static char qconsole_line[ MAX_EDIT_LINE ];
 static int qconsole_linelen = 0;
 static qboolean qconsole_drawinput = qtrue;
+static int qconsole_cursor;
 
 static HANDLE qconsole_hout;
 static HANDLE qconsole_hin;
@@ -139,6 +140,7 @@ static void CON_HistPrev( void )
 	Q_strncpyz( qconsole_line, qconsole_history[ qconsole_history_pos ], 
 		sizeof( qconsole_line ) );
 	qconsole_linelen = strlen( qconsole_line );
+	qconsole_cursor = qconsole_linelen;
 }
 
 /*
@@ -163,6 +165,7 @@ static void CON_HistNext( void )
 		qconsole_history_pos = pos;
 		qconsole_line[ 0 ] = '\0';
 		qconsole_linelen = 0;
+		qconsole_cursor = qconsole_linelen;
 		return;
 	}
 
@@ -170,6 +173,7 @@ static void CON_HistNext( void )
 	Q_strncpyz( qconsole_line, qconsole_history[ qconsole_history_pos ],
 		sizeof( qconsole_line ) );
 	qconsole_linelen = strlen( qconsole_line );
+	qconsole_cursor = qconsole_linelen;
 }
 
 
@@ -233,7 +237,11 @@ static void CON_Show( void )
 
 	// set curor position
 	cursorPos.Y = binfo.dwCursorPosition.Y;
-	cursorPos.X = qconsole_linelen > binfo.srWindow.Right ? binfo.srWindow.Right : qconsole_linelen;
+	cursorPos.X = qconsole_cursor < qconsole_linelen
+					? qconsole_cursor
+					: qconsole_linelen > binfo.srWindow.Right
+						? binfo.srWindow.Right
+						: qconsole_linelen;
 
 	SetConsoleCursorPosition( qconsole_hout, cursorPos );
 }
@@ -358,6 +366,7 @@ char *CON_Input( void )
 		if( key == VK_RETURN )
 		{
 			newlinepos = i;
+			qconsole_cursor = 0;
 			break;
 		}
 		else if( key == VK_UP )
@@ -370,6 +379,34 @@ char *CON_Input( void )
 			CON_HistNext();
 			break;
 		}
+		else if( key == VK_LEFT )
+		{
+			qconsole_cursor--;
+			if ( qconsole_cursor < 0 )
+			{
+				qconsole_cursor = 0;
+			}
+			break;
+		}
+		else if( key == VK_RIGHT )
+		{
+			qconsole_cursor++;
+			if ( qconsole_cursor > qconsole_linelen )
+			{
+				qconsole_cursor = qconsole_linelen;
+			}
+			break;
+		}
+		else if( key == VK_HOME )
+		{
+			qconsole_cursor = 0;
+			break;
+		}
+		else if( key == VK_END )
+		{
+			qconsole_cursor = qconsole_linelen;
+			break;
+		}
 		else if( key == VK_TAB )
 		{
 			field_t f;
@@ -380,6 +417,7 @@ char *CON_Input( void )
 			Q_strncpyz( qconsole_line, f.buffer,
 				sizeof( qconsole_line ) );
 			qconsole_linelen = strlen( qconsole_line );
+			qconsole_cursor = qconsole_linelen;
 			break;
 		}
 
@@ -389,15 +427,33 @@ char *CON_Input( void )
 
 			if( key == VK_BACK )
 			{
-				int pos = ( qconsole_linelen > 0 ) ?
-					qconsole_linelen - 1 : 0; 
-
-				qconsole_line[ pos ] = '\0';
-				qconsole_linelen = pos;
+				if ( qconsole_cursor > 0 )
+				{
+					int newlen = ( qconsole_linelen > 0 ) ? qconsole_linelen - 1 : 0;
+					if ( qconsole_cursor < qconsole_linelen )
+					{
+						memmove( qconsole_line + qconsole_cursor - 1,
+									qconsole_line + qconsole_cursor,
+									qconsole_linelen - qconsole_cursor );
+					}
+
+					qconsole_line[ newlen ] = '\0';
+					qconsole_linelen = newlen;
+					qconsole_cursor--;
+				}
 			}
 			else if( c )
 			{
-				qconsole_line[ qconsole_linelen++ ] = c;
+				if ( qconsole_linelen > qconsole_cursor )
+				{
+					memmove( qconsole_line + qconsole_cursor + 1,
+								qconsole_line + qconsole_cursor,
+								qconsole_linelen - qconsole_cursor );
+				}
+
+				qconsole_line[ qconsole_cursor++ ] = c;
+
+				qconsole_linelen++;
 				qconsole_line[ qconsole_linelen ] = '\0'; 
 			}
 		}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git



More information about the Pkg-games-commits mailing list