diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index d14a43944bfc23d9bce4986dc7ac336bc3deb56f..bf8fe017b3d244db77aaef6421eef4a695a7aabc 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -119,9 +119,25 @@ enum align { align_center, align_right, align_fixed, + align_fixedcenter, + align_fixedright, align_small, + align_smallfixed, + align_smallfixedcenter, + align_smallfixedright, + align_smallcenter, align_smallright, + align_smallthin, + align_smallthincenter, + align_smallthinright, + align_smallthinfixed, + align_smallthinfixedcenter, + align_smallthinfixedright, align_thin, + align_thinfixed, + align_thinfixedcenter, + align_thinfixedright, + align_thincenter, align_thinright }; static const char *const align_opt[] = { @@ -129,9 +145,25 @@ static const char *const align_opt[] = { "center", "right", "fixed", + "fixed-center", + "fixed-right", "small", + "small-fixed", + "small-fixed-center", + "small-fixed-right", + "small-center", "small-right", + "small-thin", + "small-thin-center", + "small-thin-right", + "small-thin-fixed", + "small-thin-fixed-center", + "small-thin-fixed-right", "thin", + "thin-fixed", + "thin-fixed-center", + "thin-fixed-right", + "thin-center", "thin-right", NULL}; @@ -775,20 +807,68 @@ static int libd_drawString(lua_State *L) case align_fixed: V_DrawStringAtFixed(x, y, flags, str); break; + case align_fixedcenter: + V_DrawCenteredStringAtFixed(x, y, flags, str); + break; + case align_fixedright: + V_DrawRightAlignedStringAtFixed(x, y, flags, str); + break; // hu_font, 0.5x scale case align_small: V_DrawSmallString(x, y, flags, str); break; + case align_smallfixed: + V_DrawSmallStringAtFixed(x, y, flags, str); + break; + case align_smallfixedcenter: + V_DrawCenteredSmallStringAtFixed(x, y, flags, str); + break; + case align_smallfixedright: + V_DrawRightAlignedSmallStringAtFixed(x, y, flags, str); + break; + case align_smallcenter: + V_DrawCenteredSmallString(x, y, flags, str); + break; case align_smallright: V_DrawRightAlignedSmallString(x, y, flags, str); break; + case align_smallthin: + V_DrawSmallThinString(x, y, flags, str); + break; + case align_smallthincenter: + V_DrawCenteredSmallThinString(x, y, flags, str); + break; + case align_smallthinright: + V_DrawRightAlignedSmallThinString(x, y, flags, str); + break; + case align_smallthinfixed: + V_DrawSmallThinStringAtFixed(x, y, flags, str); + break; + case align_smallthinfixedcenter: + V_DrawCenteredSmallThinStringAtFixed(x, y, flags, str); + break; + case align_smallthinfixedright: + V_DrawRightAlignedSmallThinStringAtFixed(x, y, flags, str); + break; // tny_font case align_thin: V_DrawThinString(x, y, flags, str); break; + case align_thincenter: + V_DrawCenteredThinString(x, y, flags, str); + break; case align_thinright: V_DrawRightAlignedThinString(x, y, flags, str); break; + case align_thinfixed: + V_DrawThinStringAtFixed(x, y, flags, str); + break; + case align_thinfixedcenter: + V_DrawCenteredThinStringAtFixed(x, y, flags, str); + break; + case align_thinfixedright: + V_DrawRightAlignedThinStringAtFixed(x, y, flags, str); + break; } return 0; } diff --git a/src/v_video.c b/src/v_video.c index 81625ff9ed70f832fe7e52a1b014c3035a727b67..a1e702f7e38220764574b64e5b9902b1c19216be 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2299,6 +2299,13 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) } } +void V_DrawCenteredSmallString(INT32 x, INT32 y, INT32 option, const char *string) +{ + x -= V_SmallStringWidth(string, option)/2; + V_DrawSmallString(x, y, option, string); +} + + void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *string) { x -= V_SmallStringWidth(string, option); @@ -2404,12 +2411,44 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) } } +void V_DrawCenteredThinString(INT32 x, INT32 y, INT32 option, const char *string) +{ + x -= V_ThinStringWidth(string, option)/2; + V_DrawThinString(x, y, option, string); +} + void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *string) { x -= V_ThinStringWidth(string, option); 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 +// +// Literally a wrapper. ~Golden +void V_DrawSmallThinString(INT32 x, INT32 y, INT32 option, const char *string) +{ + x <<= FRACBITS; + y <<= FRACBITS; + V_DrawSmallThinStringAtFixed((fixed_t)x, (fixed_t)y, option, string); +} + +void V_DrawCenteredSmallThinString(INT32 x, INT32 y, INT32 option, const char *string) +{ + x <<= FRACBITS; + y <<= FRACBITS; + V_DrawCenteredSmallThinStringAtFixed((fixed_t)x, (fixed_t)y, option, string); +} + +void V_DrawRightAlignedSmallThinString(INT32 x, INT32 y, INT32 option, const char *string) +{ + x <<= FRACBITS; + y <<= FRACBITS; + V_DrawRightAlignedSmallThinStringAtFixed((fixed_t)x, (fixed_t)y, option, string); +} + // Draws a string at a fixed_t location. void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { @@ -2511,6 +2550,360 @@ 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) +{ + x -= (V_StringWidth(string, option) / 2)<<FRACBITS; + V_DrawStringAtFixed(x, y, option, string); +} + +void V_DrawRightAlignedStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + x -= V_StringWidth(string, option)<<FRACBITS; + V_DrawStringAtFixed(x, y, option, string); +} + +// Draws a small string at a fixed_t location. +void V_DrawSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + fixed_t cx = x, cy = y; + INT32 w, c, 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); + + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 4; + /* FALLTHRU */ + case V_OLDSPACING: + charwidth = 4; + break; + case V_6WIDTHSPACE: + spacewidth = 3; + 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)<<FRACBITS; + else + cy += (6*dupy)<<FRACBITS; + + 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 || !hu_font[c]) + { + cx += (spacewidth * dupx)<<FRACBITS; + continue; + } + + if (charwidth) + { + w = charwidth * dupx; + center = w/2 - SHORT(hu_font[c]->width)*(dupx/4); + } + else + w = SHORT(hu_font[c]->width) * dupx / 2; + + if ((cx>>FRACBITS) > scrwidth) + break; + if ((cx>>FRACBITS)+left + w < 0) //left boundary check + { + cx += w<<FRACBITS; + continue; + } + + colormap = V_GetStringColormap(charflags); + + V_DrawFixedPatch(cx + (center<<FRACBITS), cy, FRACUNIT/2, option, hu_font[c], colormap); + + cx += w<<FRACBITS; + } +} + +void V_DrawCenteredSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + x -= (V_SmallStringWidth(string, option) / 2)<<FRACBITS; + V_DrawSmallStringAtFixed(x, y, option, string); +} + +void V_DrawRightAlignedSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + x -= V_SmallStringWidth(string, option)<<FRACBITS; + V_DrawSmallStringAtFixed(x, y, option, string); +} + +// Draws a thin string at a fixed_t location. +void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + fixed_t cx = x, cy = y; + INT32 w, c, 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); + + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 8; + /* FALLTHRU */ + case V_OLDSPACING: + charwidth = 8; + break; + case V_6WIDTHSPACE: + spacewidth = 6; + 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 += (8*dupy)<<FRACBITS; + else + cy += (12*dupy)<<FRACBITS; + + continue; + } + + c = *ch; + if (!lowercase || !tny_font[c-HU_FONTSTART]) + 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)<<FRACBITS; + continue; + } + + if (charwidth) + { + w = charwidth * dupx; + center = w/2 - SHORT(tny_font[c]->width)*(dupx/2); + } + else + w = SHORT(tny_font[c]->width) * dupx; + + if ((cx>>FRACBITS) > scrwidth) + break; + if ((cx>>FRACBITS)+left + w < 0) //left boundary check + { + cx += w<<FRACBITS; + continue; + } + + colormap = V_GetStringColormap(charflags); + + V_DrawFixedPatch(cx + (center<<FRACBITS), cy, FRACUNIT, option, tny_font[c], colormap); + + cx += w<<FRACBITS; + } +} + +void V_DrawCenteredThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + x -= (V_ThinStringWidth(string, option) / 2)<<FRACBITS; + V_DrawThinStringAtFixed(x, y, option, string); +} + +void V_DrawRightAlignedThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + x -= V_ThinStringWidth(string, option)<<FRACBITS; + V_DrawThinStringAtFixed(x, y, option, string); +} + +// Draws a small string at a fixed_t location. +void V_DrawSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + fixed_t cx = x, cy = y; + INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; + const char *ch = string; + INT32 charflags = 0; + const UINT8 *colormap = NULL; + INT32 spacewidth = 2<<FRACBITS, charwidth = 0; + + INT32 lowercase = (option & V_ALLOWLOWERCASE); + option &= ~V_FLIP; // which is also shared with V_ALLOWLOWERCASE... + + if (option & V_NOSCALESTART) + { + dupx = vid.dupx<<FRACBITS; + dupy = vid.dupy<<FRACBITS; + scrwidth = vid.width; + } + else + { + dupx = dupy = FRACUNIT; + scrwidth = FixedDiv(vid.width<<FRACBITS, vid.dupx); + left = ((scrwidth - (BASEVIDWIDTH<<FRACBITS))/2); + scrwidth -= left; + } + + charflags = (option & V_CHARCOLORMASK); + + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 4<<FRACBITS; + /* FALLTHRU */ + case V_OLDSPACING: + charwidth = 4<<FRACBITS; + break; + case V_6WIDTHSPACE: + spacewidth = 3<<FRACBITS; + 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) + c = toupper(c); + c -= HU_FONTSTART; + + // character does not exist or is a space + if (c < 0 || c >= HU_FONTSIZE || !tny_font[c]) + { + cx += FixedMul(spacewidth, dupx); + continue; + } + + if (charwidth) + { + w = FixedMul(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, cy, FRACUNIT/2, option, tny_font[c], colormap); + + cx += w; + } +} + +void V_DrawCenteredSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + x -= V_SmallThinStringWidth(string, option)/4; + V_DrawSmallThinStringAtFixed(x, y, option, string); +} + +void V_DrawRightAlignedSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) +{ + x -= V_SmallThinStringWidth(string, option)/2; + V_DrawSmallThinStringAtFixed(x, y, option, string); +} + // Draws a tallnum. Replaces two functions in y_inter and st_stuff void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num) { @@ -3068,6 +3461,15 @@ INT32 V_ThinStringWidth(const char *string, INT32 option) return w; } +// +// Find string width from tny_font chars, 0.5x scale +// +INT32 V_SmallThinStringWidth(const char *string, INT32 option) +{ + INT32 w = V_ThinStringWidth(string, option)<<FRACBITS; + return w/2 + FRACUNIT; // +FRACUNIT because otherwise it's offset wrong. +} + boolean *heatshifter = NULL; INT32 lastheight = 0; INT32 heatindex[2] = { 0, 0 }; diff --git a/src/v_video.h b/src/v_video.h index bc19f6e9970339660082c1f1c074eb4f9e25d3c3..8e671f9186e2bd9d6eb95087bbe890cfdf9c3f10 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -202,13 +202,38 @@ void V_DrawRightAlignedString(INT32 x, INT32 y, INT32 option, const char *string // draw a string using the hu_font, 0.5x scale void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string); +void V_DrawCenteredSmallString(INT32 x, INT32 y, INT32 option, const char *string); void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *string); // draw a string using the tny_font 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); +void V_DrawCenteredSmallThinString(INT32 x, INT32 y, INT32 option, const char *string); +void V_DrawRightAlignedSmallThinString(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); +void V_DrawRightAlignedStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); + +// draw a string using the hu_font at fixed_t coordinates, 0.5x scale +void V_DrawSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); +void V_DrawCenteredSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); +void V_DrawRightAlignedSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); + +// draw a string using the tny_font at fixed_t coordinates +void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); +void V_DrawCenteredThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); +void V_DrawRightAlignedThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); + +// draw a string using the tny_font at fixed_t coordinates, 0.5x scale +void V_DrawSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); +void V_DrawCenteredSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); +void V_DrawRightAlignedSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string); // Draw tall nums, used for menu, HUD, intermission void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num); @@ -234,6 +259,8 @@ INT32 V_StringWidth(const char *string, INT32 option); INT32 V_SmallStringWidth(const char *string, INT32 option); // Find string width from tny_font chars INT32 V_ThinStringWidth(const char *string, INT32 option); +// Find string width from tny_font chars, 0.5x scale +INT32 V_SmallThinStringWidth(const char *string, INT32 option); void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param);