Merge remote-tracking branch 'gzdoom/master'
This commit is contained in:
commit
942f90a759
24 changed files with 528 additions and 151 deletions
116
src/v_font.cpp
116
src/v_font.cpp
|
|
@ -94,6 +94,7 @@ The FON2 header is followed by variable length data:
|
|||
#include "r_data/r_translate.h"
|
||||
#include "colormatcher.h"
|
||||
#include "v_palette.h"
|
||||
#include "v_text.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
|
@ -340,6 +341,14 @@ FFont *V_GetFont(const char *name)
|
|||
return font;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(FFont, GetFont)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_NAME(name);
|
||||
ACTION_RETURN_POINTER(V_GetFont(name.GetChars()));
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FFont :: FFont
|
||||
|
|
@ -366,7 +375,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
|
|||
LastChar = first + count - 1;
|
||||
FontHeight = 0;
|
||||
GlobalKerning = false;
|
||||
Name = copystring (name);
|
||||
FontName = name;
|
||||
Next = FirstFont;
|
||||
FirstFont = this;
|
||||
Cursor = '_';
|
||||
|
|
@ -478,11 +487,6 @@ FFont::~FFont ()
|
|||
delete[] PatchRemap;
|
||||
PatchRemap = NULL;
|
||||
}
|
||||
if (Name)
|
||||
{
|
||||
delete[] Name;
|
||||
Name = NULL;
|
||||
}
|
||||
|
||||
FFont **prev = &FirstFont;
|
||||
FFont *font = *prev;
|
||||
|
|
@ -508,27 +512,26 @@ FFont::~FFont ()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FFont *FFont::FindFont (const char *name)
|
||||
FFont *FFont::FindFont (FName name)
|
||||
{
|
||||
if (name == NULL)
|
||||
if (name == NAME_None)
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
FFont *font = FirstFont;
|
||||
|
||||
while (font != NULL)
|
||||
while (font != nullptr)
|
||||
{
|
||||
if (stricmp (font->Name, name) == 0)
|
||||
break;
|
||||
if (font->FontName == name) return font;
|
||||
font = font->Next;
|
||||
}
|
||||
return font;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(FFont, FindFont)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_STRING(name);
|
||||
PARAM_NAME(name);
|
||||
ACTION_RETURN_POINTER(FFont::FindFont(name));
|
||||
}
|
||||
|
||||
|
|
@ -843,6 +846,65 @@ int FFont::GetCharWidth (int code) const
|
|||
return (code < 0) ? SpaceWidth : Chars[code - FirstChar].XMove;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(FFont, GetCharWidth)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(FFont);
|
||||
PARAM_INT(code);
|
||||
ACTION_RETURN_INT(self->GetCharWidth(code));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Find string width using this font
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFont::StringWidth(const BYTE *string) const
|
||||
{
|
||||
int w = 0;
|
||||
int maxw = 0;
|
||||
|
||||
while (*string)
|
||||
{
|
||||
if (*string == TEXTCOLOR_ESCAPE)
|
||||
{
|
||||
++string;
|
||||
if (*string == '[')
|
||||
{
|
||||
while (*string != '\0' && *string != ']')
|
||||
{
|
||||
++string;
|
||||
}
|
||||
}
|
||||
if (*string != '\0')
|
||||
{
|
||||
++string;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (*string == '\n')
|
||||
{
|
||||
if (w > maxw)
|
||||
maxw = w;
|
||||
w = 0;
|
||||
++string;
|
||||
}
|
||||
else
|
||||
{
|
||||
w += GetCharWidth(*string++) + GlobalKerning;
|
||||
}
|
||||
}
|
||||
|
||||
return MAX(maxw, w);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(FFont, StringWidth)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(FFont);
|
||||
PARAM_STRING(str);
|
||||
ACTION_RETURN_INT(self->StringWidth(str));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FFont :: LoadTranslations
|
||||
|
|
@ -935,7 +997,7 @@ FFont::FFont (int lump)
|
|||
Lump = lump;
|
||||
Chars = NULL;
|
||||
PatchRemap = NULL;
|
||||
Name = NULL;
|
||||
FontName = NAME_None;
|
||||
Cursor = '_';
|
||||
}
|
||||
|
||||
|
|
@ -951,7 +1013,7 @@ FSingleLumpFont::FSingleLumpFont (const char *name, int lump) : FFont(lump)
|
|||
{
|
||||
assert(lump >= 0);
|
||||
|
||||
Name = copystring (name);
|
||||
FontName = name;
|
||||
|
||||
FMemLump data1 = Wads.ReadLump (lump);
|
||||
const BYTE *data = (const BYTE *)data1.GetMem();
|
||||
|
|
@ -1189,7 +1251,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data)
|
|||
if (destSize < 0)
|
||||
{
|
||||
i += FirstChar;
|
||||
I_FatalError ("Overflow decompressing char %d (%c) of %s", i, i, Name);
|
||||
I_FatalError ("Overflow decompressing char %d (%c) of %s", i, i, FontName.GetChars());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1491,7 +1553,7 @@ FSinglePicFont::FSinglePicFont(const char *picname) :
|
|||
|
||||
FTexture *pic = TexMan[picnum];
|
||||
|
||||
Name = copystring(picname);
|
||||
FontName = picname;
|
||||
FontHeight = pic->GetScaledHeight();
|
||||
SpaceWidth = pic->GetScaledWidth();
|
||||
GlobalKerning = 0;
|
||||
|
|
@ -1905,7 +1967,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l
|
|||
|
||||
memcpy(this->notranslate, notranslate, 256*sizeof(bool));
|
||||
|
||||
Name = copystring(name);
|
||||
FontName = name;
|
||||
Chars = new CharData[count];
|
||||
charlumps = new FTexture*[count];
|
||||
PatchRemap = new BYTE[256];
|
||||
|
|
@ -2492,6 +2554,13 @@ EColorRange V_FindFontColor (FName name)
|
|||
return CR_UNTRANSLATED;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(FFont, FindFontColor)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(FFont);
|
||||
PARAM_NAME(code);
|
||||
ACTION_RETURN_INT((int)V_FindFontColor(code));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// V_LogColorFromColorRange
|
||||
|
|
@ -2666,12 +2735,3 @@ void V_ClearFonts()
|
|||
SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = NULL;
|
||||
}
|
||||
|
||||
void V_RetranslateFonts()
|
||||
{
|
||||
FFont *font = FFont::FirstFont;
|
||||
while(font)
|
||||
{
|
||||
font->LoadTranslations();
|
||||
font = font->Next;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue