From 42a095de15649f0f00ef6c681268d6623205900c Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 28 Mar 2009 10:35:49 -0600 Subject: Add a sticky button to the Window class The Minimap window uses this so you can froce it to always be open. The Minimap toggle button can be used to show or hide it temporarily, as warping will reset it's visibility based on the sticky state and weather the 'new' map has a minimap. --- src/gui/window.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) (limited to 'src/gui/window.cpp') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index a916ba38..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), @@ -135,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); @@ -283,6 +294,11 @@ bool Window::isResizable() const return mGrip; } +void Window::setStickyButton(bool flag) +{ + mStickyButton = flag; +} + void Window::setSticky(bool sticky) { mSticky = sticky; @@ -290,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() @@ -323,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); } @@ -467,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) { @@ -504,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) -- cgit v1.2.3-70-g09d2