1
Graphics / Re: sf::text size and 'highlighting'.
« on: January 16, 2014, 09:22:46 pm »Thanks for the replies!
Ive found something that works, although i'm not completely sure how. I guess whats referred to as the 'baseline' in the documentation is the bottom of the text bounding box.
static sf::Font font;
font.loadFromFile("fonts/Arial.ttf");
sf::Text text(string, font, 30);
text.setColor(fgColour);
text.setPosition(x, y*text.getGlobalBounds().height-text.getGlobalBounds().top);
int c = 0;
while(string[c]!='\0') {
sf::RectangleShape rect;
rect.setPosition(text.findCharacterPos(c).x+font.getGlyph(string[c], 30, 0).bounds.left, text.getGlobalBounds().top+(text.getGlobalBounds().height+font.getGlyph(string[c], 30, 0).bounds.top));
rect.setSize(sf::Vector2f(font.getGlyph(string[c], 30, 0).bounds.width, font.getGlyph(string[c], 30, 0).bounds.height));
rect.setFillColor(bgColour);
window->draw(rect);
c++;
}
window->draw(text);
font.loadFromFile("fonts/Arial.ttf");
sf::Text text(string, font, 30);
text.setColor(fgColour);
text.setPosition(x, y*text.getGlobalBounds().height-text.getGlobalBounds().top);
int c = 0;
while(string[c]!='\0') {
sf::RectangleShape rect;
rect.setPosition(text.findCharacterPos(c).x+font.getGlyph(string[c], 30, 0).bounds.left, text.getGlobalBounds().top+(text.getGlobalBounds().height+font.getGlyph(string[c], 30, 0).bounds.top));
rect.setSize(sf::Vector2f(font.getGlyph(string[c], 30, 0).bounds.width, font.getGlyph(string[c], 30, 0).bounds.height));
rect.setFillColor(bgColour);
window->draw(rect);
c++;
}
window->draw(text);