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.
This commit is contained in:
Tamás Bálint Misius 2023-05-01 22:22:47 +02:00
parent 60a7ce1aae
commit 3eb3481fda
No account linked to committer's email address
2 changed files with 7 additions and 4 deletions

View File

@ -131,10 +131,13 @@ void VideoBuffer::ResizeToFit(Vec2<int> bound, bool resample)
Vec2<int> size = Size(); Vec2<int> size = Size();
if (size.X > bound.X || size.Y > bound.Y) 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) 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 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); Resize(size, resample);
} }

View File

@ -614,7 +614,7 @@ void Textbox::Draw(const Point& screenPos)
if(IsFocused()) if(IsFocused())
{ {
if(border) if(border)
g->DrawRect(RectSized(Position, Size), 0xFFFFFF_rgb); g->DrawRect(RectSized(screenPos, Size), 0xFFFFFF_rgb);
g->DrawLine( g->DrawLine(
screenPos + textPosition + Vec2{ cursorPositionX, cursorPositionY-2 }, screenPos + textPosition + Vec2{ cursorPositionX, cursorPositionY-2 },
screenPos + textPosition + Vec2{ cursorPositionX, cursorPositionY+9 }, 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)); g->BlendText(screenPos + textPosition, placeHolder, textColour.NoAlpha().WithAlpha(170));
} }
if(border) if(border)
g->DrawRect(RectSized(Position, Size), 0xA0A0A0_rgb); g->DrawRect(RectSized(screenPos, Size), 0xA0A0A0_rgb);
} }
if(Appearance.icon) if(Appearance.icon)
g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon); g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon);