summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp14
-rw-r--r--src/gui/gui.h5
-rw-r--r--src/gui/widgets/window.cpp78
-rw-r--r--src/gui/widgets/window.h15
-rw-r--r--src/gui/widgets/windowcontainer.cpp10
-rw-r--r--src/gui/widgets/windowcontainer.h6
6 files changed, 76 insertions, 52 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 3d79f0cdf..e441111a9 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -99,8 +99,7 @@ Gui::Gui(Graphics *graphics):
// Initialize top GUI widget
WindowContainer *guiTop = new WindowContainer;
guiTop->setFocusable(true);
- guiTop->setDimension(gcn::Rectangle(0, 0,
- graphics->mWidth, graphics->mHeight));
+ guiTop->setSize(graphics->mWidth, graphics->mHeight);
guiTop->setOpaque(false);
Window::setWindowContainer(guiTop);
setTop(guiTop);
@@ -287,6 +286,17 @@ void Gui::draw()
mGraphics->popClipArea();
}
+void Gui::videoResized()
+{
+ WindowContainer *top = static_cast<WindowContainer*>(getTop());
+
+ int oldWidth = top->getWidth();
+ int oldHeight = top->getHeight();
+
+ top->setSize(mainGraphics->mWidth, mainGraphics->mHeight);
+ top->adjustAfterResize(oldWidth, oldHeight);
+}
+
void Gui::setUseCustomCursor(bool customCursor)
{
if (customCursor != mCustomCursor)
diff --git a/src/gui/gui.h b/src/gui/gui.h
index cadcc89ac..5ace42323 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -70,6 +70,11 @@ class Gui : public gcn::Gui
*/
void draw();
+ /**
+ * Called when the application window has been resized.
+ */
+ void videoResized();
+
gcn::FocusHandler *getFocusHandler() const
{ return mFocusHandler; }
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 3858b0d81..6e6918694 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -433,7 +433,7 @@ void Window::setVisible(bool visible, bool forceSticky)
// Check if the window is off screen...
if (visible)
- checkIfIsOffScreen();
+ ensureOnScreen();
if (isStickyButtonLock())
gcn::Window::setVisible(visible);
@@ -713,7 +713,7 @@ void Window::loadWindowState()
}
// Check if the window is off screen...
- checkIfIsOffScreen();
+ ensureOnScreen();
if (viewport)
{
@@ -848,6 +848,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 = mainGraphics->mWidth - rightMargin - getWidth();
+ if (getY() > 0 && getY() > bottomMargin)
+ dimension.y = mainGraphics->mHeight - bottomMargin - getHeight();
+
+ setDimension(dimension);
+ ensureOnScreen();
+}
+
int Window::getResizeHandles(gcn::MouseEvent &event)
{
if ((mStickyButtonLock && mSticky) || event.getX() < 0 || event.getY() < 0)
@@ -972,57 +988,27 @@ void Window::centerHorisontally()
setLocationHorisontallyRelativeTo(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 winDimension = getDimension();
-
- if (winDimension.x < 0)
- {
- winDimension.width += winDimension.x;
- winDimension.x = 0;
- }
- if (winDimension.y < 0)
- {
- winDimension.height += winDimension.y;
- winDimension.y = 0;
- }
-
- // Look if the window is partially off-screen limits...
- if (partially)
- {
- if (winDimension.x + winDimension.width > mainGraphics->mWidth)
- winDimension.x = mainGraphics->mWidth - winDimension.width;
-
- if (winDimension.y + winDimension.height > mainGraphics->mHeight)
- winDimension.y = mainGraphics->mHeight - winDimension.height;
+ gcn::Rectangle dimension = getDimension();
- setDimension(winDimension);
- return;
- }
+ // Check the left and bottom screen boundaries
+ if (dimension.x + dimension.width > mainGraphics->mWidth)
+ dimension.x = mainGraphics->mWidth - dimension.width;
+ if (dimension.y + dimension.height > mainGraphics->mHeight)
+ dimension.y = mainGraphics->mHeight - dimension.height;
- if (entirely)
- {
- if (winDimension.x > mainGraphics->mWidth)
- winDimension.x = mainGraphics->mWidth - winDimension.width;
+ // 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;
- if (winDimension.y > mainGraphics->mHeight)
- winDimension.y = mainGraphics->mHeight - winDimension.height;
- }
- setDimension(winDimension);
+ setDimension(dimension);
}
gcn::Rectangle Window::getWindowArea()
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index 65dbf196b..6fa47dedc 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -329,6 +329,13 @@ class Window : public gcn::Window, gcn::WidgetListener
virtual void resetToDefaultSize();
/**
+ * Adjusts the window position after the application window has been
+ * resized.
+ */
+ void adjustPositionAfterResize(int oldScreenWidth,
+ int oldScreenHeight);
+
+ /**
* Gets the layout handler for this window.
*/
Layout &getLayout();
@@ -406,11 +413,11 @@ class Window : public gcn::Window, gcn::WidgetListener
};
/**
- * Check if the window is off-screen and then move it to be visible
- * again. This is internally used by loadWindowState
- * and setVisible(true) members.
+ * Ensures the window is on the screen, moving it if necessary. This is
+ * used by loadWindowState and setVisible(true), and when the screen
+ * is resized.
*/
- void checkIfIsOffScreen(bool partially = true, bool entirely = true);
+ void ensureOnScreen();
/**
* Determines if the mouse is in a resize area and returns appropriate
diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp
index 43aaea8a4..ce218e042 100644
--- a/src/gui/widgets/windowcontainer.cpp
+++ b/src/gui/widgets/windowcontainer.cpp
@@ -22,6 +22,8 @@
#include "gui/widgets/windowcontainer.h"
+#include "gui/widgets/window.h"
+
#include "utils/dtor.h"
#include "debug.h"
@@ -41,3 +43,11 @@ void WindowContainer::scheduleDelete(gcn::Widget *widget)
if (widget)
mDeathList.push_back(widget);
}
+
+void WindowContainer::adjustAfterResize(int oldScreenWidth,
+ int oldScreenHeight)
+{
+ for (WidgetListIterator i = mWidgets.begin(); i != mWidgets.end(); ++i)
+ if (Window *window = dynamic_cast<Window*>(*i))
+ window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
+}
diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h
index 00ef04c19..1cec11861 100644
--- a/src/gui/widgets/windowcontainer.h
+++ b/src/gui/widgets/windowcontainer.h
@@ -48,6 +48,12 @@ class WindowContainer : public Container
*/
void scheduleDelete(gcn::Widget *widget);
+ /**
+ * Ensures that all visible windows are on the screen after the screen
+ * has been resized.
+ */
+ void adjustAfterResize(int oldScreenWidth, int oldScreenHeight);
+
private:
/**
* List of widgets that are scheduled to be deleted.