37 float r,
float g,
float b,
float a,
float halign,
float valign) :
39 _r(r), _g(g), _b(b), _a(a), _font(font), _x(0.0f), _y(0.0f), _halign(halign),_valign(valign),
40 _disableColorTokens(false) {
48 float r,
float g,
float b,
float a,
float halign,
float valign) :
50 _font(font), _x(0.0f), _y(0.0f), _halign(halign),_valign(valign),
51 _disableColorTokens(false) {
62 float r,
float g,
float b,
float a,
float halign,
float valign) :
64 _font(font), _x(0.0f), _y(0.0f), _halign(halign),_valign(valign),
65 _disableColorTokens(false) {
226 glTranslatef(
_x,
_y, 0.0f);
230 std::vector<Common::UString> lines;
233 float blockSize = lines.size() * lineHeight;
236 glTranslatef(0.0f, roundf(((
_height - blockSize) *
_valign) + blockSize - lineHeight), 0.0f);
240 ColorPositions::const_iterator color =
_colors.begin();
243 for (std::vector<Common::UString>::iterator l = lines.begin(); l != lines.end(); ++l) {
253 glTranslatef(0.0f, -lineHeight, 0.0f);
259 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
263 if ((x <
_x) || (y <
_y))
277 std::vector<Common::UString> lines;
280 float blockSize = lines.size() * lineHeight;
285 ColorPositions::const_iterator color =
_colors.begin();
289 float y =
_y + roundf(((
_height - blockSize) *
_valign) + blockSize - lineHeight);
291 for (std::vector<Common::UString>::iterator l = lines.begin(); l != lines.end(); ++l) {
296 y = saved_y - lineHeight;
312 std::vector<Common::UString> tokens;
316 for (std::vector<Common::UString>::iterator t = tokens.begin(); t != tokens.end(); ++t) {
326 if ((t->size() == 11) && t->beginsWith(
"<c") && t->endsWith(
">")) {
337 for (
int i = 0; i < 8; i++, ++it) {
341 if ((c >=
'0') && (c <=
'9'))
343 else if ((c >=
'A') && (c <=
'F'))
345 else if ((c >=
'f') && (c <=
'f'))
351 uint8 &value = colorValue[i / 2];
352 bool high = (i % 2) == 0;
365 color.
r = colorValue[0] / 255.0f;
366 color.
g = colorValue[1] / 255.0f;
367 color.
b = colorValue[2] / 255.0f;
368 color.
a = colorValue[3] / 255.0f;
370 colors.push_back(color);
372 }
else if (*t ==
"</c>") {
378 colors.push_back(color);
392 ColorPositions::const_iterator color,
403 while ((color !=
_colors.end()) && (color->position <= position)) {
404 if (color->defaultColor)
407 glColor4f(color->r, color->g, color->b, color->a);
418 ColorPositions::const_iterator color,
432 while ((color !=
_colors.end()) && (color->position <= position)) {
433 if (color->defaultColor) {
447 font.
render(*s, x, y, rgba);
float getHorizontalAlign() const
Inter-thread request events.
virtual void hide()
Hide the object.
A class holding an UTF-8 string.
virtual void draw(uint32 c) const =0
Draw this character.
double _distance
The distance of the object from the viewer.
float getLineWidth(const Common::UString &text) const
Return the width of this string.
virtual float getLineSpacing() const
Return the size of space between lines.
size_t getLineCount(const Common::UString &text, float maxWidth=0.0f, float maxHeight=0.0f) const
Return the number of lines this text spans.
void disableColorTokens(bool disabled)
Disable parsing <c color tokens into actual coloring.
float split(const Common::UString &line, std::vector< Common::UString > &lines, float maxWidth=0.0f, float maxHeight=0.0f, bool trim=true) const
void drawLineImmediate(const Common::UString &line, ColorPositions::const_iterator color, size_t position, float &x, float &y)
void setText(const Common::UString &str)
void unlockFrameIfVisible()
void lockFrameIfVisible()
const Common::UString & getFont() const
size_t getLineCount() const
void set(const Common::UString &str, float maxWidth=0.0f, float maxHeight=0.0f)
Text(const FontHandle &font, const Common::UString &str, float r=1.0f, float g=1.0f, float b=1.0f, float a=1.0f, float halign=kHAlignLeft, float valign=kVAlignTop)
void drawLine(const Common::UString &line, ColorPositions::const_iterator color, size_t position)
void getColor(float &r, float &g, float &b, float &a) const
void getPosition(float &x, float &y, float &z) const
utf8::iterator< std::string::const_iterator > iterator
void setPosition(float x, float y, float z=-FLT_MAX)
std::vector< ColorPosition > ColorPositions
void parseColors(const Common::UString &str, Common::UString &parsed, ColorPositions &colors)
static void splitTextTokens(const UString &text, std::vector< UString > &tokens)
bool isIn(float x, float y) const
Is that point within the object?
const Common::UString & get() const
bool empty() const
Is the string empty?
void setHorizontalAlign(float halign)
void renderImmediate(const glm::mat4 &parentTransform)
For shader based systems, don't sort anything, render this right_now.
void render(RenderPass pass)
Render the object.
void setVerticalAlign(float valign)
size_t size() const
Return the size of the string, in characters.
void calculateDistance()
Calculate the object's distance.
const Common::UString & getName() const
virtual void renderBind(const glm::mat4 &transform) const
void setSize(float width, float height)
virtual void buildChars(const Common::UString &str)
Build all necessary characters to display this string.
float getVerticalAlign() const
virtual float getHeight() const =0
Return the height of a character.
void clear()
Clear the string's contents.
void setFont(const Common::UString &fnt)
Change the font of the text.
virtual float getWidth(uint32 c) const =0
Return the width of a character.
Only render opaque parts.
void setColor(float r, float g, float b, float a)
#define FontMan
Shortcut for accessing the font manager.
virtual void renderUnbind() const
virtual void render(uint32 c, float &x, float &y, float *rgba) const