summaryrefslogtreecommitdiff
path: root/src/gui/widgets/window.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-01-21 12:30:36 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-01-22 11:12:17 +0100
commitc4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb (patch)
treed87655455c0a331c73bf5b762701fafaa5348688 /src/gui/widgets/window.cpp
parent0d613d75b732c0d057acc3004f9b4322cf73d449 (diff)
downloadMana-c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb.tar.gz
Mana-c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb.tar.bz2
Mana-c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb.tar.xz
Mana-c4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb.zip
Allow resizing of the game in windowed mode
Window positions are semi-smartly corrected as a result of the resize. Not supported when using OpenGL on Windows for now. Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/gui/widgets/window.cpp')
-rw-r--r--src/gui/widgets/window.cpp85
1 files changed, 32 insertions, 53 deletions
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index aa8e6df3..88c6da8a 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -328,7 +328,7 @@ void Window::setVisible(bool visible, bool forceSticky)
// Check if the window is off screen...
if (visible)
- checkIfIsOffScreen();
+ ensureOnScreen();
gcn::Window::setVisible((!forceSticky && isSticky()) || visible);
}
@@ -547,7 +547,7 @@ void Window::loadWindowState()
}
// Check if the window is off screen...
- checkIfIsOffScreen();
+ ensureOnScreen();
}
void Window::saveWindowState()
@@ -666,6 +666,22 @@ void Window::resetToDefaultSize()
saveWindowState();
}
+void Window::adjustPositionAfterResize(int oldScreenWidth, int oldScreenHeight)
+{
+ gcn::Rectangle dimension = getDimension();
+
+ // If window was aligned to the right or bottom, keep it there
+ const int rightMargin = oldScreenWidth - (getX() + getWidth());
+ const int bottomMargin = oldScreenHeight - (getY() + getHeight());
+ if (getX() > 0 && getX() > rightMargin)
+ dimension.x = graphics->getWidth() - rightMargin - getWidth();
+ if (getY() > 0 && getY() > bottomMargin)
+ dimension.y = graphics->getHeight() - bottomMargin - getHeight();
+
+ setDimension(dimension);
+ ensureOnScreen();
+}
+
int Window::getResizeHandles(gcn::MouseEvent &event)
{
int resizeHandles = 0;
@@ -761,62 +777,25 @@ void Window::center()
setLocationRelativeTo(getParent());
}
-void Window::checkIfIsOffScreen(bool partially, bool entirely)
+void Window::ensureOnScreen()
{
- // Move the window onto screen if it has become off screen
- // For instance, because of resolution change...
-
- // First of all, don't deal when a window hasn't got
- // any size initialized yet...
+ // Skip when a window hasn't got any size initialized yet
if (getWidth() == 0 && getHeight() == 0)
return;
- // Made partially the default behaviour
- if (!partially && !entirely)
- partially = true;
-
- // Keep guichan window inside screen (supports resizing any side)
+ gcn::Rectangle dimension = getDimension();
- gcn::Rectangle winDimension = 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;
- if (winDimension.x < 0)
- {
- winDimension.width += winDimension.x;
- winDimension.x = 0;
- }
- if (winDimension.y < 0)
- {
- winDimension.height += winDimension.y;
- winDimension.y = 0;
- }
+ // 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;
- // Look if the window is partially off-screen limits...
- if (partially)
- {
- if (winDimension.x + winDimension.width > graphics->getWidth())
- {
- winDimension.x = graphics->getWidth() - winDimension.width;
- }
-
- if (winDimension.y + winDimension.height > graphics->getHeight())
- {
- winDimension.y = graphics->getHeight() - winDimension.height;
- }
- setDimension(winDimension);
- return;
- }
-
- if (entirely)
- {
- if (winDimension.x > graphics->getWidth())
- {
- winDimension.x = graphics->getWidth() - winDimension.width;
- }
-
- if (winDimension.y > graphics->getHeight())
- {
- winDimension.y = graphics->getHeight() - winDimension.height;
- }
- }
- setDimension(winDimension);
+ setDimension(dimension);
}