From d82c8f449c604d0f957e3dd190f7beae3596e6f9 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 11 May 2008 10:53:20 +0000 Subject: brute force line wrapping --- src/client/console.cc | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/client/console.cc') diff --git a/src/client/console.cc b/src/client/console.cc index 9e2a782..3331792 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -148,13 +148,15 @@ void draw() console_scroll = text.size(); gl::enable(GL_TEXTURE_2D); + std::deque::reverse_iterator rit = text.rbegin(); + size_t width = (size_t) (video::width / CHARWIDTH) -2; float bottom = video::height*con_height-2*CHARHEIGHT-8; float y = bottom+console_scroll*CHARHEIGHT; while (y > 0 && rit < text.rend()) { if (y <= bottom) { std::string line(*rit); - + if (line[0] == '?') gl::color(0.7f,0.7f,0.7f, 1.0f); else if (line[0] == '*') @@ -164,21 +166,40 @@ void draw() else gl::color(1.0f,1.0f,1.0f, 1.0f); line.erase(0,2); + + std::deque lines; + + while (line.size() > width) { + lines.push_back(line.substr(0, width)); + line.erase(0, width); + } + if (line.size()) + lines.push_back(line); + - draw_text(CHARWIDTH, y, line); + std::deque::reverse_iterator lrit; + for (lrit = lines.rbegin(); (lrit != lines.rend()) && (y > 0); ++lrit) { + draw_text(CHARWIDTH, y, (*lrit)); + y -= CHARHEIGHT; + } + } else { + y -= CHARHEIGHT; } - y -= CHARHEIGHT; ++rit; } // draw the console input + size_t draw_pos = 0; + while (input_pos - draw_pos > width) + draw_pos += 2; + gl::color(0.0f, 1.0f, 0.0f, 1.0f); - draw_text(CHARWIDTH, video::height*con_height - CHARHEIGHT - 4, (*history_pos)); + draw_text(CHARWIDTH, video::height*con_height - CHARHEIGHT - 4, (*history_pos).substr(draw_pos, width)); // draw cursor if ((core::application()->time() - ::floorf(core::application()->time())) < 0.5f) { std::string cursor("_"); - draw_text(CHARWIDTH*(input_pos+1), video::height*con_height - CHARHEIGHT - 4 , cursor); + draw_text(CHARWIDTH*(input_pos-draw_pos+1), video::height*con_height - CHARHEIGHT - 4 , cursor); } } -- cgit v1.2.3