void TextWidget::recalculateText() { // perform text initialization. loadTextFont(); myText.setColor(isEnabled() ? getTextColor() : fadeColor(getTextColor(), 0.6f)); sf::FloatRect boundingBox = getTextMaxBoundingBox(); sf::Vector2f pos(boundingBox.left, boundingBox.top); myText.setMaxSize(sf::Vector2f(boundingBox.width, boundingBox.height)); sf::Vector2f textSize(getTextSize()); pos.x += (boundingBox.width - textSize.x) * getTextPreciseAlignment().x; pos.y += (boundingBox.height - textSize.y) * getTextPreciseAlignment().y; /* switch (convertAlignmentHorizontal(getTextAlignment())) { case AlignLeft: default: break; case AlignCenter: pos.x += (boundingBox.width - textSize.x) / 2.f; break; case AlignRight: pos.x += boundingBox.width - textSize.x; break; } switch (convertAlignmentVertical(getTextAlignment())) { case AlignTop: default: break; case AlignCenter: pos.y += (boundingBox.height - textSize.y) / 2.f; break; case AlignBottom: pos.y += boundingBox.height - textSize.y; break; } */ if (isTextPixelPerfect()) pos = sf::Vector2f(sf::Vector2i(pos + sf::Vector2f(0.5f, 0.5f))); if (pos != myText.getPosition()) { myText.setPosition(pos); myText.updateMinor(); } }
void TextEdit::initialize() { loadTextFont(); // Loads font, fills in the fontStruct // Save font metrics, calculate window size dx = fontStruct.max_bounds.width; // Maximal character advance ascent = fontStruct.max_bounds.ascent; // Character ascent descent = fontStruct.max_bounds.descent; // Character descent int height = ascent + descent; leading = height / 8; // Interline skip if (leading <= 2) leading = 2; dy = ascent + descent + leading; topMargin += dy + statusLineMargin; // Allocate space for the status line // Calculate window rectangle m_IWinRect.setLeft(10); m_IWinRect.setTop(10); m_IWinRect.setWidth(leftMargin + windowWidth * dx + rightMargin); m_IWinRect.setHeight(topMargin + windowHeight * dy + bottomMargin); }
void TextWidget::onUpdateFonts() { loadTextFont(); }