- Moved the text color definitions out of the executable and into an external

data file.
- Removed the setcolor CCMD. It's been obsolete for years, ever since color-
  aware cvars were added.
- Changed V_GetColorStringByName() to return an FString, because it did a
  copystring() call.
- Extended V_GetColorFromString() so that it accepts HTML-style #RRGGBB and
  #RGB color strings.


SVN r313 (trunk)
This commit is contained in:
Randy Heit 2006-08-30 02:38:39 +00:00
parent 38f650f7c5
commit 2fb55622e7
13 changed files with 941 additions and 297 deletions

View file

@ -1,3 +1,13 @@
August 29, 2006
- Moved the text color definitions out of the executable and into an external
data file.
- Removed the setcolor CCMD. It's been obsolete for years, ever since color-
aware cvars were added.
- Changed V_GetColorStringByName() to return an FString, because it did a
copystring() call.
- Extended V_GetColorFromString() so that it accepts HTML-style #RRGGBB and
#RGB color strings.
August 27, 2006 (Changes by Graf Zahl) August 27, 2006 (Changes by Graf Zahl)
- fixed: callstatechain didn`t check for NULL code pointers - fixed: callstatechain didn`t check for NULL code pointers

View file

@ -904,15 +904,14 @@ int FColorCVar::ToInt2 (UCVarValue value, ECVarType type)
if (type == CVAR_String) if (type == CVAR_String)
{ {
char *string; FString string;
// Only allow named colors after the screen exists (i.e. after // Only allow named colors after the screen exists (i.e. after
// we've got some lumps loaded, so X11R6RGB can be read). Since // we've got some lumps loaded, so X11R6RGB can be read). Since
// the only time this might be called before that is when loading // the only time this might be called before that is when loading
// zdoom.cfg, this shouldn't be a problem. // zdoom.ini, this shouldn't be a problem.
if (screen && (string = V_GetColorStringByName (value.String)) ) if (screen && !(string = V_GetColorStringByName (value.String)).IsEmpty() )
{ {
ret = V_GetColorFromString (NULL, string); ret = V_GetColorFromString (NULL, string);
delete[] string;
} }
else else
{ {

View file

@ -4,6 +4,8 @@ xx(None)
xx(Super) xx(Super)
xx(Object) xx(Object)
xx(Untranslated)
// Hexen sound sequence names // Hexen sound sequence names
xx(Platform) xx(Platform)
xx(PlatformMetal) xx(PlatformMetal)

View file

@ -249,7 +249,7 @@ void FJPEGTexture::MakeTexture ()
(cinfo.out_color_space == JCS_CMYK && cinfo.num_components == 4) || (cinfo.out_color_space == JCS_CMYK && cinfo.num_components == 4) ||
(cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1))) (cinfo.out_color_space == JCS_GRAYSCALE && cinfo.num_components == 1)))
{ {
Printf (TEXTCOLOR_ORANGE "Unsupported color format\n", Name); Printf (TEXTCOLOR_ORANGE "Unsupported color format\n");
throw -1; throw -1;
} }
@ -297,6 +297,11 @@ void FJPEGTexture::MakeTexture ()
in += 4; in += 4;
} }
break; break;
default:
// The other colorspaces were considered above and discarded,
// but GCC will complain without a default for them here.
break;
} }
y++; y++;
} }

View file

