mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-01-18 15:11:46 +00:00
- add color remapping for NewSmallFont as well.
This commit is contained in:
parent
86897560ac
commit
13841655aa
10 changed files with 88 additions and 53 deletions
|
@ -583,9 +583,7 @@ CUSTOM_CVAR (Int, msgmidcolor2, 4, CVAR_ARCHIVE)
|
|||
|
||||
EColorRange C_GetDefaultFontColor()
|
||||
{
|
||||
// Ideally this should analyze the SmallFont and pick a matching color.
|
||||
if (!generic_ui) return CR_UNTRANSLATED;
|
||||
return gameinfo.gametype == GAME_Doom ? CR_RED : gameinfo.gametype == GAME_Chex ? CR_GREEN : gameinfo.gametype == GAME_Strife ? CR_GOLD : CR_GRAY;
|
||||
return CR_UNTRANSLATED;
|
||||
}
|
||||
|
||||
FFont * C_GetDefaultHUDFont()
|
||||
|
|
|
@ -197,7 +197,7 @@ DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int h
|
|||
Top = y;
|
||||
HoldTics = (int)(holdTime * TICRATE);
|
||||
Tics = -1; // -1 to compensate for one additional Tick the message will receive.
|
||||
Font = font? font : generic_ui? SmallFont : AlternativeSmallFont;
|
||||
Font = font? font : generic_ui? NewSmallFont : AlternativeSmallFont;
|
||||
TextColor = textColor;
|
||||
State = 0;
|
||||
SourceText = copystring (text);
|
||||
|
|
|
@ -547,7 +547,10 @@ void FFont::RecordAllTextureColors(uint32_t *usedcolors)
|
|||
FFontChar1 *pic = static_cast<FFontChar1 *>(Chars[i].TranslatedPic->GetImage());
|
||||
if (pic)
|
||||
{
|
||||
RecordTextureColors(pic->GetBase(), usedcolors);
|
||||
// The remap must be temporarily reset here because this can be called on an initialized font.
|
||||
auto sr = pic->ResetSourceRemap();
|
||||
RecordTextureColors(pic, usedcolors);
|
||||
pic->SetSourceRemap(sr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,33 +194,36 @@ TArray<uint8_t> FHexFontChar2::CreatePalettedPixels(int)
|
|||
TArray<uint8_t> Pixels(destSize, true);
|
||||
uint8_t *dest_p = Pixels.Data();
|
||||
|
||||
auto drawLayer = [&](int ix, int iy, int color)
|
||||
assert(SourceData);
|
||||
if (SourceData)
|
||||
{
|
||||
const uint8_t *src_p = SourceData;
|
||||
for (int y = 0; y < Height-2; y++)
|
||||
auto drawLayer = [&](int ix, int iy, int color)
|
||||
{
|
||||
for (int x = 0; x < SourceWidth; x++)
|
||||
const uint8_t *src_p = SourceData;
|
||||
for (int y = 0; y < Height - 2; y++)
|
||||
{
|
||||
int byte = *src_p++;
|
||||
uint8_t *pixelstart = dest_p + (ix + 8 * x) * Height + (iy+y);
|
||||
for (int bit = 0; bit < 8; bit++)
|
||||
for (int x = 0; x < SourceWidth; x++)
|
||||
{
|
||||
if (byte & (128 >> bit))
|
||||
int byte = *src_p++;
|
||||
uint8_t *pixelstart = dest_p + (ix + 8 * x) * Height + (iy + y);
|
||||
for (int bit = 0; bit < 8; bit++)
|
||||
{
|
||||
pixelstart[bit*Height] = color;
|
||||
if (byte & (128 >> bit))
|
||||
{
|
||||
pixelstart[bit*Height] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
memset(dest_p, 0, destSize);
|
||||
|
||||
const int darkcolor = 3;
|
||||
const int brightcolor = 14;
|
||||
for (int xx=0;xx<3;xx++) for (int yy=0;yy<3;yy++) if (xx !=1 || yy != 1)
|
||||
drawLayer(xx, yy, darkcolor);
|
||||
drawLayer(1, 1, brightcolor);
|
||||
};
|
||||
memset(dest_p, 0, destSize);
|
||||
|
||||
const int darkcolor = 1;
|
||||
const int brightcolor = 14;
|
||||
for (int xx = 0; xx < 3; xx++) for (int yy = 0; yy < 3; yy++) if (xx != 1 || yy != 1)
|
||||
drawLayer(xx, yy, darkcolor);
|
||||
drawLayer(1, 1, brightcolor);
|
||||
}
|
||||
return Pixels;
|
||||
}
|
||||
|
||||
|
@ -369,6 +372,56 @@ public:
|
|||
BuildTranslations(luminosity, nullptr, &TranslationParms[0][0], ActiveColors, nullptr);
|
||||
}
|
||||
|
||||
void SetDefaultTranslation(uint32_t *colors) override
|
||||
{
|
||||
double myluminosity[18];
|
||||
|
||||
myluminosity[0] = 0;
|
||||
for (int i = 1; i < 18; i++)
|
||||
{
|
||||
myluminosity[i] = (i - 1) / 16.;
|
||||
}
|
||||
|
||||
uint8_t othertranslation[256], otherreverse[256];
|
||||
TArray<double> otherluminosity;
|
||||
|
||||
SimpleTranslation(colors, othertranslation, otherreverse, otherluminosity);
|
||||
|
||||
FRemapTable remap(ActiveColors);
|
||||
remap.Remap[0] = 0;
|
||||
remap.Palette[0] = 0;
|
||||
|
||||
for (unsigned l = 1; l < 18; l++)
|
||||
{
|
||||
for (unsigned o = 1; o < otherluminosity.Size() - 1; o++) // luminosity[0] is for the transparent color
|
||||
{
|
||||
if (myluminosity[l] >= otherluminosity[o] && myluminosity[l] <= otherluminosity[o + 1])
|
||||
{
|
||||
PalEntry color1 = GPalette.BaseColors[otherreverse[o]];
|
||||
PalEntry color2 = GPalette.BaseColors[otherreverse[o + 1]];
|
||||
double weight = 0;
|
||||
if (otherluminosity[o] != otherluminosity[o + 1])
|
||||
{
|
||||
weight = (myluminosity[l] - otherluminosity[o]) / (otherluminosity[o + 1] - otherluminosity[o]);
|
||||
}
|
||||
int r = int(color1.r + weight * (color2.r - color1.r));
|
||||
int g = int(color1.g + weight * (color2.g - color1.g));
|
||||
int b = int(color1.b + weight * (color2.b - color1.b));
|
||||
|
||||
r = clamp(r, 0, 255);
|
||||
g = clamp(g, 0, 255);
|
||||
b = clamp(b, 0, 255);
|
||||
remap.Remap[l] = ColorMatcher.Pick(r, g, b);
|
||||
remap.Palette[l] = PalEntry(255, r, g, b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ranges[CR_UNTRANSLATED] = remap;
|
||||
forceremap = true;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1532,12 +1532,10 @@ void V_InitFonts()
|
|||
}
|
||||
}
|
||||
}
|
||||
if (OriginalSmallFont != nullptr)
|
||||
{
|
||||
uint32_t colors[256] = {};
|
||||
SmallFont->RecordAllTextureColors(colors);
|
||||
OriginalSmallFont->SetDefaultTranslation(colors);
|
||||
}
|
||||
uint32_t colors[256] = {};
|
||||
SmallFont->RecordAllTextureColors(colors);
|
||||
if (OriginalSmallFont != nullptr) OriginalSmallFont->SetDefaultTranslation(colors);
|
||||
NewSmallFont->SetDefaultTranslation(colors);
|
||||
|
||||
if (!(SmallFont2 = V_GetFont("SmallFont2"))) // Only used by Strife
|
||||
{
|
||||
|
|
|
@ -119,7 +119,7 @@ public:
|
|||
void SetKerning(int c) { GlobalKerning = c; }
|
||||
bool NoTranslate() const { return noTranslate; }
|
||||
void RecordAllTextureColors(uint32_t *usedcolors);
|
||||
void SetDefaultTranslation(uint32_t *colors);
|
||||
virtual void SetDefaultTranslation(uint32_t *colors);
|
||||
|
||||
protected:
|
||||
FFont (int lump);
|
||||
|
|
|
@ -86,17 +86,6 @@ TArray<uint8_t> FFontChar1::CreatePalettedPixels (int)
|
|||
return Pixels;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FFontChar1 :: SetSourceRemap
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFontChar1::SetSourceRemap(const uint8_t *sourceremap)
|
||||
{
|
||||
SourceRemap = sourceremap;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FFontChar2 :: FFontChar2
|
||||
|
|
|
@ -6,7 +6,8 @@ class FFontChar1 : public FImageSource
|
|||
public:
|
||||
FFontChar1 (FImageSource *sourcelump);
|
||||
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
|
||||
void SetSourceRemap(const uint8_t *sourceremap);
|
||||
void SetSourceRemap(const uint8_t *sourceremap) { SourceRemap = sourceremap; }
|
||||
const uint8_t *ResetSourceRemap() { auto p = SourceRemap; SourceRemap = nullptr; return p; }
|
||||
FImageSource *GetBase() const { return BaseTexture; }
|
||||
|
||||
protected:
|
||||
|
|
|
@ -290,13 +290,6 @@ class Menu : Object native ui version("2.4")
|
|||
screen.DrawText (ConFont, color, x, y, str, DTA_CellX, 8 * CleanXfac, DTA_CellY, 8 * CleanYfac);
|
||||
}
|
||||
|
||||
static int OptionColor(int color)
|
||||
{
|
||||
if (color != Font.CR_UNTRANSLATED) return color;
|
||||
// This needs fixing for mods with custom fonts.
|
||||
return gameinfo.gametype == GAME_Doom ? Font.CR_RED : gameinfo.gametype == GAME_Chex ? Font.CR_GREEN : gameinfo.gametype == GAME_Strife ? Font.CR_GOLD : Font.CR_GRAY;
|
||||
}
|
||||
|
||||
static Font OptionFont()
|
||||
{
|
||||
return NewSmallFont;
|
||||
|
@ -316,7 +309,7 @@ class Menu : Object native ui version("2.4")
|
|||
{
|
||||
String label = Stringtable.Localize(text);
|
||||
int overlay = grayed? Color(96,48,0,0) : 0;
|
||||
screen.DrawText (OptionFont(), OptionColor(color), x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
|
||||
screen.DrawText (OptionFont(), color, x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -461,7 +461,7 @@ class OptionMenu : Menu
|
|||
{
|
||||
if (((MenuTime() % 8) < 6) || GetCurrentMenu() != self)
|
||||
{
|
||||
DrawOptionText(cur_indent + 3 * CleanXfac_1, y, Font.CR_UNTRANSLATED, "◄");
|
||||
DrawOptionText(cur_indent + 3 * CleanXfac_1, y, OptionMenuSettings.mFontColorSelection, "◄");
|
||||
}
|
||||
}
|
||||
y += fontheight;
|
||||
|
@ -473,11 +473,11 @@ class OptionMenu : Menu
|
|||
|
||||
if (CanScrollUp)
|
||||
{
|
||||
DrawOptionText(screen.GetWidth() - 11 * CleanXfac_1, ytop, Font.CR_UNTRANSLATED, "▲");
|
||||
DrawOptionText(screen.GetWidth() - 11 * CleanXfac_1, ytop, OptionMenuSettings.mFontColorSelection, "▲");
|
||||
}
|
||||
if (CanScrollDown)
|
||||
{
|
||||
DrawOptionText(screen.GetWidth() - 11 * CleanXfac_1 , y - 8*CleanYfac_1, Font.CR_UNTRANSLATED, "▼");
|
||||
DrawOptionText(screen.GetWidth() - 11 * CleanXfac_1 , y - 8*CleanYfac_1, OptionMenuSettings.mFontColorSelection, "▼");
|
||||
}
|
||||
Super.Drawer();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue