From d82c8f449c604d0f957e3dd190f7beae3596e6f9 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 11 May 2008 10:53:20 +0000 Subject: brute force line wrapping --- src/client/chat.cc | 10 ++++++++-- src/client/console.cc | 31 ++++++++++++++++++++++++++----- src/client/view.cc | 36 ++++++++++++++++++++++-------------- 3 files changed, 56 insertions(+), 21 deletions(-) (limited to 'src/client') diff --git a/src/client/chat.cc b/src/client/chat.cc index fc0ce1b..4d2f759 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -8,6 +8,7 @@ #include "client/chat.h" #include "client/console.h" #include "client/keyboard.h" +#include "client/video.h" #include "render/render.h" namespace client { @@ -73,6 +74,11 @@ void draw() if (console::visible() || !visible()) return; + size_t width = (size_t) (video::width / CHARWIDTH) - 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"); @@ -80,12 +86,12 @@ void draw() draw_text(CHARWIDTH*4 , 4 + CHARHEIGHT * (MAXNOTIFYLINES+1), ":"); gl::color(1.0f, 1.0f, 1.0f, 1.0f); - draw_text(CHARWIDTH*6, 4 + CHARHEIGHT * (MAXNOTIFYLINES+1), (*history_pos)); + draw_text(CHARWIDTH*6, 4 + CHARHEIGHT * (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+6), 4 + CHARHEIGHT * (MAXNOTIFYLINES+1) , cursor); + draw_text(CHARWIDTH*(input_pos - draw_pos+6), 4 + CHARHEIGHT * (MAXNOTIFYLINES+1) , cursor); } } diff --git a/src/client/console.cc b/src/client/console.cc index 9e2a782..3331792 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -148,13 +148,15 @@ void draw() console_scroll = text.size(); gl::enable(GL_TEXTURE_2D); + 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); - + if (line[0] == '?') gl::color(0.7f,0.7f,0.7f, 1.0f); else if (line[0] == '*') @@ -164,21 +166,40 @@ void draw() else gl::color(1.0f,1.0f,1.0f, 1.0f); line.erase(0,2); + + std::deque lines; + + while (line.size() > width) { + lines.push_back(line.substr(0, width)); + line.erase(0, width); + } + if (line.size()) + lines.push_back(line); + - draw_text(CHARWIDTH, y, 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; } - y -= CHARHEIGHT; ++rit; } // 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)); + draw_text(CHARWIDTH, video::height*con_height - CHARHEIGHT - 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+1), video::height*con_height - CHARHEIGHT - 4 , cursor); + draw_text(CHARWIDTH*(input_pos-draw_pos+1), video::height*con_height - CHARHEIGHT - 4 , cursor); } } diff --git a/src/client/view.cc b/src/client/view.cc index 3524403..3576b90 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -155,39 +155,47 @@ 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, 4, stats); + draw_text(video::width-CHARWIDTH*12, video::height - CHARHEIGHT*10, stats); } - /* - // print the version number in the upper right corner - gl::color(0.0f, 1.0f, 0.0f, 1.0f); - std::string version("ver. "); - version.append(core::version()); - draw_text(video::width-(version.size()+1)*CHARWIDTH, 4, version); - */ - // draw notifications gl::color(1.0f, 1.0f, 1.0f, 1.0f); + size_t width = (size_t) (video::width / CHARWIDTH) -2; size_t n = console::notify_pos % MAXNOTIFYLINES; int h = 4 + CHARHEIGHT; for (size_t l = 0; l < MAXNOTIFYLINES; l++) { if (console::notify_text[n].size() > 2 && console::notify_time[n] + 4 > core::application()->time()) { - if (console::notify_text[n][0] == '?') + std::string line(console::notify_text[n]); + + if (line[0] == '?') gl::color(0.7f,0.7f,0.7f, 1.0f); - else if (console::notify_text[n][0] == '*') + else if (line[0] == '*') gl::color(1.0f,1.0f,0.0f, 1.0f); - else if (console::notify_text[n][0] == '!') + 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); - draw_text(CHARWIDTH, h, console::notify_text[n].substr(2)); - h += CHARHEIGHT; + line.erase(0,2); + + std::deque lines; + + while (line.size() > width) { + draw_text(CHARWIDTH, h, line.substr(0, width)); + line.erase(0, width); + h += CHARHEIGHT; + } + if (line.size()) { + draw_text(CHARWIDTH, h, line); + h += CHARHEIGHT; + } } 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() << " "; -- cgit v1.2.3