Browse Source

Text: removed cursorPosition from AbstractLayouter::renderGlyph().

The parameter unnecessarily complicates the implementation, as it needs
to be reimplemented in _every_ plugin (and all current plugins have bug
in it).
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
ca6b1c9a1e
  1. 3
      src/Text/AbstractFont.h
  2. 6
      src/Text/Test/TextRendererGLTest.cpp
  3. 18
      src/Text/TextRenderer.cpp

3
src/Text/AbstractFont.h

@ -271,12 +271,11 @@ class MAGNUM_TEXT_EXPORT AbstractLayouter {
/**
* @brief Render glyph
* @param i Glyph index
* @param cursorPosition Cursor position
*
* Returns quad position, texture coordinates and advance to next
* glyph.
*/
virtual std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(const Vector2& cursorPosition, UnsignedInt i) = 0;
virtual std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(UnsignedInt i) = 0;
#ifdef DOXYGEN_GENERATING_OUTPUT
private:

6
src/Text/Test/TextRendererGLTest.cpp

@ -51,10 +51,10 @@ class TestLayouter: public Text::AbstractLayouter {
_glyphCount = glyphCount;
}
std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(const Vector2& cursorPosition, UnsignedInt i) override {
std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(UnsignedInt i) override {
return std::make_tuple(
Rectangle(cursorPosition, cursorPosition+Vector2(3.0f, 2.0f)*((i+1)*_size)),
Rectangle({i*6.0f, 0.0f}, {(i+1)*6.0f, 10.0f}),
Rectangle({}, Vector2(3.0f, 2.0f)*((i+1)*_size)),
Rectangle::fromSize({i*6.0f, 0.0f}, {6.0f, 10.0f}),
(Vector2::xAxis((i+1)*3.0f)+Vector2(1.0f, -1.0f))*_size
);
}

18
src/Text/TextRenderer.cpp

@ -78,7 +78,11 @@ std::tuple<std::vector<Vector2>, std::vector<Vector2>, std::vector<UnsignedInt>,
/* Position of the texture in the resulting glyph, texture coordinates */
Rectangle quadPosition, textureCoordinates;
Vector2 advance;
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(cursorPosition, i);
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(i);
/* Move the quad to cursor */
quadPosition.bottomLeft() += cursorPosition;
quadPosition.topRight() += cursorPosition;
/* 0---2
| |
@ -134,7 +138,11 @@ std::tuple<Mesh, Rectangle> AbstractTextRenderer::render(AbstractFont* const fon
/* Position of the texture in the resulting glyph, texture coordinates */
Rectangle quadPosition, textureCoordinates;
Vector2 advance;
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(cursorPosition, i);
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(i);
/* Move the quad to cursor */
quadPosition.bottomLeft() += cursorPosition;
quadPosition.topRight() += cursorPosition;
vertices.insert(vertices.end(), {
{quadPosition.topLeft(), textureCoordinates.topLeft()},
@ -274,7 +282,11 @@ void AbstractTextRenderer::render(const std::string& text) {
/* Position of the texture in the resulting glyph, texture coordinates */
Rectangle quadPosition, textureCoordinates;
Vector2 advance;
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(cursorPosition, i);
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(i);
/* Move the quad to cursor */
quadPosition.bottomLeft() += cursorPosition;
quadPosition.topRight() += cursorPosition;
/* Extend rectangle with current quad bounds */
_rectangle.bottomLeft() = Math::min(_rectangle.bottomLeft(), quadPosition.bottomLeft());

Loading…
Cancel
Save