From 8205408e1aab380709daf5df7b7b03658d7684c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miha=20Frange=C5=BE?= Date: Fri, 14 Jan 2022 16:12:20 +0100 Subject: [PATCH] Added text typewriter feature --- app/node/generator/text/text.cpp | 26 +++++++++++++++++++++++++- app/node/generator/text/text.h | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/node/generator/text/text.cpp b/app/node/generator/text/text.cpp index 458740523b..c47e47ebb7 100644 --- a/app/node/generator/text/text.cpp +++ b/app/node/generator/text/text.cpp @@ -20,6 +20,8 @@ #include "text.h" +#include "common/clamp.h" +#include "widget/slider/floatslider.h" #include #include #include @@ -47,6 +49,7 @@ const QString TextGenerator::kHtmlInput = QStringLiteral("html_in"); const QString TextGenerator::kVAlignInput = QStringLiteral("valign_in"); const QString TextGenerator::kFontInput = QStringLiteral("font_in"); const QString TextGenerator::kFontSizeInput = QStringLiteral("font_size_in"); +const QString TextGenerator::kTextTypewriterInput = QStringLiteral("text_typewriter_in"); TextGenerator::TextGenerator() { @@ -60,6 +63,12 @@ TextGenerator::TextGenerator() AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f); + AddInput(kTextTypewriterInput, NodeValue::kFloat, 100); + SetInputProperty(kTextTypewriterInput, QStringLiteral("min"), 0.0f); + SetInputProperty(kTextTypewriterInput, QStringLiteral("max"), GetStandardValue(kTextInput).toString().length()); + SetInputProperty(kTextTypewriterInput, QStringLiteral("view"), FloatSlider::kNormal); + SetInputProperty(kTextTypewriterInput, QStringLiteral("decimalplaces"), 0); + SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0))); SetStandardValue(kSizeInput, QVector2D(400, 300)); } @@ -94,6 +103,7 @@ void TextGenerator::Retranslate() SetInputName(kFontSizeInput, tr("Font Size")); SetInputName(kVAlignInput, tr("Vertical Align")); SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")}); + SetInputName(kTextTypewriterInput, tr("Text typewriter progress")); } void TextGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const @@ -136,7 +146,9 @@ void TextGenerator::GenerateFrame(FramePtr frame, const GenerateJob& job) const html.replace('\n', QStringLiteral("
")); text_doc.setHtml(html); } else { - text_doc.setPlainText(html); + int length = clamp(job.GetValue(kTextTypewriterInput).data().toInt(), 0, html.length()); + QString trimmed_text = html.mid(0, length); + text_doc.setPlainText(trimmed_text); } QVector2D size = job.GetValue(kSizeInput).data().value(); @@ -202,4 +214,16 @@ void TextGenerator::GenerateFrame(FramePtr frame, const GenerateJob& job) const } } +void TextGenerator::InputValueChangedEvent(const QString &input, int element) +{ + Q_UNUSED(element) + + if (input == kTextInput) { + SetInputProperty(kTextTypewriterInput, QStringLiteral("max"), GetStandardValue(kTextInput).toString().length()); + } else if (input == kHtmlInput) { + SetInputProperty(kTextTypewriterInput, QStringLiteral("enabled"), ! GetStandardValue(kHtmlInput).toBool()); + } +} + + } diff --git a/app/node/generator/text/text.h b/app/node/generator/text/text.h index d2be75cdea..aeff1edde8 100644 --- a/app/node/generator/text/text.h +++ b/app/node/generator/text/text.h @@ -45,11 +45,14 @@ class TextGenerator : public ShapeNodeBase virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override; + virtual void InputValueChangedEvent(const QString &input, int element); + static const QString kTextInput; static const QString kHtmlInput; static const QString kVAlignInput; static const QString kFontInput; static const QString kFontSizeInput; + static const QString kTextTypewriterInput; };