2020-06-21 20:34:50 +00:00
|
|
|
/*
|
|
|
|
** shared_sbar.cpp
|
|
|
|
** Base status bar implementation
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2006 Randy Heit
|
|
|
|
** Copyright 2017 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2020-08-16 00:55:50 +00:00
|
|
|
#include "build.h"
|
2020-06-21 20:34:50 +00:00
|
|
|
#include "templates.h"
|
|
|
|
#include "statusbar.h"
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "c_console.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "filesystem.h"
|
|
|
|
#include "s_soundinternal.h"
|
|
|
|
#include "serializer.h"
|
|
|
|
#include "serialize_obj.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "vm.h"
|
|
|
|
#include "gstrings.h"
|
|
|
|
#include "utf8.h"
|
|
|
|
#include "texturemanager.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "v_font.h"
|
|
|
|
#include "v_draw.h"
|
2020-07-26 21:06:27 +00:00
|
|
|
#include "gamecvars.h"
|
2020-08-16 00:55:50 +00:00
|
|
|
#include "m_fixed.h"
|
2020-08-24 21:14:55 +00:00
|
|
|
#include "gamecontrol.h"
|
2020-08-16 00:55:50 +00:00
|
|
|
#include "gamestruct.h"
|
2020-10-04 16:31:48 +00:00
|
|
|
#include "razemenu.h"
|
2020-08-24 21:14:55 +00:00
|
|
|
#include "mapinfo.h"
|
2020-06-21 20:34:50 +00:00
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
#define XHAIRSHRINKSIZE (1./18)
|
|
|
|
#define XHAIRPICKUPSIZE (2+XHAIRSHRINKSIZE)
|
|
|
|
#define POWERUPICONSIZE 32
|
|
|
|
|
|
|
|
//IMPLEMENT_CLASS(DHUDFont, true, false);
|
|
|
|
|
|
|
|
EXTERN_CVAR (Bool, am_showmonsters)
|
|
|
|
EXTERN_CVAR (Bool, am_showsecrets)
|
|
|
|
EXTERN_CVAR (Bool, am_showtime)
|
|
|
|
EXTERN_CVAR (Bool, am_showtotaltime)
|
|
|
|
EXTERN_CVAR (Bool, noisedebug)
|
|
|
|
EXTERN_CVAR(Bool, vid_fps)
|
|
|
|
EXTERN_CVAR(Bool, inter_subtitles)
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
DStatusBarCore *StatusBar;
|
2020-06-21 20:34:50 +00:00
|
|
|
|
|
|
|
extern int setblocks;
|
|
|
|
|
|
|
|
CVAR (Bool, idmypos, false, 0);
|
|
|
|
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
FGameTexture* CrosshairImage;
|
|
|
|
static int CrosshairNum;
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
CVAR(Color, crosshaircolor, 0xff0000, CVAR_ARCHIVE);
|
|
|
|
CVAR(Int, crosshairhealth, 2, CVAR_ARCHIVE);
|
|
|
|
CVAR(Float, crosshairscale, 1.0, CVAR_ARCHIVE);
|
|
|
|
CVAR(Bool, crosshairgrow, false, CVAR_ARCHIVE);
|
|
|
|
EXTERN_CVAR(Bool, vid_fps)
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void ST_LoadCrosshair(int num, bool alwaysload)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
char name[16];
|
|
|
|
char size;
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
if (!alwaysload && CrosshairNum == num && CrosshairImage != NULL)
|
|
|
|
{ // No change.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
CrosshairNum = 0;
|
|
|
|
CrosshairImage = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (num < 0)
|
|
|
|
{
|
|
|
|
num = -num;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
2020-10-28 15:56:00 +00:00
|
|
|
size = (twod->GetWidth() < 640) ? 'S' : 'B';
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
mysnprintf(name, countof(name), "XHAIR%c%d", size, num);
|
|
|
|
FTextureID texid = TexMan.CheckForTexture(name, ETextureType::MiscPatch, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ShortNameOnly);
|
|
|
|
if (!texid.isValid())
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
mysnprintf(name, countof(name), "XHAIR%c1", size);
|
|
|
|
texid = TexMan.CheckForTexture(name, ETextureType::MiscPatch, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ShortNameOnly);
|
|
|
|
if (!texid.isValid())
|
|
|
|
{
|
|
|
|
texid = TexMan.CheckForTexture("XHAIRS1", ETextureType::MiscPatch, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ShortNameOnly);
|
|
|
|
}
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
2020-10-28 15:56:00 +00:00
|
|
|
CrosshairNum = num;
|
|
|
|
CrosshairImage = TexMan.GetGameTexture(texid);
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void ST_UnloadCrosshair()
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
CrosshairImage = NULL;
|
|
|
|
CrosshairNum = 0;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-10-28 15:56:00 +00:00
|
|
|
// DrawCrosshair
|
2020-06-21 20:34:50 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void ST_DrawCrosshair(int phealth, double xpos, double ypos, double scale)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
uint32_t color;
|
|
|
|
double size;
|
|
|
|
int w, h;
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
// Don't draw the crosshair if there is none
|
|
|
|
if (CrosshairImage == NULL)
|
2020-07-26 21:06:27 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
return;
|
2020-07-26 21:06:27 +00:00
|
|
|
}
|
2020-10-28 15:56:00 +00:00
|
|
|
|
|
|
|
if (crosshairscale > 0.0f)
|
2020-07-26 21:06:27 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
size = twod->GetHeight() * crosshairscale * 0.005;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
size = 1.;
|
2020-07-26 21:06:27 +00:00
|
|
|
}
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
if (crosshairgrow)
|
|
|
|
{
|
|
|
|
size *= scale;
|
|
|
|
}
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
w = int(CrosshairImage->GetDisplayWidth() * size);
|
|
|
|
h = int(CrosshairImage->GetDisplayHeight() * size);
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
if (crosshairhealth == 1)
|
|
|
|
{
|
|
|
|
// "Standard" crosshair health (green-red)
|
|
|
|
int health = phealth;
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
if (health >= 85)
|
|
|
|
{
|
|
|
|
color = 0x00ff00;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int red, green;
|
|
|
|
health -= 25;
|
|
|
|
if (health < 0)
|
|
|
|
{
|
|
|
|
health = 0;
|
|
|
|
}
|
|
|
|
if (health < 30)
|
|
|
|
{
|
|
|
|
red = 255;
|
|
|
|
green = health * 255 / 30;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
red = (60 - health) * 255 / 30;
|
|
|
|
green = 255;
|
|
|
|
}
|
|
|
|
color = (red << 16) | (green << 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (crosshairhealth == 2)
|
|
|
|
{
|
|
|
|
// "Enhanced" crosshair health (blue-green-yellow-red)
|
|
|
|
int health = clamp(phealth, 0, 200);
|
|
|
|
float rr, gg, bb;
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
float saturation = health < 150 ? 1.f : 1.f - (health - 150) / 100.f;
|
2020-06-21 20:34:50 +00:00
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
HSVtoRGB(&rr, &gg, &bb, health * 1.2f, saturation, 1);
|
|
|
|
int red = int(rr * 255);
|
|
|
|
int green = int(gg * 255);
|
|
|
|
int blue = int(bb * 255);
|
|
|
|
|
|
|
|
color = (red << 16) | (green << 8) | blue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = crosshaircolor;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawTexture(twod, CrosshairImage,
|
|
|
|
xpos, ypos,
|
|
|
|
DTA_DestWidth, w,
|
|
|
|
DTA_DestHeight, h,
|
|
|
|
DTA_AlphaChannel, true,
|
|
|
|
DTA_FillColor, color & 0xFFFFFF,
|
|
|
|
TAG_DONE);
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
|
2020-06-21 20:34:50 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-10-28 15:56:00 +00:00
|
|
|
//
|
2020-06-21 20:34:50 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
enum ENumFlags
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
FNF_WHENNOTZERO = 0x1,
|
|
|
|
FNF_FILLZEROS = 0x2,
|
|
|
|
};
|
|
|
|
|
|
|
|
void FormatNumber(int number, int minsize, int maxsize, int flags, const FString& prefix, FString* result)
|
|
|
|
{
|
|
|
|
static int maxvals[] = { 1, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999 };
|
|
|
|
|
|
|
|
if (number == 0 && (flags & FNF_WHENNOTZERO))
|
|
|
|
{
|
|
|
|
*result = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (maxsize > 0 && maxsize < 10)
|
|
|
|
{
|
|
|
|
number = clamp(number, -maxvals[maxsize - 1], maxvals[maxsize]);
|
|
|
|
}
|
|
|
|
FString& fmt = *result;
|
|
|
|
if (minsize <= 1) fmt.Format("%s%d", prefix.GetChars(), number);
|
|
|
|
else if (flags & FNF_FILLZEROS) fmt.Format("%s%0*d", prefix.GetChars(), minsize, number);
|
|
|
|
else fmt.Format("%s%*d", prefix.GetChars(), minsize, number);
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void ValidateResolution(int &hres, int &vres)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-10-28 15:56:00 +00:00
|
|
|
if (hres == 0)
|
|
|
|
{
|
|
|
|
static const int HORIZONTAL_RESOLUTION_DEFAULT = 320;
|
|
|
|
hres = HORIZONTAL_RESOLUTION_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vres == 0)
|
|
|
|
{
|
|
|
|
static const int VERTICAL_RESOLUTION_DEFAULT = 200;
|
|
|
|
vres = VERTICAL_RESOLUTION_DEFAULT;
|
|
|
|
}
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
|
2020-06-21 20:34:50 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// draw stuff
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void DStatusBarCore::StatusbarToRealCoords(double &x, double &y, double &w, double &h) const
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-07-26 21:06:27 +00:00
|
|
|
x = ST_X + x * SBarScale.X;
|
|
|
|
y = ST_Y + y * SBarScale.Y;
|
|
|
|
w *= SBarScale.X;
|
|
|
|
h *= SBarScale.Y;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// draw stuff
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void DStatusBarCore::DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color, int translation, double rotate, ERenderStyle style)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
|
|
|
if (!texture.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
FGameTexture* tex = TexMan.GetGameTexture(texture, !(flags & DI_DONTANIMATE));
|
2020-08-02 06:39:51 +00:00
|
|
|
DrawGraphic(tex, x, y, flags, Alpha, boxwidth, boxheight, scaleX, scaleY, color, translation, rotate, style);
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void DStatusBarCore::DrawGraphic(FGameTexture* tex, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color, int translation, double rotate, ERenderStyle style)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
|
|
|
double texwidth = tex->GetDisplayWidth() * scaleX;
|
|
|
|
double texheight = tex->GetDisplayHeight() * scaleY;
|
|
|
|
|
|
|
|
if (boxwidth > 0 || boxheight > 0)
|
|
|
|
{
|
|
|
|
if (!(flags & DI_FORCEFILL))
|
|
|
|
{
|
|
|
|
double scale1 = 1., scale2 = 1.;
|
|
|
|
|
|
|
|
if (boxwidth > 0 && (boxwidth < texwidth || (flags & DI_FORCESCALE)))
|
|
|
|
{
|
|
|
|
scale1 = boxwidth / texwidth;
|
|
|
|
}
|
|
|
|
if (boxheight != -1 && (boxheight < texheight || (flags & DI_FORCESCALE)))
|
|
|
|
{
|
|
|
|
scale2 = boxheight / texheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DI_FORCESCALE)
|
|
|
|
{
|
|
|
|
if (boxwidth <= 0 || (boxheight > 0 && scale2 < scale1))
|
|
|
|
scale1 = scale2;
|
|
|
|
}
|
|
|
|
else scale1 = MIN(scale1, scale2);
|
|
|
|
|
|
|
|
boxwidth = texwidth * scale1;
|
|
|
|
boxheight = texheight * scale1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boxwidth = texwidth;
|
|
|
|
boxheight = texheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// resolve auto-alignment before making any adjustments to the position values.
|
|
|
|
if (!(flags & DI_SCREEN_MANUAL_ALIGN))
|
|
|
|
{
|
|
|
|
if (x < 0) flags |= DI_SCREEN_RIGHT;
|
|
|
|
else flags |= DI_SCREEN_LEFT;
|
|
|
|
if (y < 0) flags |= DI_SCREEN_BOTTOM;
|
|
|
|
else flags |= DI_SCREEN_TOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
Alpha *= this->Alpha;
|
|
|
|
if (Alpha <= 0) return;
|
|
|
|
x += drawOffset.X;
|
|
|
|
y += drawOffset.Y;
|
|
|
|
|
2020-07-24 19:08:33 +00:00
|
|
|
double xo = 0, yo = 0;
|
2020-07-24 21:08:48 +00:00
|
|
|
if (flags & DI_ITEM_RELCENTER)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-07-24 21:08:48 +00:00
|
|
|
xo = tex->GetDisplayWidth() / 2 + tex->GetDisplayLeftOffset();
|
|
|
|
yo = tex->GetDisplayHeight() / 2 + tex->GetDisplayTopOffset();
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
2020-07-24 21:08:48 +00:00
|
|
|
else
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
2020-07-24 21:08:48 +00:00
|
|
|
switch (flags & DI_ITEM_HMASK)
|
|
|
|
{
|
|
|
|
case DI_ITEM_HCENTER: xo = tex->GetDisplayWidth() / 2; break;
|
|
|
|
case DI_ITEM_RIGHT: xo = tex->GetDisplayWidth(); break;
|
|
|
|
case DI_ITEM_HOFFSET: xo = tex->GetDisplayLeftOffset(); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (flags & DI_ITEM_VMASK)
|
|
|
|
{
|
|
|
|
case DI_ITEM_VCENTER: yo = tex->GetDisplayHeight() / 2; break;
|
|
|
|
case DI_ITEM_BOTTOM: yo = tex->GetDisplayHeight(); break;
|
|
|
|
case DI_ITEM_VOFFSET: yo = tex->GetDisplayTopOffset(); break;
|
|
|
|
}
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fullscreenOffsets)
|
|
|
|
{
|
|
|
|
StatusbarToRealCoords(x, y, boxwidth, boxheight);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double orgx, orgy;
|
|
|
|
|
|
|
|
switch (flags & DI_SCREEN_HMASK)
|
|
|
|
{
|
|
|
|
default: orgx = 0; break;
|
2020-10-28 15:56:00 +00:00
|
|
|
case DI_SCREEN_HCENTER: orgx = twod->GetWidth() / 2; break;
|
|
|
|
case DI_SCREEN_RIGHT: orgx = twod->GetWidth(); break;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (flags & DI_SCREEN_VMASK)
|
|
|
|
{
|
|
|
|
default: orgy = 0; break;
|
2020-10-28 15:56:00 +00:00
|
|
|
case DI_SCREEN_VCENTER: orgy = twod->GetHeight() / 2; break;
|
|
|
|
case DI_SCREEN_BOTTOM: orgy = twod->GetHeight(); break;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// move stuff in the top right corner a bit down if the fps counter is on.
|
2020-10-28 15:56:00 +00:00
|
|
|
if ((flags & (DI_SCREEN_HMASK | DI_SCREEN_VMASK)) == DI_SCREEN_RIGHT_TOP && vid_fps) y += 10;
|
2020-06-21 20:34:50 +00:00
|
|
|
|
|
|
|
DVector2 Scale = GetHUDScale();
|
|
|
|
|
|
|
|
x *= Scale.X;
|
|
|
|
y *= Scale.Y;
|
|
|
|
boxwidth *= Scale.X;
|
|
|
|
boxheight *= Scale.Y;
|
|
|
|
x += orgx;
|
|
|
|
y += orgy;
|
|
|
|
}
|
2020-07-24 19:08:33 +00:00
|
|
|
// Now reapply the texture offsets. We will need them
|
2020-06-21 20:34:50 +00:00
|
|
|
DrawTexture(twod, tex, x, y,
|
2020-07-24 19:08:33 +00:00
|
|
|
DTA_TopOffsetF, yo,
|
|
|
|
DTA_LeftOffsetF, xo,
|
2020-06-21 20:34:50 +00:00
|
|
|
DTA_DestWidthF, boxwidth,
|
|
|
|
DTA_DestHeightF, boxheight,
|
|
|
|
DTA_Color, color,
|
|
|
|
DTA_TranslationIndex, translation, // (flags & DI_TRANSLATABLE) ? GetTranslation() : 0,
|
|
|
|
DTA_ColorOverlay, (flags & DI_DIM) ? MAKEARGB(170, 0, 0, 0) : 0,
|
|
|
|
DTA_Alpha, Alpha,
|
|
|
|
DTA_AlphaChannel, !!(flags & DI_ALPHAMAPPED),
|
|
|
|
DTA_FillColor, (flags & DI_ALPHAMAPPED) ? 0 : -1,
|
|
|
|
DTA_FlipX, !!(flags & DI_MIRROR),
|
2020-08-19 22:55:31 +00:00
|
|
|
DTA_FlipY, !!(flags& DI_MIRRORY),
|
2020-07-24 21:08:48 +00:00
|
|
|
DTA_Rotate, rotate,
|
2020-08-19 22:55:31 +00:00
|
|
|
DTA_FlipOffsets, true,
|
2020-08-02 06:39:51 +00:00
|
|
|
DTA_LegacyRenderStyle, style,
|
2020-06-21 20:34:50 +00:00
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// draw a string
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void DStatusBarCore::DrawString(FFont *font, const FString &cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
|
|
|
bool monospaced = monospacing != EMonospacing::Off;
|
|
|
|
double dx = 0;
|
|
|
|
|
|
|
|
switch (flags & DI_TEXT_ALIGN)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case DI_TEXT_ALIGN_RIGHT:
|
|
|
|
dx = monospaced
|
|
|
|
? static_cast<int> ((spacing)*cstring.CharacterCount()) //monospaced, so just multiply the character size
|
|
|
|
: static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount()));
|
|
|
|
break;
|
|
|
|
case DI_TEXT_ALIGN_CENTER:
|
|
|
|
dx = monospaced
|
|
|
|
? static_cast<int> ((spacing)*cstring.CharacterCount()) / 2 //monospaced, so just multiply the character size
|
|
|
|
: static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())) / 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take text scale into account
|
|
|
|
x -= dx * scaleX;
|
|
|
|
|
|
|
|
const uint8_t* str = (const uint8_t*)cstring.GetChars();
|
|
|
|
const EColorRange boldTranslation = EColorRange(translation ? translation - 1 : NumTextColors - 1);
|
|
|
|
int fontcolor = translation;
|
|
|
|
double orgx = 0, orgy = 0;
|
|
|
|
DVector2 Scale;
|
|
|
|
|
|
|
|
if (fullscreenOffsets)
|
|
|
|
{
|
|
|
|
Scale = GetHUDScale();
|
|
|
|
shadowX *= (int)Scale.X;
|
|
|
|
shadowY *= (int)Scale.Y;
|
|
|
|
|
|
|
|
switch (flags & DI_SCREEN_HMASK)
|
|
|
|
{
|
|
|
|
default: orgx = 0; break;
|
2020-10-28 15:56:00 +00:00
|
|
|
case DI_SCREEN_HCENTER: orgx = twod->GetWidth() / 2; break;
|
|
|
|
case DI_SCREEN_RIGHT: orgx = twod->GetWidth(); break;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (flags & DI_SCREEN_VMASK)
|
|
|
|
{
|
|
|
|
default: orgy = 0; break;
|
2020-10-28 15:56:00 +00:00
|
|
|
case DI_SCREEN_VCENTER: orgy = twod->GetHeight() / 2; break;
|
|
|
|
case DI_SCREEN_BOTTOM: orgy = twod->GetHeight(); break;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// move stuff in the top right corner a bit down if the fps counter is on.
|
|
|
|
if ((flags & (DI_SCREEN_HMASK | DI_SCREEN_VMASK)) == DI_SCREEN_RIGHT_TOP && vid_fps) y += 10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Scale = { 1.,1. };
|
|
|
|
}
|
|
|
|
int ch;
|
|
|
|
while (ch = GetCharFromString(str), ch != '\0')
|
|
|
|
{
|
|
|
|
if (ch == ' ')
|
|
|
|
{
|
|
|
|
x += monospaced ? spacing : font->GetSpaceWidth() + spacing;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (ch == TEXTCOLOR_ESCAPE)
|
|
|
|
{
|
|
|
|
EColorRange newColor = V_ParseFontColor(str, translation, boldTranslation);
|
|
|
|
if (newColor != CR_UNDEFINED)
|
|
|
|
fontcolor = newColor;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width;
|
|
|
|
FGameTexture* c = font->GetChar(ch, fontcolor, &width);
|
|
|
|
if (c == NULL) //missing character.
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-25 13:41:11 +00:00
|
|
|
width += font->GetDefaultKerning();
|
2020-06-21 20:34:50 +00:00
|
|
|
|
|
|
|
if (!monospaced) //If we are monospaced lets use the offset
|
|
|
|
x += (c->GetDisplayLeftOffset() + 1); //ignore x offsets since we adapt to character size
|
|
|
|
|
|
|
|
double rx, ry, rw, rh;
|
|
|
|
rx = x + drawOffset.X;
|
|
|
|
ry = y + drawOffset.Y;
|
|
|
|
rw = c->GetDisplayWidth();
|
|
|
|
rh = c->GetDisplayHeight();
|
|
|
|
|
|
|
|
if (monospacing == EMonospacing::CellCenter)
|
|
|
|
rx += (spacing - rw) / 2;
|
|
|
|
else if (monospacing == EMonospacing::CellRight)
|
|
|
|
rx += (spacing - rw);
|
|
|
|
|
|
|
|
if (!fullscreenOffsets)
|
|
|
|
{
|
|
|
|
StatusbarToRealCoords(rx, ry, rw, rh);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rx *= Scale.X;
|
|
|
|
ry *= Scale.Y;
|
|
|
|
rw *= Scale.X;
|
|
|
|
rh *= Scale.Y;
|
|
|
|
|
|
|
|
rx += orgx;
|
|
|
|
ry += orgy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply text scale
|
|
|
|
rw *= scaleX;
|
|
|
|
rh *= scaleY;
|
|
|
|
|
|
|
|
// This is not really such a great way to draw shadows because they can overlap with previously drawn characters.
|
|
|
|
// This may have to be changed to draw the shadow text up front separately.
|
|
|
|
if ((shadowX != 0 || shadowY != 0) && !(flags & DI_NOSHADOW))
|
|
|
|
{
|
|
|
|
DrawChar(twod, font, CR_UNTRANSLATED, rx + shadowX, ry + shadowY, ch,
|
|
|
|
DTA_DestWidthF, rw,
|
|
|
|
DTA_DestHeightF, rh,
|
2020-10-28 15:56:00 +00:00
|
|
|
DTA_Alpha, (Alpha * 0.4),
|
2020-06-21 20:34:50 +00:00
|
|
|
DTA_FillColor, 0,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
DrawChar(twod, font, fontcolor, rx, ry, ch,
|
|
|
|
DTA_DestWidthF, rw,
|
|
|
|
DTA_DestHeightF, rh,
|
|
|
|
DTA_Alpha, Alpha,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
dx = monospaced
|
|
|
|
? spacing
|
|
|
|
: width + spacing - (c->GetDisplayLeftOffset() + 1);
|
|
|
|
|
|
|
|
// Take text scale into account
|
|
|
|
x += dx * scaleX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void SBar_DrawString(DStatusBarCore *self, DHUDFont *font, const FString &string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing, double scaleX, double scaleY)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
|
|
|
//if (font == nullptr) ThrowAbortException(X_READ_NIL, nullptr);
|
|
|
|
//if (!screen->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))
|
|
|
|
{
|
|
|
|
if (x < 0) flags |= DI_SCREEN_RIGHT;
|
|
|
|
else flags |= DI_SCREEN_LEFT;
|
|
|
|
if (y < 0) flags |= DI_SCREEN_BOTTOM;
|
|
|
|
else flags |= DI_SCREEN_TOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wrapwidth > 0)
|
|
|
|
{
|
|
|
|
auto brk = V_BreakLines(font->mFont, int(wrapwidth * scaleX), string, true);
|
|
|
|
for (auto &line : brk)
|
|
|
|
{
|
|
|
|
self->DrawString(font->mFont, line.Text, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY, scaleX, scaleY);
|
|
|
|
y += (font->mFont->GetHeight() + linespacing) * scaleY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY, scaleX, scaleY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// draw stuff
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2020-10-28 15:56:00 +00:00
|
|
|
void DStatusBarCore::TransformRect(double &x, double &y, double &w, double &h, int flags)
|
2020-06-21 20:34:50 +00:00
|
|
|
{
|
|
|
|
// resolve auto-alignment before making any adjustments to the position values.
|
|
|
|
if (!(flags & DI_SCREEN_MANUAL_ALIGN))
|
|
|
|
{
|
|
|
|
if (x < 0) flags |= DI_SCREEN_RIGHT;
|
|
|
|
else flags |= DI_SCREEN_LEFT;
|
|
|
|
if (y < 0) flags |= DI_SCREEN_BOTTOM;
|
|
|
|
else flags |= DI_SCREEN_TOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
x += drawOffset.X;
|
|
|
|
y += drawOffset.Y;
|
|
|
|
|
|
|
|
if (!fullscreenOffsets)
|
|
|
|
{
|
|
|
|
StatusbarToRealCoords(x, y, w, h);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double orgx, orgy;
|
|
|
|
|
|
|
|
switch (flags & DI_SCREEN_HMASK)
|
|
|
|
{
|
|
|
|
default: orgx = 0; break;
|
2020-10-28 15:56:00 +00:00
|
|
|
case DI_SCREEN_HCENTER: orgx = twod->GetWidth() / 2; break;
|
|
|
|
case DI_SCREEN_RIGHT: orgx = twod->GetWidth(); break;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (flags & DI_SCREEN_VMASK)
|
|
|
|
{
|
|
|
|
default: orgy = 0; break;
|
2020-10-28 15:56:00 +00:00
|
|
|
case DI_SCREEN_VCENTER: orgy = twod->GetHeight() / 2; break;
|
|
|
|
case DI_SCREEN_BOTTOM: orgy = twod->GetHeight(); break;
|
2020-06-21 20:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// move stuff in the top right corner a bit down if the fps counter is on.
|
|
|
|
if ((flags & (DI_SCREEN_HMASK | DI_SCREEN_VMASK)) == DI_SCREEN_RIGHT_TOP && vid_fps) y += 10;
|
|
|
|
|
|
|
|
DVector2 Scale = GetHUDScale();
|
|
|
|
|
|
|
|
x *= Scale.X;
|
|
|
|
y *= Scale.Y;
|
|
|
|
w *= Scale.X;
|
|
|
|
h *= Scale.Y;
|
|
|
|
x += orgx;
|
|
|
|
y += orgy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|