diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-03-28 10:35:49 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-03-28 10:35:49 -0600 |
commit | 42a095de15649f0f00ef6c681268d6623205900c (patch) | |
tree | 1f7d509f088208fd5349e9a77d208637354636f3 /src/gui/window.cpp | |
parent | ef2e1bafa7c5f19b0353e0bf01a7ad9d7f8cddf5 (diff) | |
download | mana-42a095de15649f0f00ef6c681268d6623205900c.tar.gz mana-42a095de15649f0f00ef6c681268d6623205900c.tar.bz2 mana-42a095de15649f0f00ef6c681268d6623205900c.tar.xz mana-42a095de15649f0f00ef6c681268d6623205900c.zip |
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.
Diffstat (limited to 'src/gui/window.cpp')
-rw-r--r-- | src/gui/window.cpp | 58 |
1 files changed, 53 insertions, 5 deletions
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) |