Text wrapper conversion.

G_PrintGameText(), minitext_(), G_DrawTXDigiNumZ(), and menutext_() now wrap G_ScreenText().
G_GameTextLen() now wraps G_ScreenTextSize().
G_DrawDigiNum_() now wraps G_DrawTXDigiNumZ().

git-svn-id: https://svn.eduke32.com/eduke32@3836 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2013-06-01 06:56:00 +00:00
parent 4504716fa0
commit bf9b91352b
3 changed files with 70 additions and 317 deletions

View file

@ -1142,14 +1142,14 @@ vec2_t G_ScreenText(const int32_t font,
// flags
// 4: small font, wrap strings?
int32_t G_PrintGameText(int32_t f, int32_t tile, int32_t x, int32_t y, const char *t,
int32_t G_PrintGameText(int32_t hack, int32_t tile, int32_t x, int32_t y, const char *t,
int32_t s, int32_t p, int32_t o,
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z)
{
int32_t ac;
const int32_t squishtext = (f&2) != 0 ? 1 : 0;
const int32_t widthx = 320<<16;
int32_t origx = x, origy, j = 0;
vec2_t dim;
int32_t f = TEXT_GAMETEXTNUMHACK;
int32_t xbetween = 0;
int32_t orient = 8|16|(o&1)|(o&32);
if (t == NULL)
return -1;
@ -1160,149 +1160,55 @@ int32_t G_PrintGameText(int32_t f, int32_t tile, int32_t x, int32_t y, const
y <<= 16;
}
origy = y;
if (x == (widthx>>1)) // center
if (hack & 4)
{
const char *oldt = t;
int32_t newx = 0;
x = textsc(x);
z = textsc(z);
f |= TEXT_LINEWRAP;
}
else if (!(hack & 1))
orient = 2|o;
do
if (hack & 8)
{
int32_t i;
if (*t == 32)
{
newx += ((((f & 8) ? 8 : 5) - squishtext) * z);
continue;
f |= TEXT_XOFFSETZERO;
xbetween = 8;
}
if (*t == '^' && isdigit(*(t+1)))
{
t++;
if (isdigit(*(t+1)))
t++;
// t += 1 + isdigit(*(t+2)); // This code is wrong, see C99 6.5 #2
continue;
}
// order is important, this bit comes after the rest
if (hack & 2) // squishtext
--xbetween;
ac = *t - '!' + tile;
if (x == (160<<16))
f |= TEXT_XCENTER;
if (ac < tile || ac > (tile + 93))
break;
dim = G_ScreenText(tile, x, y, z, 0, 0, t, s, p, orient|ROTATESPRITE_FULL16, 0, (5<<16), (8<<16), (xbetween<<16), 0, f, x1, y1, x2, y2);
i = ((((f & 8) ? 8 : tilesizx[ac]) - squishtext) * z);
newx += i;
x += dim.x;
if (*t >= '0' && *t <= '9')
newx -= i - ((8 * z));
}
while (*(++t));
if (!(o & ROTATESPRITE_FULL16))
x >>= 16;
t = oldt;
x = (f & 4) ?
(xres>>1)-textsc(newx>>1) :
(widthx>>1)-(newx>>1);
}
do
{
int32_t i;
if (*t == 32)
{
j += ((((f & 8) ? 8 : 5) - squishtext) * z);
continue;
}
if (*t == '^' && isdigit(*(t+1)))
{
char smallbuf[4];
if (!isdigit(*(++t+1)))
{
smallbuf[0] = *(t);
smallbuf[1] = '\0';
p = Batoi(smallbuf);
continue;
}
smallbuf[0] = *(t++);
smallbuf[1] = *(t);
smallbuf[2] = '\0';
p = Batoi(smallbuf);
continue;
}
ac = *t - '!' + tile;
if (ac < tile || ac > (tile + 93))
break;
if (f&4)
{
rotatesprite(textsc(x+j), (origy)+textsc((y-origy)), textsc(z),
0,ac,s,p,(8|16|(o&1)|(o&32)),x1,y1,x2,y2);
}
else
{
const int32_t orient = (f&1) ? (8|16|(o&1)|(o&32)) : (2|o);
rotatesprite(x+j, y, z,
0,ac,s,p,orient,x1,y1,x2,y2);
}
i = (f & 8) ?
((8 - squishtext) * z):
((tilesizx[ac] - squishtext) * z);
j += i;
if (*t >= '0' && *t <= '9')
j -= i-((8*z));
// wrapping long strings doesn't work for precise coordinates due to overflow
// XXX: above comment obsolete?
if (!(o&ROTATESPRITE_FULL16))
{
if (((f&4) ? textsc(x+j) : (x+j)) > (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET)<<16)
j = 0, y += z<<3; // z == 65536 --> 8<<16
}
}
while (*(++t));
return origx + ((o & ROTATESPRITE_FULL16) ? j : (j>>16));
return x;
}
int32_t G_GameTextLen(int32_t x,const char *t)
{
int32_t ac;
vec2_t dim;
if (t == NULL)
return -1;
do
{
if (*t == 32)
{
x+=5;
continue;
}
dim = G_ScreenTextSize(STARTALPHANUM, x, 0, textsc(65536L), 0, t, 2, 5, 8, 0, 0, TEXT_GAMETEXTNUMHACK, 0, 0, xdim-1, ydim-1);
ac = *t - '!' + STARTALPHANUM;
x += dim.x;
if (ac < STARTALPHANUM || ac > (STARTALPHANUM + 93))
break;
x += (*t >= '0' && *t <= '9') ? 8 : tilesizx[ac];
}
while (*(++t));
return (textsc(x));
return x;
}
int32_t mpgametext(int32_t y,const char *t,int32_t s,int32_t dabits)
{
return(G_PrintGameText(4,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536));
return G_PrintGameText(4,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536);
}
// minitext_yofs: in hud_scale-independent, (<<16)-scaled, 0-200-normalized y coords,
@ -1311,11 +1217,9 @@ static int32_t minitext_yofs = 0;
static int32_t minitext_lowercase = 0;
int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t sb)
{
int32_t ac, j = 0;
char ch, cmode;
cmode = (sb&ROTATESPRITE_MAX)!=0;
sb &= (ROTATESPRITE_MAX-1)|RS_CENTERORIGIN;
vec2_t dim;
int32_t z = 65536L;
int32_t f = 0;
if (t == NULL)
{
@ -1323,50 +1227,32 @@ int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t
return 0;
}
if (!(sb&ROTATESPRITE_FULL16))
if (!(sb & ROTATESPRITE_FULL16))
{
x<<=16;
y<<=16;
}
do
{
if (*t == '^' && isdigit(*(t+1)))
{
char smallbuf[4];
if (!isdigit(*(++t+1)))
{
smallbuf[0] = *(t);
smallbuf[1] = '\0';
p = Batoi(smallbuf);
continue;
}
smallbuf[0] = *(t++);
smallbuf[1] = *(t);
smallbuf[2] = '\0';
p = Batoi(smallbuf);
continue;
}
if (!minitext_lowercase)
ch = Btoupper(*t);
else
ch = *t;
f |= TEXT_UPPERCASE;
if (ch == 32)
if (sb & ROTATESPRITE_MAX)
{
j+=5;
continue;
x = sbarx16(x);
y = minitext_yofs+sbary16(y);
z = sbarsc(z);
}
else ac = ch - '!' + MINIFONT;
if (cmode) rotatesprite_fs(sbarx16(x+(j<<16)),minitext_yofs+sbary16(y),sbarsc(65536L),0,ac,s,p,sb);
else rotatesprite_fs(x+(j<<16),y,65536L,0,ac,s,p,sb);
j += (tilesizx[ac] > 0 ? tilesizx[ac] : 3) + 1;
sb &= (ROTATESPRITE_MAX-1)|RS_CENTERORIGIN;
}
while (*(++t));
dim = G_ScreenText(MINIFONT, x, y, z, 0, 0, t, s, p, sb|ROTATESPRITE_FULL16, 0, (4<<16), (8<<16), (1<<16), 0, f, 0, 0, xdim-1, ydim-1);
return x+(j<<((sb&ROTATESPRITE_FULL16)?16:0));
x += dim.x;
if (!(sb & ROTATESPRITE_FULL16))
x >>= 16;
return x;
}
void G_AddUserQuote(const char *daquote)
@ -1795,25 +1681,13 @@ static void G_DrawWeapAmounts(const DukePlayer_t *p,int32_t x,int32_t y,int32_t
// yofs: in hud_scale-independent, (<<16)-scaled, 0-200-normalized y coords.
static void G_DrawDigiNum_(int32_t x, int32_t yofs, int32_t y, int32_t n, char s, int32_t cs)
{
int32_t i, j = 0, k, p, c;
char b[12];
i = Bsprintf(b,"%d",n);
for (k=i-1; k>=0; k--)
if (!(cs & ROTATESPRITE_FULL16))
{
p = DIGITALNUM + b[k]-'0';
j += tilesizx[p]+1;
x <<= 16;
y <<= 16;
}
c = x-(j>>1);
j = 0;
for (k=0; k<i; k++)
{
p = DIGITALNUM + b[k]-'0';
rotatesprite_fs(sbarx(c+j), yofs+sbary(y), sbarsc(65536), 0, p, s, 0, cs);
j += tilesizx[p]+1;
}
G_DrawTXDigiNumZ(DIGITALNUM, sbarx16(x), yofs + sbary16(y), n, s, 0, cs|ROTATESPRITE_FULL16, 0, 0, xdim-1, ydim-1, sbarsc(65536L));
}
static inline void G_DrawDigiNum(int32_t x, int32_t y, int32_t n, char s, int32_t cs)
@ -1824,27 +1698,16 @@ static inline void G_DrawDigiNum(int32_t x, int32_t y, int32_t n, char s, int32_
void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s,int32_t pal,
int32_t cs,int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z)
{
int32_t i, j = 0, k, p, c;
char b[12];
const int32_t shift = (cs&ROTATESPRITE_FULL16)?0:16;
Bsprintf(b,"%d",n);
i = Bsprintf(b,"%d",n);
// center the number string
for (k=i-1; k>=0; k--)
if (!(cs & ROTATESPRITE_FULL16))
{
p = starttile + b[k]-'0';
j += ((1+tilesizx[p])*z);
x <<= 16;
y <<= 16;
}
c = (x<<shift)-(j>>1);
j = 0;
for (k=0; k<i; k++)
{
p = starttile + b[k]-'0';
rotatesprite(c+j,y<<shift,z,0,p,s,pal,2|cs,x1,y1,x2,y2);
j += ((1+tilesizx[p])*z);
}
G_ScreenText(starttile, x, y, z, 0, 0, b, s, pal, cs|2|ROTATESPRITE_FULL16, 0, (4<<16), (8<<16), (1<<16), 0, TEXT_XCENTER|TEXT_DIGITALNUMBER, x1, y1, x2, y2);
}
static void G_DrawAltDigiNum(int32_t x, int32_t y, int32_t n, char s, int32_t cs)

View file

@ -307,7 +307,7 @@ int32_t A_Spawn(int32_t j,int32_t pn);
int32_t G_DoMoveThings(void);
//int32_t G_EndOfLevel(void);
int32_t G_GameTextLen(int32_t x,const char *t);
int32_t G_PrintGameText(int32_t f,int32_t tile,int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t o,int32_t x1,int32_t y1,int32_t x2,int32_t y2,int32_t z);
int32_t G_PrintGameText(int32_t hack,int32_t tile,int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t o,int32_t x1,int32_t y1,int32_t x2,int32_t y2,int32_t z);
int32_t GetTime(void);
int32_t kopen4loadfrommod(const char *filename,char searchfirst);
int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t sb);

