/* client/console.cc This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #include "client/client.h" #include "client/console.h" #include "core/core.h" #include "render/render.h" #include namespace client { Console::Console() { console_visible = true; } std::ostream & Console::messagestream() { return (buffer << ". "); } std::ostream & Console::warningstream() { return (buffer << "* "); } std::ostream & Console::errorstream() { return (buffer << "! "); } std::ostream & Console::debugstream() { return (buffer << "? "); } void Console::draw() { using namespace render; console.flush(); if(!console_visible) return; float con_height = 0.70f; glBindTexture(GL_TEXTURE_2D, render::textures[1]); // bitmaps/conchars.tga // draw version below the bottom of the console gl::enable(GL_TEXTURE_2D); gl::color(0.0f, 1.0f, 0.0f, 0.5f); std:: string version = std::string("The Osirion Project "); version.append(VERSION); draw_text(video.width-CHARWIDTH*(version.size()+1), video.height*con_height-CHARHEIGHT-4, version); gl::disable(GL_TEXTURE_2D); // draw the transparent console background gl::color(1.0f, 1.0f, 1.0f, 0.01f); gl::begin(gl::Quads); gl::vertex(0.0f, 0.0f, 0.0f); gl::vertex(video.width, 0.0f,0.0f); gl::vertex(video.width,video.height*con_height,0.0f); gl::vertex(0,video.height*con_height,0.0f); gl::end(); // draw the console text gl::enable(GL_TEXTURE_2D); std::deque::reverse_iterator rit = console.text.rbegin(); float y = video.height*con_height-2*CHARHEIGHT-8; while (y > 0 && rit < console.text.rend()) { 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); y -= CHARHEIGHT; ++rit; } // draw the console input gl::color(0.0f, 1.0f, 0.0f, 1.0f); draw_text(CHARWIDTH, video.height*con_height - CHARHEIGHT - 4, input); // draw cursor if ((core::time() - floorf(core::time())) < 0.5f) { std::string cursor("_"); draw_text(CHARWIDTH*(input.size()+1), video.height*con_height - CHARHEIGHT - 4 , cursor); } gl::disable(GL_TEXTURE_2D); } void Console::flush() { char line[MAXCMDSIZE]; while(this->buffer.getline(line, MAXCMDSIZE-1)) { while (text.size() >= MAXCONLINES) { text.pop_front(); } text.push_back(std::string(line)); std::cout << line << std::endl; } buffer.clear(); } void Console::toggle() { console_visible = !console_visible; } void Console::handle_keyreleased(SDL_keysym* keysym) { switch( keysym->sym ) { case SDLK_RETURN: if (input.size()) { core::cmd << input << std::endl; input.clear(); } break; case SDLK_BACKSPACE: if (input.size()) { input.erase(input.size()-1, 1); } break; default: break; } if (keysym->sym >= 32 && keysym->sym <= 175) { input += (char) keysym->sym; } } } // namespace client