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>2010-09-19 19:44:13 +0000
committerStijn Buys <ingar@osirion.org>2010-09-19 19:44:13 +0000
commitcc18095cded14f5e7e3f049e47fca2224134b647 (patch)
tree2a057f4836925083a19988d571dc0664925c9e48 /src/render
parentbadfb31888a6bd62e0a019b3f3dec517df4121ec (diff)
text rendering cleanups, inventory capacity & cargo volume
Diffstat (limited to 'src/render')
-rw-r--r--src/render/text.cc42
-rw-r--r--src/render/text.h39
2 files changed, 47 insertions, 34 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
diff --git a/src/render/text.h b/src/render/text.h
index 631f1cd..3f743ae 100644
--- a/src/render/text.h
+++ b/src/render/text.h
@@ -26,23 +26,34 @@ public:
/// assign system colors
static void assign_color(const char c, const math::Color &color);
- /// draw a text string
- static void draw(float x, float y, const std::string & text);
-
- /// draw a text string
-
- static void draw(float x, float y, const char *text);
- /// draw a text stream
- /** If the stream contains multiple lines, each new line will be
- * drawn at the same x value. The stream is cleared after reading
- */
- static void draw(float x, float y, std::stringstream & textstream);
+ /**
+ * @brief draw a single character
+ */
+ static void draw(const float x, const float y, const char ascii);
+
+ /**
+ * @brief draw a text string
+ * end-of-characters will be respected
+ */
+ static void draw(const float x, const float y, const char *text);
+
+ /**
+ * @brief draw a text string
+ * end-of-characters will be respected
+ */
+ inline static void draw(const float x, const float y, const std::string & text) {
+ draw(x, y, text.c_str());
+ }
- /// draw a character
- static void draw(float x, float y, const char ascii);
+ /* *
+ * @brief draw a text stream
+ * If the stream contains multiple lines, each new line will be
+ * drawn at the same x value. The stream is cleared after reading
+ */
+ //static void draw(float x, float y, std::stringstream & textstream);
/// set the font
- static void setfont(const char *texture, float width, float height);
+ static void setfont(const char *texture, const float width, const float height);
/// set the color
static void setcolor(const char color);