Skip to content

Commit

Permalink
Overlay: TextArea - simplify glyph positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Nov 21, 2024
1 parent 4e0b4f8 commit e31c7e7
Showing 1 changed file with 14 additions and 35 deletions.
49 changes: 14 additions & 35 deletions Components/Overlay/src/OgreTextAreaOverlayElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ namespace Ogre {
}

const auto& glyphInfo = mFont->getGlyphInfo(character);
Real horiz_height = glyphInfo.aspectRatio * mViewportAspectCoef ;
float width = glyphInfo.aspectRatio * mViewportAspectCoef * mCharHeight * 2.0f;
const Font::UVRect& uvRect = glyphInfo.uvRect;

if(uvRect.isNull())
Expand All @@ -328,73 +328,52 @@ namespace Ogre {
}

left += glyphInfo.bearing * mCharHeight * 2 * mViewportAspectCoef;
FloatRect pos(left, top, left + width, top - mCharHeight * 2);

// each vert is (x, y, z, u, v)
//-------------------------------------------------------------------------------------
// First tri
//
// Upper left
*pVert++ = left;
*pVert++ = top;
*pVert++ = pos.left;
*pVert++ = pos.top;
*pVert++ = -1.0;
*pVert++ = uvRect.left;
*pVert++ = uvRect.top;

top -= mCharHeight * 2.0f;

// Bottom left
*pVert++ = left;
*pVert++ = top;
*pVert++ = pos.left;
*pVert++ = pos.bottom;
*pVert++ = -1.0;
*pVert++ = uvRect.left;
*pVert++ = uvRect.bottom;

top += mCharHeight * 2.0f;
left += horiz_height * mCharHeight * 2.0f;

// Top right
*pVert++ = left;
*pVert++ = top;
*pVert++ = pos.right;
*pVert++ = pos.top;
*pVert++ = -1.0;
*pVert++ = uvRect.right;
*pVert++ = uvRect.top;
//-------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------
// Second tri
//
// Top right (again)
*pVert++ = left;
*pVert++ = top;
*pVert++ = pos.right;
*pVert++ = pos.top;
*pVert++ = -1.0;
*pVert++ = uvRect.right;
*pVert++ = uvRect.top;

top -= mCharHeight * 2.0f;
left -= horiz_height * mCharHeight * 2.0f;

// Bottom left (again)
*pVert++ = left;
*pVert++ = top;
*pVert++ = pos.left;
*pVert++ = pos.bottom;
*pVert++ = -1.0;
*pVert++ = uvRect.left;
*pVert++ = uvRect.bottom;

left += horiz_height * mCharHeight * 2.0f;

// Bottom right
*pVert++ = left;
*pVert++ = top;
*pVert++ = pos.right;
*pVert++ = pos.bottom;
*pVert++ = -1.0;
*pVert++ = uvRect.right;
*pVert++ = uvRect.bottom;
//-------------------------------------------------------------------------------------

// Go back up with top
top += mCharHeight * 2.0f;

// advance
left -= horiz_height * mCharHeight * 2.0f;
left += (glyphInfo.advance - glyphInfo.bearing) * mCharHeight * 2.0f * mViewportAspectCoef;

float currentWidth = (left + 1)/2 - _getDerivedLeft();
Expand Down

0 comments on commit e31c7e7

Please sign in to comment.