- defined a new constant, CR_NATIVEPAL, to use the font functions with a predefined palette.

This is mainly for code clarification, the value is the same as CR_UNDEFINED.
This commit is contained in:
Christoph Oelckers 2021-05-29 11:47:05 +02:00
parent 22be26bd2d
commit 8fae793341
19 changed files with 34 additions and 32 deletions

View file

@ -185,7 +185,7 @@ void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double
{
return;
}
bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0);
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
PalEntry color = 0xffffffff;
if (!palettetrans) parms.TranslationId = font->GetColorTranslation((EColorRange)normalcolor, &color);
parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255);
@ -210,7 +210,7 @@ void DrawChar(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double
uint32_t tag = ListGetInt(args);
bool res = ParseDrawTextureTags(drawer, pic, x, y, tag, args, &parms, false);
if (!res) return;
bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0);
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
PalEntry color = 0xffffffff;
if (!palettetrans) parms.TranslationId = font->GetColorTranslation((EColorRange)normalcolor, &color);
parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255);
@ -265,7 +265,7 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d
if (parms.celly == 0) parms.celly = font->GetHeight() + 1;
parms.celly = int (parms.celly * scaley);
bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0);
bool palettetrans = (normalcolor == CR_NATIVEPAL && parms.TranslationId != 0);
if (normalcolor >= NumTextColors)
normalcolor = CR_UNTRANSLATED;

View file

