From fa99fc534662083328833af86471f8862939d7de Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 19:42:34 +0200 Subject: [PATCH] - added global variants of the main 2D-draw functions taking an F2DDrawer as their first parameter. This is a preparation for refactoring the calls to these so that they no longer require a 'screen' parameter. --- src/rendering/2d/v_draw.cpp | 15 ++++++++++ src/rendering/2d/v_drawtext.cpp | 50 +++++++++++++++++++++++++++++++++ src/rendering/v_video.h | 7 +++++ 3 files changed, 72 insertions(+) diff --git a/src/rendering/2d/v_draw.cpp b/src/rendering/2d/v_draw.cpp index c41b4fa37..bd23b5dd1 100644 --- a/src/rendering/2d/v_draw.cpp +++ b/src/rendering/2d/v_draw.cpp @@ -168,6 +168,21 @@ void DFrameBuffer::DrawTexture (FTexture *img, double x, double y, int tags_firs DrawTextureParms(img, parms); } +void DrawTexture(F2DDrawer *drawer, FTexture* img, double x, double y, int tags_first, ...) +{ + Va_List tags; + va_start(tags.list, tags_first); + DrawParms parms; + + bool res = screen->ParseDrawTextureTags(img, x, y, tags_first, tags, &parms, false); + va_end(tags.list); + if (!res) + { + return; + } + screen->DrawTextureParms(img, parms); +} + //========================================================================== // // ZScript texture drawing function diff --git a/src/rendering/2d/v_drawtext.cpp b/src/rendering/2d/v_drawtext.cpp index be5d9230d..1c606ebb5 100644 --- a/src/rendering/2d/v_drawtext.cpp +++ b/src/rendering/2d/v_drawtext.cpp @@ -199,6 +199,36 @@ void DFrameBuffer::DrawChar (FFont *font, int normalcolor, double x, double y, i } } +void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, int character, int tag_first, ...) +{ + if (font == NULL) + return; + + if (normalcolor >= NumTextColors) + normalcolor = CR_UNTRANSLATED; + + FTexture* pic; + int dummy; + bool redirected; + + if (NULL != (pic = font->GetChar(character, normalcolor, &dummy, &redirected))) + { + DrawParms parms; + Va_List tags; + va_start(tags.list, tag_first); + bool res = screen->ParseDrawTextureTags(pic, x, y, tag_first, tags, &parms, false); + va_end(tags.list); + if (!res) + { + return; + } + PalEntry color = 0xffffffff; + 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); + screen->DrawTextureParms(pic, parms); + } +} + void DFrameBuffer::DrawChar(FFont *font, int normalcolor, double x, double y, int character, VMVa_List &args) { if (font == NULL) @@ -365,6 +395,26 @@ void DFrameBuffer::DrawText(FFont *font, int normalcolor, double x, double y, co DrawTextCommon(font, normalcolor, x, y, (const uint8_t*)string, parms); } +// For now the 'drawer' parameter is a placeholder - this should be the way to handle it later to allow different drawers. +void DrawText(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, const char* string, int tag_first, ...) +{ + Va_List tags; + DrawParms parms; + + if (font == NULL || string == NULL) + return; + + va_start(tags.list, tag_first); + bool res = screen->ParseDrawTextureTags(nullptr, 0, 0, tag_first, tags, &parms, true); + va_end(tags.list); + if (!res) + { + return; + } + screen->DrawTextCommon(font, normalcolor, x, y, (const uint8_t*)string, parms); +} + + void DFrameBuffer::DrawText(FFont *font, int normalcolor, double x, double y, const char32_t *string, int tag_first, ...) { Va_List tags; diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 6ffa0c2e2..105776751 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -356,6 +356,9 @@ class FTexture; class DFrameBuffer { + friend void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, const char* string, int tag_first, ...); + friend void DrawChar(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, int character, int tag_first, ...); + friend void DrawTexture(F2DDrawer* drawer, FTexture* img, double x, double y, int tags_first, ...); protected: void DrawTextureV(FTexture *img, double x, double y, uint32_t tag, va_list tags) = delete; @@ -678,4 +681,8 @@ public: }; +void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, const char* string, int tag_first, ...); +void DrawChar(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, int character, int tag_first, ...); +void DrawTexture(F2DDrawer* drawer, FTexture* img, double x, double y, int tags_first, ...); + #endif // __V_VIDEO_H__