diff options
Diffstat (limited to 'src/gui/window.cpp')
-rw-r--r-- | src/gui/window.cpp | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 650016cb..8317684a 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -64,7 +64,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent): mWindowName("window"), mShowTitle(true), mModal(modal), - mResizable(false), mCloseButton(false), mSticky(false), mMinWinWidth(100), @@ -134,7 +133,7 @@ Window::~Window() config.setValue(name + "WinX", getX()); config.setValue(name + "WinY", getY()); - if (mResizable) + if (mGrip) { config.setValue(name + "WinWidth", getWidth()); config.setValue(name + "WinHeight", getHeight()); @@ -208,64 +207,64 @@ void Window::setContentHeight(int height) void Window::setContentSize(int width, int height) { - setContentWidth(width); - setContentHeight(height); + mChrome->setSize(width, height); + setSize(width + 2 * getPadding(), + height + getPadding() + getTitleBarHeight()); } -void Window::setWidth(int width) +void Window::setSize(int width, int height) { - gcn::Window::setWidth(width); + if (width == mDimension.width && height == mDimension.height) return; + + // No call to ancestor! Infinite loop otherwise. + mDimension.width = width; + mDimension.height = height; if (mGrip) { - mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); + gcn::Rectangle const &area = getChildrenArea(); + mGrip->setPosition(width - mGrip->getWidth() - area.x, + height - mGrip->getHeight() - area.y); } fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); } -void Window::setHeight(int height) +void Window::setWidth(int width) { - gcn::Window::setHeight(height); - - if (mGrip) - { - mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); - } + setSize(width, mDimension.height); +} - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); +void Window::setHeight(int height) +{ + setSize(mDimension.width, height); } -void Window::setDimension(const gcn::Rectangle &dimension) +void Window::setPosition(int x, int y) { - gcn::Window::setDimension(dimension); + if (x == mDimension.x && y == mDimension.y) return; - if (mGrip) - { - mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); - mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); - } + // No call to ancestor! + mDimension.x = x; + mDimension.y = y; - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); } -void Window::setPosition(int x, int y) +void Window::setDimension(const gcn::Rectangle &dimension) { - gcn::Window::setPosition(x, y); - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); + setPosition(dimension.x, dimension.y); + setSize(dimension.width, dimension.height); } void Window::setX(int x) { - gcn::Window::setX(x); - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); + setPosition(x, mDimension.y); } void Window::setY(int y) { - gcn::Window::setY(y); - fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_MOVED)); + setPosition(mDimension.x, y); } void Window::setLocationRelativeTo(gcn::Widget *widget) @@ -302,9 +301,9 @@ void Window::setMaxHeight(unsigned int height) void Window::setResizable(bool r) { - mResizable = r; + if ((bool)mGrip == r) return; - if (mResizable) + if (r) { mGrip = new ResizeGrip(); mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); @@ -325,7 +324,7 @@ void Window::setCloseButton(bool flag) bool Window::isResizable() { - return mResizable; + return mGrip; } void Window::setSticky(bool sticky) @@ -397,7 +396,7 @@ void Window::mousePressed(gcn::MouseEvent &event) void Window::mouseReleased(gcn::MouseEvent &event) { - if (mResizable && mouseResize) + if (mGrip && mouseResize) { mouseResize = 0; gui->setCursorType(Gui::CURSOR_POINTER); @@ -409,7 +408,7 @@ void Window::mouseReleased(gcn::MouseEvent &event) void Window::mouseExited(gcn::MouseEvent &event) { - if (mResizable && !mouseResize) + if (mGrip && !mouseResize) { gui->setCursorType(Gui::CURSOR_POINTER); } @@ -530,7 +529,7 @@ Window::loadWindowState() setPosition((int) config.getValue(name + "WinX", getX()), (int) config.getValue(name + "WinY", getY())); - if (mResizable) + if (mGrip) { setSize((int) config.getValue(name + "WinWidth", getWidth()), (int) config.getValue(name + "WinHeight", getHeight())); @@ -563,7 +562,7 @@ int Window::getResizeHandles(gcn::MouseEvent &event) int resizeHandles = 0; const int y = event.getY(); - if (mResizable && y > (int) mTitleBarHeight) + if (mGrip && y > (int) mTitleBarHeight) { const int x = event.getX(); |