From 840dbce493d6fe38e82a9a34da8c5ffa77ee2a0b Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Tue, 16 May 2023 18:48:34 +0200 Subject: [PATCH] individual letterDelays on cpp side --- src/GPUFontLayer.cpp | 35 +++++++++++++++++++++++++++++------ src/GPUFontLayer.h | 3 ++- src/Layer.h | 17 +---------------- src/MsdfLayer.cpp | 2 +- src/MsdfLayer.h | 2 +- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/GPUFontLayer.cpp b/src/GPUFontLayer.cpp index 1183122..b0a993c 100644 --- a/src/GPUFontLayer.cpp +++ b/src/GPUFontLayer.cpp @@ -74,6 +74,7 @@ void GPUFontLayer::setMomsComboIdentifier(const ComboIdentifier & identifier){ void GPUFontLayer::setProps(const Props & props){ OFX_PROFILER_FUNCTION(); + delayProps = props; bool propsBufferEmpty = propsBuffer.size() == 0; bool setAppearanceAlready = false; if(propsBufferEmpty || lastProps.text != props.text @@ -88,7 +89,7 @@ void GPUFontLayer::setProps(const Props & props){ int i = 0; for(const char c : props.text){ OFX_PROFILER_SCOPE("char"); - const Props & vProps = propsBufferEmpty ? props : getProps(i * props.letterDelay); + const Props & vProps = propsBufferEmpty ? props : getProps(i); ofxGPUFont::GlyphIdentity glyphIdentity; ofxGPUFont::GlyphAppearance glyphAppearance; glyphIdentity.charcode = ofxGPUFont::decodeCharcode(&c); @@ -124,7 +125,11 @@ void GPUFontLayer::setProps(const Props & props){ notHappyWithMom = true; } - int maxPropsBufferSize = max(0, int(props.letterDelay * settings.letterDelayRatio * props.text.size())); + float maxLetterDelay = 0; + for(const auto & ld : props.letterDelays){ + maxLetterDelay = max(maxLetterDelay, ld.second); + } + int maxPropsBufferSize = max(0, int(maxLetterDelay * settings.letterDelayRatio * props.text.size())); if(maxPropsBufferSize > 0){ propsBuffer.push_front(props); } @@ -133,10 +138,28 @@ void GPUFontLayer::setProps(const Props & props){ } lastProps = props; } -const Layer::Props & GPUFontLayer::getProps(float delay_seconds) const { - if(delay_seconds != 0 && propsBuffer.size() > 0){ - int index = max(0, min(int(propsBuffer.size() - 1), int(delay_seconds * settings.letterDelayRatio))); - return propsBuffer[index]; // gets newest +const Layer::Props & GPUFontLayer::getProps(float i){ + if(i != 0 && propsBuffer.size() > 0){ + for(const auto & ld : lastProps.letterDelays){ + float delay = ld.second; + int index = max(0, min(int(propsBuffer.size() - 1), int(i * delay * settings.letterDelayRatio))); + if(ld.first == "fontSize_px"){ + delayProps.fontSize_px = propsBuffer[index].fontSize_px; + }else if(ld.first == "letterSpacing"){ + delayProps.letterSpacing = propsBuffer[index].letterSpacing; + }else if(ld.first == "color"){ + delayProps.color = propsBuffer[index].color; + }else if(ld.first.rfind("fontVariationAxes_") == 0){ + int fv_i = 0; + for(auto & fv : delayProps.fontVariations){ + if(ld.first.rfind(fv.name) == 18){ + fv.value = propsBuffer[index].fontVariations[fv_i].value; + } + fv_i++; + } + } + } + return delayProps; }else{ return lastProps; } diff --git a/src/GPUFontLayer.h b/src/GPUFontLayer.h index dd38df3..c19278e 100644 --- a/src/GPUFontLayer.h +++ b/src/GPUFontLayer.h @@ -23,7 +23,7 @@ class GPUFontLayer : public Layer { float scale = 1, ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; void setProps(const Props & props) override; - const Props & getProps(float delay = 0) const override; + const Props & getProps(float delay = 0) override; void clearPropsBuffer() override; void setId(const LayerID & id) override; const LayerID & getId() override; @@ -64,6 +64,7 @@ class GPUFontLayer : public Layer { private: std::deque propsBuffer; Props lastProps; + Props delayProps; ComboIdentifier momsComboIdentifier; bool notHappyWithMom = false; LayerType type = GPUFONT; diff --git a/src/Layer.h b/src/Layer.h index ce9d838..8a95257 100644 --- a/src/Layer.h +++ b/src/Layer.h @@ -48,21 +48,6 @@ class Layer { std::map letterDelays; string text = "abc"; string fontPath = "data/celines-fonts/Version-2-var.ttf"; - //NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Props, - //x, - //y, - //rotation, - //fontSize_px, - //color, - //mirror_x, - //mirror_x_distance, - //mirror_y, - //mirror_y_distance, - //letterDelay, - //transformOrigin, - //fontVariations, - //text, - //fontPath) }; struct BoundingBox { float x; @@ -109,7 +94,7 @@ class Layer { float scale = 1, ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) = 0; virtual void setProps(const Props & props) = 0; - virtual const Props & getProps(float delay = 0) const = 0; + virtual const Props & getProps(float delay = 0) = 0; virtual void clearPropsBuffer() = 0; virtual void setId(const LayerID & id) = 0; virtual const LayerID & getId() = 0; diff --git a/src/MsdfLayer.cpp b/src/MsdfLayer.cpp index d39d626..79d4e9b 100644 --- a/src/MsdfLayer.cpp +++ b/src/MsdfLayer.cpp @@ -329,7 +329,7 @@ void MsdfLayer::setProps(const Props & props){ } lastProps = props; } -const Layer::Props & MsdfLayer::getProps(float delay_seconds) const { +const Layer::Props & MsdfLayer::getProps(float delay_seconds){ if(delay_seconds != 0 && propsBuffer.size() > 0){ int index = max(0, min(int(propsBuffer.size() - 1), int(delay_seconds * settings.letterDelayRatio))); return propsBuffer[index]; // gets newest diff --git a/src/MsdfLayer.h b/src/MsdfLayer.h index 7265bd4..8b9d917 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(float delay = 0) const override; + const Props & getProps(float delay = 0) override; void clearPropsBuffer() override; void setId(const LayerID & id) override; const LayerID & getId() override;