- added Raze-style HUD scaling.

This commit is contained in:
Christoph Oelckers 2022-06-05 10:57:21 +02:00
parent 0ee1cc85ec
commit efaaa3c118
5 changed files with 79 additions and 9 deletions

View file

@ -62,6 +62,7 @@ CVAR(Bool, crosshairgrow, false, CVAR_ARCHIVE);
EXTERN_CVAR(Bool, vid_fps)
EXTERN_CVAR(Float, hud_scalefactor)
EXTERN_CVAR(Bool, hud_aspectscale)
void ST_LoadCrosshair(int num, bool alwaysload)
{
@ -353,10 +354,12 @@ void DStatusBarCore::SetScale()
int vert = VerticalResolution;
double refaspect = horz / double(vert);
double screenaspect = w / double(h);
double aspectscale = 1.0;
if ((horz == 320 && vert == 200) || (horz == 640 && vert == 400))
{
refaspect = 1.333;
if (!hud_aspectscale) aspectscale = 1 / 1.2;
}
if (screenaspect < refaspect)
@ -370,14 +373,14 @@ void DStatusBarCore::SetScale()
refw = h * refaspect;
}
refw *= hud_scalefactor;
refh *= hud_scalefactor;
refh *= hud_scalefactor * aspectscale;
int sby = VerticalResolution - RelTop;
int sby = vert - int(RelTop * hud_scalefactor * aspectscale);
// Use full pixels for destination size.
ST_X = xs_CRoundToInt((w - refw) / 2);
ST_Y = xs_CRoundToInt(h - refh);
SBarTop = Scale(sby, h, VerticalResolution);
SBarTop = Scale(sby, h, vert);
SBarScale.X = refw / horz;
SBarScale.Y = refh / vert;
}

View file

@ -120,6 +120,7 @@
#include "doomfont.h"
#include "screenjob.h"
#include "startscreen.h"
#include "shiftstate.h"
#ifdef __unix__
#include "i_system.h" // for SHARE_DIR
@ -2630,6 +2631,8 @@ bool System_WantLeftButton()
static bool System_DispatchEvent(event_t* ev)
{
shiftState.AddEvent(ev);
if (ev->type == EV_Mouse && menuactive == MENU_Off && ConsoleState != c_down && ConsoleState != c_falling && !primaryLevel->localEventManager->Responder(ev) && !paused)
{
if (buttonMap.ButtonDown(Button_Mlook) || freelook)

View file

@ -160,15 +160,30 @@ void DBaseStatusBar::CreateAltHUD()
//
//---------------------------------------------------------------------------
EXTERN_CVAR(Bool, hud_aspectscale)
EXTERN_CVAR(Bool, hud_oldscale)
EXTERN_CVAR(Float, hud_scalefactor)
void DBaseStatusBar::DrawAltHUD()
{
player_t * CPlayer = StatusBar->CPlayer;
players[consoleplayer].inventorytics = 0;
int scale = GetUIScale(twod, hud_althudscale);
int hudwidth = twod->GetWidth() / scale;
int hudheight = hud_aspectscale ? int(twod->GetHeight() / (scale*1.2)) : twod->GetHeight() / scale;
int hudwidth;
int hudheight;
if (hud_oldscale)
{
int scale = GetUIScale(twod, hud_althudscale);
hudwidth = twod->GetWidth() / scale;
hudheight = twod->GetHeight() / scale;
}
else
{
hudwidth = int(640 / hud_scalefactor);
hudheight = hudwidth * twod->GetHeight() / twod->GetWidth();
}
if (hud_aspectscale) hudheight = hudheight * 5 / 6;
IFVIRTUALPTRNAME(AltHud, "AltHud", Draw)
{

View file

@ -0,0 +1,33 @@
#pragma once
#include <stdint.h>
#include "d_event.h"
class ShiftState
{
bool ShiftStatus = false;
public:
bool ShiftPressed()
{
return ShiftStatus;
}
void AddEvent(const event_t *ev)
{
if ((ev->type == EV_KeyDown || ev->type == EV_KeyUp) && (ev->data1 == KEY_LSHIFT || ev->data1 == KEY_RSHIFT))
{
ShiftStatus = ev->type == EV_KeyDown;
}
}
void Clear()
{
ShiftStatus = false;
}
};
inline ShiftState shiftState;

View file

@ -65,6 +65,7 @@
#include "d_player.h"
#include "teaminfo.h"
#include "i_time.h"
#include "shiftstate.h"
#include "hwrenderer/scene/hw_drawinfo.h"
EXTERN_CVAR(Int, cl_gfxlocalization)
@ -72,6 +73,7 @@ EXTERN_CVAR(Bool, m_quickexit)
EXTERN_CVAR(Bool, saveloadconfirmation) // [mxd]
EXTERN_CVAR(Bool, quicksaverotation)
EXTERN_CVAR(Bool, show_messages)
EXTERN_CVAR(Float, hud_scalefactor)
CVAR(Bool, m_simpleoptions, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
@ -504,14 +506,28 @@ EXTERN_CVAR (Int, screenblocks)
CCMD (sizedown)
{
screenblocks = screenblocks - 1;
if (shiftState.ShiftPressed())
{
hud_scalefactor = hud_scalefactor - 0.04f;
}
else
{
screenblocks = screenblocks - 1;
}
S_Sound (CHAN_VOICE, CHANF_UI, "menu/change", snd_menuvolume, ATTN_NONE);
}
CCMD (sizeup)
{
screenblocks = screenblocks + 1;
S_Sound (CHAN_VOICE, CHANF_UI, "menu/change", snd_menuvolume, ATTN_NONE);
if (shiftState.ShiftPressed())
{
hud_scalefactor = hud_scalefactor + 0.04f;
}
else
{
screenblocks = screenblocks + 1;
}
S_Sound(CHAN_VOICE, CHANF_UI, "menu/change", snd_menuvolume, ATTN_NONE);
}
CCMD(reset2defaults)