View file

@ -349,125 +349,15 @@ static int32_t Menu_EnterText(int32_t x,int32_t y,char *t,int32_t dalen,int32_t
int32_t menutext_(int32_t x,int32_t y,int32_t s,int32_t p,char *t,int32_t bits)
{
int16_t i, ac, centre;
// int32_t ht = usehightile;
vec2_t dim;
int32_t f = TEXT_BIGALPHANUM|TEXT_UPPERCASE|TEXT_LITERALESCAPE;
y -= 12;
if (x == 160)
f |= TEXT_XCENTER;
i = centre = 0;
dim = G_ScreenText(BIGALPHANUM, x, y-12, 65536L, 0, 0, t, s, p, bits, 0, 5, 16, 0, 0, f, 0, 0, xdim-1, ydim-1);
if (x == (320>>1))
{
while (*(t+i))
{
if (*(t+i) == ' ')
{
centre += 5;
i++;
continue;
}
ac = 0;
if (*(t+i) >= '0' && *(t+i) <= '9')
ac = *(t+i) - '0' + BIGALPHANUM-10;
else if (*(t+i) >= 'a' && *(t+i) <= 'z')
ac = toupper(*(t+i)) - 'A' + BIGALPHANUM;
else if (*(t+i) >= 'A' && *(t+i) <= 'Z')
ac = *(t+i) - 'A' + BIGALPHANUM;
else switch (*(t+i))
{
case '-':
ac = BIGALPHANUM-11;
break;
case '.':
ac = BIGPERIOD;
break;
case '\'':
ac = BIGAPPOS;
break;
case ',':
ac = BIGCOMMA;
break;
case '!':
ac = BIGX_;
break;
case '?':
ac = BIGQ;
break;
case ';':
ac = BIGSEMI;
break;
case ':':
ac = BIGSEMI;
break;
default:
centre += 5;
i++;
continue;
}
centre += tilesizx[ac]-1;
i++;
}
}
if (centre)
x = (320-centre-10)>>1;
// usehightile = (ht && r_downsize < 3);
while (*t)
{
if (*t == ' ')
{
x+=5;
t++;
continue;
}
ac = 0;
if (*t >= '0' && *t <= '9')
ac = *t - '0' + BIGALPHANUM-10;
else if (*t >= 'a' && *t <= 'z')
ac = toupper(*t) - 'A' + BIGALPHANUM;
else if (*t >= 'A' && *t <= 'Z')
ac = *t - 'A' + BIGALPHANUM;
else switch (*t)
{
case '-':
ac = BIGALPHANUM-11;
break;
case '.':
ac = BIGPERIOD;
break;
case ',':
ac = BIGCOMMA;
break;
case '!':
ac = BIGX_;
break;
case '\'':
ac = BIGAPPOS;
break;
case '?':
ac = BIGQ;
break;
case ';':
ac = BIGSEMI;
break;
case ':':
ac = BIGCOLIN;
break;
default:
x += 5;
t++;
continue;
}
rotatesprite_fs(x<<16,y<<16,65536L,0,ac,s,p,bits);
x += tilesizx[ac];
t++;
}
// usehightile = ht;
return (x);
return dim.x;
}