diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-01-06 17:50:52 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-01-06 17:50:52 +0100 |
commit | 9219f1ffd4b05886b66c9074c918850fc97c430c (patch) | |
tree | cc6750b62b825636abb898297489d1372fc55848 /src/gui/window.cpp | |
parent | 631a8a85e8be0ec472850ba672676fe31679e7c3 (diff) | |
download | mana-9219f1ffd4b05886b66c9074c918850fc97c430c.tar.gz mana-9219f1ffd4b05886b66c9074c918850fc97c430c.tar.bz2 mana-9219f1ffd4b05886b66c9074c918850fc97c430c.tar.xz mana-9219f1ffd4b05886b66c9074c918850fc97c430c.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.cpp | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 630b4ddd..dfe7ac64 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -20,8 +20,8 @@ */ #include <algorithm> -#include <climits> #include <cassert> +#include <climits> #include <guichan/exception.hpp> #include <guichan/widgets/icon.hpp> @@ -29,9 +29,9 @@ #include "window.h" #include "gui.h" -#include "gccontainer.h" #include "windowcontainer.h" +#include "widgets/layout.h" #include "widgets/resizegrip.h" #include "../configlistener.h" @@ -63,6 +63,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): gcn::Window(caption), mGrip(0), mParent(parent), + mLayout(NULL), mWindowName("window"), mShowTitle(true), mModal(modal), @@ -76,7 +77,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): 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"); } if (instances == 0) @@ -108,11 +109,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent): 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); @@ -145,6 +141,15 @@ Window::~Window() } } + delete mLayout; + + while (!mWidgets.empty()) + { + gcn::Widget *w = mWidgets.front(); + remove(w); + delete(w); + } + instances--; if (instances == 0) @@ -165,9 +170,6 @@ Window::~Window() delete border.grid[8]; closeImage->decRef(); } - - delete mChrome; - delete mGrip; } void Window::setWindowContainer(WindowContainer *wc) @@ -202,7 +204,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()); } @@ -248,10 +249,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; } @@ -259,15 +261,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) @@ -292,14 +298,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() @@ -307,16 +306,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 @@ -535,3 +524,29 @@ int Window::getResizeHandles(gcn::MouseEvent &event) return resizeHandles; } + +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); +} |