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

Method updateGlyphBox

examples/text/Text.cpp:145–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143 }
144
145 void updateGlyphBox(int offset)
146 {
147 const auto& shapedGlyphs = text.getShapedGlyphs();
148
149 glyphIndex = static_cast<std::size_t>(
150 std::clamp(static_cast<int>(glyphIndex) + offset, 0, static_cast<int>(shapedGlyphs.size()) - 1));
151
152 const auto& shapedGlyph = shapedGlyphs[glyphIndex];
153 const auto& localBounds = text.getLocalBounds();
154 const auto boxHeight = static_cast<float>(text.getCharacterSize());
155
156 // Check if we are dealing with whitespace or a glyph with a texture
157 // The bounds of a whitespace glyph will either have no width or no height depending on orientation
158 if (shapedGlyph.glyph.bounds.size.y == 0.0f)
159 {
160 // Horizontal space
161 glyphBox.setPosition({(shapedGlyph.position + shapedGlyph.glyph.bounds.position).x,
162 localBounds.position.y + shapedGlyph.position.y - boxHeight});
163 glyphBox.setSize({shapedGlyph.glyph.bounds.size.x, boxHeight});
164 glyphBox.setOutlineColor(sf::Color(0, 127, 255));
165 }
166 else if (shapedGlyph.glyph.bounds.size.x == 0.0f)
167 {
168 // Vertical space
169 glyphBox.setPosition({-localBounds.size.x / 2.0f, localBounds.position.y + shapedGlyph.position.y - boxHeight});
170 glyphBox.setSize({localBounds.size.x, shapedGlyph.glyph.bounds.size.y});
171 glyphBox.setOutlineColor(sf::Color(0, 127, 255));
172 }
173 else
174 {
175 glyphBox.setPosition({shapedGlyph.position + shapedGlyph.glyph.bounds.position});
176 glyphBox.setSize(shapedGlyph.glyph.bounds.size);
177 glyphBox.setOutlineColor(sf::Color::Green);
178 }
179 }
180
181 void computeCursorPositions()
182 {

Callers 1

mainFunction · 0.80

Calls 6

getCharacterSizeMethod · 0.80
ColorClass · 0.50
getLocalBoundsMethod · 0.45
setPositionMethod · 0.45
setSizeMethod · 0.45
setOutlineColorMethod · 0.45

Tested by

no test coverage detected