From 297542abc9e6213c22cbf40a2406d33e2c8e1ce6 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Tue, 18 Apr 2023 18:05:33 +0200 Subject: [PATCH] letterDelay for variations --- src/GPUFontLayer.cpp | 13 ++++++++----- src/GPUFontLayer.h | 3 ++- src/Layer.h | 2 +- src/MsdfLayer.cpp | 2 +- src/MsdfLayer.h | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/GPUFontLayer.cpp b/src/GPUFontLayer.cpp index 8dda300..102e572 100644 --- a/src/GPUFontLayer.cpp +++ b/src/GPUFontLayer.cpp @@ -74,9 +74,10 @@ void GPUFontLayer::setProps(const Props & props){ for(const char c : props.text){ ofxGPUFont::GlyphIdentity glyphIdentity; glyphIdentity.charcode = ofxGPUFont::decodeCharcode(&c); - for(const auto & fv : props.fontVariations){ + const Props & vProps = getProps(i * props.letterDelay); + for(const auto & fv : vProps.fontVariations){ glyphIdentity.coords.push_back( - std::move(ofxGPUFont::float2f16dot16(round(fv.value))) // convert to FT + std::move(ofxGPUFont::float2f16dot16(round(fv.value * 0.1) * 10)) // convert to FT // NOTE: we are also rounding here, since in practice a variation // of 100.0 will not look much different than 100.124 ); @@ -84,18 +85,20 @@ void GPUFontLayer::setProps(const Props & props){ variationText[i] = std::move(glyphIdentity); i++; } + } if(props.fontPath != propsBuffer[0].fontPath){ notHappyWithMom = true; } - while(propsBuffer.size() > max(0, int(settings.maxBufferSize - 1))){ + while(propsBuffer.size() > max(0, int(props.letterDelay * 30 * props.text.size()))){ propsBuffer.pop_back(); } propsBuffer.push_front(props); } -const Layer::Props & GPUFontLayer::getProps() const { - return propsBuffer[0]; // gets newest +const Layer::Props & GPUFontLayer::getProps(float delay) const { + int index = max(0, min(int(propsBuffer.size() - 1), int(delay * 30))); + return propsBuffer[index]; // gets newest } const glm::vec4 & GPUFontLayer::getColor() const { return color; diff --git a/src/GPUFontLayer.h b/src/GPUFontLayer.h index 3739f7f..6121f14 100644 --- a/src/GPUFontLayer.h +++ b/src/GPUFontLayer.h @@ -22,7 +22,7 @@ class GPUFontLayer : public Layer { float scale = 1, ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; void setProps(const Props & props) override; - const Props & getProps() const override; + const Props & getProps(float delay = 0) const override; const glm::vec4 & getColor() const; void clearPropsBuffer() override; void setId(const LayerID & id) override; @@ -69,5 +69,6 @@ class GPUFontLayer : public Layer { glm::vec4 color; ofNode outerNode; ofNode innerNode; + int letterDelayBufferSize = 0; }; } diff --git a/src/Layer.h b/src/Layer.h index cbc2517..3927502 100644 --- a/src/Layer.h +++ b/src/Layer.h @@ -67,7 +67,7 @@ class Layer { float scale = 1, ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) = 0; virtual void setProps(const Props & props) = 0; - virtual const Props & getProps() const = 0; + virtual const Props & getProps(float delay = 0) const = 0; virtual const glm::vec4 & getColor() const = 0; virtual void clearPropsBuffer() = 0; virtual void setId(const LayerID & id) = 0; diff --git a/src/MsdfLayer.cpp b/src/MsdfLayer.cpp index ea6b863..fa7c5cd 100644 --- a/src/MsdfLayer.cpp +++ b/src/MsdfLayer.cpp @@ -324,7 +324,7 @@ void MsdfLayer::setProps(const Props & props){ } propsBuffer.push_front(props); } -const Layer::Props & MsdfLayer::getProps() const { +const Layer::Props & MsdfLayer::getProps(float delay) const { return propsBuffer[0]; } const glm::vec4 & MsdfLayer::getColor() const { diff --git a/src/MsdfLayer.h b/src/MsdfLayer.h index a25a29e..8ac6c28 100644 --- a/src/MsdfLayer.h +++ b/src/MsdfLayer.h @@ -21,7 +21,7 @@ class MsdfLayer : public Layer { float scale = 1, ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; void setProps(const Props & props) override; - const Props & getProps() const override; + const Props & getProps(float delay = 0) const override; const glm::vec4 & getColor() const; void clearPropsBuffer() override; void setId(const LayerID & id) override;