Fix various unintended layout changes since 97.0

Also fix a few unused variable warnings.
This commit is contained in:
Tamás Bálint Misius 2023-04-29 12:52:29 +02:00
parent ad1420152c
commit 8f10210c77
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
7 changed files with 6 additions and 8 deletions

View File

@ -169,7 +169,7 @@ Graphics::Graphics()
int Graphics::textwidth(const String &str)
{
return TextSize(str).X;
return TextSize(str).X - 1;
}
void Graphics::draw_icon(int x, int y, Icon icon, unsigned char alpha, bool invert)

View File

@ -92,7 +92,7 @@ public:
static std::vector<RGB<uint8_t>> Gradient(std::vector<GradientStop> stops, int resolution);
//Font/text metrics
[[deprecated("Use TextSize().X")]]
[[deprecated("Use TextSize().X - 1 (yes this is very bad code eww)")]]
static int textwidth(const String &s);
VideoBuffer DumpFrame();

View File

@ -334,7 +334,7 @@ template<typename Derived>
Vec2<int> RasterDrawMethods<Derived>::TextSize(String const &str)
{
Vec2<int> size = Vec2(0, FONT_H - 2);
int curX = -1; // characters have 1px of spacing between them
int curX = 0; // characters have 1px of spacing between them
for (size_t i = 0; i < str.length(); i++)
{
if (str[i] == '\n')

View File

@ -115,7 +115,6 @@ void Renderer::DrawBlob(int x, int y, unsigned char cr, unsigned char cg, unsign
void Renderer::render_gravlensing(pixel * source)
{
int nx, ny, rx, ry, gx, gy, bx, by, co;
int r, g, b;
pixel *src = source;
pixel *dst = vid;
if (!dst)

View File

@ -25,7 +25,7 @@ void Button::TextPosition(String ButtonText)
buttonDisplayText = ButtonText;
if(buttonDisplayText.length())
{
if (Graphics::TextSize(buttonDisplayText).X > Size.X - (Appearance.icon ? 22 : 0))
if (Graphics::TextSize(buttonDisplayText).X - 1 > Size.X - (Appearance.icon ? 22 : 0))
{
auto it = Graphics::TextFit(buttonDisplayText, Size.X - (Appearance.icon ? 38 : 22));
buttonDisplayText.erase(it, buttonDisplayText.end());

View File

@ -39,7 +39,7 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save_) : SaveButto
if(save)
{
name = save->name;
if (Graphics::TextSize(name).X > Size.X)
if (Graphics::TextSize(name).X - 1 > Size.X)
{
auto it = Graphics::TextFit(name, Size.X - (Appearance.icon ? 38 : 22));
name.erase(it, name.end());
@ -100,7 +100,7 @@ SaveButton::SaveButton(Point position, Point size, SaveFile * file_) : SaveButto
if(file)
{
name = file->GetDisplayName();
if (Graphics::TextSize(name).X > Size.X)
if (Graphics::TextSize(name).X - 1 > Size.X)
{
auto it = Graphics::TextFit(name, Size.X - (Appearance.icon ? 38 : 22));
name.erase(it, name.end());

View File

@ -3785,7 +3785,6 @@ void LuaScriptInterface::initGraphicsAPI()
int LuaScriptInterface::graphics_textSize(lua_State * l)
{
int width, height;
auto text = tpt_lua_optString(l, 1, "");
auto size = Graphics::TextSize(text);