/* 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() { visible = false; } 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; flush(); float height; if (core::game()) { if (!core::game()->ready()) height = 0.6f; else if (visible) height = 0.6f; else return; } else height = 1.0f; // console background rectangle gl::enable(GL_BLEND); gl::begin(gl::Quads); gl::color(1, 1, 1, .1); gl::vertex(-0.5f*video.ratio , 0.5, -1.0f); gl::vertex(0.5f*video.ratio ,0.5, -1.0f); gl::vertex(0.5f*video.ratio , 0.5-height, -1.0f); gl::vertex(-0.5f*video.ratio , 0.5-height, -1.0f); gl::end(); gl::disable(GL_BLEND); } void Console::flush() { char line[MAXCMDSIZE]; while(this->buffer.getline(line, MAXCMDSIZE-1)) { while (text.size() >= 32765 - MAXCMDSIZE) { size_t i = 0; while (i+1 < text.size() && text[i] != '\n') i++; text.erase(0, i+1); } text.append(line); text.append("\n"); std::cout << line << std::endl; } buffer.clear(); } void Console::toggle() { visible = !visible; } } // namespace client