| 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 | { |
no test coverage detected