Skip to content

Commit

Permalink
CLIENT: implemented con_scale and reduced code duplication in charact…
Browse files Browse the repository at this point in the history
…er rendering

used stuff from Con_CheckSize from quake3e
  • Loading branch information
mgerhardy committed May 15, 2024
1 parent f0f1a6f commit 038ce0f
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 133 deletions.
127 changes: 84 additions & 43 deletions code/client/cl_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "client.h"

int g_console_field_width = 78;
static fontSize_t fontSize;

#define MAX_CONSOLE_WIDTH 120
#define NUM_CON_TIMES 4

#define CON_TEXTSIZE 32768
Expand All @@ -38,6 +40,7 @@ typedef struct {

int linewidth; // characters across screen
int totallines; // total lines in console scrollback
int viswidth;

float xadjust; // for wide aspect screens

Expand All @@ -51,11 +54,12 @@ typedef struct {
vec4_t color;
} console_t;

console_t con;
static console_t con;

cvar_t *con_conspeed;
cvar_t *con_autoclear;
cvar_t *con_notifytime;
static cvar_t *con_conspeed;
static cvar_t *con_autoclear;
static cvar_t *con_notifytime;
static cvar_t *con_scale;

#define DEFAULT_CONSOLE_WIDTH 78

Expand Down Expand Up @@ -156,7 +160,7 @@ static void Con_MessageMode4_f(void) {
Con_Clear_f
================
*/
void Con_Clear_f(void) {
static void Con_Clear_f(void) {
int i;

for (i = 0; i < CON_TEXTSIZE; i++) {
Expand Down Expand Up @@ -265,54 +269,79 @@ If the line width has changed, reformat the buffer.
================
*/
void Con_CheckResize(void) {
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
short tbuf[CON_TEXTSIZE];
float scale;

width = (SCREEN_WIDTH / SMALLCHAR_WIDTH) - 2;

if (width == con.linewidth)
if (con.viswidth == cls.glconfig.vidWidth && !con_scale->modified) {
return;
}

scale = con_scale->value;

con.viswidth = cls.glconfig.vidWidth;

if (width < 1) // video hasn't been initialized yet
fontSize.w = SMALLCHAR_WIDTH * scale;
fontSize.h = SMALLCHAR_HEIGHT * scale;

if (cls.glconfig.vidWidth == 0) // video hasn't been initialized yet
{
width = DEFAULT_CONSOLE_WIDTH;
int width;
g_console_field_width = DEFAULT_CONSOLE_WIDTH;
width = DEFAULT_CONSOLE_WIDTH * scale;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;
for (i = 0; i < CON_TEXTSIZE; i++)

con.text[i] = (ColorIndex(COLOR_WHITE) << 8) | ' ';
Con_Clear_f();
} else {
int oldcurrent, oldwidth, oldtotallines;
short tbuf[CON_TEXTSIZE];
int i, j, width, numlines, numchars;

width = ((cls.glconfig.vidWidth / fontSize.w) - 2);

g_console_field_width = width;
g_consoleField.widthInChars = g_console_field_width;

if (width > MAX_CONSOLE_WIDTH)
width = MAX_CONSOLE_WIDTH;

oldwidth = con.linewidth;
con.linewidth = width;
oldtotallines = con.totallines;
con.totallines = CON_TEXTSIZE / con.linewidth;
numlines = oldtotallines;
oldcurrent = con.current;

if (con.totallines < numlines)
numlines = con.totallines;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;

numchars = oldwidth;

if (con.linewidth < numchars)
if (numchars > con.linewidth)
numchars = con.linewidth;

if (oldcurrent > oldtotallines)
numlines = oldtotallines;
else
numlines = oldcurrent + 1;

if (numlines > con.totallines)
numlines = con.totallines;

Com_Memcpy(tbuf, con.text, CON_TEXTSIZE * sizeof(short));
for (i = 0; i < CON_TEXTSIZE; i++)

for (i = 0; i < CON_TEXTSIZE; i++)
con.text[i] = (ColorIndex(COLOR_WHITE) << 8) | ' ';

for (i = 0; i < numlines; i++) {
for (j = 0; j < numchars; j++) {
con.text[(con.totallines - 1 - i) * con.linewidth + j] =
tbuf[((con.current - i + oldtotallines) % oldtotallines) * oldwidth + j];
}
const short *src = &tbuf[((oldcurrent - i + oldtotallines) % oldtotallines) * oldwidth];
short *dst = &con.text[(numlines - 1 - i) * con.linewidth];
for (j = 0; j < numchars; j++)
*dst++ = *src++;
}

Con_ClearNotify();

con.current = numlines - 1;
}

con.current = con.totallines - 1;
con.display = con.current;
con_scale->modified = qfalse;
}

/*
Expand All @@ -337,6 +366,11 @@ void Con_Init(void) {
con_notifytime = Cvar_Get("con_notifytime", "-4", 0);
con_conspeed = Cvar_Get("scr_conspeed", "3", 0);
con_autoclear = Cvar_Get("con_autoclear", "1", CVAR_ARCHIVE);
con_scale = Cvar_Get("con_scale", "1", CVAR_ARCHIVE);
Cvar_CheckRange(con_scale, 1, 4, qtrue);

fontSize.w = SMALLCHAR_WIDTH * con_scale->value;
fontSize.h = SMALLCHAR_HEIGHT * con_scale->value;

Field_Clear(&g_consoleField);
g_consoleField.widthInChars = g_console_field_width;
Expand Down Expand Up @@ -426,8 +460,15 @@ void CL_ConsolePrint(const char *txt) {
}

if (!con.initialized) {
static cvar_t null_cvar = { 0 };
fontSize.w = SMALLCHAR_WIDTH;
fontSize.h = SMALLCHAR_HEIGHT;
con.color[0] = con.color[1] = con.color[2] = con.color[3] = 1.0f;
con.viswidth = -9999;
con.linewidth = -1;
con_scale = &null_cvar;
con_scale->value = 1.0f;
con_scale->modified = qtrue;
Con_CheckResize();
con.initialized = qtrue;
}
Expand Down Expand Up @@ -508,13 +549,13 @@ static void Con_DrawInput(void) {
return;
}

y = con.vislines - (SMALLCHAR_HEIGHT * 2);
y = con.vislines - (fontSize.h * 2);

re.SetColor(con.color);

SCR_DrawSmallChar(con.xadjust + 1 * SMALLCHAR_WIDTH, y, ']');
SCR_DrawChar(con.xadjust + 1 * fontSize.w, y, ']', fontSize);

Field_Draw(&g_consoleField, con.xadjust + 2 * SMALLCHAR_WIDTH, y, SCREEN_WIDTH - 3 * SMALLCHAR_WIDTH, qtrue, qtrue);
Field_Draw(&g_consoleField, con.xadjust + 2 * fontSize.w, y, SCREEN_WIDTH - 3 * fontSize.w, qtrue, qtrue, fontSize);
}

/*
Expand Down Expand Up @@ -559,10 +600,10 @@ void Con_DrawNotify(void) {
currentColor = ColorIndexForNumber(text[x] >> 8);
re.SetColor(g_color_table[currentColor]);
}
SCR_DrawSmallChar(cl_conXOffset->integer + con.xadjust + (x + 1) * SMALLCHAR_WIDTH, v, text[x] & 0xff);
SCR_DrawChar(cl_conXOffset->integer + con.xadjust + (x + 1) * fontSize.w, v, text[x] & 0xff, fontSize);
}

v += SMALLCHAR_HEIGHT;
v += fontSize.h;
}

re.SetColor(NULL);
Expand All @@ -574,14 +615,14 @@ void Con_DrawNotify(void) {
// draw the chat line
if (Key_GetCatcher() & KEYCATCH_MESSAGE) {
if (chat_team) {
SCR_DrawBigString(8, v, "say_team:", 1.0f, qfalse);
SCR_DrawString(8, v, "say_team:", qfalse, FONT_BIG);
skip = 10;
} else {
SCR_DrawBigString(8, v, "say:", 1.0f, qfalse);
SCR_DrawString(8, v, "say:", qfalse, FONT_BIG);
skip = 5;
}

Field_BigDraw(&chatField, skip * BIGCHAR_WIDTH, v, SCREEN_WIDTH - (skip + 1) * BIGCHAR_WIDTH, qtrue, qtrue);
Field_Draw(&chatField, skip * FONT_BIG.w, v, SCREEN_WIDTH - (skip + 1) * FONT_BIG.w, qtrue, qtrue, FONT_BIG);
}
}

Expand Down Expand Up @@ -635,23 +676,23 @@ static void Con_DrawSolidConsole(float frac) {
i = strlen(Q3_VERSION);

for (x = 0; x < i; x++) {
SCR_DrawSmallChar(cls.glconfig.vidWidth - (i - x + 1) * SMALLCHAR_WIDTH, lines - SMALLCHAR_HEIGHT,
Q3_VERSION[x]);
SCR_DrawChar(cls.glconfig.vidWidth - (i - x + 1) * fontSize.w, lines - fontSize.h,
Q3_VERSION[x], fontSize);
}

// draw the text
con.vislines = lines;
rows = (lines - SMALLCHAR_HEIGHT) / SMALLCHAR_HEIGHT; // rows of text to draw
rows = (lines - fontSize.h) / fontSize.h; // rows of text to draw

y = lines - (SMALLCHAR_HEIGHT * 3);
y = lines - (fontSize.h * 3);

// draw from the bottom up
if (con.display != con.current) {
// draw arrows to show the buffer is backscrolled
re.SetColor(g_color_table[ColorIndex(COLOR_RED)]);
for (x = 0; x < con.linewidth; x += 4)
SCR_DrawSmallChar(con.xadjust + (x + 1) * SMALLCHAR_WIDTH, y, '^');
y -= SMALLCHAR_HEIGHT;
SCR_DrawChar(con.xadjust + (x + 1) * fontSize.w, y, '^', fontSize);
y -= fontSize.h;
rows--;
}

Expand All @@ -664,7 +705,7 @@ static void Con_DrawSolidConsole(float frac) {
currentColor = 7;
re.SetColor(g_color_table[currentColor]);

for (i = 0; i < rows; i++, y -= SMALLCHAR_HEIGHT, row--) {
for (i = 0; i < rows; i++, y -= fontSize.h, row--) {
if (row < 0)
break;
if (con.current - row >= con.totallines) {
Expand All @@ -683,7 +724,7 @@ static void Con_DrawSolidConsole(float frac) {
currentColor = ColorIndexForNumber(text[x] >> 8);
re.SetColor(g_color_table[currentColor]);
}
SCR_DrawSmallChar(con.xadjust + (x + 1) * SMALLCHAR_WIDTH, y, text[x] & 0xff);
SCR_DrawChar(con.xadjust + (x + 1) * fontSize.w, y, text[x] & 0xff, fontSize);
}
}

Expand Down
33 changes: 8 additions & 25 deletions code/client/cl_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,11 @@ Handles horizontal scrolling and cursor blinking
x, y, and width are in pixels
===================
*/
static void Field_VariableSizeDraw(field_t *edit, int x, int y, int width, int size, qboolean showCursor,
static void Field_VariableSizeDraw(field_t *edit, int x, int y, int width, int fontsize, qboolean showCursor,
qboolean noColorEscape) {
}

void Field_Draw(field_t *edit, int x, int y, int width, qboolean showCursor, qboolean noColorEscape, fontSize_t fontsize) {
int len;
int drawLen;
int prestep;
Expand Down Expand Up @@ -366,15 +369,7 @@ static void Field_VariableSizeDraw(field_t *edit, int x, int y, int width, int s
str[drawLen] = 0;

// draw it
if (size == SMALLCHAR_WIDTH) {
float color[4];

color[0] = color[1] = color[2] = color[3] = 1.0f;
SCR_DrawSmallStringExt(x, y, str, color, qfalse, noColorEscape);
} else {
// draw big string with drop shadow
SCR_DrawBigString(x, y, str, 1.0f, noColorEscape);
}
SCR_DrawString(x, y, str, noColorEscape, fontsize);

// draw the cursor
if (showCursor) {
Expand All @@ -390,24 +385,12 @@ static void Field_VariableSizeDraw(field_t *edit, int x, int y, int width, int s

i = drawLen - strlen(str);

if (size == SMALLCHAR_WIDTH) {
SCR_DrawSmallChar(x + (edit->cursor - prestep - i) * size, y, cursorChar);
} else {
str[0] = cursorChar;
str[1] = 0;
SCR_DrawBigString(x + (edit->cursor - prestep - i) * size, y, str, 1.0f, qfalse);
}
str[0] = cursorChar;
str[1] = 0;
SCR_DrawString(x + (edit->cursor - prestep - i) * fontsize.w, y, str, qfalse, fontsize);
}
}

void Field_Draw(field_t *edit, int x, int y, int width, qboolean showCursor, qboolean noColorEscape) {
Field_VariableSizeDraw(edit, x, y, width, SMALLCHAR_WIDTH, showCursor, noColorEscape);
}

void Field_BigDraw(field_t *edit, int x, int y, int width, qboolean showCursor, qboolean noColorEscape) {
Field_VariableSizeDraw(edit, x, y, width, BIGCHAR_WIDTH, showCursor, noColorEscape);
}

static void Field_CharEvent(field_t *edit, int ch);

/*
Expand Down
3 changes: 3 additions & 0 deletions code/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,9 @@ static void CL_InitRenderer(void) {
cls.charsetShader = re.RegisterShader("fontascii");
cls.whiteShader = re.RegisterShader("white");
cls.consoleShader = re.RegisterShader("console");

Con_CheckResize();

g_console_field_width = cls.glconfig.vidWidth / SMALLCHAR_WIDTH - 2;
g_consoleField.widthInChars = g_console_field_width;
}
Expand Down
Loading

0 comments on commit 038ce0f

Please sign in to comment.