diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-04-11 13:31:52 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-04-11 13:31:52 +0000 |
commit | 4b9e2b6c41e740a3eac10078d5fa4fbc63788bbe (patch) | |
tree | 6b8aea437d454de40808a7f1289c264d7bd563e3 /src/gui/window.cpp | |
parent | f97ddedaa9672c78147fc13282bd14a5be46eb19 (diff) | |
download | mana-4b9e2b6c41e740a3eac10078d5fa4fbc63788bbe.tar.gz mana-4b9e2b6c41e740a3eac10078d5fa4fbc63788bbe.tar.bz2 mana-4b9e2b6c41e740a3eac10078d5fa4fbc63788bbe.tar.xz mana-4b9e2b6c41e740a3eac10078d5fa4fbc63788bbe.zip |
Ported trunk over to Guichan 0.8.0. Based on merge from 0.0 branch, but because
of quite a bit of GUI differences there were additional changes and probably
additional issues. You have been warned. ;)
Merged revisions 4045-4049,4051-4059 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0
........
r4045 | b_lindeijer | 2008-04-07 17:23:07 +0200 (Mon, 07 Apr 2008) | 3 lines
Upgraded to Guichan 0.8.0 (merge from guichan-0.8 branch, except for
gcn::TabbedArea usage)
........
r4059 | b_lindeijer | 2008-04-09 16:25:42 +0200 (Wed, 09 Apr 2008) | 2 lines
Fixed problem with row height in shop list box.
........
Diffstat (limited to 'src/gui/window.cpp')
-rw-r--r-- | src/gui/window.cpp | 117 |
1 files changed, 23 insertions, 94 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 7629e2e7..75288eb5 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -106,7 +106,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): instances++; - setBorderSize(0); + setFrameSize(0); setPadding(3); setTitleBarHeight(20); @@ -121,6 +121,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent): // Windows are invisible by default setVisible(false); + + addWidgetListener(this); } Window::~Window() @@ -202,84 +204,12 @@ void Window::draw(gcn::Graphics *graphics) drawChildren(graphics); } -void Window::setContentWidth(int width) -{ - setWidth(width + 2 * getPadding()); -} - -void Window::setContentHeight(int height) -{ - setHeight(height + getPadding() + getTitleBarHeight()); -} - void Window::setContentSize(int width, int height) { setSize(width + 2 * getPadding(), height + getPadding() + getTitleBarHeight()); } -void Window::setSize(int width, int height) -{ - if (width == mDimension.width && height == mDimension.height) return; - - // No call to ancestor! Infinite loop otherwise. - mDimension.width = width; - mDimension.height = height; - - if (mGrip) - { - gcn::Rectangle const &area = getChildrenArea(); - mGrip->setPosition(width - mGrip->getWidth() - area.x, - height - mGrip->getHeight() - area.y); - } - - if (mLayout) - { - int w = width - 2 * getPadding(), - h = height - getPadding() - getTitleBarHeight(); - mLayout->reflow(w, h); - } - - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); -} - -void Window::setWidth(int width) -{ - setSize(width, mDimension.height); -} - -void Window::setHeight(int height) -{ - setSize(mDimension.width, height); -} - -void Window::setPosition(int x, int y) -{ - if (x == mDimension.x && y == mDimension.y) return; - - // No call to ancestor! - mDimension.x = x; - mDimension.y = y; - - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); -} - -void Window::setDimension(const gcn::Rectangle &dimension) -{ - setPosition(dimension.x, dimension.y); - setSize(dimension.width, dimension.height); -} - -void Window::setX(int x) -{ - setPosition(x, mDimension.y); -} - -void Window::setY(int y) -{ - setPosition(mDimension.x, y); -} - void Window::setLocationRelativeTo(gcn::Widget *widget) { int wx, wy; @@ -331,6 +261,23 @@ void Window::setResizable(bool r) } } +void Window::widgetResized(const gcn::Event &event) +{ + if (mGrip) + { + gcn::Rectangle const &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) { mCloseButton = flag; @@ -407,7 +354,7 @@ void Window::mouseReleased(gcn::MouseEvent &event) } // This should be the responsibility of Guichan (and is from 0.8.0 on) - mIsMoving = false; + mMoved = false; } void Window::mouseExited(gcn::MouseEvent &event) @@ -449,7 +396,7 @@ void Window::mouseDragged(gcn::MouseEvent &event) gcn::Window::mouseDragged(event); // Keep guichan window inside screen when it may be moved - if (isMovable() && mIsMoving) + if (isMovable() && mMoved) { int newX = std::max(0, getX()); int newY = std::max(0, getY()); @@ -458,7 +405,7 @@ void Window::mouseDragged(gcn::MouseEvent &event) setPosition(newX, newY); } - if (mouseResize && !mIsMoving) + if (mouseResize && !mMoved) { const int dx = event.getX() - mDragOffsetX; const int dy = event.getY() - mDragOffsetY; @@ -585,24 +532,6 @@ int Window::getResizeHandles(gcn::MouseEvent &event) return resizeHandles; } -void Window::fireWindowEvent(const WindowEvent &event) -{ - WindowListeners::iterator i_end = mListeners.end(); - WindowListeners::iterator i = mListeners.begin(); - - switch (event.getType()) - { - case WindowEvent::WINDOW_MOVED: - for (; i != i_end; ++i) - { (*i)->windowMoved(event); } - break; - case WindowEvent::WINDOW_RESIZED: - for (; i != i_end; ++i) - { (*i)->windowResized(event); } - break; - } -} - Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; |