From 1de9c63d45caf0707770977abc34f84eecce39c7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Nov 2021 21:01:48 +0100 Subject: [PATCH] - fixed center aligned rendering of 2D content. This calculates the centered pivot point in integer texel coordinate space so for odd numbers it must round down instead of using a fractional position. --- source/common/2d/v_draw.cpp | 12 +++++++++--- source/core/gamehud.cpp | 2 +- source/games/blood/src/qav.cpp | 2 +- source/games/duke/src/game_misc.cpp | 2 +- source/games/sw/src/draw.cpp | 2 +- source/games/sw/src/player.cpp | 4 ++-- source/games/sw/src/sumo.cpp | 4 ++-- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/source/common/2d/v_draw.cpp b/source/common/2d/v_draw.cpp index 2d1296fe5..a7d213cb4 100644 --- a/source/common/2d/v_draw.cpp +++ b/source/common/2d/v_draw.cpp @@ -1015,10 +1015,16 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double case DTA_CenterOffsetRel: assert(fortext == false); if (fortext) return false; - if (ListGetInt(tags)) + intval = ListGetInt(tags); + if (intval == 1) { - parms->left = img->GetDisplayLeftOffset() + img->GetDisplayWidth() * 0.5; - parms->top = img->GetDisplayTopOffset() + img->GetDisplayHeight() * 0.5; + parms->left = img->GetDisplayLeftOffset() + (img->GetDisplayWidth() * 0.5); + parms->top = img->GetDisplayTopOffset() + (img->GetDisplayHeight() * 0.5); + } + else if (intval == 2) + { + parms->left = img->GetDisplayLeftOffset() + floor(img->GetDisplayWidth() * 0.5); + parms->top = img->GetDisplayTopOffset() + floor(img->GetDisplayHeight() * 0.5); } break; diff --git a/source/core/gamehud.cpp b/source/core/gamehud.cpp index baee0c248..31d18fe57 100644 --- a/source/core/gamehud.cpp +++ b/source/core/gamehud.cpp @@ -68,7 +68,7 @@ void hud_drawsprite(double sx, double sy, double sz, double a, int picnum, int d DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_ViewportHeight, windowxy2.y - windowxy1.y + 1, DTA_FullscreenScale, (dastat & RS_STRETCH)? FSMode_ScaleToScreen: FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, - DTA_CenterOffsetRel, !(dastat & (RS_TOPLEFT | RS_CENTER)), + DTA_CenterOffsetRel, (dastat & (RS_TOPLEFT | RS_CENTER))? 0:2, DTA_TopLeft, !!(dastat & RS_TOPLEFT), DTA_CenterOffset, !!(dastat & RS_CENTER), DTA_FlipX, !!(dastat & RS_XFLIPHUD), diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index 955e6820c..242f85679 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -129,7 +129,7 @@ void DrawFrame(double x, double y, double z, double a, double alpha, int picnum, auto color = shadeToLight(shade); DrawTexture(twod, tex, x, y, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Rotate, angle, DTA_LegacyRenderStyle, renderstyle, DTA_Alpha, alpha, DTA_Pin, pin, DTA_TranslationIndex, translation, - DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, FSMode_Fit320x200, DTA_FlipOffsets, true, DTA_Color, color, + DTA_TopLeft, topleft, DTA_CenterOffsetRel, topleft? 0:2, DTA_FullscreenScale, FSMode_Fit320x200, DTA_FlipOffsets, true, DTA_Color, color, DTA_FlipX, xflip, DTA_FlipY, yflip, TAG_DONE); } else diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index f0e4a48cc..928297cd8 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -317,7 +317,7 @@ void cameratext(DDukeActor *cam) { auto drawitem = [=](int tile, double x, double y, bool flipx, bool flipy) { - DrawTexture(twod, tileGetTexture(tile), x, y, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_CenterOffsetRel, true, + DrawTexture(twod, tileGetTexture(tile), x, y, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_CenterOffsetRel, 2, DTA_ViewportHeight, windowxy2.y - windowxy1.y + 1, DTA_FlipX, flipx, DTA_FlipY, flipy, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE); }; if (!cam->temp_data[0]) diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 7251da5a0..e8073a176 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1773,7 +1773,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int if (spnum >= 0) { DrawTexture(twod, tileGetTexture(1196 + pspr_ndx[myconnectindex], true), xx, yy, DTA_ScaleX, sc, DTA_ScaleY, sc, DTA_Rotate, daang * -BAngToDegree, - DTA_CenterOffsetRel, true, DTA_TranslationIndex, TRANSLATION(Translation_Remap, spr->pal), DTA_Color, shadeToLight(spr->shade), + DTA_CenterOffsetRel, 2, DTA_TranslationIndex, TRANSLATION(Translation_Remap, spr->pal), DTA_Color, shadeToLight(spr->shade), DTA_Alpha, (spr->cstat & 2) ? 0.33 : 1., TAG_DONE); } } diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index a4773e0b4..d147a7db1 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -4437,10 +4437,10 @@ void DoPlayerDiveMeter(PLAYERp pp) color = 22; DrawTexture(twod, tileGetTexture(5408, true), 208, y, DTA_FullscreenScale, FSMode_Fit320x200, - DTA_CenterOffsetRel, true, DTA_TranslationIndex, TRANSLATION(Translation_Remap, 1), TAG_DONE); + DTA_CenterOffsetRel, 2, DTA_TranslationIndex, TRANSLATION(Translation_Remap, 1), TAG_DONE); DrawTexture(twod, tileGetTexture(5406 - metertics, true), 265, y, DTA_FullscreenScale, FSMode_Fit320x200, - DTA_CenterOffsetRel, true, DTA_TranslationIndex, TRANSLATION(Translation_Remap, color), TAG_DONE); + DTA_CenterOffsetRel, 2, DTA_TranslationIndex, TRANSLATION(Translation_Remap, color), TAG_DONE); } void DoPlayerDive(PLAYERp pp) diff --git a/source/games/sw/src/sumo.cpp b/source/games/sw/src/sumo.cpp index 71d91ca69..647288e79 100644 --- a/source/games/sw/src/sumo.cpp +++ b/source/games/sw/src/sumo.cpp @@ -943,10 +943,10 @@ void BossHealthMeter(void) color = 22; DrawTexture(twod, tileGetTexture(5407, true), 85, y, DTA_FullscreenScale, FSMode_Fit320x200, - DTA_CenterOffsetRel, true, DTA_TranslationIndex, TRANSLATION(Translation_Remap, 1), TAG_DONE); + DTA_CenterOffsetRel, 2, DTA_TranslationIndex, TRANSLATION(Translation_Remap, 1), TAG_DONE); DrawTexture(twod, tileGetTexture(5406 - metertics, true), 147, y, DTA_FullscreenScale, FSMode_Fit320x200, - DTA_CenterOffsetRel, true, DTA_TranslationIndex, TRANSLATION(Translation_Remap, color), TAG_DONE); + DTA_CenterOffsetRel, 2, DTA_TranslationIndex, TRANSLATION(Translation_Remap, color), TAG_DONE); } }