MCPcopy Create free account
hub / github.com/SFML/SFML / DemoText

Method DemoText

examples/text/Text.cpp:43–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41struct DemoText
42{
43 DemoText(const std::filesystem::path& fontFilename, std::string_view message) :
44 font(std::make_unique<sf::Font>(resourcesDir() / fontFilename)),
45 text(*font, sf::String::fromUtf8(message.begin(), message.end()), textSize)
46 {
47 // Generate per-character effect data
48 // Since this is peformed on the input string data it only has to be done once
49 generateEffectData();
50
51 const auto localBounds = text.getLocalBounds();
52
53 // Fix cases where the text is so tall it starts at a negative offset
54 currentYPosition -= localBounds.position.y;
55 text.setPosition({(static_cast<float>(windowWidth) - localBounds.size.x) / 2.0f, currentYPosition});
56 currentYPosition = text.getGlobalBounds().position.y + text.getGlobalBounds().size.y + textSpacing;
57
58 // Set up text bounding box
59 boundingBox.setFillColor(sf::Color::Transparent);
60 boundingBox.setOutlineColor(sf::Color::Red);
61 boundingBox.setOutlineThickness(1.0f);
62
63 // Set up glyph bounding box
64 glyphBox.setFillColor(sf::Color::Transparent);
65 glyphBox.setOutlineColor(sf::Color::Green);
66 glyphBox.setOutlineThickness(1.0f);
67
68 // Set up cursor
69 cursor.setFillColor(sf::Color::White);
70
71 // Set up dynamic data
72 update();
73 }
74
75 void setPosition(const sf::Vector2f& position)
76 {

Callers

nothing calls this directly

Calls 10

resourcesDirFunction · 0.70
updateFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
getLocalBoundsMethod · 0.45
setPositionMethod · 0.45
getGlobalBoundsMethod · 0.45
setFillColorMethod · 0.45
setOutlineColorMethod · 0.45
setOutlineThicknessMethod · 0.45

Tested by

no test coverage detected