summaryrefslogtreecommitdiff
path: root/src/gui/window.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-01-06 17:50:52 +0100
committerIra Rice <irarice@gmail.com>2009-01-06 11:06:36 -0700
commit14a12cbe586f88ace6d90d9ca5b802edfb546768 (patch)
tree74a724358ec376df7347e566dab1f23fde92751a /src/gui/window.cpp
parent394989d94081cbc462ba7d567fc88d0c4dff8134 (diff)
downloadmana-14a12cbe586f88ace6d90d9ca5b802edfb546768.tar.gz
mana-14a12cbe586f88ace6d90d9ca5b802edfb546768.tar.bz2
mana-14a12cbe586f88ace6d90d9ca5b802edfb546768.tar.xz
mana-14a12cbe586f88ace6d90d9ca5b802edfb546768.zip
Merged layout handler from mainline
Also fixed login dialog layout. This is the layout handler by Guillaume Melquiond, which he started in commit 59472ef68fdef3f7e8858a81a46e28c127119c58.
Diffstat (limited to 'src/gui/window.cpp')
-rw-r--r--src/gui/window.cpp83
1 files changed, 49 insertions, 34 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index dee5832a..e82a370e 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -22,7 +22,6 @@
#include <algorithm>
#include <cassert>
#include <climits>
-#include <cassert>
#include <guichan/exception.hpp>
@@ -33,6 +32,7 @@
#include "window.h"
#include "windowcontainer.h"
+#include "widgets/layout.h"
#include "widgets/resizegrip.h"
#include "../configlistener.h"
@@ -68,6 +68,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std
gcn::Window(caption),
mGrip(0),
mParent(parent),
+ mLayout(NULL),
mWindowName("window"),
mShowTitle(true),
mModal(modal),
@@ -82,7 +83,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std
logger->log("Window::Window(\"%s\")", caption.c_str());
if (!windowContainer) {
- throw GCN_EXCEPTION("Window::Window. no windowContainer set");
+ throw GCN_EXCEPTION("Window::Window(): no windowContainer set");
}
// Loads the skin
@@ -104,11 +105,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std
setPadding(3);
setTitleBarHeight(20);
- // Add chrome
- mChrome = new GCContainer();
- mChrome->setOpaque(false);
- gcn::Window::add(mChrome);
-
// Add this window to the window container
windowContainer->add(this);
@@ -141,6 +137,15 @@ Window::~Window()
}
}
+ delete mLayout;
+
+ while (!mWidgets.empty())
+ {
+ gcn::Widget *w = mWidgets.front();
+ remove(w);
+ delete(w);
+ }
+
instances--;
// Clean up static resources
@@ -158,9 +163,6 @@ Window::~Window()
closeImage->decRef();
}
-
- delete mChrome;
- delete mGrip;
}
void Window::setWindowContainer(WindowContainer *wc)
@@ -195,7 +197,6 @@ void Window::draw(gcn::Graphics *graphics)
void Window::setContentSize(int width, int height)
{
- mChrome->setSize(width, height);
setSize(width + 2 * getPadding(),
height + getPadding() + getTitleBarHeight());
}
@@ -241,10 +242,11 @@ void Window::setResizable(bool r)
mGrip = new ResizeGrip();
mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x);
mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y);
- gcn::Window::add(mGrip);
+ add(mGrip);
}
else
{
+ remove(mGrip);
delete mGrip;
mGrip = 0;
}
@@ -252,15 +254,19 @@ void Window::setResizable(bool r)
void Window::widgetResized(const gcn::Event &event)
{
- const gcn::Rectangle area = getChildrenArea();
-
- mChrome->setSize(area.width, area.height);
-
if (mGrip)
{
+ const gcn::Rectangle area = getChildrenArea();
mGrip->setPosition(getWidth() - mGrip->getWidth() - area.x,
getHeight() - mGrip->getHeight() - area.y);
}
+
+ if (mLayout)
+ {
+ int w = getWidth() - 2 * getPadding();
+ int h = getHeight() - getPadding() - getTitleBarHeight();
+ mLayout->reflow(w, h);
+ }
}
void Window::setCloseButton(bool flag)
@@ -285,14 +291,7 @@ bool Window::isSticky()
void Window::setVisible(bool visible)
{
- if (isSticky())
- {
- gcn::Window::setVisible(true);
- }
- else
- {
- gcn::Window::setVisible(visible);
- }
+ gcn::Window::setVisible(isSticky() || visible);
}
void Window::scheduleDelete()
@@ -300,16 +299,6 @@ void Window::scheduleDelete()
windowContainer->scheduleDelete(this);
}
-void Window::add(gcn::Widget *w)
-{
- mChrome->add(w);
-}
-
-void Window::add(gcn::Widget *w, int x, int y)
-{
- mChrome->add(w, x, y);
-}
-
void Window::mousePressed(gcn::MouseEvent &event)
{
// Let Guichan move window to top and figure out title bar drag
@@ -710,3 +699,29 @@ void Window::loadSkin(const std::string filename)
closeImage = resman->getImage("graphics/gui/close_button.png");
}
+Layout &Window::getLayout()
+{
+ if (!mLayout) mLayout = new Layout;
+ return *mLayout;
+}
+
+LayoutCell &Window::place(int x, int y, gcn::Widget *wg, int w, int h)
+{
+ add(wg);
+ return getLayout().place(wg, x, y, w, h);
+}
+
+ContainerPlacer Window::getPlacer(int x, int y)
+{
+ return ContainerPlacer(this, &getLayout().at(x, y));
+}
+
+void Window::reflowLayout(int w, int h)
+{
+ assert(mLayout);
+ mLayout->reflow(w, h);
+ delete mLayout;
+ mLayout = NULL;
+ setContentSize(w, h);
+}
+