- 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.
This commit is contained in:
Christoph Oelckers 2020-04-11 19:42:34 +02:00
parent 3bf7686cfb
commit fa99fc5346
3 changed files with 72 additions and 0 deletions

View file

@ -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

View file

@ -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;

View file

@ -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__