diff options
Diffstat (limited to 'src/gui/window.cpp')
-rw-r--r-- | src/gui/window.cpp | 63 |
1 files changed, 54 insertions, 9 deletions
diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 3bc03fb8..1f9dab5b 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -48,6 +48,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent, const std mShowTitle(true), mModal(modal), mCloseButton(false), + mStickyButton(false), mSticky(false), mMinWinWidth(100), mMinWinHeight(40), @@ -60,7 +61,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent, const std throw GCN_EXCEPTION("Window::Window(): no windowContainer set"); if (instances == 0) - skinLoader = new SkinLoader(); + skinLoader = new SkinLoader; instances++; @@ -118,9 +119,6 @@ void Window::setWindowContainer(WindowContainer *wc) void Window::draw(gcn::Graphics *graphics) { - if (!isVisible()) - return; - Graphics *g = static_cast<Graphics*>(graphics); g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); @@ -138,8 +136,18 @@ void Window::draw(gcn::Graphics *graphics) { g->drawImage(mSkin->getCloseImage(), getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(), - getPadding() - ); + getPadding()); + } + + // Draw Sticky Button + if (mStickyButton) + { + Image *button = mSkin->getStickyImage(mSticky); + int x = getWidth() - button->getWidth() - getPadding(); + if (mCloseButton) + x -= mSkin->getCloseImage()->getWidth(); + + g->drawImage(button, x, getPadding()); } drawChildren(graphics); @@ -286,6 +294,11 @@ bool Window::isResizable() const return mGrip; } +void Window::setStickyButton(bool flag) +{ + mStickyButton = flag; +} + void Window::setSticky(bool sticky) { mSticky = sticky; @@ -293,7 +306,12 @@ void Window::setSticky(bool sticky) void Window::setVisible(bool visible) { - gcn::Window::setVisible(isSticky() || visible); + setVisible(visible, false); +} + +void Window::setVisible(bool visible, bool forceSticky) +{ + gcn::Window::setVisible((!forceSticky && isSticky()) || visible); } void Window::scheduleDelete() @@ -326,6 +344,22 @@ void Window::mousePressed(gcn::MouseEvent &event) } } + // Handle sticky button + if (mStickyButton) + { + Image *button = mSkin->getStickyImage(mSticky); + int rx = getWidth() - button->getWidth() - getPadding(); + if (mCloseButton) + rx -= mSkin->getCloseImage()->getWidth(); + gcn::Rectangle stickyButtonRect(rx, getPadding(), + button->getWidth(), button->getHeight()); + + if (stickyButtonRect.isPointInRect(x, y)) + { + setSticky(!isSticky()); + } + } + // Handle window resizing mouseResize = getResizeHandles(event); } @@ -470,7 +504,12 @@ void Window::loadWindowState() setPosition((int) config.getValue(name + "WinX", mDefaultX), (int) config.getValue(name + "WinY", mDefaultY)); - setVisible((bool) config.getValue(name + "Visible", false)); + + if (mCloseButton) + setVisible((bool) config.getValue(name + "Visible", false)); + + if (mStickyButton) + setSticky((bool) config.getValue(name + "Sticky", isSticky())); if (skinName.compare(mSkin->getFilePath()) != 0) { @@ -507,7 +546,13 @@ void Window::saveWindowState() { config.setValue(mWindowName + "WinX", getX()); config.setValue(mWindowName + "WinY", getY()); - config.setValue(mWindowName + "Visible", isVisible()); + + if (mCloseButton) + config.setValue(mWindowName + "Visible", isVisible()); + + if (mStickyButton) + config.setValue(mWindowName + "Sticky", isSticky()); + config.setValue(mWindowName + "Skin", mSkin->getFilePath()); if (mGrip) |