Skip to content

Commit

Permalink
GRAPHICS: Move line drawing to an extra function
Browse files Browse the repository at this point in the history
  • Loading branch information
farmboy0 committed Nov 24, 2017
1 parent e61aee6 commit 3e12a1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/graphics/aurora/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,7 @@ void Text::render(RenderPass pass) {
// Save the current position
glPushMatrix();

// Align
glTranslatef(roundf((maxLength - font.getLineWidth(*l)) * _align), 0.0f, 0.0f);

// Draw line
for (Common::UString::iterator s = l->begin(); s != l->end(); ++s, position++) {
// If we have color changes, apply them
while ((color != _colors.end()) && (color->position <= position)) {
if (color->defaultColor)
glColor4f(_r, _g, _b, _a);
else
glColor4f(color->r, color->g, color->b, color->a);

++color;
}

font.draw(*s);
}
drawLine(*l, maxLength, color, position);

// Restore position to the start of the line
glPopMatrix();
Expand Down Expand Up @@ -294,6 +278,30 @@ void Text::setFont(const Common::UString &fnt) {
_font = FontMan.get(fnt);
}

void Text::drawLine(const Common::UString &line, float maxLength,
ColorPositions::const_iterator color, size_t position) {

Font &font = _font.getFont();

// Align
glTranslatef(roundf((maxLength - font.getLineWidth(line)) * _align), 0.0f, 0.0f);

// Draw line
for (Common::UString::iterator s = line.begin(); s != line.end(); ++s, position++) {
// If we have color changes, apply them
while ((color != _colors.end()) && (color->position <= position)) {
if (color->defaultColor)
glColor4f(_r, _g, _b, _a);
else
glColor4f(color->r, color->g, color->b, color->a);

++color;
}

font.draw(*s);
}
}

} // End of namespace Aurora

} // End of namespace Graphics
2 changes: 2 additions & 0 deletions src/graphics/aurora/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class Text : public GUIElement {

void parseColors(const Common::UString &str, Common::UString &parsed,
ColorPositions &colors);

void drawLine(const Common::UString &line, float maxLength, ColorPositions::const_iterator color, size_t position);
};

} // End of namespace Aurora
Expand Down

0 comments on commit 3e12a1a

Please sign in to comment.