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/render/text.cc
parente4f2faa8d5895ba30207c09c7886afb21a697d5f (diff)
console colors
Diffstat (limited to 'src/render/text.cc')
-rw-r--r--src/render/text.cc90
1 files changed, 82 insertions, 8 deletions
diff --git a/src/render/text.cc b/src/render/text.cc
index 668f4ec..7c1ae8e 100644
--- a/src/render/text.cc
+++ b/src/render/text.cc
@@ -1,18 +1,83 @@
/*
render/text.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
+#include "auxiliary/functions.h"
#include "render/text.h"
#include "render/textures.h"
#include "sys/sys.h"
-namespace render {
+namespace render
+{
float Text::text_fontwidth = 16.0f;
float Text::text_fontheight = 24.0f;
+math::Color * Text::base_color[10];
+math::Color * Text::core_color[26];
+
+void Text::init()
+{
+ // base colors
+ // Black=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7
+ base_color[0] = new math::Color(0, 0, 0);
+ base_color[1] = new math::Color(1, 0, 0);
+ base_color[2] = new math::Color(0, 1, 0);
+ base_color[3] = new math::Color(1, 1, 0);
+ base_color[4] = new math::Color(0, 0, 1);
+ base_color[5] = new math::Color(0, 1, 1);
+ base_color[6] = new math::Color(1, 0, 1);
+ base_color[7] = new math::Color(1, 1, 1);
+
+ for (size_t i=0; i< 26; i++) {
+ core_color[i] = new math::Color(.7, .7, .7);
+ }
+
+ // N - normal color
+ core_color[(size_t)('N'-'A')]->assign(.7, .7, .7);
+ // D - Debug color
+ core_color[(size_t)('D'-'A')]->assign(.6, .6, .6);
+ // B - bold color
+ core_color[(size_t)('B'-'A')]->assign(1, 1, 1);
+ // W - warning color
+ core_color[(size_t)('W'-'A')]->assign(1, 1, 0);
+ // R - Error color
+ core_color[(size_t)('R'-'A')]->assign(1, 0, 0);
+ // F - Fancy color
+ core_color[(size_t)('F'-'A')]->assign(0, 1, 0);
+}
+
+void Text::shutdown()
+{
+ for (size_t i=0; i< 7; i++) {
+ delete base_color[i];
+ base_color[i] = 0;
+ }
+
+ for (size_t i=0; i< 26; i++) {
+ delete core_color[i];
+ core_color[i] = 0;
+ }
+}
+
+void Text::setcolor(const char color)
+{
+ if (('A' <= color) && (color <= 'Z')) {
+ gl::color(*core_color[(size_t) (color - 'A')]);
+ }
+
+ else if (('0' <= color) && (color <= '9')) {
+ gl::color(*base_color[(size_t) (color - '0')]);
+ }
+
+ else {
+ gl::color(1, 1, 1);
+ }
+
+}
+
void Text::setfont(const char *texture, float width, float height)
{
Textures::bind(texture, false);
@@ -20,6 +85,7 @@ void Text::setfont(const char *texture, float width, float height)
text_fontheight = height;
}
+
void Text::draw(float x, float y, const char ascii)
{
if (ascii != ' ') {
@@ -28,9 +94,9 @@ void Text::draw(float x, float y, const char ascii)
float frow = row * 0.0625f;
float fcol = col * 0.0625f;
-
+
gl::begin(gl::Quads);
-
+
glTexCoord2f(fcol, frow);
gl::vertex(x,y,1);
@@ -52,13 +118,21 @@ void Text::draw(float x, float y, const char *text)
{
const char *c = text;
while (*c) {
- draw(x, y, *c);
+ if (aux::is_base_color_code(c)) {
+ c++;
+ gl::color(*base_color[ (size_t)(*c - '0')]);
+ } else if (aux::is_core_color_code(c)) {
+ c++;
+ gl::color(*core_color[ (size_t)(*c - 'A')]);
+ } else {
+ draw(x, y, *c);
+ x += text_fontwidth;
+ }
c++;
- x += text_fontwidth;
}
}
-void Text::draw(float x, float y, std::stringstream & textstream)
+void Text::draw(float x, float y, std::stringstream & textstream)
{
char line[MAXCMDSIZE];
while (textstream.getline(line, MAXCMDSIZE-1)) {