- the basics for creating font objects for the in-game bitmap fonts.

Definitions were added to RedNukem frontend for testing, not used yet.
This commit is contained in:
Christoph Oelckers 2020-05-25 17:01:56 +02:00
parent 7c3cac5721
commit 2f672da7ba
8 changed files with 89 additions and 11 deletions

View file

@ -68,7 +68,7 @@
//
//==========================================================================
FFont::FFont (const char *name, const char *nametemplate, const char *filetemplate, int lfirst, int lcount, int start, int fdlump, int spacewidth, bool notranslate, bool iwadonly, bool doomtemplate)
FFont::FFont (const char *name, const char *nametemplate, const char *filetemplate, int lfirst, int lcount, int start, int fdlump, int spacewidth, bool notranslate, bool iwadonly, bool doomtemplate, GlyphSet *baseGlyphs)
{
int i;
FTextureID lump;
@ -185,6 +185,22 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
}
else
{
if (baseGlyphs)
{
// First insert everything from the given glyph set.
GlyphSet::Iterator it(*baseGlyphs);
GlyphSet::Pair* pair;
while (it.NextPair(pair))
{
if (pair->Value && pair->Value->GetTexelWidth() > 0 && pair->Value->GetTexelHeight() > 0)
{
auto position = pair->Key;
if (position < minchar) minchar = position;
if (position > maxchar) maxchar = position;
charMap.Insert(position, pair->Value);
}
}
}
if (nametemplate != nullptr)
{
if (!iwadonly)

View file

@ -78,6 +78,7 @@ enum EColorRange : int
extern int NumTextColors;
using GlyphSet = TMap<int, FTexture*>;
class FFont
{
@ -94,7 +95,7 @@ public:
Custom
};
FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false);
FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false, GlyphSet *baseGlpyphs = nullptr);
virtual ~FFont ();
virtual FTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const;

View file

@ -149,7 +149,7 @@ struct DrawParms
double top;
double left;
float Alpha;
int remap;
int TranslationId;
PalEntry fillcolor;
PalEntry colorOverlay;
PalEntry color;

View file

@ -261,7 +261,7 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms)
dg.mVertCount = 4;
dg.mTexture = img;
dg.mRemapIndex = parms.remap;
dg.mRemapIndex = parms.TranslationId;
SetStyle(img, parms, vertexcolor, dg);
u1 = parms.srcx;

View file

@ -262,7 +262,7 @@ bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, Va_Li
parms->burn = false;
parms->monospace = EMonospacing::Off;
parms->spacing = 0;
parms->remap = -1;
parms->TranslationId = -1;
// Parse the tag list for attributes. (For floating point attributes,
// consider that the C ABI dictates that all floats be promoted to
@ -412,7 +412,7 @@ bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, Va_Li
break;
case DTA_TranslationIndex:
parms->remap = ListGetInt(tags);
parms->TranslationId = ListGetInt(tags);
break;
case DTA_ColorOverlay:

View file

