From 3eb3481fda5a7077798c9ed0632a8915b7f878ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Mon, 1 May 2023 22:22:47 +0200 Subject: [PATCH] Fix local save browser crashing in some cases This also fixes local save thumbnails being resized such that they are just short of filling the space they are supposed to. Also fix textboxes drawing their borders in the wrong place. --- src/graphics/Graphics.cpp | 7 +++++-- src/gui/interface/Textbox.cpp | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index c2ce36bf3..13c9c907c 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -131,10 +131,13 @@ void VideoBuffer::ResizeToFit(Vec2 bound, bool resample) Vec2 size = Size(); if (size.X > bound.X || size.Y > bound.Y) { + auto ceilDiv = [](int a, int b) { + return a / b + ((a % b) ? 1 : 0); + }; if (bound.X * size.Y < bound.Y * size.X) - size = size * bound.X / size.X; + size = { ceilDiv(size.X * bound.X, size.X), ceilDiv(size.Y * bound.X, size.X) }; else - size = size * bound.Y / size.Y; + size = { ceilDiv(size.X * bound.Y, size.Y), ceilDiv(size.Y * bound.Y, size.Y) }; } Resize(size, resample); } diff --git a/src/gui/interface/Textbox.cpp b/src/gui/interface/Textbox.cpp index 1a6f18591..1b44f2cc1 100644 --- a/src/gui/interface/Textbox.cpp +++ b/src/gui/interface/Textbox.cpp @@ -614,7 +614,7 @@ void Textbox::Draw(const Point& screenPos) if(IsFocused()) { if(border) - g->DrawRect(RectSized(Position, Size), 0xFFFFFF_rgb); + g->DrawRect(RectSized(screenPos, Size), 0xFFFFFF_rgb); g->DrawLine( screenPos + textPosition + Vec2{ cursorPositionX, cursorPositionY-2 }, screenPos + textPosition + Vec2{ cursorPositionX, cursorPositionY+9 }, @@ -627,7 +627,7 @@ void Textbox::Draw(const Point& screenPos) g->BlendText(screenPos + textPosition, placeHolder, textColour.NoAlpha().WithAlpha(170)); } if(border) - g->DrawRect(RectSized(Position, Size), 0xA0A0A0_rgb); + g->DrawRect(RectSized(screenPos, Size), 0xA0A0A0_rgb); } if(Appearance.icon) g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon);