From d2e93235b9ccd37bf8c8fb7c4376ab1911c83639 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 11 May 2008 15:16:25 +0000 Subject: console font --- src/client/console.cc | 53 +++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'src/client/console.cc') diff --git a/src/client/console.cc b/src/client/console.cc index 3331792..fae402c 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -7,6 +7,7 @@ #include "filesystem/filesystem.h" #include "core/core.h" #include "render/render.h" +#include "render/textures.h" #include "client/console.h" #include "client/video.h" #include "client/keyboard.h" @@ -124,13 +125,13 @@ void draw() return; float con_height = 0.70f; - + // draw version below the bottom of the console gl::color(0.0f, 1.0f, 0.0f, 0.5f); std::string version(core::name()); version += ' '; version.append(core::version()); - draw_text(video::width-CHARWIDTH*(version.size()+1), video::height*con_height-CHARHEIGHT-4, version); + Text::draw(video::width-Text::fontwidth()*(version.size()+1), video::height*con_height-Text::fontheight()-4, version); gl::disable(GL_TEXTURE_2D); // draw the transparent console background @@ -148,15 +149,15 @@ void draw() console_scroll = text.size(); gl::enable(GL_TEXTURE_2D); + + //gl::color(0.7f,0.7f,0.7f, 1.0f); + gl::color(1.0f,1.0f,1.0f, 1.0f); - 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); - + size_t height = (size_t) (video::height * con_height / Text::fontheight()) -1; + size_t width = (size_t) (video::width / Text::fontwidth()) -2; + size_t bottom = text.size() - console_scroll; + size_t current_line = 0; +/* if (line[0] == '?') gl::color(0.7f,0.7f,0.7f, 1.0f); else if (line[0] == '*') @@ -165,41 +166,43 @@ void draw() 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); - - std::deque lines; +*/ + std::deque lines; + for (std::deque::iterator it = text.begin(); it != text.end() && current_line < bottom; it++) { + if (current_line >= bottom - height) { + std::string line(*it); + line.erase(0,2); + while (line.size() > width) { lines.push_back(line.substr(0, width)); line.erase(0, width); } if (line.size()) lines.push_back(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; } - ++rit; + current_line++; } + float y = video::height*con_height-2*Text::fontheight()-4; + for (std::deque::reverse_iterator rit = lines.rbegin(); (y >= 4) && (rit != lines.rend()); ++rit) { + Text::draw(4, y, (*rit)); + y -= Text::fontheight(); + } + + // 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).substr(draw_pos, width)); + Text::draw(Text::fontwidth(), video::height*con_height - Text::fontheight() - 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-draw_pos+1), video::height*con_height - CHARHEIGHT - 4 , cursor); + Text::draw(Text::fontwidth()*(input_pos-draw_pos+1), video::height*con_height - Text::fontheight() - 4 , cursor); } } -- cgit v1.2.3