diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-03-29 01:18:21 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-03-29 01:18:21 +0300 |
commit | b0ce837b66ddc34a9b2a9346291b252f748c577f (patch) | |
tree | 6bcd1c475d48e2cb12972556a1f62eaf9c392048 /src/gui/chatwindow.cpp | |
parent | f474ad785704a904fd2b95d56fa67cccf69c876f (diff) | |
download | plus-b0ce837b66ddc34a9b2a9346291b252f748c577f.tar.gz plus-b0ce837b66ddc34a9b2a9346291b252f748c577f.tar.bz2 plus-b0ce837b66ddc34a9b2a9346291b252f748c577f.tar.xz plus-b0ce837b66ddc34a9b2a9346291b252f748c577f.zip |
Add option to auto hide chat window (chat window visible by default)
Option in chat \ Auto hide chat window.
Diffstat (limited to 'src/gui/chatwindow.cpp')
-rw-r--r-- | src/gui/chatwindow.cpp | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 674c34039..528c1e39e 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -94,6 +94,8 @@ class ChatInput : public TextField, public gcn::FocusListener void focusLost(const gcn::Event &event A_UNUSED) { processVisible(false); + if (chatWindow) + chatWindow->updateVisibility(); } void processVisible(bool n) @@ -157,7 +159,9 @@ ChatWindow::ChatWindow(): Window(_("Chat"), false, nullptr, "chat.xml"), mTmpVisible(false), mChatHistoryIndex(0), - mGMLoaded(false) + mGMLoaded(false), + mHaveMouse(false), + mAutoHide(false) { listen(CHANNEL_NOTICES); listen(CHANNEL_ATTRIBUTES); @@ -222,10 +226,14 @@ ChatWindow::ChatWindow(): initTradeFilter(); loadCustomList(); parseHighlights(); + + config.addListener("autohideChat", this); + mAutoHide = config.getBoolValue("autohideChat"); } ChatWindow::~ChatWindow() { + config.removeListener("autohideChat", this); saveState(); config.setValue("ReturnToggles", mReturnToggles); removeAllWhispers(); @@ -535,6 +543,7 @@ bool ChatWindow::requestChatFocus() // Give focus to the chat input mChatInput->processVisible(true); + unHideWindow(); mChatInput->requestFocus(); return true; } @@ -1607,3 +1616,57 @@ void ChatWindow::copyToClipboard(int x, int y) std::string str = text->getTextAtPos(x, y); sendBuffer(str); } + +void ChatWindow::optionChanged(const std::string &name) +{ + if (name == "autohideChat") + mAutoHide = config.getBoolValue("autohideChat"); +} + +void ChatWindow::mouseMoved(gcn::MouseEvent &event) +{ + mHaveMouse = true; + gcn::Window::mouseMoved(event); +} + +void ChatWindow::mouseEntered(gcn::MouseEvent& mouseEvent) +{ + mHaveMouse = true; + gcn::Window::mouseEntered(mouseEvent); +} + +void ChatWindow::mouseExited(gcn::MouseEvent& mouseEvent) +{ + updateVisibility(); + gcn::Window::mouseExited(mouseEvent); +} + +void ChatWindow::draw(gcn::Graphics* graphics) +{ + if (!mAutoHide || mHaveMouse) + Window::draw(graphics); +} + +void ChatWindow::updateVisibility() +{ + int mouseX = 0; + int mouseY = 0; + int x = 0; + int y = 0; + SDL_GetMouseState(&mouseX, &mouseY); + getAbsolutePosition(x, y); + if (mChatInput->isVisible()) + { + mHaveMouse = true; + } + else + { + mHaveMouse = mouseX >= x && mouseX <= x + getWidth() + && mouseY >= y && mouseY <= y + getHeight(); + } +} + +void ChatWindow::unHideWindow() +{ + mHaveMouse = true; +} |