diff options
author | Stijn Buys <ingar@osirion.org> | 2008-05-11 15:16:25 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-05-11 15:16:25 +0000 |
commit | d2e93235b9ccd37bf8c8fb7c4376ab1911c83639 (patch) | |
tree | 61bfbf023228ba10abe488d8c8bd27359171c9f7 /src/client | |
parent | d82c8f449c604d0f957e3dd190f7beae3596e6f9 (diff) |
console font
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/chat.cc | 10 | ||||
-rw-r--r-- | src/client/console.cc | 53 | ||||
-rw-r--r-- | src/client/view.cc | 60 |
3 files changed, 69 insertions, 54 deletions
diff --git a/src/client/chat.cc b/src/client/chat.cc index 4d2f759..0d1def6 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -74,24 +74,24 @@ void draw() if (console::visible() || !visible()) return; - size_t width = (size_t) (video::width / CHARWIDTH) - 7; + size_t width = (size_t) (video::width / Text::fontwidth()) - 7; size_t draw_pos = 0; while (input_pos - draw_pos > width) draw_pos += 2; // draw the console input gl::color(1.0f, 1.0f, 1.0f, 1.0f); - draw_text(CHARWIDTH , 4 + CHARHEIGHT * (MAXNOTIFYLINES+1), "say"); + Text::draw(4 , 5 + Text::fontheight() * (MAXNOTIFYLINES+1), "say"); gl::color(0.0f, 1.0f, .0f, 1.0f); - draw_text(CHARWIDTH*4 , 4 + CHARHEIGHT * (MAXNOTIFYLINES+1), ":"); + Text::draw(4+Text::fontwidth()*3 , 5 + Text::fontheight() * (MAXNOTIFYLINES+1), ":"); gl::color(1.0f, 1.0f, 1.0f, 1.0f); - draw_text(CHARWIDTH*6, 4 + CHARHEIGHT * (MAXNOTIFYLINES+1), (*history_pos).substr(draw_pos, width)); + Text::draw(4+Text::fontwidth()*5, 5 + Text::fontheight() * (MAXNOTIFYLINES+1), (*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+6), 4 + CHARHEIGHT * (MAXNOTIFYLINES+1) , cursor); + Text::draw(4+Text::fontwidth()*(input_pos - draw_pos+5), 5 + Text::fontheight() * (MAXNOTIFYLINES+1) , cursor); } } 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<std::string>::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<std::string> lines; +*/ + std::deque<std::string> lines; + for (std::deque<std::string>::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<std::string>::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<std::string>::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); } } diff --git a/src/client/view.cc b/src/client/view.cc index 3576b90..7d11df3 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -142,7 +142,7 @@ void draw_status() int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f); status << "time " << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; - draw_text(CHARWIDTH, 4, status); + Text::draw(4, 4, status); } // print stats if desired @@ -155,14 +155,37 @@ void draw_status() } stats << "tx "<< std::setw(5) << (core::Stats::network_bytes_sent >> 10) << "\n"; stats << "rx "<< std::setw(5) << (core::Stats::network_bytes_received >> 10) << "\n"; - draw_text(video::width-CHARWIDTH*12, video::height - CHARHEIGHT*10, stats); + Text::draw(video::width-Text::fontwidth()*12, video::height - Text::fontheight()*8, stats); } + // draw a basic HUD + if (core::localcontrol()) { + gl::color(1.0f,1.0f,1.0f, 1.0f); + + status.str(""); + status << "thrust " << std::setfill(' ') << std::setw(5) << std::fixed + << std::setprecision(2) << core::localcontrol()->thrust() << " "; + + status << "speed " << std::setfill(' ') << std::setw(5) << std::fixed + << std::setprecision(2) << core::localcontrol()->speed(); + + Text::draw(4, video::height - Text::fontheight() -4, status); + } + +} + +void draw_notify() +{ + using namespace render; + + if (console::visible()) + return; + // draw notifications gl::color(1.0f, 1.0f, 1.0f, 1.0f); - size_t width = (size_t) (video::width / CHARWIDTH) -2; + size_t width = (size_t) ((video::width - 8) / Text::fontwidth()); size_t n = console::notify_pos % MAXNOTIFYLINES; - int h = 4 + CHARHEIGHT; + float h = 4 + 2*Text::fontheight(); for (size_t l = 0; l < MAXNOTIFYLINES; l++) { if (console::notify_text[n].size() > 2 && console::notify_time[n] + 4 > core::application()->time()) { std::string line(console::notify_text[n]); @@ -180,32 +203,17 @@ void draw_status() std::deque<std::string> lines; while (line.size() > width) { - draw_text(CHARWIDTH, h, line.substr(0, width)); + Text::draw(4, h, line.substr(0, width)); line.erase(0, width); - h += CHARHEIGHT; + h += Text::fontheight(); } if (line.size()) { - draw_text(CHARWIDTH, h, line); - h += CHARHEIGHT; + Text::draw(4, h, line); + h += Text::fontheight(); } } n = (n+1) % MAXNOTIFYLINES; } - - // draw a basic HUD - if (core::localcontrol()) { - gl::color(1.0f,1.0f,1.0f, 1.0f); - - status.str(""); - status << "thrust " << std::setfill(' ') << std::setw(5) << std::fixed - << std::setprecision(2) << core::localcontrol()->thrust() << " "; - - status << "speed " << std::setfill(' ') << std::setw(5) << std::fixed - << std::setprecision(2) << core::localcontrol()->speed(); - - draw_text(CHARWIDTH, video::height - CHARHEIGHT -4, status); - } - } void draw_cursor() @@ -301,10 +309,14 @@ void frame(float seconds) } // draw text elements - render::Textures::bind("bitmaps/conchars"); + // FIXME width and height should be derived from texture size + Text::setfont("bitmaps/fonts/console", 12, 18); console::draw(); + draw_notify(); chat::draw(); + + Text::setfont("bitmaps/fonts/gui", 16, 24); draw_status(); // draw the mouse cursor |