@ -102,7 +102,7 @@ void DrawChar (F2DDrawer* drawer, FFont *font, int normalcolor, double x, double
return;
}
PalEntry color = 0xffffffff;
parms.remap = font->GetColorTranslation((EColorRange)normalcolor, &color);
parms.TranslationId = redirected? -1 : 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);
drawer->AddTexture(pic, parms);
}
@ -140,7 +140,7 @@ void DrawTextCommon(F2DDrawer* drawer, FFont *font, int normalcolor, double x, d
PalEntry colorparm = parms.color;
PalEntry color = 0xffffffff;
parms.remap = font->GetColorTranslation((EColorRange)normalcolor, &color);
parms.TranslationId = font->GetColorTranslation((EColorRange)normalcolor, &color);
parms.color = PalEntry(colorparm.a, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255);
kerning = font->GetDefaultKerning();
@ -167,7 +167,7 @@ void DrawTextCommon(F2DDrawer* drawer, FFont *font, int normalcolor, double x, d
EColorRange newcolor = V_ParseFontColor(ch, normalcolor, boldcolor);
if (newcolor != CR_UNDEFINED)
{
parms.remap = font->GetColorTranslation(newcolor, &color);
parms.TranslationId = font->GetColorTranslation(newcolor, &color);
parms.color = PalEntry(colorparm.a, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255);
currentcolor = newcolor;
}

View file

@ -6752,6 +6752,8 @@ void G_PostCreateGameState(void)
A_InitEnemyFlags();
}
void InitFonts();
static void G_Startup(void)
{
int32_t i;
@ -6813,6 +6815,8 @@ static void G_Startup(void)
if (TileFiles.artLoadFiles("tiles%03i.art") < 0)
G_GameExit("Failed loading art.");
InitFonts();
// Make the fullscreen nuke logo background non-fullbright. Has to be
// after dynamic tile remapping (from C_Compile) and loading tiles.
picanm[LOADSCREEN].sf |= PICANM_NOFULLBRIGHT_BIT;
@ -7020,6 +7024,7 @@ static const char* actions[] = {
"Toggle_Crouch", // This is the last one used by EDuke32.
};
int GameInterface::app_main()
{
buttonMap.SetButtons(actions, NUM_ACTIONS);

View file

@ -21,12 +21,68 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
#include "v_font.h"
#include "duke3d.h"
#include "compat.h"
#include "sbar.h"
BEGIN_RR_NS
void InitFonts()
{
GlyphSet fontdata;
// Small font
for (int i = 0; i < 95; i++)
{
auto tile = TileFiles.GetTile(STARTALPHANUM + i);
if (tile && tile->GetTexelWidth() > 0 && tile->GetTexelHeight() > 0)
fontdata.Insert('!' + i, tile);
}
SmallFont = new ::FFont("SmallFont", nullptr, "defsmallfont", 0, 0, 0, -1, -1, false, false, false, &fontdata);
fontdata.Clear();
// Big font
// This font is VERY messy...
fontdata.Insert('_', TileFiles.GetTile(BIGALPHANUM - 11));
fontdata.Insert('-', TileFiles.GetTile(BIGALPHANUM - 11));
for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, TileFiles.GetTile(BIGALPHANUM - 10 + i));
for (int i = 0; i < 26; i++) fontdata.Insert('A' + i, TileFiles.GetTile(BIGALPHANUM + i));
fontdata.Insert('.', TileFiles.GetTile(BIGPERIOD));
fontdata.Insert(',', TileFiles.GetTile(BIGCOMMA));
fontdata.Insert('!', TileFiles.GetTile(BIGX_));
fontdata.Insert('?', TileFiles.GetTile(BIGQ));
fontdata.Insert(';', TileFiles.GetTile(BIGSEMI));
fontdata.Insert(':', TileFiles.GetTile(BIGCOLIN));
fontdata.Insert('\\', TileFiles.GetTile(BIGALPHANUM + 68));
fontdata.Insert('/', TileFiles.GetTile(BIGALPHANUM + 68));
fontdata.Insert('%', TileFiles.GetTile(BIGALPHANUM + 69));
fontdata.Insert('`', TileFiles.GetTile(BIGAPPOS));
fontdata.Insert('"', TileFiles.GetTile(BIGAPPOS));
fontdata.Insert('\'', TileFiles.GetTile(BIGAPPOS));
BigFont = new ::FFont("BigFont", nullptr, "defbigfont", 0, 0, 0, -1, -1, false, false, false, &fontdata);
fontdata.Clear();
// Tiny font
for (int i = 0; i < 95; i++)
{
auto tile = TileFiles.GetTile(MINIFONT + i);
if (tile && tile->GetTexelWidth() > 0 && tile->GetTexelHeight() > 0)
fontdata.Insert('!' + i, tile);
}
SmallFont2 = new ::FFont("SmallFont2", nullptr, "defsmallfont2", 0, 0, 0, -1, -1, false, false, false, &fontdata);
fontdata.Clear();
// SBAR index font
for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, TileFiles.GetTile(THREEBYFIVE + i));
fontdata.Insert(':', TileFiles.GetTile(THREEBYFIVE + 10));
fontdata.Insert('/', TileFiles.GetTile(THREEBYFIVE + 11));
new ::FFont("IndexFont", nullptr, nullptr, 0, 0, 0, -1, -1, false, false, false, &fontdata);
}
static int32_t sbarx(int32_t x)
{
if (ud.screen_size == 4) return sbarsc(x<<16);
@ -42,7 +98,7 @@ static int32_t sbarxr(int32_t x)
static int32_t sbary(int32_t y)
{
if (hud_position == 1 && ud.screen_size == 4 && ud.althud == 1) return sbarsc(y << 16);
else return (200<<16) - sbarsc(200<<16) + sbarsc(y<<16);
else return (100<<16) - sbarsc(200<<16) + sbarsc(y<<16);
}
int32_t sbarx16(int32_t x)
@ -67,7 +123,7 @@ static int32_t sbarxr16(int32_t x)
int32_t sbary16(int32_t y)
{
return (200<<16) - sbarsc(200<<16) + sbarsc(y);
return (100<<16) - sbarsc(200<<16) + sbarsc(y);
}
static void G_PatchStatusBar(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t aspectCorrect = 1)