void TextBox::layout() { font->setSize(fontSize); if (updateLineHeightRequest && lineHeightFactor > 0) { lineHeight = font->getHeight() * lineHeightFactor; } if (updateWrapRequest) { if (wrap && !autoWidth) { wrapper.wrap(*font, text, width - paddingLeft - paddingRight); } else { contentWidth = wrapper.wrap(*font, text); } } if (updateWidthRequest || updateWrapRequest) { if (autoWidth) { width = paddingLeft + contentWidth + paddingRight; } overflowX = !autoWidth && (contentWidth > (width - paddingLeft - paddingRight)); } if (updateHeightRequest || updateWrapRequest || updateLineHeightRequest) { contentHeight = getLinesHeight(wrapper.size); if (autoHeight) { height = paddingTop + contentHeight + paddingBottom; } overflowY = !autoHeight && (contentHeight > (height - paddingTop - paddingBottom)); } updateLineHeightRequest = false; updateWrapRequest = false; updateWidthRequest = false; updateHeightRequest = false; }
void SWFontRenderer::updateMesh() { if ( !getMesh() ) return; if ( !m_fontInfo.isValid() ) return; SWMesh* mesh = getMesh(); mesh->resizeVertexStream( m_text.size() * 4 ); mesh->resizeTexCoordStream( m_text.size() * 4 ); mesh->resizeTriangleStream( m_text.size() * 2 ); tuint32 lastID = '\r'; tvec2 cursor( 0, 0 ); tvec2 scale( m_fontInfo()->getScaleW(), m_fontInfo()->getScaleH() ); float lineHeight = getLinesHeight( m_text ); switch ( m_alignV ) { case SW_Align_Top : cursor.y = 0; break; case SW_Align_Bottom : cursor.y = lineHeight; break; case SW_Align_Center : cursor.y = lineHeight/2.0f; break; } for ( tuint i = 0 ; i < m_text.size() ; ++i ) { //! convert character to unsigned char id tbyte byteID = m_text[i]; tuint32 id = byteID; if ( lastID == (int)'\n' || lastID == (int)'\r' ) { float lineWidth = (float)getLineWidth( m_text, i ); switch ( m_alignH ) { case SW_Align_Left : cursor.x = 0; break; case SW_Align_Right : cursor.x = -lineWidth; break; case SW_Align_Center : cursor.x = -lineWidth/2.0f; break; } } if ( id == (int)'\n' || id == (int)'\r' ) { lastID = id; cursor.y -= m_fontInfo()->getLineHeight(); continue; } SWFontInfo::Char* fontChar = m_fontInfo()->getChar( id ); if ( fontChar == NULL ) continue; SWFontInfo::Kerning* kerning = m_fontInfo()->getKerning( lastID, id ); cursor.x += (kerning != NULL)? kerning->amount : 0; lastID = id; tuint base = i*4; float left = cursor.x + fontChar->xoffset; float top = cursor.y - fontChar->yoffset; float right = left + fontChar->width; float bottom = top - fontChar->height; cursor.x += fontChar->xadvence; mesh->setTriangle( (i*2)+0, tindex3( base+0, base+1, base+2 ) ); mesh->setTriangle( (i*2)+1, tindex3( base+3, base+2, base+1 ) ); mesh->setVertex( base+0, tvec3( left, top, 0 ) ); mesh->setVertex( base+1, tvec3( right, top, 0 ) ); mesh->setVertex( base+2, tvec3( left, bottom, 0 ) ); mesh->setVertex( base+3, tvec3( right, bottom, 0 ) ); mesh->setTexCoord( base+0, tvec2( fontChar->x/scale.x, fontChar->y/scale.y ) ); mesh->setTexCoord( base+1, tvec2( (fontChar->x + fontChar->width)/scale.x, fontChar->y/scale.y ) ); mesh->setTexCoord( base+2, tvec2( fontChar->x/scale.x, (fontChar->y + fontChar->height)/scale.y ) ); mesh->setTexCoord( base+3, tvec2( (fontChar->x + fontChar->width)/scale.x, (fontChar->y + fontChar->height)/scale.y ) ); } }