From a185c11f2397c0296a4b62cc266b4fa00a63c1e2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 14 May 2008 21:07:10 +0000 Subject: console, camera & interpolation --- src/client/chat.cc | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'src/client/chat.cc') diff --git a/src/client/chat.cc b/src/client/chat.cc index 1953390..9171387 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -4,6 +4,7 @@ the terms and conditions of the GNU General Public License version 2 */ +#include "auxiliary/functions.h" #include "core/core.h" #include "client/chat.h" #include "client/console.h" @@ -71,24 +72,54 @@ void draw() { using namespace render; - if (console::visible() || !visible()) + if (console()->visible() || !visible()) return; - size_t width = (size_t) (video::width / Text::fontwidth()) - 7; - size_t draw_pos = 0; - while (input_pos - draw_pos > width) - draw_pos += 2; + size_t width = (size_t) (video::width / Text::fontwidth()) - 8; + float y = video::height*8/10; + Text::draw(4, y, "^BSay^F:^B "); - // draw the chat input - float y = video::height * 8.0 / 10.0; + std::string firstpart((*history_pos).substr(0, input_pos)); + size_t draw_width = 0; + const char *c = firstpart.c_str(); - Text::draw(4 , y, "^Bsay^F:^B"); - Text::draw(4+Text::fontwidth()*5 , y, (*history_pos).substr(draw_pos, width)); + while (*c) { + if (aux::is_color_code(c)) { + c++; + } else { + draw_width++; + } + c++; + } + + c = firstpart.c_str(); + while (*c && draw_width > width - 2) { + if (aux::is_color_code(c)) { + c++; + Text::setcolor(*c); + } else { + draw_width--; + } + c++; + } + + if (*c) { + Text::draw(4+5*Text::fontwidth(), y, c); + } + + if (input_pos < (*history_pos).size()) { + // FIXME limit to width + if (input_pos > 1 && aux::is_color_code((*history_pos).c_str() + input_pos -1)) { + Text::setcolor((*history_pos)[input_pos]); + } + c = (*history_pos).c_str() + input_pos; + Text::draw(4+Text::fontwidth()*(draw_width+5), y, c); + } // draw cursor if ((core::application()->time() - ::floorf(core::application()->time())) < 0.5f) { std::string cursor("^B_"); - Text::draw(4+Text::fontwidth()*(input_pos - draw_pos+5), y, cursor); + Text::draw(4+Text::fontwidth()*(draw_width+5), y , cursor); } } -- cgit v1.2.3