diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-23 19:32:41 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-23 19:32:41 +1000 |
commit | 01356293019e77ccaadd636b1c4d62733db419b0 (patch) | |
tree | d5375b6df92a281d1e0f45d9d2b9c713241e370d /source/rendering/StarTextPainter.cpp | |
parent | 49c487cd826d158b7ceabefe1f1058cf3862f4ce (diff) |
small cleanup in TextPainter
Diffstat (limited to 'source/rendering/StarTextPainter.cpp')
-rw-r--r-- | source/rendering/StarTextPainter.cpp | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/source/rendering/StarTextPainter.cpp b/source/rendering/StarTextPainter.cpp index 599ffaf..0b77acc 100644 --- a/source/rendering/StarTextPainter.cpp +++ b/source/rendering/StarTextPainter.cpp @@ -325,13 +325,43 @@ void TextPainter::cleanup(int64_t timeout) { m_fontTextureGroup.cleanup(timeout); } +void TextPainter::applyCommands(String const& unsplitCommands) { + auto commands = unsplitCommands.split(','); + for (auto& command : commands) { + try { + if (command == "reset") { + m_renderSettings = m_savedRenderSettings; + } else if (command == "set") { + m_savedRenderSettings = m_renderSettings; + } else if (command == "shadow") { + m_renderSettings.mode = (FontMode)((int)m_renderSettings.mode | (int)FontMode::Shadow); + } else if (command == "noshadow") { + m_renderSettings.mode = (FontMode)((int)m_renderSettings.mode & (-1 ^ (int)FontMode::Shadow)); + } else if (command.beginsWith("font=")) { + m_renderSettings.font = command.substr(5); + } else if (command.beginsWith("directives=")) { + // Honestly this is really stupid but I just couldn't help myself + // Should probably limit in the future + m_renderSettings.directives = command.substr(11); + } else { + // expects both #... sequences and plain old color names. + Color c = jsonToColor(command); + c.setAlphaF(c.alphaF() * ((float)m_savedRenderSettings.color[3]) / 255); + m_renderSettings.color = c.toRgba(); + } + } catch (JsonException&) { + } catch (ColorException&) { + } + } +} + RectF TextPainter::doRenderText(String const& s, TextPositioning const& position, bool reallyRender, unsigned* charLimit) { Vec2F pos = position.pos; StringList lines = wrapText(s, position.wrapWidth); int height = (lines.size() - 1) * m_lineSpacing * m_fontSize + m_fontSize; - RenderSettings savedRenderSettings = m_renderSettings; + RenderSettings backupRenderSettings = m_renderSettings; m_savedRenderSettings = m_renderSettings; if (position.vAnchor == VerticalAnchor::BottomAnchor) @@ -348,7 +378,7 @@ RectF TextPainter::doRenderText(String const& s, TextPositioning const& position break; } - m_renderSettings = move(savedRenderSettings); + m_renderSettings = move(backupRenderSettings); return bounds; } @@ -393,33 +423,7 @@ RectF TextPainter::doRenderLine(String const& s, TextPositioning const& position bounds.combine(glyphBounds); pos.pos[0] += glyphBounds.width(); } else if (c == Text::EndEsc) { - auto commands = escapeCode.split(','); - for (auto& command : commands) { - try { - if (command == "reset") { - m_renderSettings = m_savedRenderSettings; - } else if (command == "set") { - m_savedRenderSettings = m_renderSettings; - } else if (command == "shadow") { - m_renderSettings.mode = (FontMode)((int)m_renderSettings.mode | (int)FontMode::Shadow); - } else if (command == "noshadow") { - m_renderSettings.mode = (FontMode)((int)m_renderSettings.mode & (-1 ^ (int)FontMode::Shadow)); - } else if (command.beginsWith("font=")) { - m_renderSettings.font = command.substr(5); - } else if (command.beginsWith("directives=")) { - // Honestly this is really stupid but I just couldn't help myself - // Should probably limit in the future - m_renderSettings.directives = command.substr(11); - } else { - // expects both #... sequences and plain old color names. - Color c = jsonToColor(command); - c.setAlphaF(c.alphaF() * ((float)m_savedRenderSettings.color[3]) / 255); - m_renderSettings.color = c.toRgba(); - } - } catch (JsonException&) { - } catch (ColorException&) { - } - } + applyCommands(escapeCode); escape = false; escapeCode = ""; } |