- 2D drawer cleanup.

This commit is contained in:
Christoph Oelckers 2020-04-11 19:46:57 +02:00
commit b18faacab0
36 changed files with 1032 additions and 1147 deletions

View file

@ -61,6 +61,7 @@
#include "g_game.h"
#include "utf8.h"
#include "texturemanager.h"
#include "v_palette.h"
#include "../version.h"
@ -501,7 +502,7 @@ void DBaseStatusBar::SetScale ()
// Since status bars and HUDs can be designed for non 320x200 screens this needs to be factored in here.
// The global scaling factors are for resources at 320x200, so if the actual ones are higher resolution
// the resulting scaling factor needs to be reduced accordingly.
int realscale = clamp((320 * GetUIScale(st_scale)) / HorizontalResolution, 1, w / HorizontalResolution);
int realscale = clamp((320 * GetUIScale(twod, st_scale)) / HorizontalResolution, 1, w / HorizontalResolution);
double realscaley = realscale * (hud_aspectscale ? 1.2 : 1.);
@ -534,7 +535,7 @@ DVector2 DBaseStatusBar::GetHUDScale() const
{
return defaultScale;
}
scale = GetUIScale(hud_scale);
scale = GetUIScale(twod, hud_scale);
int hres = HorizontalResolution;
int vres = VerticalResolution;
@ -588,10 +589,10 @@ void FormatMapName(FLevelLocals *self, int cr, FString *result);
void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
{
auto scale = GetUIScale(hud_scale);
auto scale = GetUIScale(twod, hud_scale);
auto font = generic_ui ? NewSmallFont : SmallFont;
auto font2 = font;
auto vwidth = screen->GetWidth() / scale;
auto vwidth = twod->GetWidth() / scale;
auto vheight = screen->GetHeight() / scale;
auto fheight = font->GetHeight();
FString textbuffer;
@ -608,10 +609,10 @@ void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
if (am_showtime)
{
if (vid_fps) y += (NewConsoleFont->GetHeight() * active_con_scale() + 5) / scale;
if (vid_fps) y += (NewConsoleFont->GetHeight() * active_con_scale(twod) + 5) / scale;
sec = Tics2Seconds(primaryLevel->time);
textbuffer.Format("%02d:%02d:%02d", sec / 3600, (sec % 3600) / 60, sec % 60);
screen->DrawText(font, crdefault, vwidth - zerowidth * 8 - textdist, y, textbuffer, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight,
DrawText(twod, font, crdefault, vwidth - zerowidth * 8 - textdist, y, textbuffer, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight,
DTA_Monospace, EMonospacing::CellCenter, DTA_Spacing, zerowidth, DTA_KeepRatio, true, TAG_END);
y += fheight;
}
@ -620,7 +621,7 @@ void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
{
sec = Tics2Seconds(primaryLevel->totaltime);
textbuffer.Format("%02d:%02d:%02d", sec / 3600, (sec % 3600) / 60, sec % 60);
screen->DrawText(font, crdefault, vwidth - zerowidth * 8 - textdist, y, textbuffer, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight,
DrawText(twod, font, crdefault, vwidth - zerowidth * 8 - textdist, y, textbuffer, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight,
DTA_Monospace, EMonospacing::CellCenter, DTA_Spacing, zerowidth, DTA_KeepRatio, true, TAG_END);
}
@ -630,14 +631,14 @@ void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
if (am_showmonsters)
{
textbuffer.Format("%s\34%c %d/%d", GStrings("AM_MONSTERS"), crdefault + 65, primaryLevel->killed_monsters, primaryLevel->total_monsters);
screen->DrawText(font2, highlight, textdist, y, textbuffer, DTA_KeepRatio, true, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
DrawText(twod, font2, highlight, textdist, y, textbuffer, DTA_KeepRatio, true, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
y += fheight;
}
if (am_showsecrets)
{
textbuffer.Format("%s\34%c %d/%d", GStrings("AM_SECRETS"), crdefault + 65, primaryLevel->found_secrets, primaryLevel->total_secrets);
screen->DrawText(font2, highlight, textdist, y, textbuffer, DTA_KeepRatio, true, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
DrawText(twod, font2, highlight, textdist, y, textbuffer, DTA_KeepRatio, true, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
y += fheight;
}
@ -645,7 +646,7 @@ void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
if (am_showitems)
{
textbuffer.Format("%s\34%c %d/%d", GStrings("AM_ITEMS"), crdefault + 65, primaryLevel->found_items, primaryLevel->total_items);
screen->DrawText(font2, highlight, textdist, y, textbuffer, DTA_KeepRatio, true, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
DrawText(twod, font2, highlight, textdist, y, textbuffer, DTA_KeepRatio, true, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
y += fheight;
}
@ -685,7 +686,7 @@ void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
for (unsigned i = 0; i < numlines; i++)
{
int x = (vwidth - font->StringWidth(lines[i].Text)) / 2;
screen->DrawText(font, highlight, x, y, lines[i].Text, DTA_KeepRatio, true, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
DrawText(twod, font, highlight, x, y, lines[i].Text, DTA_KeepRatio, true, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, TAG_DONE);
y += fheight;
}
}
@ -952,18 +953,18 @@ void DBaseStatusBar::RefreshViewBorder ()
{
if (setblocks < 10)
{
int Width = screen->GetWidth();
int Width = twod->GetWidth();
if (viewwidth == Width)
{
return;
}
auto tex = GetBorderTexture(primaryLevel);
screen->DrawBorder (tex, 0, 0, Width, viewwindowy);
screen->DrawBorder (tex, 0, viewwindowy, viewwindowx, viewheight + viewwindowy);
screen->DrawBorder (tex, viewwindowx + viewwidth, viewwindowy, Width, viewheight + viewwindowy);
screen->DrawBorder (tex, 0, viewwindowy + viewheight, Width, StatusBar->GetTopOfStatusbar());
DrawBorder(twod, tex, 0, 0, Width, viewwindowy);
DrawBorder(twod, tex, 0, viewwindowy, viewwindowx, viewheight + viewwindowy);
DrawBorder(twod, tex, viewwindowx + viewwidth, viewwindowy, Width, viewheight + viewwindowy);
DrawBorder(twod, tex, 0, viewwindowy + viewheight, Width, StatusBar->GetTopOfStatusbar());
screen->DrawFrame (viewwindowx, viewwindowy, viewwidth, viewheight);
DrawFrame(twod, viewwindowx, viewwindowy, viewwidth, viewheight);
}
}
@ -989,8 +990,8 @@ void DBaseStatusBar::RefreshBackground () const
{
if(y < SCREENHEIGHT)
{
screen->DrawBorder (tex, x+1, y, SCREENWIDTH, y+1);
screen->DrawBorder (tex, x+1, SCREENHEIGHT-1, SCREENWIDTH, SCREENHEIGHT);
DrawBorder(twod, tex, x+1, y, SCREENWIDTH, y+1);
DrawBorder(twod, tex, x+1, SCREENHEIGHT-1, SCREENWIDTH, SCREENHEIGHT);
}
}
else
@ -1009,16 +1010,16 @@ void DBaseStatusBar::RefreshBackground () const
x2 = SCREENWIDTH;
}
screen->DrawBorder (tex, 0, y, x+1, SCREENHEIGHT);
screen->DrawBorder (tex, x2-1, y, SCREENWIDTH, SCREENHEIGHT);
DrawBorder(twod, tex, 0, y, x+1, SCREENHEIGHT);
DrawBorder(twod, tex, x2-1, y, SCREENWIDTH, SCREENHEIGHT);
if (setblocks >= 10)
{
FTexture *p = TexMan.GetTextureByName(gameinfo.Border.b);
if (p != NULL)
{
screen->FlatFill(0, y, x, y + p->GetDisplayHeight(), p, true);
screen->FlatFill(x2, y, SCREENWIDTH, y + p->GetDisplayHeight(), p, true);
twod->AddFlatFill(0, y, x, y + p->GetDisplayHeight(), p, true);
twod->AddFlatFill(x2, y, SCREENWIDTH, y + p->GetDisplayHeight(), p, true);
}
}
}
@ -1120,7 +1121,7 @@ void DBaseStatusBar::DrawCrosshair ()
color = crosshaircolor;
}
screen->DrawTexture (CrosshairImage,
DrawTexture(twod, CrosshairImage,
viewwidth / 2 + viewwindowx,
viewheight / 2 + viewwindowy,
DTA_DestWidth, w,
@ -1220,7 +1221,7 @@ void DBaseStatusBar::CallDraw(EHudState state, double ticFrac)
VMCall(func, params, countof(params), nullptr, 0);
}
else Draw(state, ticFrac);
screen->ClearClipRect(); // make sure the scripts don't leave a valid clipping rect behind.
twod->ClearClipRect(); // make sure the scripts don't leave a valid clipping rect behind.
BeginStatusBar(BaseSBarHorizontalResolution, BaseSBarVerticalResolution, BaseRelTop, false);
}
@ -1232,7 +1233,7 @@ void DBaseStatusBar::DrawLog ()
if (text.IsNotEmpty())
{
// This uses the same scaling as regular HUD messages
auto scale = active_con_scaletext(generic_ui || log_vgafont);
auto scale = active_con_scaletext(twod, generic_ui || log_vgafont);
hudwidth = SCREENWIDTH / scale;
hudheight = SCREENHEIGHT / scale;
FFont *font = (generic_ui || log_vgafont)? NewSmallFont : SmallFont;
@ -1258,13 +1259,13 @@ void DBaseStatusBar::DrawLog ()
if (y<0) y=0;
w=600;
}
screen->Dim(0, 0.5f, Scale(x, SCREENWIDTH, hudwidth), Scale(y, SCREENHEIGHT, hudheight),
Dim(twod, 0, 0.5f, Scale(x, SCREENWIDTH, hudwidth), Scale(y, SCREENHEIGHT, hudheight),
Scale(w, SCREENWIDTH, hudwidth), Scale(height, SCREENHEIGHT, hudheight));
x+=20;
y+=10;
for (const FBrokenLines &line : lines)
{
screen->DrawText (font, CPlayer->SubtitleCounter? CR_CYAN : CR_UNTRANSLATED, x, y, line.Text,
DrawText(twod, font, CPlayer->SubtitleCounter? CR_CYAN : CR_UNTRANSLATED, x, y, line.Text,
DTA_KeepRatio, true,
DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, TAG_DONE);
y += font->GetHeight ();
@ -1317,7 +1318,7 @@ void DBaseStatusBar::DrawTopStuff (EHudState state)
{
if (demoplayback && demover != DEMOGAMEVERSION)
{
screen->DrawText (SmallFont, CR_TAN, 0, GetTopOfStatusbar() - 40 * CleanYfac,
DrawText(twod, SmallFont, CR_TAN, 0, GetTopOfStatusbar() - 40 * CleanYfac,
"Demo was recorded with a different version\n"
"of " GAMENAME ". Expect it to go out of sync.",
DTA_CleanNoMove, true, TAG_DONE);
@ -1390,8 +1391,8 @@ void DBaseStatusBar::DrawConsistancy () const
players[1-consoleplayer].inconsistant/ticdup);
}
}
screen->DrawText (SmallFont, CR_GREEN,
(screen->GetWidth() - SmallFont->StringWidth (conbuff)*CleanXfac) / 2,
DrawText(twod, SmallFont, CR_GREEN,
(twod->GetWidth() - SmallFont->StringWidth (conbuff)*CleanXfac) / 2,
0, conbuff, DTA_CleanNoMove, true, TAG_DONE);
}
}
@ -1422,8 +1423,8 @@ void DBaseStatusBar::DrawWaiting () const
if (buff_p != NULL)
{
screen->DrawText (SmallFont, CR_ORANGE,
(screen->GetWidth() - SmallFont->StringWidth (conbuff)*CleanXfac) / 2,
DrawText(twod, SmallFont, CR_ORANGE,
(twod->GetWidth() - SmallFont->StringWidth (conbuff)*CleanXfac) / 2,
SmallFont->GetHeight()*CleanYfac, conbuff, DTA_CleanNoMove, true, TAG_DONE);
}
}
@ -1523,7 +1524,7 @@ void DBaseStatusBar::StatusbarToRealCoords(double &x, double &y, double &w, doub
int vres = VerticalResolution;
ValidateResolution(hres, vres);
screen->VirtualToRealCoords(x, y, w, h, hres, vres, true, true);
VirtualToRealCoords(twod, x, y, w, h, hres, vres, true, true);
}
else
{
@ -1621,8 +1622,8 @@ void DBaseStatusBar::DrawGraphic(FTextureID texture, double x, double y, int fla
switch (flags & DI_SCREEN_HMASK)
{
default: orgx = 0; break;
case DI_SCREEN_HCENTER: orgx = screen->GetWidth() / 2; break;
case DI_SCREEN_RIGHT: orgx = screen->GetWidth(); break;
case DI_SCREEN_HCENTER: orgx = twod->GetWidth() / 2; break;
case DI_SCREEN_RIGHT: orgx = twod->GetWidth(); break;
}
switch (flags & DI_SCREEN_VMASK)
@ -1644,7 +1645,7 @@ void DBaseStatusBar::DrawGraphic(FTextureID texture, double x, double y, int fla
x += orgx;
y += orgy;
}
screen->DrawTexture(tex, x, y,
DrawTexture(twod, tex, x, y,
DTA_TopOffset, 0,
DTA_LeftOffset, 0,
DTA_DestWidthF, boxwidth,
@ -1704,8 +1705,8 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
switch (flags & DI_SCREEN_HMASK)
{
default: orgx = 0; break;
case DI_SCREEN_HCENTER: orgx = screen->GetWidth() / 2; break;
case DI_SCREEN_RIGHT: orgx = screen->GetWidth(); break;
case DI_SCREEN_HCENTER: orgx = twod->GetWidth() / 2; break;
case DI_SCREEN_RIGHT: orgx = twod->GetWidth(); break;
}
switch (flags & DI_SCREEN_VMASK)
@ -1782,14 +1783,14 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
// This may have to be changed to draw the shadow text up front separately.
if ((shadowX != 0 || shadowY != 0) && !(flags & DI_NOSHADOW))
{
screen->DrawChar(font, CR_UNTRANSLATED, rx + shadowX, ry + shadowY, ch,
DrawChar(twod, font, CR_UNTRANSLATED, rx + shadowX, ry + shadowY, ch,
DTA_DestWidthF, rw,
DTA_DestHeightF, rh,
DTA_Alpha, (Alpha * HR_SHADOW),
DTA_FillColor, 0,
TAG_DONE);
}
screen->DrawChar(font, fontcolor, rx, ry, ch,
DrawChar(twod, font, fontcolor, rx, ry, ch,
DTA_DestWidthF, rw,
DTA_DestHeightF, rh,
DTA_Alpha, Alpha,
@ -1807,7 +1808,7 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
void SBar_DrawString(DBaseStatusBar *self, DHUDFont *font, const FString &string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing, double scaleX, double scaleY)
{
if (font == nullptr) ThrowAbortException(X_READ_NIL, nullptr);
if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
// resolve auto-alignment before making any adjustments to the position values.
if (!(flags & DI_SCREEN_MANUAL_ALIGN))
@ -1865,8 +1866,8 @@ void DBaseStatusBar::TransformRect(double &x, double &y, double &w, double &h, i
switch (flags & DI_SCREEN_HMASK)
{
default: orgx = 0; break;
case DI_SCREEN_HCENTER: orgx = screen->GetWidth() / 2; break;
case DI_SCREEN_RIGHT: orgx = screen->GetWidth(); break;
case DI_SCREEN_HCENTER: orgx = twod->GetWidth() / 2; break;
case DI_SCREEN_RIGHT: orgx = twod->GetWidth(); break;
}
switch (flags & DI_SCREEN_VMASK)
@ -1909,7 +1910,7 @@ void DBaseStatusBar::Fill(PalEntry color, double x, double y, double w, double h
int ww = int(x + w - x1); // account for scaling to non-integers. Truncating the values separately would fail for cases like
int hh = int(y + h - y1); // y=3.5, height = 5.5 where adding both values gives a larger integer than adding the two integers.
screen->Dim(color, float(Alpha), x1, y1, ww, hh);
Dim(twod, color, float(Alpha), x1, y1, ww, hh);
}
@ -1926,7 +1927,7 @@ void DBaseStatusBar::SetClipRect(double x, double y, double w, double h, int fla
int y1 = int(y);
int ww = int(x + w - x1); // account for scaling to non-integers. Truncating the values separately would fail for cases like
int hh = int(y + h - y1); // y=3.5, height = 5.5 where adding both values gives a larger integer than adding the two integers.
screen->SetClipRect(x1, y1, ww, hh);
twod->SetClipRect(x1, y1, ww, hh);
}