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

Method generateEffectData

examples/text/Text.cpp:413–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411 }
412
413 void generateEffectData()
414 {
415 static constexpr std::array<sf::Color, 6> colors =
416 {sf::Color(255, 127, 127),
417 sf::Color(127, 255, 127),
418 sf::Color(127, 127, 255),
419 sf::Color(127, 255, 255),
420 sf::Color(255, 127, 255),
421 sf::Color(255, 255, 127)};
422
423 effectData.resize(text.getString().getSize());
424
425 std::size_t nextFillColorIndex{};
426 bool isCurrentlyOutlined{};
427 bool isCurrentlyItalic{};
428 bool isCurrentlyBold{};
429
430 // Generate effect data per unicode codepoint
431 for (auto i = 0u; i < text.getString().getSize(); ++i)
432 {
433 // Skip whitespace
434 if ((text.getString()[i] == ' ') || (text.getString()[i] == '\t') || (text.getString()[i] == '\n'))
435 continue;
436
437 if (text.getString().isWordBoundary(i))
438 {
439 // Color each word a different color
440 ++nextFillColorIndex;
441 if (nextFillColorIndex >= colors.size())
442 nextFillColorIndex = 0;
443
444 // Outline alternating words
445 isCurrentlyOutlined = !isCurrentlyOutlined;
446 }
447
448 if (text.getString().isSentenceBoundary(i))
449 {
450 // Italicize alternating sentences
451 isCurrentlyItalic = !isCurrentlyItalic;
452
453 // Embolden alternating sentences
454 isCurrentlyBold = !isCurrentlyBold;
455 }
456
457 effectData[i].color = colors[nextFillColorIndex];
458 effectData[i].outline = isCurrentlyOutlined;
459 effectData[i].italicize = isCurrentlyItalic;
460 effectData[i].embolden = isCurrentlyBold;
461 }
462 }
463
464 void preProcessGlyph(const sf::Text::ShapedGlyph& shapedGlyph,
465 std::uint32_t& style,

Callers

nothing calls this directly

Calls 6

isWordBoundaryMethod · 0.80
isSentenceBoundaryMethod · 0.80
ColorClass · 0.50
resizeMethod · 0.45
getSizeMethod · 0.45
getStringMethod · 0.45

Tested by

no test coverage detected