@ -44,6 +44,7 @@ struct FRemapTable;
enum EColorRange : int
{
CR_UNDEFINED = -1,
CR_NATIVEPAL = -1,
CR_BRICK,
CR_TAN,
CR_GRAY,

View file

@ -817,7 +817,7 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d
DTA_FillColor, 0,
TAG_DONE);
}
DrawChar(twod, font, pt == 0? fontcolor : CR_UNDEFINED, rx, ry, ch,
DrawChar(twod, font, pt == 0? fontcolor : CR_NATIVEPAL, rx, ry, ch,
DTA_DestWidthF, rw,
DTA_DestHeightF, rh,
DTA_Alpha, Alpha,

View file

@ -173,9 +173,9 @@ void drawMapTitle()
if (shadow)
{
DrawText(twod, BigFont, CR_UNDEFINED, x+1, y+1, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, alpha / 2., DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
DrawText(twod, BigFont, CR_UNTRANSLATED, x+1, y+1, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, alpha / 2., DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
}
DrawText(twod, BigFont, CR_UNDEFINED, x, y, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
DrawText(twod, BigFont, CR_UNTRANSLATED, x, y, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
}
}

View file

@ -127,9 +127,9 @@ void viewDrawText(int nFont, const char *pString, int x, int y, int nShade, int
if (shadow)
{
DrawText(twod, pFont, CR_UNDEFINED, x+1, y+1, pString, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, 0.5, TAG_DONE);
DrawText(twod, pFont, CR_UNTRANSLATED, x+1, y+1, pString, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, 0.5, TAG_DONE);
}
DrawText(twod, pFont, CR_UNDEFINED, x, y, pString, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, TRANSLATION(Translation_Remap, nPalette),
DrawText(twod, pFont, CR_NATIVEPAL, x, y, pString, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, TRANSLATION(Translation_Remap, nPalette),
DTA_Color, shadeToLight(nShade), DTA_Alpha, alpha / 255., TAG_DONE);
}

View file

@ -428,7 +428,7 @@ void TextOverlay::DisplayText()
while (i < screentext.Size() && y <= 199)
{
if (y >= -10) {
DrawText(twod, SmallFont, CR_UNDEFINED, nLeft[i], y, screentext[i], DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, TRANSLATION(Translation_BasePalettes, currentCinemaPalette), TAG_DONE);
DrawText(twod, SmallFont, CR_NATIVEPAL, nLeft[i], y, screentext[i], DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, TRANSLATION(Translation_BasePalettes, currentCinemaPalette), TAG_DONE);
}
i++;

View file

@ -1673,7 +1673,7 @@ drawscreen(PLAYERp pp, double smoothratio)
{
auto str = GStrings("Game Paused");
int w = SmallFont->StringWidth(str);
DrawText(twod, SmallFont, CR_UNDEFINED, 160-w, 100, str, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
DrawText(twod, SmallFont, CR_UNTRANSLATED, 160-w, 100, str, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
}
if (!CommEnabled && TEST(pp->Flags, PF_DEAD))

View file

@ -99,13 +99,13 @@ void UpdateStatusBar()
if (hud_textfont || !SmallFont2->CanPrint(pp->cookieQuote))
{
int x = 320 - SmallFont->StringWidth(pp->cookieQuote) / 2;
DrawText(twod, SmallFont, CR_UNDEFINED, x, MESSAGE_LINE*2, pp->cookieQuote, DTA_FullscreenScale, FSMode_Fit640x400,
DrawText(twod, SmallFont, CR_UNTRANSLATED, x, MESSAGE_LINE*2, pp->cookieQuote, DTA_FullscreenScale, FSMode_Fit640x400,
DTA_Alpha, clamp(pp->cookieTime / 60., 0., 1.), TAG_DONE);
}
else
{
int x = 160 - SmallFont2->StringWidth(pp->cookieQuote) / 2;
DrawText(twod, SmallFont2, CR_UNDEFINED, x, MESSAGE_LINE, pp->cookieQuote, DTA_FullscreenScale, FSMode_Fit320x200,
DrawText(twod, SmallFont2, CR_UNTRANSLATED, x, MESSAGE_LINE, pp->cookieQuote, DTA_FullscreenScale, FSMode_Fit320x200,
DTA_Alpha, clamp(pp->cookieTime / 60., 0., 1.), TAG_DONE);
}

View file

@ -442,6 +442,7 @@ struct Font native
enum EColorRange
{
CR_UNDEFINED = -1,
CR_NATIVEPAL = -1,
CR_BRICK,
CR_TAN,
CR_GRAY,

View file

@ -600,7 +600,7 @@ class TextOverlay
bool drawclean;
BrokenLines screentext;
void Init(String text, int cr = Font.CR_UNDEFINED, int pal = 0, bool clean = false)
void Init(String text, int cr = Font.CR_NATIVEPAL, int pal = 0, bool clean = false)
{
screentext = SmallFont.BreakLines(StringTable.Localize(text), 320);
nCrawlY = 199;
@ -667,7 +667,7 @@ class TextTypeOnOverlay
//
//==========================================================================
void Init(Font fnt, String text, int x = 10, int y = 10, int rowpadding = 2, int speed = 2, int cr = Font.CR_UNDEFINED, int pal = 0)
void Init(Font fnt, String text, int x = 10, int y = 10, int rowpadding = 2, int speed = 2, int cr = Font.CR_NATIVEPAL, int pal = 0)
{
let tt = StringTable.Localize(text);
Array<String> lines;

View file

@ -61,13 +61,13 @@ class ListMenuItemBloodTextItem : ListMenuItemTextItem
int pal = 5;
let gamefont = generic_ui ? NewSmallFont : BigFont;
int xpos = mXpos - gamefont.StringWidth(mText) / 2;
int cr = generic_ui? Font.CR_GRAY : Font.CR_UNDEFINED;
int cr = generic_ui? Font.CR_GRAY : Font.CR_NATIVEPAL;
int trans = generic_ui? 0 : Translation.MakeID(Translation_Remap, pal);
if (selected) shade = 32 - ((MSTime() * 120 / 1000) & 63);
Screen.DrawText(gamefont, Font.CR_UNDEFINED, xpos+1, mYpos+1, mText, DTA_Color, 0xff000000, DTA_FullscreenScale, FSMode_Fit320x200);
Screen.DrawText(gamefont, Font.CR_UNDEFINED, xpos, mYpos, mText, DTA_TranslationIndex, trans, DTA_Color, Raze.shadeToLight(shade), DTA_FullscreenScale, FSMode_Fit320x200);
Screen.DrawText(gamefont, Font.CR_UNTRANSLATED, xpos+1, mYpos+1, mText, DTA_Color, 0xff000000, DTA_FullscreenScale, FSMode_Fit320x200);
Screen.DrawText(gamefont, Font.CR_NATIVEPAL, xpos, mYpos, mText, DTA_TranslationIndex, trans, DTA_Color, Raze.shadeToLight(shade), DTA_FullscreenScale, FSMode_Fit320x200);
}
}

View file

@ -330,7 +330,7 @@ class BloodStatusBar : RazeStatusBar
int x = -160 + 80 * (i & 3);
int y = 9 * (i / 4);
int col = players[i].teamId & 3;
int cr = col == 0? Font.CR_UNDEFINED : col == 1? Font.CR_BLUE : Font.CR_RED;
int cr = col == 0? Font.CR_UNTRANSLATED : col == 1? Font.CR_BLUE : Font.CR_RED;
DrawString(tinyf, Raze.PlayerName(i), (x + 4, y), DI_SCREEN_CENTER_TOP, cr, 1., -1, -1);
String gTempStr = String.Format("%2d", players[i].fragCount);
DrawString(tinyf, gTempStr, (x + 76, y), DI_SCREEN_CENTER_TOP, cr, 1., -1, -1);
@ -353,7 +353,7 @@ class BloodStatusBar : RazeStatusBar
int y = 9 * (i / 4);
int col = players[i].teamId & 3;
gTempStr = String.Format("%s", Raze.PlayerName(i));
int cr = col == 0? Font.CR_UNDEFINED : col == 1? Font.CR_BLUE : Font.CR_RED;
int cr = col == 0? Font.CR_UNTRANSLATED : col == 1? Font.CR_BLUE : Font.CR_RED;
DrawString(tinyf, gTempStr.MakeUpper(), (x + 4, y), DI_SCREEN_CENTER_TOP, cr, 1., -1, -1);
x += 76;

View file

@ -100,7 +100,7 @@ struct BloodScreen
if (texsize.X - 10 < width) scalex = width / (texsize.X - 10);
screen.DrawTexture(texid, false, 160, 20, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_CenterOffsetRel, true, DTA_ScaleX, scalex);
}
screen.DrawText(font, Font.CR_UNDEFINED, 160 - width / 2, 20 - fonth / 2, title, DTA_FullscreenScale, FSMode_Fit320x200Top);
screen.DrawText(font, Font.CR_UNTRANSLATED, 160 - width / 2, 20 - fonth / 2, title, DTA_FullscreenScale, FSMode_Fit320x200Top);
}
double fx, fy, fw, fh;
[fx, fy, fw, fh] = Screen.GetFullscreenRect(320, 200, FSMode_ScaleToFit43Top);
@ -117,8 +117,8 @@ struct BloodScreen
static void DrawText(Font pFont, String pString, int x, int y, int position = 0, int nShade = 0, int nPalette = 0, bool shadow = true, float alpha = 1.)
{
if (position > 0) x -= pFont.StringWidth(pString) * position / 2;
if (shadow) Screen.DrawText(pFont, Font.CR_UNDEFINED, x+1, y+1, pString, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, 0.5);
Screen.DrawText(pFont, Font.CR_UNDEFINED, x, y, pString, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, Translation.MakeID(Translation_Remap, nPalette),
if (shadow) Screen.DrawText(pFont, Font.CR_UNTRANSLATED, x+1, y+1, pString, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, 0.5);
Screen.DrawText(pFont, Font.CR_NATIVEPAL, x, y, pString, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, Translation.MakeID(Translation_Remap, nPalette),
DTA_Color, Raze.shadeToLight(nShade), DTA_Alpha, alpha);
}

View file

@ -108,7 +108,7 @@ struct Duke native
fsmode = FSMode_Fit640x400;
}
if (align != -1) x -= SmallFont.StringWidth(t) * (align == 0 ? 0.5 : 1);
Screen.DrawText(SmallFont, Font.CR_UNDEFINED, x, y + 2, t, DTA_FullscreenScale, fsmode, DTA_TranslationIndex, Translation.MakeID(Translation_Remap, trans), DTA_Color, Raze.shadeToLight(shade));
Screen.DrawText(SmallFont, Font.CR_NATIVEPAL, x, y + 2, t, DTA_FullscreenScale, fsmode, DTA_TranslationIndex, Translation.MakeID(Translation_Remap, trans), DTA_Color, Raze.shadeToLight(shade));
}
}

View file

@ -91,8 +91,8 @@ class DukeMenuDelegate : RazeMenuDelegate
double x = xx / 65536.;
double y = yy / 65536.;
Screen.DrawText(SmallFont2, Font.CR_UNDEFINED, x + 1, y + 1, t, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, 0.5);
Screen.DrawText(SmallFont2, Font.CR_UNDEFINED, x, y, t, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, TRANSLATION.MakeID(Translation_Remap, p));
Screen.DrawText(SmallFont2, Font.CR_UNTRANSLATED, x + 1, y + 1, t, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, 0.5);
Screen.DrawText(SmallFont2, Font.CR_NATIVEPAL, x, y, t, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, TRANSLATION.MakeID(Translation_Remap, p));
}
static void mgametextcenter(int xx, int yy, String t)
@ -100,7 +100,7 @@ class DukeMenuDelegate : RazeMenuDelegate
double x = xx / 65536. + 160. - SmallFont.StringWidth(t) * 0.5;
double y = yy / 65536.;
Screen.DrawText(SmallFont, Font.CR_UNDEFINED, x, y + 2, t, DTA_FullscreenScale, FSMode_Fit320x200);
Screen.DrawText(SmallFont, Font.CR_UNTRANSLATED, x, y + 2, t, DTA_FullscreenScale, FSMode_Fit320x200);
}
@ -183,7 +183,7 @@ class ListMenuItemDukeTextItem : ListMenuItemTextItem
pe = Color(255, 160, 160, 160);
}
Screen.DrawText(BigFont, Font.CR_UNDEFINED, xpos, mYpos, mText, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Color, pe, DTA_TranslationIndex, trans);
Screen.DrawText(BigFont, Font.CR_NATIVEPAL, xpos, mYpos, mText, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Color, pe, DTA_TranslationIndex, trans);
}
}

View file

@ -454,12 +454,12 @@ class DukeStatusBar : DukeCommonStatusBar
int percentv = getinvamount(p);
format = String.Format("%3d%%", percentv);
int color = percentv > 50 ? 11 : percentv > 25 ? 23 : 2;
DrawString(miniFont, format, (x + 34, top + 24), DI_TEXT_ALIGN_RIGHT, Font.CR_UNDEFINED, 1, 0, 0, (1, 1), Translation.MakeID(Translation_Remap, color));
DrawString(miniFont, format, (x + 34, top + 24), DI_TEXT_ALIGN_RIGHT, Font.CR_NATIVEPAL, 1, 0, 0, (1, 1), Translation.MakeID(Translation_Remap, color));
String text;
int pal;
[text, pal] = ontext(p);
if (text.length() > 0) DrawString(miniFont, text, (x + 34, top + 14), DI_TEXT_ALIGN_RIGHT, Font.CR_UNDEFINED, 1, 0, 0, (1, 1), Translation.MakeID(Translation_Remap, pal));
if (text.length() > 0) DrawString(miniFont, text, (x + 34, top + 14), DI_TEXT_ALIGN_RIGHT, Font.CR_NATIVEPAL, 1, 0, 0, (1, 1), Translation.MakeID(Translation_Remap, pal));
}
}

