/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "chat.h"
#include <algorithm>
#include <cctype>
#include <sstream>
#include "config.h"
#include "debug.h"
#include "util/strfnd.h"
#include "util/string.h"
#include "util/numeric.h"
ChatBuffer::ChatBuffer(u32 scrollback):
m_scrollback(scrollback)
{
if (m_scrollback == 0)
m_scrollback = 1;
m_empty_formatted_line.first = true;
// Curses mode cannot access g_settings here
if(g_settings != NULL)
{
m_cache_clickable_chat_weblinks = g_settings->getBool("clickable_chat_weblinks");
if(m_cache_clickable_chat_weblinks)
{
std::string hexcode = g_settings->get("chat_weblink_color");
u32 colorval = strtol(hexcode.c_str(), NULL, 16);
u32 redval,greenval,blueval;
blueval = colorval % 256;
colorval /= 256;
greenval = colorval % 256;
colorval /= 256;
redval = colorval % 256;
// discard alpha, if included
m_cache_chat_weblink_color = irr::video::SColor(255,redval,greenval,blueval);
}
}
}
void ChatBuffer::addLine(const std::wstring &name, const std::wstring &text)
{
ChatLine line(name, text);
m_unformatted.push_back(line);
if (m_rows > 0) {
// m_formatted is valid and must be kept valid
bool scrolled_at_bottom = (m_scroll == getBottomScrollPos());
u32 num_added = formatChatLine(line, m_cols, m_formatted);
if (scrolled_at_bottom)
m_scroll += num_added;
}
// Limit number of lines by m_scrollback
if (m_unformatted.size() > m_scrollback) {
deleteOldest(m_unformatted.size() - m_scrollback);
}
}
|