From b0ce837b66ddc34a9b2a9346291b252f748c577f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 29 Mar 2012 01:18:21 +0300 Subject: Add option to auto hide chat window (chat window visible by default) Option in chat \ Auto hide chat window. --- src/gui/chatwindow.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'src/gui/chatwindow.cpp') 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; +} -- cgit v1.2.3-60-g2f50