diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-02-07 18:03:09 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-02-07 18:03:09 +0200 |
commit | b2ce88bae2b95adb612456d9659669d6b686de7b (patch) | |
tree | b165a1f2a98c4c99ce1c0a142a53e71f3d0b3b00 /src/gui/windowmenu.cpp | |
parent | 2c765dc21314b1b32f7a75686571127f8af38bf9 (diff) | |
download | mv-b2ce88bae2b95adb612456d9659669d6b686de7b.tar.gz mv-b2ce88bae2b95adb612456d9659669d6b686de7b.tar.bz2 mv-b2ce88bae2b95adb612456d9659669d6b686de7b.tar.xz mv-b2ce88bae2b95adb612456d9659669d6b686de7b.zip |
Add ability to show/hide buttons in top right window corner.
Diffstat (limited to 'src/gui/windowmenu.cpp')
-rw-r--r-- | src/gui/windowmenu.cpp | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index eb146f700..2a3ef51fa 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -91,9 +91,8 @@ WindowMenu::WindowMenu(): addButton(N_("DR"), _("Drop"), x, h, KeyboardConfig::KEY_WINDOW_DROP); addButton(N_("SET"), _("Setup"), x, h, KeyboardConfig::KEY_WINDOW_SETUP); + loadButtons(); mTextPopup = new TextPopup; - setDimension(gcn::Rectangle(graphics->getWidth() - x - 3, 3, - x - 3, h)); addMouseListener(this); setVisible(true); @@ -239,7 +238,10 @@ void WindowMenu::mousePressed(gcn::MouseEvent &event) if (!btn) return; if (viewport) - viewport->showPopup(event.getX(), event.getY(), btn); + { + viewport->showPopup(getX() + event.getX(), + getY() + event.getY(), btn); + } } } @@ -282,4 +284,76 @@ void WindowMenu::mouseExited(gcn::MouseEvent& mouseEvent _UNUSED_) return; mTextPopup->hide(); -}
\ No newline at end of file +} + +void WindowMenu::showButton(std::string name, bool isVisible) +{ + Button *btn = dynamic_cast<Button*>(mButtonNames[name]); + if (!btn) + return; + + btn->setVisible(isVisible); + updateButtons(); + saveButtons(); +} + +void WindowMenu::updateButtons() +{ + int x = 0, h = 0; + std::list <gcn::Button*>::iterator it, it_end; + for (it = mButtons.begin(), it_end = mButtons.end(); it != it_end; ++it) + safeRemove(*it); + for (it = mButtons.begin(), it_end = mButtons.end(); it != it_end; ++it) + { + Button *btn = dynamic_cast<Button*>(*it); + if (!btn) + continue; + if (btn->isVisible()) + { + btn->setPosition(x, 0); + add(btn); + x += btn->getWidth() + 3; + h = btn->getHeight(); + } + } + if (graphics) + { + setDimension(gcn::Rectangle(graphics->getWidth() - x - 3, + 3, x - 3, h)); + } +} + +void WindowMenu::loadButtons() +{ + if (config.getValue("windowmenu0", "") == "") + return; + + for (int f = 0; f < 15; f ++) + { + std::string str = config.getValue("windowmenu" + toString(f), ""); + if (str == "" || str == "SET") + continue; + Button *btn = dynamic_cast<Button*>(mButtonNames[str]); + if (!btn) + continue; + btn->setVisible(false); + } + updateButtons(); +} + +void WindowMenu::saveButtons() +{ + std::list <gcn::Button*>::iterator it, it_end; + int i = 0; + for (it = mButtons.begin(), it_end = mButtons.end(); + it != it_end; ++it) + { + Button *btn = dynamic_cast<Button*>(*it); + if (!btn->isVisible()) + { + config.setValue("windowmenu" + toString(i), + btn->getActionEventId()); + i ++; + } + } +} |