Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-05-12 18:32:15 +0000
committerStijn Buys <ingar@osirion.org>2008-05-12 18:32:15 +0000
commit5ceb4694a05ec68b5cfba18b0f25ba804be88a80 (patch)
treed1baddc086de4bb4fa04cf59d11516f4ecc89bf3 /src/client/console.cc
parente4f2faa8d5895ba30207c09c7886afb21a697d5f (diff)
console colors
Diffstat (limited to 'src/client/console.cc')
-rw-r--r--src/client/console.cc223
1 files changed, 178 insertions, 45 deletions
diff --git a/src/client/console.cc b/src/client/console.cc
index 914d32f..b60e179 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -4,8 +4,9 @@
the terms and conditions of the GNU General Public License version 2
*/
-#include "filesystem/filesystem.h"
+#include "auxiliary/functions.h"
#include "core/core.h"
+#include "filesystem/filesystem.h"
#include "render/render.h"
#include "render/textures.h"
#include "client/console.h"
@@ -65,25 +66,25 @@ size_t notify_pos = 0;
std::string notify_text[MAXNOTIFYLINES];
float notify_time[MAXNOTIFYLINES];
-
//--- engine functions --------------------------------------------
void func_con_toggle(std::string const &args)
{
+
std::istringstream argstream(args);
int i;
if (argstream >> i) {
- if (i) console_visible = true; else console_visible = false;
- } else
- console_visible = !console_visible;
+ if (i) console_visible = false; else console_visible = true;
+ }
+ toggle();
}
//--- public ------------------------------------------------------
void init()
{
- con_print << "Initializing console..." << std::endl;
+ con_print << "^BInitializing console..." << std::endl;
console_visible = false;
@@ -103,7 +104,7 @@ void init()
void shutdown()
{
- con_print << "Shutting down console..." << std::endl;
+ con_print << "^BShutting down console..." << std::endl;
save_history();
@@ -117,26 +118,125 @@ void shutdown()
input_pos = 0;
}
-void draw()
+void clear_notify()
+{
+ for (size_t i=0; i < MAXNOTIFYLINES; i++)
+ notify_time[i] = 0;
+}
+
+void draw_notify()
+{
+ using namespace render;
+
+ // draw notifications
+ Text::setcolor('N');
+ size_t width = (size_t) ((video::width - 8) / Text::fontwidth());
+ size_t n = notify_pos % MAXNOTIFYLINES;
+ float h = 4 + 2*Text::fontheight();
+ for (size_t l = 0; l < MAXNOTIFYLINES; l++) {
+ if (notify_text[n].size() > 2 && notify_time[n] + 4 > core::application()->time()) {
+ std::string linedata(notify_text[n]);
+ linedata += '\n';
+
+ std::string word;
+ size_t word_length = 0;
+
+ std::string line;
+ size_t line_length = 0;
+
+ const char *c = linedata.c_str();
+ char pen = 'N';
+
+ while (*c) {
+
+ // color code
+ if (aux::is_color_code(c)) {
+ c++;
+ pen = *c;
+ word += '^';
+ word += pen;
+ }
+
+ // new word, wrap if necessary
+ else if ((*c == '\n' ) || ( *c == ' ')) {
+
+ if (line_length + word_length > width) {
+ if (line.size()) {
+ Text::draw(4, h, line);
+ h += Text::fontheight();
+ line.clear();
+ line += '^';
+ line += pen;
+ line_length = 0;
+ }
+ }
+
+ line.append(word);
+ line_length += word_length;
+
+ word.clear();
+ word_length = 0;
+
+ // new line
+ if (*c == '\n' ) {
+ Text::draw(4, h, line);
+ h += Text::fontheight();
+ line.clear();
+ line_length = 0;
+ // new word
+ } else if (*c == ' ' ) {
+ line += ' ';
+ line_length++;
+ }
+ }
+
+ // new character
+ else {
+ word += *c;
+ word_length++;
+
+ if (word_length == width) {
+ if (line.size()) {
+ Text::draw(4, h, line);
+ h += Text::fontheight();
+ line.clear();
+ line += '^';
+ line += pen;
+ line_length = 0;
+ }
+
+ line.append(word);
+ line_length = word_length;
+
+ word.clear();
+ word_length = 0;
+ }
+ }
+
+ c++;
+ }
+
+ }
+ n = (n+1) % MAXNOTIFYLINES;
+ }
+}
+
+void draw_console()
{
using namespace render;
-
- if(!console_visible)
- 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());
+ gl::color(0.0f, 1.0f, 0.0f, 0.5f);
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
gl::color(1.0f, 1.0f, 1.0f, 0.02f);
-
gl::begin(gl::Quads);
gl::vertex(0.0f, 0.0f, 0.0f);
gl::vertex(video::width, 0.0f,0.0f);
@@ -150,23 +250,10 @@ void draw()
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);
-
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] == '*')
- 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);
-*/
std::deque<std::string> lines;
for (std::deque<std::string>::iterator it = text.begin(); it != text.end() && current_line < bottom; it++) {
@@ -175,41 +262,75 @@ void draw()
linedata += '\n';
std::string word;
+ size_t word_length = 0;
+
std::string line;
+ size_t line_length = 0;
+
const char *c = linedata.c_str();
+ char pen = 'N';
while (*c) {
+
+ // color code
+ if (aux::is_color_code(c)) {
+ c++;
+ pen = *c;
+ word += '^';
+ word += pen;
+ }
+
// new word, wrap if necessary
- if ((*c == '\n' ) || ( *c == ' ')) {
+ else if ((*c == '\n' ) || ( *c == ' ')) {
- if (line.size() + word.size() > width) {
+ if (line_length + word_length > width) {
if (line.size()) {
lines.push_back(line);
line.clear();
+ line += '^';
+ line += pen;
+ line_length = 0;
}
}
line.append(word);
+ line_length += word_length;
+
word.clear();
-
- // force break words longer than width
- while (line.size() > width) {
- lines.push_back(line.substr(0, width));
- line.erase(0, width);
- }
-
+ word_length = 0;
+
// new line
if (*c == '\n' ) {
lines.push_back(line);
line.clear();
+ line_length = 0;
// new word
} else if (*c == ' ' ) {
line += ' ';
+ line_length++;
}
+ }
+
// new character
- } else {
-
+ else {
word += *c;
+ word_length++;
+
+ if (word_length == width) {
+ if (line.size()) {
+ lines.push_back(line);
+ line.clear();
+ line += '^';
+ line += pen;
+ line_length = 0;
+ }
+
+ line.append(word);
+ line_length = word_length;
+
+ word.clear();
+ word_length = 0;
+ }
}
c++;
@@ -220,6 +341,7 @@ void draw()
}
float y = video::height*con_height-2*Text::fontheight()-4;
+ Text::setcolor('N');
for (std::deque<std::string>::reverse_iterator rit = lines.rbegin(); (y >= 4) && (rit != lines.rend()); ++rit) {
Text::draw(4, y, (*rit));
y -= Text::fontheight();
@@ -228,20 +350,29 @@ void draw()
// draw the console input
size_t draw_pos = 0;
+ y = video::height*con_height - Text::fontheight() - 4;
+
while (input_pos - draw_pos > width)
draw_pos += 2;
- gl::color(0.0f, 1.0f, 0.0f, 1.0f);
- Text::draw(Text::fontwidth(), video::height*con_height - Text::fontheight() - 4, (*history_pos).substr(draw_pos, width));
+ Text::draw(4, y, "^B>");
+ Text::draw(4+Text::fontwidth(), y , (*history_pos).substr(draw_pos, width-1));
// draw cursor
if ((core::application()->time() - ::floorf(core::application()->time())) < 0.5f) {
- std::string cursor("_");
- Text::draw(Text::fontwidth()*(input_pos-draw_pos+1), video::height*con_height - Text::fontheight() - 4 , cursor);
+ std::string cursor("^B_");
+ Text::draw(4+Text::fontwidth()*(input_pos-draw_pos+1), y , cursor);
}
}
+void draw(){
+ if (visible())
+ draw_console();
+ else
+ draw_notify();
+}
+
void flush()
{
char line[MAXCMDSIZE];
@@ -279,6 +410,7 @@ void toggle()
} else {
SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(SDL_DISABLE);
+ clear_notify();
}
setkeyboardmode(console::visible());
@@ -300,6 +432,7 @@ void keypressed(int key)
}
core::cmd() << (*history_pos) << std::endl;
+ con_print << "^B>" << (*history_pos) << std::endl;
(*history.rbegin()) = (*history_pos);
history.push_back("");
@@ -425,22 +558,22 @@ void Console::flush()
std::ostream & Console::messagestream()
{
- return (buffer << ". ");
+ return (buffer << "^N");
}
std::ostream & Console::warningstream()
{
- return (buffer << "* ");
+ return (buffer << "^W");
}
std::ostream & Console::errorstream()
{
- return (buffer << "! ");
+ return (buffer << "^R");
}
std::ostream & Console::debugstream()
{
- return (buffer << "? ");
+ return (buffer << "^D");
}
} // namespace console