diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 906afede8..c10bc2efd 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -119,6 +119,7 @@ enum align { align_smallfixed, align_smallcenter, align_smallright, + align_smallthin, align_thin, align_thinfixed, align_thincenter, @@ -135,6 +136,7 @@ static const char *const align_opt[] = { "small-fixed", "small-center", "small-right", + "small-thin", "thin", "thin-fixed", "thin-center", @@ -760,6 +762,9 @@ static int libd_drawString(lua_State *L) case align_smallright: V_DrawRightAlignedSmallString(x, y, flags, str); break; + case align_smallthin: + V_DrawSmallThinString(x, y, flags, str); + break; // tny_font case align_thin: V_DrawThinString(x, y, flags, str); diff --git a/src/v_video.c b/src/v_video.c index d4aad6a64..7a51c9088 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2423,6 +2423,211 @@ void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *st V_DrawThinString(x, y, option, string); } +// +// Write a string using the tny_font, 0.5x scale +// NOTE: the text is centered for screens larger than the base width +// +/* +void V_DrawSmallThinString(INT32 x, INT32 y, INT32 option, const char *string) +{ + INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; + const char *ch = string; + INT32 charflags = 0; + const UINT8 *colormap = NULL; + INT32 spacewidth = 2, charwidth = 0; + + INT32 lowercase = (option & V_ALLOWLOWERCASE); + option &= ~V_FLIP; // which is also shared with V_ALLOWLOWERCASE... + + if (option & V_NOSCALESTART) + { + dupx = vid.dupx; + dupy = vid.dupy; + scrwidth = vid.width; + } + else + { + dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/4; + scrwidth -= left; + } + + charflags = (option & V_CHARCOLORMASK); + + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 3; + // FALLTHRU + case V_OLDSPACING: + charwidth = 3; + break; + case V_6WIDTHSPACE: + spacewidth = 2; + default: + break; + } + + for (;;ch++) + { + if (!*ch) + break; + if (*ch & 0x80) //color parsing -x 2.16.09 + { + // manually set flags override color codes + if (!(option & V_CHARCOLORMASK)) + charflags = ((*ch & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK; + continue; + } + if (*ch == '\n') + { + cx = x; + + if (option & V_RETURN8) + cy += 4*dupy; + else + cy += 6*dupy; + + continue; + } + + c = *ch; + if (!lowercase || !tny_font[c-HU_FONTSTART]) + c = toupper(c); + c -= HU_FONTSTART; + + if (c < 0 || c >= HU_FONTSIZE || !tny_font[c]) + { + cx += spacewidth * dupx; + continue; + } + + if (charwidth) + { + w = charwidth * dupx; + center = w/2 - SHORT(tny_font[c]->width)*dupx/4; + } + else + w = SHORT(tny_font[c]->width) * dupx / 2; + if (cx > scrwidth) + break; + if (cx+left + w < 0) //left boundary check + { + cx += w; + continue; + } + + colormap = V_GetStringColormap(charflags); + V_DrawFixedPatch((cx + center)<<FRACBITS, cy<<FRACBITS, FRACUNIT/2, option, tny_font[c], colormap); + + cx += w; + } +}*/ +void V_DrawSmallThinString(INT32 x, INT32 y, INT32 option, const char *string) +{ + INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; + const char *ch = string; + INT32 charflags = 0; + const UINT8 *colormap = NULL; + INT32 spacewidth = 2, charwidth = 0; + + INT32 lowercase = (option & V_ALLOWLOWERCASE); + option &= ~V_FLIP; // which is also shared with V_ALLOWLOWERCASE... + + if (option & V_NOSCALESTART) + { + dupx = vid.dupx; + dupy = vid.dupy; + scrwidth = vid.width; + } + else + { + dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/2; + scrwidth -= left; + } + + charflags = (option & V_CHARCOLORMASK); + + // Monospace only + spacing changes, otherwise the characters are squished together. ~Golden + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 3; + /* FALLTHRU */ + case V_OLDSPACING: + charwidth = 3; + break; + case V_6WIDTHSPACE: + spacewidth = 2; + charwidth = 3; + break; + default: + spacewidth = 3; + charwidth = 3; + break; + } + + for (;;ch++) + { + if (!*ch) + break; + if (*ch & 0x80) //color parsing -x 2.16.09 + { + // manually set flags override color codes + if (!(option & V_CHARCOLORMASK)) + charflags = ((*ch & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK; + continue; + } + if (*ch == '\n') + { + cx = x; + + if (option & V_RETURN8) + cy += 4*dupy; + else + cy += 6*dupy; + + continue; + } + + c = *ch; + if (!lowercase) + c = toupper(c); + c -= HU_FONTSTART; + + // character does not exist or is a space + if (c < 0 || c >= HU_FONTSIZE || !tny_font[c]) + { + cx += spacewidth * dupx; + continue; + } + + if (charwidth) + { + w = charwidth * dupx; + center = w/2 - SHORT(tny_font[c]->width)*dupx/4; + } + else + w = SHORT(tny_font[c]->width) * dupx / 2; + + if (cx > scrwidth) + break; + if (cx+left + w < 0) //left boundary check + { + cx += w; + continue; + } + + colormap = V_GetStringColormap(charflags); + V_DrawFixedPatch((cx + center)<<FRACBITS, cy<<FRACBITS, FRACUNIT/2, option, tny_font[c], colormap); + + cx += w; + } +} + // Draws a string at a fixed_t location. void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { diff --git a/src/v_video.h b/src/v_video.h index f89c9f12d..e48511264 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -213,6 +213,9 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawCenteredThinString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *string); +// draw a string using the tny_font, 0.5x scale +void V_DrawSmallThinString(INT32 x, INT32 y, INT32 option, const char *string); + // draw a string using the hu_font at fixed_t coordinates void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); void V_DrawCenteredStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string);