From 15ca94f41b77cdf439774fe1e6502979be9d3f8e Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 6 Feb 2008 00:56:15 +0000 Subject: console scroll --- src/client/console.cc | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/client/console.cc') diff --git a/src/client/console.cc b/src/client/console.cc index 42ef78a..83d69de 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -50,6 +50,9 @@ std::deque text; // console visibility bool console_visible; +size_t console_scroll = 0; +size_t input_pos = 0; + //--- engine functions -------------------------------------------- extern "C" void func_con_toggle(std::stringstream &args) @@ -108,23 +111,29 @@ void draw() gl::end(); // draw the console text + if (console_scroll > text.size()) + console_scroll = text.size(); + gl::enable(GL_TEXTURE_2D); std::deque::reverse_iterator rit = text.rbegin(); - float y = video::height*con_height-2*CHARHEIGHT-8; + float bottom = video::height*con_height-2*CHARHEIGHT-8; + float y = bottom+console_scroll*CHARHEIGHT; while (y > 0 && rit < text.rend()) { - std::string line(*rit); + if (y <= bottom) { + std::string line(*rit); - if (line[0] == '?') - gl::color(0.7f,0.7f,0.7f, 1.0f); - else if (line[0] == '*') - gl::color(1.0f,1.0f,0.0f, 1.0f); - else if (line[0] == '!') - gl::color(1.0f,0.0f,0.0f, 1.0f); - else - gl::color(1.0f,1.0f,1.0f, 1.0f); - line.erase(0,2); - - draw_text(CHARWIDTH, y, line); + if (line[0] == '?') + gl::color(0.7f,0.7f,0.7f, 1.0f); + else if (line[0] == '*') + gl::color(1.0f,1.0f,0.0f, 1.0f); + else if (line[0] == '!') + gl::color(1.0f,0.0f,0.0f, 1.0f); + else + gl::color(1.0f,1.0f,1.0f, 1.0f); + line.erase(0,2); + + draw_text(CHARWIDTH, y, line); + } y -= CHARHEIGHT; ++rit; } @@ -159,6 +168,9 @@ void toggle() { console_visible = !console_visible; setkeyboardmode(console_visible); + console_scroll = 0; + input.clear(); + input_pos = 0; } void keypressed(const SDL_keysym &keysym) @@ -175,6 +187,14 @@ void keypressed(const SDL_keysym &keysym) input.erase(input.size()-1, 1); } break; + case SDLK_PAGEUP: + console_scroll +=5; + if (console_scroll > text.size()) console_scroll = text.size(); + break; + case SDLK_PAGEDOWN: + if (console_scroll > 5) console_scroll -=5; + else console_scroll = 0; + break; default: break; } -- cgit v1.2.3