Skip to content

Commit

Permalink
client: add cvar to set console background color (incl. alpha)
Browse files Browse the repository at this point in the history
* Added con_background cvar to set solid color for console background.
  • Loading branch information
isRyven committed Aug 1, 2021
1 parent c399152 commit 7e6848b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/client/cl_console.c
Expand Up @@ -47,6 +47,7 @@ console_t con;
cvar_t *con_notifytime;
cvar_t *con_openspeed;
cvar_t *con_autoclear;
cvar_t *con_background;

vec4_t console_highlightcolor = { 0.5f, 0.5f, 0.2f, 0.45f };

Expand Down Expand Up @@ -321,6 +322,7 @@ void Con_Init(void)
con_notifytime = Cvar_Get("con_notifytime", "7", 0); // increased per id req for obits
con_openspeed = Cvar_Get("con_openspeed", "3", 0);
con_autoclear = Cvar_Get("con_autoclear", "1", CVAR_ARCHIVE);
con_background = Cvar_GetAndDescribe("con_background", "", CVAR_ARCHIVE, "Console background color in normalized RGBA format, eg. \"0.2 0.2 0.2 0.8\".");

Field_Clear(&g_consoleField);
g_consoleField.widthInChars = g_console_field_width;
Expand Down Expand Up @@ -750,8 +752,14 @@ void Con_DrawSolidConsole(float frac)
}
else
{
SCR_DrawPic(0, 0, SCREEN_WIDTH, y, cls.consoleShader);

if (Q_ParseColorRGBA(con_background->string, color))

This comment has been minimized.

Copy link
@rmarquis

rmarquis Aug 1, 2021

Contributor

Now the obvious, unavoidable bikeshedding: What if we wanted to keep the consoleShader but add some color on top of it? Would it make sense to add that option?

This comment has been minimized.

Copy link
@isRyven

isRyven Aug 1, 2021

Author Member

It was an option i considered, but would require to setup vertices to draw the poly to gain full control over the toning/transparency we would want to apply, but just to be clear the idea was to add some sort of simple debugging feature, which would help to keep checking both environment and console logs at the same time with the help of background transparency. We have similar thing built in mod-land in etjump. But we could open up the ticket and discuss improvements / new requirements.

This comment has been minimized.

Copy link
@rmarquis

rmarquis Aug 1, 2021

Contributor

I see, so it's not only a cosmetic feature. Keep going, but I admit having a semi-transparent console with shader is now appealing to me.

{
SCR_FillRect(0, 0, SCREEN_WIDTH, y, color);
}
else
{
SCR_DrawPic(0, 0, SCREEN_WIDTH, y, cls.consoleShader);
}
/*
// draw the logo
if (frac >= 0.5f)
Expand Down
26 changes: 26 additions & 0 deletions src/qcommon/q_shared.c
Expand Up @@ -1856,6 +1856,32 @@ void Q_ColorizeString(char colorCode, const char *inStr, char *outStr, size_t ou
}
}

/**
* @brief Parses normalized RGBA color string
* @param[in] inStr input string to parse
* @param[out] outColor output vector to set
* @return Number of matched color components in the input string
*/
int Q_ParseColorRGBA(const char *inStr, vec4_t outColor)
{
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
float a = 1.0f;
int components;

if (!inStr || !inStr[0] || !outColor)
{
return 0;
}

components = sscanf(inStr, "%f %f %f %f", &r, &g, &b, &a);
Vector4Set(outColor, r, g, b, a);
ClampColor(outColor);

return components;
}

/**
* @brief Strips whitespaces and bad characters
* @param[in] c
Expand Down
3 changes: 3 additions & 0 deletions src/qcommon/q_shared.h
Expand Up @@ -824,6 +824,9 @@ char *Q_TrimStr(char *string);
/// Encodes a plain un-colored string so that it'll be drawn with the given color code.
void Q_ColorizeString(char colorCode, const char *inStr, char *outStr, size_t outBufferLen);

// Parses normalized rgba color string
int Q_ParseColorRGBA(const char *inStr, vec4_t outColor);

// #define Q_IsColorString(p) (*p == Q_COLOR_ESCAPE && *(p + 1) && *(p + 1) != Q_COLOR_ESCAPE && isgraph((*(p + 1))))
// Checks if the string contains color coded text
static ID_INLINE qboolean Q_IsColorString(const char *p)
Expand Down

0 comments on commit 7e6848b

Please sign in to comment.