1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

code review

This commit is contained in:
Laserlicht
2024-08-17 12:25:16 +02:00
parent f7e01eaf67
commit 0c836e0797
4 changed files with 14 additions and 6 deletions

View File

@@ -156,12 +156,17 @@ void CIntObject::setRedrawParent(bool on)
}
void CIntObject::fitToScreen(int borderWidth, bool propagate)
{
fitToRect(Rect(Point(0, 0), GH.screenDimensions()), borderWidth, propagate);
}
void CIntObject::fitToRect(Rect rect, int borderWidth, bool propagate)
{
Point newPos = pos.topLeft();
vstd::amax(newPos.x, borderWidth);
vstd::amax(newPos.y, borderWidth);
vstd::amin(newPos.x, GH.screenDimensions().x - borderWidth - pos.w);
vstd::amin(newPos.y, GH.screenDimensions().y - borderWidth - pos.h);
vstd::amax(newPos.x, rect.x + borderWidth);
vstd::amax(newPos.y, rect.y + borderWidth);
vstd::amin(newPos.x, rect.x + rect.w - borderWidth - pos.w);
vstd::amin(newPos.y, rect.y + rect.h - borderWidth - pos.h);
if (newPos != pos.topLeft())
moveTo(newPos, propagate);
}