diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-06-03 17:56:33 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-08-04 21:24:44 +0200 |
commit | 350e7468d14e0b88e6b2eeb367d9488b394df8ba (patch) | |
tree | 79b0a1879f546e9e4bc1711600f8d6e3ec23c784 /src/gui/widgets | |
parent | f94d3280c2f2520a80e9099e0dd4d6d9491e18a5 (diff) | |
download | mana-350e7468d14e0b88e6b2eeb367d9488b394df8ba.tar.gz mana-350e7468d14e0b88e6b2eeb367d9488b394df8ba.tar.bz2 mana-350e7468d14e0b88e6b2eeb367d9488b394df8ba.tar.xz mana-350e7468d14e0b88e6b2eeb367d9488b394df8ba.zip |
Reuse Window::ensureOnScreen
Less code duplication.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/window.cpp | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 25ca7684..6b36ebe2 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -437,13 +437,7 @@ void Window::mouseDragged(gcn::MouseEvent &event) // Keep guichan window inside screen when it may be moved if (isMovable() && mMoved) - { - int newX = std::max(0, getX()); - int newY = std::max(0, getY()); - newX = std::min(graphics->getWidth() - getWidth(), newX); - newY = std::min(graphics->getHeight() - getHeight(), newY); - setPosition(newX, newY); - } + ensureOnScreen(); if (mouseResize && !mMoved) { @@ -785,19 +779,15 @@ void Window::ensureOnScreen() if (getWidth() == 0 && getHeight() == 0) return; - gcn::Rectangle dimension = getDimension(); + gcn::Rectangle dim = getDimension(); // Check the left and bottom screen boundaries - if (dimension.x + dimension.width > graphics->getWidth()) - dimension.x = graphics->getWidth() - dimension.width; - if (dimension.y + dimension.height > graphics->getHeight()) - dimension.y = graphics->getHeight() - dimension.height; + dim.x = std::min(graphics->getWidth() - dim.width, dim.x); + dim.y = std::min(graphics->getHeight() - dim.height, dim.y); // But never allow the windows to disappear in to the right and top - if (dimension.x < 0) - dimension.x = 0; - if (dimension.y < 0) - dimension.y = 0; + dim.x = std::max(0, dim.x); + dim.y = std::max(0, dim.y); - setDimension(dimension); + setPosition(dim.x, dim.y); } |