From f474ad785704a904fd2b95d56fa67cccf69c876f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 28 Mar 2012 22:42:38 +0300 Subject: Add option to autohide buttons on top right corner. By default buttons hidden. --- src/defaults.cpp | 1 + src/gui/setup_other.cpp | 5 +++++ src/gui/windowmenu.cpp | 24 +++++++++++++++++++++++- src/gui/windowmenu.h | 10 ++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/defaults.cpp b/src/defaults.cpp index 1ca64d4e6..8b62f6d02 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -239,6 +239,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "soundinfo", "notify"); AddDEF(configData, "soundrequest", "attention"); AddDEF(configData, "soundguild", "newmessage"); + AddDEF(configData, "autohideButtons", true); return configData; } diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 148037732..02ad9ae5e 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -162,6 +162,11 @@ Setup_Other::Setup_Other() "guild support"), "", "enableGuildBot", this, "enableGuildBotEvent", false); + new SetupItemLabel(_("Windows"), "", this); + + new SetupItemCheckBox(_("Auto hide shortcuts buttons."), "", + "autohideButtons", this, "autohideButtonsEvent"); + new SetupItemLabel(_("Other"), "", this); new SetupItemCheckBox(_("Enable server side attack"), "", diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 138090075..c57cd8974 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -58,7 +58,9 @@ extern Window *botCheckerWindow; extern Window *socialWindow; WindowMenu::WindowMenu(): - mEmotePopup(nullptr) + mEmotePopup(nullptr), + mHaveMouse(false), + mAutoHide(true) { int x = 0, h = 0; @@ -110,10 +112,15 @@ WindowMenu::WindowMenu(): addMouseListener(this); setVisible(true); + + config.addListener("autohideButtons", this); + mAutoHide = config.getBoolValue("autohideButtons"); } WindowMenu::~WindowMenu() { + config.removeListener("autohideButtons", this); + delete mTextPopup; mTextPopup = nullptr; mButtonNames.clear(); @@ -276,6 +283,8 @@ void WindowMenu::mousePressed(gcn::MouseEvent &event) void WindowMenu::mouseMoved(gcn::MouseEvent &event) { + mHaveMouse = true; + if (!mTextPopup) return; @@ -309,6 +318,7 @@ void WindowMenu::mouseMoved(gcn::MouseEvent &event) void WindowMenu::mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED) { + mHaveMouse = false; if (!mTextPopup) return; @@ -388,3 +398,15 @@ void WindowMenu::saveButtons() for (int f = i; f < 15; f ++) config.deleteKey("windowmenu" + toString(f)); } + +void WindowMenu::drawChildren(gcn::Graphics* graphics) +{ + if (!mAutoHide || mHaveMouse) + Container::drawChildren(graphics); +} + +void WindowMenu::optionChanged(const std::string &name) +{ + if (name == "autohideButtons") + mAutoHide = config.getBoolValue("autohideButtons"); +} diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h index 8abc5e87a..7bb9aa549 100644 --- a/src/gui/windowmenu.h +++ b/src/gui/windowmenu.h @@ -23,6 +23,8 @@ #ifndef WINDOWMENU_H #define WINDOWMENU_H +#include "configlistener.h" + #include "gui/widgets/container.h" #include "gui/widgets/button.h" @@ -44,12 +46,14 @@ class TextPopup; * \ingroup Interface */ class WindowMenu : public Container, + public ConfigListener, public gcn::ActionListener, public gcn::SelectionListener, public gcn::MouseListener { public: WindowMenu(); + ~WindowMenu(); void action(const gcn::ActionEvent &event); @@ -74,6 +78,10 @@ class WindowMenu : public Container, void saveButtons(); + void drawChildren(gcn::Graphics* graphics); + + void optionChanged(const std::string &name); + private: inline void addButton(const char* text, std::string description, int &x, int &h, int key); @@ -84,6 +92,8 @@ class WindowMenu : public Container, TextPopup *mTextPopup; std::vector mButtons; std::map mButtonNames; + bool mHaveMouse; + bool mAutoHide; }; extern WindowMenu *windowMenu; -- cgit v1.2.3-70-g09d2