Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/text.cc')
-rw-r--r--src/render/text.cc42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/render/text.cc b/src/render/text.cc
index bfa1474..c45357d 100644
--- a/src/render/text.cc
+++ b/src/render/text.cc
@@ -9,8 +9,7 @@
#include "render/textures.h"
#include "sys/sys.h"
-namespace render
-{
+namespace render {
float Text::text_fontwidth = 16.0f;
float Text::text_fontheight = 24.0f;
@@ -84,25 +83,26 @@ void Text::setcolor(const char color)
}
}
-void Text::setfont(const char *texture, float width, float height)
+void Text::setfont(const char *texture, const float width, const float height)
{
- std::string tf("bitmaps/fonts/");
- tf.append(texture);
+ std::string texture_filename("bitmaps/fonts/");
+ texture_filename.append(texture);
- Textures::bind(tf, false);
+ Textures::bind(texture_filename, false);
text_fontwidth = width;
text_fontheight = height;
}
-void Text::draw(float x, float y, const char ascii)
+// draw a single character
+void Text::draw(const float x, const float y, const char ascii)
{
if (ascii != ' ') {
int row = (int) ascii >> 4;
int col = (int) ascii & 15;
- float frow = row * 0.0625f;
- float fcol = col * 0.0625f;
+ float frow = (float) row * 0.0625f;
+ float fcol = (float) col * 0.0625f;
gl::begin(gl::Quads);
@@ -122,10 +122,13 @@ void Text::draw(float x, float y, const char ascii)
}
}
-
-void Text::draw(float x, float y, const char *text)
+// draw one or more lines of text
+void Text::draw(const float x, const float y, const char *text)
{
const char *c = text;
+ float x1 = x;
+ float y1 = y;
+
while (*c) {
if (aux::is_base_color_code(c)) {
c++;
@@ -133,14 +136,17 @@ void Text::draw(float x, float y, const char *text)
} else if (aux::is_core_color_code(c)) {
c++;
gl::color(*core_color[(size_t)(*c - 'A')]);
+ } else if (*c == '\n' ) {
+ y1 += text_fontheight;
+ x1 = x;
} else {
- draw(x, y, *c);
- x += text_fontwidth;
+ draw(x1, y1, *c);
+ x1 += text_fontwidth;
}
c++;
}
}
-
+/*
void Text::draw(float x, float y, std::stringstream & textstream)
{
char line[MAXCMDSIZE];
@@ -150,10 +156,6 @@ void Text::draw(float x, float y, std::stringstream & textstream)
}
textstream.clear();
}
+*/
-void Text::draw(float x, float y, const std::string & text)
-{
- draw(x, y, text.c_str());
-}
-
-}
+} // namespace render