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
parente4f2faa8d5895ba30207c09c7886afb21a697d5f (diff)
console colors
Diffstat (limited to 'src/client')
-rw-r--r--src/client/chat.cc15
-rw-r--r--src/client/client.cc6
-rw-r--r--src/client/console.cc223
-rw-r--r--src/client/input.cc4
-rw-r--r--src/client/video.cc4
-rw-r--r--src/client/view.cc71
6 files changed, 200 insertions, 123 deletions
diff --git a/src/client/chat.cc b/src/client/chat.cc
index 0d1def6..1953390 100644
--- a/src/client/chat.cc
+++ b/src/client/chat.cc
@@ -79,19 +79,16 @@ void draw()
while (input_pos - draw_pos > width)
draw_pos += 2;
- // draw the console input
- gl::color(1.0f, 1.0f, 1.0f, 1.0f);
- Text::draw(4 , 5 + Text::fontheight() * (MAXNOTIFYLINES+1), "say");
- gl::color(0.0f, 1.0f, .0f, 1.0f);
- Text::draw(4+Text::fontwidth()*3 , 5 + Text::fontheight() * (MAXNOTIFYLINES+1), ":");
+ // draw the chat input
+ float y = video::height * 8.0 / 10.0;
- gl::color(1.0f, 1.0f, 1.0f, 1.0f);
- Text::draw(4+Text::fontwidth()*5, 5 + Text::fontheight() * (MAXNOTIFYLINES+1), (*history_pos).substr(draw_pos, width));
+ Text::draw(4 , y, "^Bsay^F:^B");
+ Text::draw(4+Text::fontwidth()*5 , y, (*history_pos).substr(draw_pos, width));
// draw cursor
if ((core::application()->time() - ::floorf(core::application()->time())) < 0.5f) {
- std::string cursor("_");
- Text::draw(4+Text::fontwidth()*(input_pos - draw_pos+5), 5 + Text::fontheight() * (MAXNOTIFYLINES+1) , cursor);
+ std::string cursor("^B_");
+ Text::draw(4+Text::fontwidth()*(input_pos - draw_pos+5), y, cursor);
}
}
diff --git a/src/client/client.cc b/src/client/client.cc
index c607c64..6a4d23e 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -82,7 +82,7 @@ void Client::quit(int status)
void Client::init(int count, char **arguments)
{
- con_print << "Initializing client..." << std::endl;
+ con_print << "^BInitializing client..." << std::endl;
// initialize core
core::Cvar::sv_dedicated = core::Cvar::set("sv_private", "0");
@@ -123,7 +123,7 @@ void Client::init(int count, char **arguments)
void Client::run()
{
- con_print << "Running client..." << std::endl;
+ con_print << "^BRunning client..." << std::endl;
Uint32 client_framerate = (Uint32)(1000/120);
Uint32 elapsed = 0;
@@ -154,7 +154,7 @@ void Client::run()
void Client::shutdown()
{
- con_print << "Shutting down client..." << std::endl;
+ con_print << "^BShutting down client..." << std::endl;
console::flush();
// remove engine functions
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
diff --git a/src/client/input.cc b/src/client/input.cc
index 45c39a9..f40591c 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -48,7 +48,7 @@ const float thruster_offset = 0.05f;
void init()
{
- con_print << "Initializing input..." << std::endl;
+ con_print << "^BInitializing input..." << std::endl;
client::setkeyboardmode(false);
SDL_ShowCursor(SDL_DISABLE);
SDL_WM_GrabInput(SDL_GRAB_ON);
@@ -59,7 +59,7 @@ void init()
void shutdown()
{
- con_print << "Shutting down input..." << std::endl;
+ con_print << "^BShutting down input..." << std::endl;
// SDL_EnableUNICODE(0);
}
diff --git a/src/client/video.cc b/src/client/video.cc
index cd25d19..2253c52 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -54,7 +54,7 @@ void reset()
bool init()
{
- con_print << "Initializing video..." << std::endl;
+ con_print << "^BInitializing video..." << std::endl;
// initialize cvars
r_width = core::Cvar::get("r_width", width_default, core::Cvar::Archive);
@@ -134,7 +134,7 @@ void frame(float seconds)
void shutdown()
{
- con_print << "Shutting down video..." << std::endl;
+ con_print << "^BShutting down video..." << std::endl;
view::shutdown();
diff --git a/src/client/view.cc b/src/client/view.cc
index 7d11df3..0fa47d4 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -129,44 +129,36 @@ void draw_status()
return;
// print the status in the upper left corner
- gl::color(1.0f, 1.0f, 1.0f, 1.0f);
std::stringstream status;
-
- /*
- int minutes = (int) floorf(core::application()->time() / 60.0f);
- int seconds = (int) floorf(core::application()->time() - (float) minutes* 60.0f);
- */
-
+
if (core::game()) {
int minutes = (int) floorf(core::game()->clientframetime() / 60.0f);
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;
+ status << "^Ntime ^B" << std::setfill('0') << std::setw(2) << minutes << "^N:^B" << std::setfill('0') << std::setw(2) << seconds;
Text::draw(4, 4, status);
}
// print stats if desired
if (draw_stats && draw_stats->value()) {
std::stringstream stats;
- stats << "fps " << std::setw(6) << fps << "\n";
+ stats << "^Nfps ^B" << std::setw(6) << fps << "\n";
if (core::application()->connected()) {
- stats << "tris " << std::setw(5) << render::Stats::tris << "\n";
- stats << "quads " << std::setw(5) << render::Stats::quads << "\n";
+ stats << "^Ntris ^B" << std::setw(5) << render::Stats::tris << "\n";
+ stats << "^Nquads ^B" << std::setw(5) << render::Stats::quads << "\n";
}
- stats << "tx "<< std::setw(5) << (core::Stats::network_bytes_sent >> 10) << "\n";
- stats << "rx "<< std::setw(5) << (core::Stats::network_bytes_received >> 10) << "\n";
+ stats << "^Ntx ^B"<< std::setw(5) << (core::Stats::network_bytes_sent >> 10) << "\n";
+ stats << "^Nrx ^B"<< std::setw(5) << (core::Stats::network_bytes_received >> 10) << "\n";
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
+ status << "^Nthrust ^B" << std::setfill(' ') << std::setw(5) << std::fixed
<< std::setprecision(2) << core::localcontrol()->thrust() << " ";
- status << "speed " << std::setfill(' ') << std::setw(5) << std::fixed
+ status << "^Nspeed ^B" << std::setfill(' ') << std::setw(5) << std::fixed
<< std::setprecision(2) << core::localcontrol()->speed();
Text::draw(4, video::height - Text::fontheight() -4, status);
@@ -174,48 +166,6 @@ void draw_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 - 8) / Text::fontwidth());
- size_t n = console::notify_pos % MAXNOTIFYLINES;
- 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]);
-
- 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);
- line.erase(0,2);
-
- std::deque<std::string> lines;
-
- while (line.size() > width) {
- Text::draw(4, h, line.substr(0, width));
- line.erase(0, width);
- h += Text::fontheight();
- }
- if (line.size()) {
- Text::draw(4, h, line);
- h += Text::fontheight();
- }
- }
- n = (n+1) % MAXNOTIFYLINES;
- }
-}
-
void draw_cursor()
{
if (!core::localcontrol() || console::visible())
@@ -309,11 +259,8 @@ void frame(float seconds)
}
// draw text elements
-
- // 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);