Skip to content

Commit

Permalink
Fixed use of LineSpacing, horizontal alignment and AABB calculation i…
Browse files Browse the repository at this point in the history
…n MovableText (#1200)

* Fixed use of LineSpacing, horizontal alignment and AABB calculation in MovableText

* Corrected calculation of Bounding Box and start position for Horizontal centered text
  • Loading branch information
ecazaubon authored and dhood committed Apr 26, 2018
1 parent 921767b commit a54d547
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/rviz/ogre_helpers/movable_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,17 @@ void MovableText::_setupGeometry()
{
if (*i == '\n')
{
total_height += mCharHeight + 0.01;
total_height += mCharHeight + mLineSpacing;

if ( current_width > total_width )
{
total_width = current_width;
current_width = 0.0;
}
current_width = 0.0;
}
else if (*i == ' ')
{
current_width += spaceWidth;
}
else
{
Expand Down Expand Up @@ -374,7 +378,7 @@ void MovableText::_setupGeometry()
if (*i == '\n')
{
left = starting_left;
top -= mCharHeight * 2.0;
top -= (mCharHeight + mLineSpacing) * 2.0;
newLine = true;
continue;
}
Expand All @@ -383,6 +387,10 @@ void MovableText::_setupGeometry()
{
// Just leave a gap, no tris
left += spaceWidth;
currPos = Ogre::Vector3(left, top, 0.0);
min.makeFloor(currPos);
max.makeCeil(currPos);
maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
continue;
}

Expand Down Expand Up @@ -498,7 +506,15 @@ void MovableText::_setupGeometry()
if (currentWidth > largestWidth)
largestWidth = currentWidth;
}

// Taking empty last line into account for the AABB
if(newLine)
{
top -= mCharHeight * 2.0;
currPos = Ogre::Vector3(left, top, 0.0);
min.makeFloor(currPos);
max.makeCeil(currPos);
maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
}
// Unlock vertex buffer
ptbuf->unlock();

Expand Down

0 comments on commit a54d547

Please sign in to comment.