added Draw_nString for displaying a non \0 terminated string

This commit is contained in:
Chris Ison 2002-01-09 21:20:22 +00:00
parent 96c7159f66
commit 6073ff8d58
11 changed files with 75 additions and 51 deletions

View file

@ -48,6 +48,7 @@ void Draw_TileClear (int x, int y, int w, int h);
void Draw_Fill (int x, int y, int w, int h, int c);
void Draw_FadeScreen (void);
void Draw_String (int x, int y, const char *str);
void Draw_nString (int x, int y, const char *str, int count);
void Draw_AltString (int x, int y, const char *str);
qpic_t *Draw_PicFromWad (const char *name);
qpic_t *Draw_CachePic (const char *path, qboolean alpha);

View file

@ -346,6 +346,40 @@ Draw_String (int x, int y, const char *str)
qfglEnd ();
}
void
Draw_nString (int x, int y, const char *str, int count)
{
unsigned char num;
float frow, fcol;
int size;
if (!str || !str[0])
return;
if (y <= -8)
return; // totally off screen
qfglBindTexture (GL_TEXTURE_2D, char_texture);
qfglBegin (GL_QUADS);
for (size = 0; size < count; size++, x+=8) {
if ((num = *str++) != 32) // Don't render spaces
{
frow = (num >> 4) * CELL_SIZE;
fcol = (num & 15) * CELL_SIZE;
qfglTexCoord2f (fcol, frow);
qfglVertex2f (x, y);
qfglTexCoord2f (fcol + CELL_SIZE, frow);
qfglVertex2f (x + 8, y);
qfglTexCoord2f (fcol + CELL_SIZE, frow + CELL_SIZE);
qfglVertex2f (x + 8, y + 8);
qfglTexCoord2f (fcol, frow + CELL_SIZE);
qfglVertex2f (x, y + 8);
}
}
qfglEnd ();
}
void
Draw_AltString (int x, int y, const char *str)
{

View file

@ -708,7 +708,7 @@ void
SCR_DrawNotifyString (void)
{
char *start;
int j, l, x, y;
int l, x, y;
start = scr_notifystring;
@ -720,8 +720,7 @@ SCR_DrawNotifyString (void)
if (start[l] == '\n' || !start[l])
break;
x = (vid.width - l * 8) / 2;
for (j = 0; j < l; j++, x += 8)
Draw_Character (x, y, start[j]);
Draw_nString (x, y, start, l);
y += 8;

View file

@ -262,6 +262,16 @@ Draw_String (int x, int y, const char *str)
}
void
Draw_nString (int x, int y, const char *str, int count)
{
int size;
for (size = 0; size < count; size++, x +=8) {
Draw_Character (x, y, *str++);
}
}
void
Draw_AltString (int x, int y, const char *str)
{

View file

@ -767,7 +767,6 @@ SCR_DrawNotifyString (void)
{
char *start;
int l;
int j;
int x, y;
start = scr_notifystring;
@ -780,8 +779,7 @@ SCR_DrawNotifyString (void)
if (start[l] == '\n' || !start[l])
break;
x = (vid.width - l * 8) / 2;
for (j = 0; j < l; j++, x += 8)
Draw_Character (x, y, start[j]);
Draw_nString (x, y, start, l);
y += 8;

View file

@ -324,6 +324,15 @@ Draw_String (int x, int y, const char *str)
}
}
void
Draw_nString (int x, int y, const char *str, int count)
{
int size;
for (size = 0; size < count; size++, x += 8) {
Draw_Character (x, y, *str++);
}
}
void
Draw_AltString (int x, int y, const char *str)

View file

@ -787,7 +787,6 @@ SCR_DrawNotifyString (void)
{
char *start;
int l;
int j;
int x, y;
start = scr_notifystring;
@ -800,10 +799,7 @@ SCR_DrawNotifyString (void)
if (start[l] == '\n' || !start[l])
break;
x = (vid.width - l * 8) / 2;
for (j = 0; j < l; j++, x += 8)
Draw_Character (x, y, start[j]);
y += 8;
Draw_nString (x, y, start, l);
while (*start && *start != '\n')
start++;

View file

@ -373,8 +373,7 @@ Con_DrawInput (void)
// draw it
y = con_vislines - 22;
for (i = 0; i < con_linewidth; i++)
Draw_Character ((i + 1) << 3, con_vislines - 22, text[i]);
Draw_nString (3, y, text, con_linewidth);
}
/*
@ -404,8 +403,7 @@ Con_DrawNotify (void)
clearnotify = 0;
scr_copytop = 1;
for (x = 0; x < con_linewidth; x++)
Draw_Character ((x + 1) << 3, v, text[x]);
Draw_nString (3, v, text, con_linewidth);
v += 8;
}
@ -426,11 +424,8 @@ Con_DrawNotify (void)
if (chat_bufferlen > (vid.width >> 3) - (skip + 1))
s += chat_bufferlen - ((vid.width >> 3) - (skip + 1));
x = 0;
while (s[x]) {
Draw_Character ((x + skip) << 3, v, s[x]);
x++;
}
Draw_Character ((x + skip) << 3, v,
Draw_String (skip >> 3, v, s);
Draw_Character ((strlen(s) + skip) << 3, v,
10 + ((int) (realtime * con_cursorspeed) & 1));
v += 8;
}
@ -483,8 +478,7 @@ Con_DrawConsole (int lines)
text = con->text + (row % con_totallines) * con_linewidth;
for (x = 0; x < con_linewidth; x++)
Draw_Character ((x + 1) << 3, y, text[x]);
Draw_nString (3, y, text, con_linewidth);
}
// draw the input prompt, user text, and cursor if desired
@ -533,8 +527,7 @@ Con_DrawDownload (int lines)
" %02d%%", cls.downloadpercent);
// draw it
y = lines - 22 + 8;
for (i = 0; i < strlen (dlbar); i++)
Draw_Character ((i + 1) << 3, y, dlbar[i]);
Draw_nString (3, y, dlbar, strlen (dlbar));
}
/*

View file

@ -953,9 +953,7 @@ Sbar_DeathmatchOverlay (void)
f = s->frags;
snprintf (num, sizeof (num), "%3i", f);
Draw_Character (x + 8, y, num[0]);
Draw_Character (x + 16, y, num[1]);
Draw_Character (x + 24, y, num[2]);
Draw_nString (x + 8, y, num, 3);
if (k == cl.viewentity - 1)
Draw_Character (x - 8, y, 12);
@ -1028,10 +1026,8 @@ Sbar_MiniDeathmatchOverlay (void)
f = s->frags;
snprintf (num, sizeof (num), "%3i", f);
Draw_Character (x + 8, y, num[0]);
Draw_Character (x + 16, y, num[1]);
Draw_Character (x + 24, y, num[2]);
Draw_nString (x + 8, y, num, 3);
if (k == cl.viewentity - 1) {
Draw_Character (x, y, 16);
Draw_Character (x + 32, y, 17);

View file

@ -419,8 +419,7 @@ Con_DrawInput (void)
// draw it
y = con_vislines - 22;
for (i = 0; i < con_linewidth; i++)
Draw_Character ((i + 1) << 3, con_vislines - 22, text[i]);
Draw_nString (3, y, text, con_linewidth);
}
/*
@ -450,9 +449,7 @@ Con_DrawNotify (void)
clearnotify = 0;
scr_copytop = 1;
for (x = 0; x < con_linewidth; x++)
Draw_Character ((x + 1) << 3, v, text[x]);
Draw_nString (3, v, text, con_linewidth);
v += 8;
}
@ -472,11 +469,8 @@ Con_DrawNotify (void)
if (chat_bufferlen > (vid.width >> 3) - (skip + 1))
s += chat_bufferlen - ((vid.width >> 3) - (skip + 1));
x = 0;
while (s[x]) {
Draw_Character ((x + skip) << 3, v, s[x]);
x++;
}
Draw_Character ((x + skip) << 3, v,
Draw_String (skip >> 3, v, s);
Draw_Character ((strlen(s) + skip) << 3, v,
10 + ((int) (realtime * con_cursorspeed) & 1));
v += 8;
}
@ -529,8 +523,7 @@ Con_DrawConsole (int lines)
text = con->text + (row % con_totallines) * con_linewidth;
for (x = 0; x < con_linewidth; x++)
Draw_Character ((x + 1) << 3, y, text[x]);
Draw_nString(3, y, text, con_linewidth);
}
// draw the input prompt, user text, and cursor if desired
@ -579,8 +572,7 @@ Con_DrawDownload (int lines)
" %02d%%", cls.downloadpercent);
// draw it
y = lines - 22 + 8;
for (i = 0; i < strlen (dlbar); i++)
Draw_Character ((i + 1) << 3, y, dlbar[i]);
Draw_nString (3, y, dlbar, strlen (dlbar));
}
/*

View file

@ -1015,9 +1015,7 @@ Sbar_DeathmatchOverlay (int start)
f = s->frags;
snprintf (num, sizeof (num), "%3i", f);
Draw_Character (x + 112, y, num[0]);
Draw_Character (x + 120, y, num[1]);
Draw_Character (x + 128, y, num[2]);
Draw_nString (x + 112, y, num, 3);
if (k == cl.playernum) {
Draw_Character (x + 104, y, 16);
@ -1114,9 +1112,7 @@ Sbar_MiniDeathmatchOverlay (void)
f = s->frags;
snprintf (num, sizeof (num), "%3i", f);
Draw_Character (x + 8, y, num[0]);
Draw_Character (x + 16, y, num[1]);
Draw_Character (x + 24, y, num[2]);
Draw_nString (x + 8, y, num, 3);
if (k == cl.playernum) {
Draw_Character (x, y, 16);