Add support for a long input line when we decide to enable it

This commit is contained in:
michaelangel007 2023-04-16 16:47:33 -07:00
parent 589b1ada56
commit ea269a381f

View File

@ -1246,8 +1246,10 @@ void DrawConsoleCursor ()
int nLineHeight = GetConsoleLineHeightPixels();
int y = 0;
const int nInputWidth = min( g_nConsoleInputChars, g_nConsoleInputScrollWidth ); // NOTE: Keep in Sync! DrawConsoleInput() and DrawConsoleCursor()
RECT rect;
rect.left = (g_nConsoleInputChars + g_nConsolePromptLen) * nWidth;
rect.left = (nInputWidth + g_nConsolePromptLen) * nWidth;
rect.top = GetConsoleTopPixels( y );
rect.bottom = rect.top + nLineHeight; //g_nFontHeight;
rect.right = rect.left + nWidth;
@ -1295,9 +1297,31 @@ void DrawConsoleInput ()
RECT rect;
GetConsoleRect( 0, rect );
// Console background is drawn in DrawWindowBackground_Info
// DrawConsoleLine( g_aConsoleInput, 0 );
PrintText( g_aConsoleInput, rect );
// For long input only show last g_nConsoleInputScrollWidth characters
if (g_nConsoleInputChars > g_nConsoleInputScrollWidth)
{
assert(g_nConsoleInputScrollWidth <= CONSOLE_WIDTH); // NOTE: To support a wider input line the size of g_aConsoleInput[] must be increased
// g_nConsoleInputMaxLen = 16;
// g_nConsoleInputScrollWidth = 10;
//
// 123456789ABCDEF g_aConsoleInput[]
// ^ g_nConsoleInputChars = 15
// [--------] g_nConsoleInputScrollWidth = 10
// >6789ABCDEF_ g_nConsoleInputMaxLen = 16
static char aScrollingInput[ CONSOLE_WIDTH+1 ];
aScrollingInput[0] = g_aConsoleInput[0]; // 1. SOL
const int nInputOffset = g_nConsoleInputChars - g_nConsoleInputScrollWidth ; // 2. Middle
const int nInputWidth = min( g_nConsoleInputChars, g_nConsoleInputScrollWidth ); // NOTE: Keep in Sync! DrawConsoleInput() and DrawConsoleCursor()
strncpy( aScrollingInput+1, g_aConsoleInput + 1 + nInputOffset, nInputWidth ); // +1 to skip prompt
aScrollingInput[ g_nConsoleInputScrollWidth+1 ] = 0; // 3. EOL leave room for cursor
PrintText( aScrollingInput, rect );
}
else
PrintText( g_aConsoleInput, rect );
}