From 01b095c9115e5790457f2dc51a827f82f829eb1a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 21:22:05 +0200 Subject: [PATCH] - added colorization for untranslated fonts. This uses the light color of the vertices. The software rendered 2D code will ignore this infomation. - added a virtual OnRetrun method to menus. --- src/gl/renderer/gl_2ddrawer.cpp | 1 + src/gl/system/gl_swframebuffer.cpp | 6 ++++++ src/menu/menu.cpp | 6 ++++++ src/v_draw.cpp | 5 +++++ src/v_font.cpp | 13 +++++++++++-- src/v_font.h | 2 +- src/v_text.cpp | 16 ++++++++++++---- src/v_video.h | 4 ++++ src/win32/fb_d3d9.cpp | 6 ++++++ wadsrc/static/zscript/menu/menu.txt | 1 + 10 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/gl/renderer/gl_2ddrawer.cpp b/src/gl/renderer/gl_2ddrawer.cpp index 3f4f74cc5..0e08073cc 100644 --- a/src/gl/renderer/gl_2ddrawer.cpp +++ b/src/gl/renderer/gl_2ddrawer.cpp @@ -140,6 +140,7 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms) color = PalEntry(light, light, light); } color.a = (uint8_t)(parms.Alpha * 255); + 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); // scissor test doesn't use the current viewport for the coordinates, so use real screen coordinates dg.mScissor[0] = GLRenderer->ScreenToWindowX(parms.lclip); diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index acf5dc40b..3bb0fd8d8 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -2773,6 +2773,12 @@ void OpenGLSWFrameBuffer::DrawTextureParms(FTexture *img, DrawParms &parms) vert = &VertexData[VertexPos]; + { + PalEntry color = color1; + 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); + color1 = color; + } + // Fill the vertex buffer. vert[0].x = float(x0); vert[0].y = float(y0); diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 6d82bd680..be14b2f09 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -243,6 +243,12 @@ void DMenu::Close () if (CurrentMenu != nullptr) { GC::WriteBarrier(CurrentMenu); + IFVIRTUALPTR(CurrentMenu, DMenu, OnReturn) + { + VMValue params[] = { CurrentMenu }; + GlobalVMStack.Call(func, params, 1, nullptr, 0, nullptr); + } + } else { diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 97aa21ef0..c8da6ac4d 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -366,6 +366,7 @@ bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t t parms->colorOverlay = 0; parms->alphaChannel = false; parms->flipX = false; + parms->color = 0xffffffff; //parms->shadowAlpha = 0; parms->shadowColor = 0; parms->virtWidth = this->GetWidth(); @@ -542,6 +543,10 @@ bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t t parms->colorOverlay = ListGetInt(tags); break; + case DTA_Color: + parms->color = ListGetInt(tags); + break; + case DTA_FlipX: parms->flipX = ListGetInt(tags); break; diff --git a/src/v_font.cpp b/src/v_font.cpp index a1730bd04..e6aa57a50 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -756,9 +756,18 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity // //========================================================================== -FRemapTable *FFont::GetColorTranslation (EColorRange range) const +FRemapTable *FFont::GetColorTranslation (EColorRange range, PalEntry *color) const { - if (ActiveColors == 0 || noTranslate) + if (noTranslate) + { + PalEntry retcolor = PalEntry(255, 255, 255, 255); + if (range >= 0 && range < NumTextColors && range != CR_UNTRANSLATED) + { + retcolor = TranslationColors[range]; + } + if (color != nullptr) *color = retcolor; + } + if (ActiveColors == 0) return NULL; else if (range >= NumTextColors) range = CR_UNTRANSLATED; diff --git a/src/v_font.h b/src/v_font.h index 6553f5855..c3d2ce561 100644 --- a/src/v_font.h +++ b/src/v_font.h @@ -80,7 +80,7 @@ public: virtual FTexture *GetChar (int code, int *const width) const; virtual int GetCharWidth (int code) const; - FRemapTable *GetColorTranslation (EColorRange range) const; + FRemapTable *GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const; int GetLump() const { return Lump; } int GetSpaceWidth () const { return SpaceWidth; } int GetHeight () const { return FontHeight; } diff --git a/src/v_text.cpp b/src/v_text.cpp index 90131ed86..f068b876c 100644 --- a/src/v_text.cpp +++ b/src/v_text.cpp @@ -80,7 +80,9 @@ void DCanvas::DrawChar (FFont *font, int normalcolor, double x, double y, int ch { return; } - parms.remap = font->GetColorTranslation((EColorRange)normalcolor); + PalEntry color; + parms.remap = 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); DrawTextureParms(pic, parms); } } @@ -102,7 +104,9 @@ void DCanvas::DrawChar(FFont *font, int normalcolor, double x, double y, int cha uint32_t tag = ListGetInt(args); bool res = ParseDrawTextureTags(pic, x, y, tag, args, &parms, false); if (!res) return; - parms.remap = font->GetColorTranslation((EColorRange)normalcolor); + PalEntry color; + parms.remap = 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); DrawTextureParms(pic, parms); } } @@ -151,7 +155,10 @@ void DCanvas::DrawTextCommon(FFont *font, int normalcolor, double x, double y, c normalcolor = CR_UNTRANSLATED; boldcolor = normalcolor ? normalcolor - 1 : NumTextColors - 1; - range = font->GetColorTranslation((EColorRange)normalcolor); + PalEntry colorparm = parms.color; + PalEntry color; + range = font->GetColorTranslation((EColorRange)normalcolor, &color); + parms.color = PalEntry((color.a * colorparm.a) / 255, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255); kerning = font->GetDefaultKerning(); @@ -171,7 +178,8 @@ void DCanvas::DrawTextCommon(FFont *font, int normalcolor, double x, double y, c EColorRange newcolor = V_ParseFontColor(ch, normalcolor, boldcolor); if (newcolor != CR_UNDEFINED) { - range = font->GetColorTranslation(newcolor); + range = font->GetColorTranslation(newcolor, &color); + parms.color = PalEntry((color.a * colorparm.a) / 255, (color.r * colorparm.r) / 255, (color.g * colorparm.g) / 255, (color.b * colorparm.b) / 255); } continue; } diff --git a/src/v_video.h b/src/v_video.h index 81ae91c70..e92b045b1 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -125,6 +125,9 @@ enum DTA_TextLen, // stop after this many characters, even if \0 not hit DTA_CellX, // horizontal size of character cell DTA_CellY, // vertical size of character cell + + // New additions. + DTA_Color, }; enum @@ -161,6 +164,7 @@ struct DrawParms uint32_t fillcolor; FRemapTable *remap; uint32_t colorOverlay; + PalEntry color; INTBOOL alphaChannel; INTBOOL flipX; //float shadowAlpha; diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index 4fd198a1b..332e2416d 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -2942,6 +2942,12 @@ void D3DFB::DrawTextureParms (FTexture *img, DrawParms &parms) vert = &VertexData[VertexPos]; + { + PalEntry color = color1; + 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); + color1 = color; + } + // Fill the vertex buffer. vert[0].x = float(x0); vert[0].y = float(y0); diff --git a/wadsrc/static/zscript/menu/menu.txt b/wadsrc/static/zscript/menu/menu.txt index 09f5d9cde..32b738c5c 100644 --- a/wadsrc/static/zscript/menu/menu.txt +++ b/wadsrc/static/zscript/menu/menu.txt @@ -271,6 +271,7 @@ class Menu : Object native ui version("2.4") virtual void ResetColor() {} virtual bool MouseEvent(int type, int mx, int my) { return true; } virtual void Ticker() {} + virtual void OnReturn() {} //============================================================================= //