View file

@ -471,7 +471,7 @@ class Cinema : SkippableScreenJob
cinematile = TexMan.CheckForTexture(bgTexture, TexMan.Type_Any);
textov = new("TextOverlay");
palette = Translation.MakeID(Translation_BasePalette, pal);
textov.Init(text, Font.CR_UNDEFINED, palette);
textov.Init(text, Font.CR_NATIVEPAL, palette);
cdtrack = cdtrk;
return self;
}

View file

@ -134,7 +134,7 @@ struct SW native
static void DrawString(int x, int y, String text, int shade, int pal, int align = -1)
{
if (align != -1) x -= SmallFont.StringWidth(text) * (align == 0 ? 0.5 : 1);
Screen.DrawText(SmallFont, Font.CR_UNDEFINED, x, y, text, DTA_FullscreenScale, FSMode_Fit320x200,
Screen.DrawText(SmallFont, Font.CR_NATIVEPAL, x, y, text, DTA_FullscreenScale, FSMode_Fit320x200,
DTA_Color, Raze.shadeToLight(shade), DTA_TranslationIndex, Translation.MakeID(Translation_Remap, pal));
}
}

View file

@ -101,7 +101,7 @@ class ListMenuItemSWTextItem : ListMenuItemTextItem
override void Draw(bool selected, ListMenuDescriptor desc)
{
let gamefont = generic_ui ? NewSmallFont : mFont;
int cr = mColor != Font.CR_UNDEFINED? mColor : generic_ui? Font.CR_RED : Font.CR_UNDEFINED;
int cr = mColor != Font.CR_UNDEFINED? mColor : generic_ui? Font.CR_RED : Font.CR_UNTRANSLATED;
double scalex = generic_ui && mFont == SmallFont? 0.5 : 1.;
// The font here is very bulky and may cause problems with localized content. Account for that by squashing the text if needed.