fixed color handling and cursor position in console/messagemode input buffers

This commit is contained in:
myT 2017-12-19 03:23:45 +01:00
parent 0f3598820c
commit 945cf03af5
6 changed files with 42 additions and 60 deletions

View file

@ -1,6 +1,10 @@
DD Mmm 17 - 1.49
fix: console/messagemode input buffers would sometimes display the cursor at the wrong position
chg: console/messagemode input buffers now display the "^" character of color codes
fix: taking screenshots with a render width (r_width) that wasn't a multiple of 4
would either crash or produce bad screenshots

View file

@ -507,12 +507,12 @@ static void Con_DrawNotify()
if (chat_team)
{
SCR_DrawString( 8, y, cw, ch, "say_team:", qtrue );
SCR_DrawStringEx( 8, y, cw, ch, "say_team:", qtrue, qtrue );
skip = 10;
}
else
{
SCR_DrawString( 8, y, cw, ch, "say:", qtrue );
SCR_DrawStringEx( 8, y, cw, ch, "say:", qtrue, qtrue );
skip = 5;
}

View file

@ -222,8 +222,8 @@ void Field_Draw( field_t* edit, int x, int y, int cw, int ch )
char str[MAX_STRING_CHARS];
int i;
drawLen = edit->widthInChars;
len = strlen( edit->buffer ) + 1;
drawLen = edit->widthInChars + 1;
len = strlen( edit->buffer );
// guarantee that cursor will be visible
if ( len <= drawLen ) {
@ -236,14 +236,6 @@ void Field_Draw( field_t* edit, int x, int y, int cw, int ch )
}
}
prestep = edit->scroll;
/*
if ( edit->cursor < len - drawLen ) {
prestep = edit->cursor; // cursor at start
} else {
prestep = len - drawLen;
}
*/
}
if ( prestep + drawLen > len ) {
@ -258,7 +250,7 @@ void Field_Draw( field_t* edit, int x, int y, int cw, int ch )
Com_Memcpy( str, edit->buffer + prestep, drawLen );
str[ drawLen ] = 0;
SCR_DrawString( x, y, cw, ch, str, qtrue );
SCR_DrawStringEx( x, y, cw, ch, str, qtrue, qtrue );
if ( (int)( cls.realtime >> 8 ) & 1 ) {
return; // off blink
@ -270,7 +262,7 @@ void Field_Draw( field_t* edit, int x, int y, int cw, int ch )
cursorChar = 10;
}
i = drawLen - ( Q_PrintStrlen( str ) + 1 );
i = drawLen - strlen( str );
SCR_DrawChar( x + ( edit->cursor - prestep - i ) * cw, y, cw, ch, cursorChar );
}
@ -388,50 +380,27 @@ static void Field_KeyDownEvent( field_t *edit, int key )
len = strlen( edit->buffer );
if ( key == K_DEL ) {
if ( edit->cursor < len ) {
memmove( edit->buffer + edit->cursor,
edit->buffer + edit->cursor + 1, len - edit->cursor );
}
return;
}
if ( key == K_RIGHTARROW )
{
if ( edit->cursor < len ) {
if ( edit->cursor < len )
memmove( edit->buffer + edit->cursor, edit->buffer + edit->cursor + 1, len - edit->cursor );
} else if ( key == K_RIGHTARROW ) {
if ( edit->cursor < len )
edit->cursor++;
}
if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len )
{
edit->scroll++;
}
return;
}
if ( key == K_LEFTARROW )
{
if ( edit->cursor > 0 ) {
} else if ( key == K_LEFTARROW ) {
if ( edit->cursor > 0 )
edit->cursor--;
}
if ( edit->cursor < edit->scroll )
{
edit->scroll--;
}
return;
}
if ( key == K_HOME || ( tolower(key) == 'a' && keys[K_CTRL].down ) ) {
} else if ( key == K_HOME || ( tolower(key) == 'a' && keys[K_CTRL].down ) ) {
edit->cursor = 0;
return;
}
if ( key == K_END || ( tolower(key) == 'e' && keys[K_CTRL].down ) ) {
} else if ( key == K_END || ( tolower(key) == 'e' && keys[K_CTRL].down ) ) {
edit->cursor = len;
return;
} else if ( key == K_INS ) {
key_overstrikeMode = !key_overstrikeMode;
}
if ( key == K_INS ) {
key_overstrikeMode = !key_overstrikeMode;
return;
// fix up the scroll after we're done changing the cursor position
if ( edit->cursor < edit->scroll ) {
edit->scroll = edit->cursor;
} else if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len ) {
edit->scroll = edit->cursor - edit->widthInChars + 1;
}
}

View file

@ -1584,7 +1584,7 @@ static void CL_InitRenderer()
// load character sets
cls.charSetShader = re.RegisterShader( "gfx/2d/bigchars" );
cls.whiteShader = re.RegisterShader( "white" );
g_console_field_width = cls.glconfig.vidWidth / SMALLCHAR_WIDTH - 2;
g_console_field_width = CONSOLE_WIDTH;
g_consoleField.widthInChars = g_console_field_width;
}

View file

@ -87,7 +87,7 @@ void SCR_DrawChar( float x, float y, float cw, float ch, int c )
// draws a string with a drop shadow, optionally with colorcodes
void SCR_DrawString( float x, float y, float cw, float ch, const char* string, qbool allowColor )
void SCR_DrawStringEx( float x, float y, float cw, float ch, const char* string, qbool allowColor, qbool showColorCodes )
{
float xx;
const char* s;
@ -102,7 +102,7 @@ void SCR_DrawString( float x, float y, float cw, float ch, const char* string, q
s = string;
xx = x + 1;
while ( *s ) {
if ( Q_IsColorString( s ) ) {
if ( !showColorCodes && Q_IsColorString( s ) ) {
s += 2;
continue;
}
@ -116,12 +116,12 @@ void SCR_DrawString( float x, float y, float cw, float ch, const char* string, q
xx = x;
re.SetColor( colorWhite );
while ( *s ) {
if ( Q_IsColorString( s ) ) {
if ( allowColor ) {
re.SetColor( ColorFromChar( s[1] ) );
if ( allowColor && Q_IsColorString( s ) ) {
re.SetColor( ColorFromChar( s[1] ) );
if ( !showColorCodes ) {
s += 2;
continue;
}
s += 2;
continue;
}
SCR_DrawChar( xx, y, cw, ch, *s );
xx += cw;
@ -132,6 +132,14 @@ void SCR_DrawString( float x, float y, float cw, float ch, const char* string, q
}
// draws a string with a drop shadow, optionally with colorcodes
void SCR_DrawString( float x, float y, float cw, float ch, const char* string, qbool allowColor )
{
SCR_DrawStringEx( x, y, cw, ch, string, allowColor, qfalse );
}
///////////////////////////////////////////////////////////////

View file

@ -446,6 +446,7 @@ void SCR_AdjustFrom640( float *x, float *y, float *w, float *h );
void SCR_DrawChar( float x, float y, float cw, float ch, int c );
void SCR_DrawString( float x, float y, float cw, float ch, const char* s, qbool allowColor );
void SCR_DrawStringEx( float x, float y, float cw, float ch, const char* s, qbool allowColor, qbool showColorCodes );
void SCR_DebugGraph( float value, int color );