@ -64,22 +64,22 @@ void FTexture::InitGrayMap()
FTexture * FTexture::CreateTexture (int lumpnum, int usetype) FTexture * FTexture::CreateTexture (int lumpnum, int usetype)
{ {
static TexCreateInfo CreateInfo[]={ static TexCreateInfo CreateInfo[]={
{ FIMGZTexture::Check, FIMGZTexture::Create, FTexture::TEX_Any }, { FIMGZTexture::Check, FIMGZTexture::Create, TEX_Any },
{ FPNGTexture::Check, FPNGTexture::Create, FTexture::TEX_Any }, { FPNGTexture::Check, FPNGTexture::Create, TEX_Any },
{ FJPEGTexture::Check, FJPEGTexture::Create, FTexture::TEX_Any }, { FJPEGTexture::Check, FJPEGTexture::Create, TEX_Any },
{ FDDSTexture::Check, FDDSTexture::Create, FTexture::TEX_Any }, { FDDSTexture::Check, FDDSTexture::Create, TEX_Any },
{ FPCXTexture::Check, FPCXTexture::Create, FTexture::TEX_Any }, { FPCXTexture::Check, FPCXTexture::Create, TEX_Any },
{ FTGATexture::Check, FTGATexture::Create, FTexture::TEX_Any }, { FTGATexture::Check, FTGATexture::Create, TEX_Any },
{ FRawPageTexture::Check, FRawPageTexture::Create, FTexture::TEX_MiscPatch }, { FRawPageTexture::Check, FRawPageTexture::Create, TEX_MiscPatch },
{ FFlatTexture::Check, FFlatTexture::Create, FTexture::TEX_Flat }, { FFlatTexture::Check, FFlatTexture::Create, TEX_Flat },
{ FPatchTexture::Check, FPatchTexture::Create, FTexture::TEX_Any }, { FPatchTexture::Check, FPatchTexture::Create, TEX_Any },
{ FAutomapTexture::Check, FAutomapTexture::Create, FTexture::TEX_Autopage }, { FAutomapTexture::Check, FAutomapTexture::Create, TEX_Autopage },
}; };
FWadLump data = Wads.OpenLumpNum (lumpnum); FWadLump data = Wads.OpenLumpNum (lumpnum);
for(int i = 0; i < countof(CreateInfo); i++) for(size_t i = 0; i < countof(CreateInfo); i++)
{ {
if ((CreateInfo[i].usetype == usetype || CreateInfo[i].usetype == TEX_Any) && if ((CreateInfo[i].usetype == usetype || CreateInfo[i].usetype == TEX_Any) &&
CreateInfo[i].Check(data)) CreateInfo[i].Check(data))

View file

@ -42,10 +42,9 @@
bool FTGATexture::Check(FileReader & data) bool FTGATexture::Check(FileReader & data)
{ {
TGAHeader hdr; TGAHeader hdr;
if (data.GetLength() < sizeof(hdr)) return false; if (data.GetLength() < (long)sizeof(hdr)) return false;
data.Seek(0, SEEK_SET); data.Seek(0, SEEK_SET);
data.Read(&hdr, sizeof(hdr)); data.Read(&hdr, sizeof(hdr));

File diff suppressed because it is too large Load diff

View file

@ -97,7 +97,7 @@ public:
protected: protected:
FFont (); FFont ();
void BuildTranslations (const double *luminosity, const BYTE *identity); void BuildTranslations (const double *luminosity, const BYTE *identity, const void *ranges);
static int SimpleTranslation (byte *colorsused, byte *translation, byte *identity, double **luminosity); static int SimpleTranslation (byte *colorsused, byte *translation, byte *identity, double **luminosity);
@ -121,19 +121,13 @@ protected:
friend void V_Shutdown(); friend void V_Shutdown();
#if defined(_MSC_VER) && _MSC_VER < 1310
template<> friend FArchive &operator<< (FArchive &arc, FFont* &font);
#else
friend FArchive &SerializeFFontPtr (FArchive &arc, FFont* &font); friend FArchive &SerializeFFontPtr (FArchive &arc, FFont* &font);
#endif
}; };
#if !defined(_MSC_VER) || _MSC_VER >= 1310
template<> inline FArchive &operator<< <FFont> (FArchive &arc, FFont* &font) template<> inline FArchive &operator<< <FFont> (FArchive &arc, FFont* &font)
{ {
return SerializeFFontPtr (arc, font); return SerializeFFontPtr (arc, font);
} }
#endif
class FSingleLumpFont : public FFont class FSingleLumpFont : public FFont
{ {
@ -141,6 +135,7 @@ public:
FSingleLumpFont (const char *fontname, int lump); FSingleLumpFont (const char *fontname, int lump);
protected: protected:
void CheckFON1Chars (int lump, const BYTE *data, double *luminosity);
void BuildTranslations2 (); void BuildTranslations2 ();
void FixupPalette (BYTE *identity, double *luminosity, const BYTE *palette, bool rescale); void FixupPalette (BYTE *identity, double *luminosity, const BYTE *palette, bool rescale);
void LoadFON1 (int lump, const BYTE *data); void LoadFON1 (int lump, const BYTE *data);
@ -153,5 +148,7 @@ void RecordTextureColors (FTexture *pic, byte *colorsused);
extern FFont *SmallFont, *SmallFont2, *BigFont, *ConFont; extern FFont *SmallFont, *SmallFont2, *BigFont, *ConFont;
void V_InitCustomFonts (); void V_InitCustomFonts ();
void V_InitFontColors ();
EColorRange V_FindFontColor (const char *name);
#endif //__V_FONT_H__ #endif //__V_FONT_H__

View file

@ -486,7 +486,7 @@ void V_ForceBlend (int blendr, int blendg, int blendb, int blenda)
CCMD (testblend) CCMD (testblend)
{ {
char *colorstring; FString colorstring;
int color; int color;
float amt; float amt;
@ -496,10 +496,9 @@ CCMD (testblend)
} }
else else
{ {
if ( (colorstring = V_GetColorStringByName (argv[1])) ) if ( !(colorstring = V_GetColorStringByName (argv[1])).IsEmpty() )
{ {
color = V_GetColorFromString (NULL, colorstring); color = V_GetColorFromString (NULL, colorstring);
delete[] colorstring;
} }
else else
{ {
@ -519,7 +518,7 @@ CCMD (testblend)
CCMD (testfade) CCMD (testfade)
{ {
char *colorstring; FString colorstring;
DWORD color; DWORD color;
if (argv.argc() < 2) if (argv.argc() < 2)
@ -528,10 +527,9 @@ CCMD (testfade)
} }
else else
{ {
if ( (colorstring = V_GetColorStringByName (argv[1])) ) if ( !(colorstring = V_GetColorStringByName (argv[1])).IsEmpty() )
{ {
color = V_GetColorFromString (NULL, colorstring); color = V_GetColorFromString (NULL, colorstring);
delete[] colorstring;
} }
else else
{ {
@ -762,7 +760,7 @@ void FDynamicColormap::ChangeColorFade (PalEntry lightcolor, PalEntry fadecolor)
CCMD (testcolor) CCMD (testcolor)
{ {
char *colorstring; FString colorstring;
DWORD color; DWORD color;
int desaturate; int desaturate;
@ -772,10 +770,9 @@ CCMD (testcolor)
} }
else else
{ {
if ( (colorstring = V_GetColorStringByName (argv[1])) ) if ( !(colorstring = V_GetColorStringByName (argv[1])).IsEmpty() )
{ {
color = V_GetColorFromString (NULL, colorstring); color = V_GetColorFromString (NULL, colorstring);
delete[] colorstring;
} }
else else
{ {

View file

@ -261,59 +261,94 @@ void DCanvas::Dim (PalEntry color, float damount, int x1, int y1, int w, int h)
int V_GetColorFromString (const DWORD *palette, const char *cstr) int V_GetColorFromString (const DWORD *palette, const char *cstr)
{ {
int c[3], i, p; int c[3], i, p;
char val[5]; char val[3];
const char *s, *g;
val[4] = 0; val[2] = '\0';
for (s = cstr, i = 0; i < 3; i++)
// Check for HTML-style #RRGGBB or #RGB color string
if (cstr[0] == '#')
{
size_t len = strlen (cstr);
if (len == 7)
{
// Extract each eight-bit component into c[].
for (i = 0; i < 3; ++i)
{
val[0] = cstr[1 + i*2];
val[1] = cstr[2 + i*2];
c[i] = ParseHex (val);
}
}
else if (len == 4)
{
// Extract each four-bit component into c[], expanding to eight bits.
for (i = 0; i < 3; ++i)
{
val[1] = val[0] = cstr[1 + i];
c[i] = ParseHex (val);
}
}
else
{
// Bad HTML-style; pretend it's black.
c[2] = c[1] = c[0] = 0;
}
}
else
{
// Treat it as a space-delemited hexadecimal string
for (i = 0; i < 3; ++i)
{
// Skip leading whitespace
while (*cstr <= ' ' && *cstr != '\0')
{
cstr++;
}
// Extract a component and convert it to eight-bit
for (p = 0; *cstr > ' '; ++p, ++cstr)
{
if (p < 2)
{
val[p] = *cstr;
}
}
if (p == 0)
{ {
c[i] = 0; c[i] = 0;
while ((*s <= ' ') && (*s != 0))
s++;
if (*s)
{
p = 0;
while (*s > ' ')
{
if (p < 4)
{
val[p++] = *s;
} }
s++; else
}
g = val;
while (p < 4)
{ {
val[p++] = *g++; if (p == 1)
{
val[1] = val[0];
} }
c[i] = ParseHex (val); c[i] = ParseHex (val);
} }
} }
}
if (palette) if (palette)
return ColorMatcher.Pick (c[0]>>8, c[1]>>8, c[2]>>8); return ColorMatcher.Pick (c[0]>>8, c[1]>>8, c[2]>>8);
else else
return ((c[0] << 8) & 0xff0000) | return MAKERGB(c[0], c[1], c[2]);
((c[1]) & 0x00ff00) |
((c[2] >> 8));
} }
char *V_GetColorStringByName (const char *name) FString V_GetColorStringByName (const char *name)
{ {
FMemLump rgbNames; FMemLump rgbNames;
char *rgbEnd; char *rgbEnd;
char *rgb, *endp; char *rgb, *endp;
char descr[5*3];
int rgblump; int rgblump;
int c[3], step; int c[3], step;
size_t namelen; size_t namelen;
if (Wads.GetNumLumps()==0) return NULL; if (Wads.GetNumLumps()==0) return FString();
rgblump = Wads.CheckNumForName ("X11R6RGB"); rgblump = Wads.CheckNumForName ("X11R6RGB");
if (rgblump == -1) if (rgblump == -1)
{ {
Printf ("X11R6RGB lump not found\n"); Printf ("X11R6RGB lump not found\n");
return NULL; return FString();
} }
rgbNames = Wads.ReadLump (rgblump); rgbNames = Wads.ReadLump (rgblump);
@ -364,8 +399,9 @@ char *V_GetColorStringByName (const char *name)
size_t checklen = ++endp - rgb; size_t checklen = ++endp - rgb;
if (checklen == namelen && strnicmp (rgb, name, checklen) == 0) if (checklen == namelen && strnicmp (rgb, name, checklen) == 0)
{ {
sprintf (descr, "%02x %02x %02x", c[0], c[1], c[2]); FString descr;
return copystring (descr); descr.Format ("#%02x%02x%02x", c[0], c[1], c[2]);
return descr;
} }
rgb = endp; rgb = endp;
step = 0; step = 0;
@ -375,18 +411,17 @@ char *V_GetColorStringByName (const char *name)
{ {
Printf ("X11R6RGB lump is corrupt\n"); Printf ("X11R6RGB lump is corrupt\n");
} }
return NULL; return FString();
} }
int V_GetColor (const DWORD *palette, const char *str) int V_GetColor (const DWORD *palette, const char *str)
{ {
char *string = V_GetColorStringByName (str); FString string = V_GetColorStringByName (str);
int res; int res;
if (string != NULL) if (!string.IsEmpty())
{ {
res = V_GetColorFromString (palette, string); res = V_GetColorFromString (palette, string);
delete[] string;
} }
else else
{ {
@ -395,24 +430,6 @@ int V_GetColor (const DWORD *palette, const char *str)
return res; return res;
} }
CCMD (setcolor)
{
char *desc, setcmd[256];
if (argv.argc() < 3)
{
Printf ("Usage: setcolor <cvar> <color>\n");
return;
}
if ( (desc = V_GetColorStringByName (argv[2])) )
{
sprintf (setcmd, "set %s \"%s\"", argv[1], desc);
C_DoCommand (setcmd);
delete[] desc;
}
}
// Build the tables necessary for blending // Build the tables necessary for blending
static void BuildTransTable (const PalEntry *palette) static void BuildTransTable (const PalEntry *palette)
{ {
@ -858,36 +875,6 @@ void V_Init (void)
// [RH] Initialize palette management // [RH] Initialize palette management
InitPalette (); InitPalette ();
// load the heads-up font
if (Wads.CheckNumForName ("FONTA_S") >= 0)
{
SmallFont = new FFont ("SmallFont", "FONTA%02u", HU_FONTSTART, HU_FONTSIZE, 1);
}
else
{
SmallFont = new FFont ("SmallFont", "STCFN%.3d", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART);
}
if (Wads.CheckNumForName ("STBFN033", ns_graphics) >= 0)
{
SmallFont2 = new FFont ("SmallFont2", "STBFN%.3d", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART);
}
else
{
SmallFont2 = SmallFont;
}
if (gameinfo.gametype == GAME_Doom)
{
BigFont = new FSingleLumpFont ("BigFont", Wads.GetNumForName ("DBIGFONT"));
}
else if (gameinfo.gametype == GAME_Strife)
{
BigFont = new FSingleLumpFont ("BigFont", Wads.GetNumForName ("SBIGFONT"));
}
else
{
BigFont = new FFont ("BigFont", "FONTB%02u", HU_FONTSTART, HU_FONTSIZE, 1);
}
width = height = bits = 0; width = height = bits = 0;
if ( (i = Args.CheckValue ("-width")) ) if ( (i = Args.CheckValue ("-width")) )
@ -929,6 +916,37 @@ void V_Init (void)
Printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT); Printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
FBaseCVar::ResetColors (); FBaseCVar::ResetColors ();
V_InitFontColors ();
// load the heads-up font
if (Wads.CheckNumForName ("FONTA_S") >= 0)
{
SmallFont = new FFont ("SmallFont", "FONTA%02u", HU_FONTSTART, HU_FONTSIZE, 1);
}
else
{
SmallFont = new FFont ("SmallFont", "STCFN%.3d", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART);
}
if (Wads.CheckNumForName ("STBFN033", ns_graphics) >= 0)
{
SmallFont2 = new FFont ("SmallFont2", "STBFN%.3d", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART);
}
else
{
SmallFont2 = SmallFont;
}
if (gameinfo.gametype == GAME_Doom)
{
BigFont = new FSingleLumpFont ("BigFont", Wads.GetNumForName ("DBIGFONT"));
}
else if (gameinfo.gametype == GAME_Strife)
{
BigFont = new FSingleLumpFont ("BigFont", Wads.GetNumForName ("SBIGFONT"));
}
else
{
BigFont = new FFont ("BigFont", "FONTB%02u", HU_FONTSTART, HU_FONTSIZE, 1);
}
ConFont = new FSingleLumpFont ("ConsoleFont", Wads.GetNumForName ("CONFONT")); ConFont = new FSingleLumpFont ("ConsoleFont", Wads.GetNumForName ("CONFONT"));
V_InitCustomFonts (); V_InitCustomFonts ();

View file

@ -292,7 +292,7 @@ void V_MarkRect (int x, int y, int width, int height);
int V_GetColorFromString (const DWORD *palette, const char *colorstring); int V_GetColorFromString (const DWORD *palette, const char *colorstring);
// Scans through the X11R6RGB lump for a matching color // Scans through the X11R6RGB lump for a matching color
// and returns a color string suitable for V_GetColorFromString. // and returns a color string suitable for V_GetColorFromString.
char *V_GetColorStringByName (const char *name); FString V_GetColorStringByName (const char *name);
// Tries to get color by name, then by string // Tries to get color by name, then by string
int V_GetColor (const DWORD *palette, const char *str); int V_GetColor (const DWORD *palette, const char *str);

169
wadsrc/textcolors.txt Normal file
View file

@ -0,0 +1,169 @@
Brick
{
#470000 #FFB8B8
Console:
#470000 #A35C5C 0 127
#800000 #FFFEFE 128 256
}
Tan
{
#332B13 #FFEBDF
Console:
#332B13 #998B79 0 127
#998B79 #FFFFFF 128 256
}
Gray Grey
{
#272727 #EFEFEF
Console:
#272727 #8B8B8B 0 127
#505050 #FFFFFF 128 256
}
Green
{
#0B1707 #77FF6F
Console:
#000000 #007F00 0 127
#00FF00 #FEFFFE 128 256
}
Brown
{
#533F2F #BFA78F
Console:
#000000 #7F4000 0 127
#432F1F #FFE7CF 128 256
}
Gold
{
#732B00 #FFFF73
Console:
#000000 #7FC040 0 127
#DFBF00 #DFFFFE 128 256
}
Red
{
#3F0000 #FF0000
Console:
#000000 #7F0000 0 127
#FF0000 #FFFEFE 128 256
}
Blue
{
#000027 #0000FF
Console:
#000000 #00007F 0 127
#4040FF #DEDEFF 128 256
}
Orange
{
#200000 #FF8000
Console:
#200000 #904000 0 127
#FF7F00 #FFFEFE 128 256
}
// This is designed to match the white Heretic/Hexen font.
// It is close to the gray BOOM font, but not quite the same.
White
{
#242424 #FFFFFF
Console:
#000000 #7F7F7F 0 127
#808080 #FFFFFF 128 256
}
// This is designed to match the yellow Hexen font, which has a
// gray outline filled with shades of yellow.
Yellow
{
#272727 #515151 0 64
#865318 #EB9F18 80 192
#F3A82A #FCD043 208 256
Console:
#000000 #7F7F00 0 127
#FFFF00 #FFFFFF 128 256
}
Untranslated
{
}
Black
{
#131313 #505050
Console:
#000000 #323232 0 127
#0A0A0A #505050 128 256
}
LightBlue "Light Blue"
{
#000073 #B4B4FF
Console:
#00003C #5050FF 0 127
#8080FF #FFFFFF 128 256
}
Cream
{
#CF8353 #FFD7BB
Console:
#2B230F #BF7B4B 0 127
#FFB383 #FFFFFF 128 256
}
Olive
{
#2F371F #7B7F50
Console:
#373F27 #7B7F63 0 127
#676B4F #D1D8A8 128 256
}
DarkGreen "Dark Green"
{
#0B1707 #439337
Console:
#000000 #005800 0 127
#008C00 #DCFFDC 128 256
}
DarkRed "Dark Red"
{
#2B0000 #AF2B2B
Console:
#000000 #730000 0 127
#800000 #FFDCDC 128 255
}
DarkBrown "Dark Brown"
{
#1F170B #A36B3F
Console:
#2B230F #773000 0 127
#735743 #F7BD58 128 256
}
Purple
{
#230023 #CF00CF
Console:
#000000 #9F009B 0 127
#FF00FF #FFFFFF 128 256
}
DarkGray DarkGrey "Dark Gray" "Dark Grey"
{
#232323 #8B8B8B
Console:
#000000 #646464 0 127
#404040 #B4B4B4 128 256
}

View file

@ -231,6 +231,9 @@ acs/strfhelp.o strfhelp.o
======== ========
# Font color ranges
textcolors.txt textcolors.txt
======== ========
# Decorate stuff # Decorate stuff