tweaked console scrolling (binds and speed), fixed the clamping and the backtick insertion on Windows

This commit is contained in:
myT 2017-01-23 07:33:53 +01:00
parent 9b350a7d0c
commit 0f89ca6853
5 changed files with 61 additions and 33 deletions

View file

@ -49,6 +49,8 @@ struct console_t {
int linewidth; // characters across screen
int totallines; // total lines in console scrollback
int rowsVisible; // number of full rows that can currently be rendered in a page
float displayFrac; // approaches finalFrac at con_speed
float finalFrac; // 0.0 to 1.0 lines of console to display
@ -539,6 +541,7 @@ static void Con_DrawSolidConsole( float frac )
char color = COLOR_WHITE;
re.SetColor( ColorFromChar( color ) );
con.rowsVisible = 0;
for (i = 0; i < rows; ++i, --row, y -= con.ch )
{
if (row < 0)
@ -548,6 +551,9 @@ static void Con_DrawSolidConsole( float frac )
continue;
}
if (y >= 0)
con.rowsVisible++;
const short* text = con.text + (row % con.totallines)*con.linewidth;
re.SetColor( colorBlack );
@ -627,24 +633,33 @@ void Con_RunConsole()
}
static const int CON_PAGELINES = 4;
void Con_PageUp()
static void Con_FixPosition()
{
con.display -= CON_PAGELINES;
if ( con.current - con.display >= con.totallines ) {
con.display = con.current - con.totallines + 1;
}
}
void Con_PageDown()
{
con.display += CON_PAGELINES;
if (con.display > con.current) {
if ( con.display < con.totallines ) {
con.display = con.totallines;
} else if ( con.display > con.current ) {
con.display = con.current;
}
}
void Con_ScrollLines( int lines )
{
if (lines == 0)
return;
con.display += lines;
Con_FixPosition();
}
void Con_ScrollPages( int pages )
{
if (pages == 0)
return;
// we allow a single line of overlap for readability
con.display += pages * (con.rowsVisible - 1);
Con_FixPosition();
}
void Con_Top()
{

View file

@ -498,8 +498,8 @@ static void Console_Key( int key )
// command history (ctrl-p ctrl-n for unix style)
if ( (key == K_MWHEELUP && keys[K_SHIFT].down) || ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ||
( ( tolower(key) == 'p' ) && keys[K_CTRL].down ) ) {
if ( ( key == K_UPARROW ) ||
( ( tolower(key) == 'p' ) && keys[K_CTRL].down ) ) {
if ( nextHistoryLine - historyLine < COMMAND_HISTORY
&& historyLine > 0 ) {
historyLine--;
@ -508,8 +508,8 @@ static void Console_Key( int key )
return;
}
if ( (key == K_MWHEELDOWN && keys[K_SHIFT].down) || ( key == K_DOWNARROW ) || ( key == K_KP_DOWNARROW ) ||
( ( tolower(key) == 'n' ) && keys[K_CTRL].down ) ) {
if ( ( key == K_DOWNARROW ) ||
( ( tolower(key) == 'n' ) && keys[K_CTRL].down ) ) {
historyLine++;
if (historyLine >= nextHistoryLine) {
historyLine = nextHistoryLine;
@ -521,22 +521,30 @@ static void Console_Key( int key )
return;
}
// console scrolling (faster if +CTRL)
if ((key == K_PGUP) || (key == K_MWHEELUP)) {
Con_PageUp();
if (keys[K_CTRL].down) {
Con_PageUp();
Con_PageUp();
}
// console scrolling (faster if +SHIFT)
if ( key == K_MWHEELUP ) {
Con_ScrollLines( keys[K_SHIFT].down ? -6 : -2 );
return;
}
if ((key == K_PGDN) || (key == K_MWHEELDOWN)) {
Con_PageDown();
if (keys[K_CTRL].down) {
Con_PageDown();
Con_PageDown();
}
if ( key == K_MWHEELDOWN ) {
Con_ScrollLines( keys[K_SHIFT].down ? 6 : 2 );
return;
}
if ( key == K_PGUP ) {
if ( keys[K_SHIFT].down )
Con_ScrollPages( -1 );
else
Con_ScrollLines( -6 );
return;
}
if ( key == K_PGDN ) {
if ( keys[K_SHIFT].down )
Con_ScrollPages( 1 );
else
Con_ScrollLines( 6 );
return;
}

View file

@ -415,8 +415,8 @@ void Con_ToggleConsole_f( void );
void Con_ClearNotify();
void Con_RunConsole();
void Con_DrawConsole();
void Con_PageUp();
void Con_PageDown();
void Con_ScrollLines( int lines ); // positive means down
void Con_ScrollPages( int pages ); // positive means down
void Con_Top();
void Con_Bottom();
void Con_Close();

View file

@ -525,6 +525,7 @@ static void Cvar_List_f( void )
Com_Printf( (var->flags & CVAR_ARCHIVE) ? "A" : " " );
Com_Printf( (var->flags & CVAR_LATCH) ? "L" : " " );
Com_Printf( (var->flags & CVAR_CHEAT) ? "C" : " " );
Com_Printf( (var->flags & CVAR_USER_CREATED) ? "?" : " " );
Com_Printf(" %s \"%s\"\n", var->name, var->string);
}

View file

@ -321,7 +321,11 @@ LRESULT CALLBACK MainWndProc (
break;
case WM_CHAR:
Sys_QueEvent( g_wv.sysMsgTime, SE_CHAR, wParam, 0, 0, NULL );
{
const char scanCode = (char)( ( lParam >> 16 ) & 0xFF );
if ( scanCode != 0x29 ) // never send an event for the console key ('~' or '`')
Sys_QueEvent( g_wv.sysMsgTime, SE_CHAR, wParam, 0, 0, NULL );
}
break;
default: