From 34f943198afd1f7f342d63bd70d30cdeacd3dbad Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 15 Jan 2014 21:54:48 +0300 Subject: fix rainbow chat colors for different utf8 chars and smiles. --- src/gui/windows/chatwindow.cpp | 59 +++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'src/gui') diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index c434bea2f..e1afb6e5b 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -1240,6 +1240,39 @@ WhisperTab *ChatWindow::getWhisperTab(const std::string &nick) const return ret; } + +#define changeColor(fun) \ + { \ + msg = removeColors(msg); \ + int skip = 0; \ + const size_t sz = msg.length(); \ + for (size_t f = 0; f < sz; f ++) \ + { \ + if (skip > 0) \ + { \ + newMsg += msg.at(f); \ + skip --; \ + continue; \ + } \ + const unsigned char ch = static_cast(msg.at(f)); \ + if (f + 2 < sz && msg.substr(f, 2) == "%%") \ + { \ + newMsg += msg.at(f); \ + skip = 2; \ + } \ + else if (ch > 0xc0 || ch < 0x80) \ + { \ + newMsg += "##" + toString(fun) + msg.at(f); \ + if (mRainbowColor > 9) \ + mRainbowColor = 0; \ + } \ + else \ + { \ + newMsg += msg.at(f); \ + } \ + } \ + } + std::string ChatWindow::addColors(std::string &msg) { // default color or chat command @@ -1256,31 +1289,13 @@ std::string ChatWindow::addColors(std::string &msg) switch (mChatColor) { case 11: - msg = removeColors(msg); - for (unsigned int f = 0; f < msg.length(); f ++) - { - newMsg += "##" + toString(mRainbowColor++) + msg.at(f); - if (mRainbowColor > 9) - mRainbowColor = 0; - } + changeColor(mRainbowColor++) return newMsg; case 12: - msg = removeColors(msg); - for (unsigned int f = 0; f < msg.length(); f ++) - { - newMsg += "##" + toString(cMap[mRainbowColor++]) + msg.at(f); - if (mRainbowColor > 9) - mRainbowColor = 0; - } + changeColor(cMap[mRainbowColor++]) return newMsg; case 13: - msg = removeColors(msg); - for (unsigned int f = 0; f < msg.length(); f ++) - { - newMsg += "##" + toString(cMap[9-mRainbowColor++]) + msg.at(f); - if (mRainbowColor > 9) - mRainbowColor = 0; - } + changeColor(cMap[9-mRainbowColor++]) return newMsg; default: break; @@ -1290,6 +1305,8 @@ std::string ChatWindow::addColors(std::string &msg) return std::string("##").append(toString(mChatColor - 1)).append(msg); } +#undef changeColor + void ChatWindow::autoComplete() { const int caretPos = mChatInput->getCaretPosition(); -- cgit v1.2.3-60-g2f50