diff --git a/src/GPUFontLayer.cpp b/src/GPUFontLayer.cpp index 0c8e07e..0b128ee 100644 --- a/src/GPUFontLayer.cpp +++ b/src/GPUFontLayer.cpp @@ -19,12 +19,6 @@ void GPUFontLayer::setup(const LayerSettings & settings){ } void GPUFontLayer::update(){ - if(propsBuffer.size() > 0){ - color = glm::vec4(propsBuffer[0].color[0], - propsBuffer[0].color[1], - propsBuffer[0].color[2], - propsBuffer[0].color[3]); - } } void GPUFontLayer::draw(glm::vec3 position){ @@ -68,8 +62,8 @@ void GPUFontLayer::setProps(const Props & props){ OFX_PROFILER_FUNCTION(); bool propsBufferEmpty = propsBuffer.size() == 0; bool setAppearanceAlready = false; - if(propsBufferEmpty || props.text != propsBuffer[0].text - || propsBuffer[0].fontVariations != props.fontVariations){ + if(propsBufferEmpty || lastProps.text != props.text + || lastProps.fontVariations != props.fontVariations){ setAppearanceAlready = true; OFX_PROFILER_SCOPE("variations"); setDirtyDirty(true); @@ -85,10 +79,7 @@ void GPUFontLayer::setProps(const Props & props){ ofxGPUFont::GlyphAppearance glyphAppearance; glyphIdentity.charcode = ofxGPUFont::decodeCharcode(&c); glyphAppearance.charcode = glyphIdentity.charcode; - glyphAppearance.color.r = vProps.color[0]; - glyphAppearance.color.g = vProps.color[1]; - glyphAppearance.color.b = vProps.color[2]; - glyphAppearance.color.a = vProps.color[3]; + glyphAppearance.color = vProps.color; glyphAppearance.fontSize_px = vProps.fontSize_px; for(const auto & fv : vProps.fontVariations){ glyphIdentity.coords.push_back( @@ -103,34 +94,35 @@ void GPUFontLayer::setProps(const Props & props){ } } if(!setAppearanceAlready - && !propsBufferEmpty - && (propsBuffer[0].fontSize_px != props.fontSize_px - || propsBuffer[0].color != props.color)){ + && (lastProps.fontSize_px != props.fontSize_px + || lastProps.color != props.color)){ for(int i = 0; i < props.text.size(); i++){ - const Props & vProps = getProps(i * props.letterDelay); + const Props & vProps = propsBufferEmpty ? props : getProps(i * props.letterDelay); ofxGPUFont::GlyphAppearance & glyphAppearance = variationTextAppearance[i]; glyphAppearance.fontSize_px = vProps.fontSize_px; - variationTextAppearance[i].color.r = vProps.color[0]; - variationTextAppearance[i].color.g = vProps.color[1]; - variationTextAppearance[i].color.b = vProps.color[2]; - variationTextAppearance[i].color.a = vProps.color[3]; + variationTextAppearance[i].color = vProps.color; } } - if(!propsBufferEmpty && props.fontPath != propsBuffer[0].fontPath){ + if(lastProps.fontPath != props.fontPath){ notHappyWithMom = true; } - while(propsBuffer.size() > max(0, int(props.letterDelay * 30 * props.text.size()))){ + int maxPropsBufferSize = max(0, int(props.letterDelay * settings.letterDelayRatio * props.text.size())); + if(maxPropsBufferSize > 0){ + propsBuffer.push_front(props); + } + while(propsBuffer.size() > maxPropsBufferSize){ propsBuffer.pop_back(); } - propsBuffer.push_front(props); + lastProps = props; } -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; +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 + }else{ + return lastProps; + } } ofNode & GPUFontLayer::getOuterNode(){ return outerNode; diff --git a/src/GPUFontLayer.h b/src/GPUFontLayer.h index 68bb122..192a6a2 100644 --- a/src/GPUFontLayer.h +++ b/src/GPUFontLayer.h @@ -24,7 +24,6 @@ class GPUFontLayer : public Layer { ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; void setProps(const Props & props) override; const Props & getProps(float delay = 0) const override; - const glm::vec4 & getColor() const; void clearPropsBuffer() override; void setId(const LayerID & id) override; const LayerID & getId() override; @@ -61,10 +60,10 @@ class GPUFontLayer : public Layer { private: std::deque propsBuffer; + Props lastProps; ComboIdentifier momsComboIdentifier; bool notHappyWithMom = false; LayerType type = GPUFONT; - glm::vec4 color; ofNode outerNode; ofNode innerNode; int letterDelayBufferSize = 0; diff --git a/src/Layer.h b/src/Layer.h index 9a0b5d1..5b9b235 100644 --- a/src/Layer.h +++ b/src/Layer.h @@ -8,12 +8,13 @@ #include "ofxMsdfgen.h" #include "Utils.h" #include +#include namespace ofxVariableLab { struct LayerSettings { - uint32_t maxBufferSize = 100; VFlipBehaviour vFlipBehaviour = V_FLIP_ONCE_AUTO; + float letterDelayRatio = 30.0f; // }; class Layer { @@ -30,7 +31,7 @@ class Layer { float y = 200; float rotation = 0; float fontSize_px = 42; - std::array color; + std::array color = {0, 0, 0, 1}; bool mirror_x = false; float mirror_x_distance = 0; bool mirror_y = false; @@ -52,11 +53,40 @@ class Layer { //mirror_y, //mirror_y_distance, //letterDelay, + //transformOrigin, //fontVariations, //text, //fontPath) }; + static std::string asString(const ofxVariableLab::Layer::Props & props){ + stringstream s; + s << "asString::props:" << endl + << "\tx:" << ofToString(props.x) << endl + << "\ty:" << ofToString(props.y) << endl + << "\trotation:" << ofToString(props.rotation) << endl + << "\tfontSize_px:" << ofToString(props.fontSize_px) << endl + << "\tcolor: [" + << ofToString(props.color[0]) << "," + << ofToString(props.color[1]) << "," + << ofToString(props.color[2]) << "," + << ofToString(props.color[3]) << "]" + << endl + << "\tmirror_x:" << ofToString(props.mirror_x) << endl + << "\tmirror_x_distance:" << ofToString(props.mirror_x_distance) << endl + << "\tmirror_y:" << ofToString(props.mirror_y) << endl + << "\tmirror_y_distance:" << ofToString(props.mirror_y_distance) << endl + << "\tletterDelay:" << ofToString(props.letterDelay) << endl + << "\ttransformOrigin:" << ofToString(props.transformOrigin) << endl; + for(const auto & fv : props.fontVariations){ + s << "\tfontVariations (" << fv.name << "):" << ofToString(fv.value) << endl; + } + s << "\ttext: " << props.text << endl + << "\tfontPath: " << props.fontPath << endl + ; + return s.str(); + } + virtual void setup(const LayerSettings & settings = LayerSettings()) = 0; virtual void update() = 0; virtual void draw(glm::vec3 position = glm::vec3(0, 0, 0)) = 0; @@ -68,7 +98,6 @@ class Layer { ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) = 0; virtual void setProps(const Props & props) = 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; virtual const LayerID & getId() = 0; diff --git a/src/LayerComposition.cpp b/src/LayerComposition.cpp index ab49e5a..dac066f 100644 --- a/src/LayerComposition.cpp +++ b/src/LayerComposition.cpp @@ -9,10 +9,6 @@ namespace ofxVariableLab { void LayerComposition::setup(){ - //auto combo = make_shared (); - //ComboIdentifier comboIdentifier = {"lol", Layer::GPUFONT}; - //combo->setup(comboIdentifier); - //atlasLayerCombos[comboIdentifier] = combo; } void LayerComposition::update(){ @@ -28,7 +24,7 @@ void LayerComposition::update(){ momIdentifier.type }; cout << "ideal mom looks like this: " << l.second->getProps().fontPath - << (momIdentifier.type == LayerType::GPUFONT ? "gpufont" : "msdfgen") + << (momIdentifier.type == LayerType::GPUFONT ? " gpufont" : " msdfgen") << endl; findOrCreateNewMomForLayer(l.second, idealMom); } diff --git a/src/MsdfLayer.cpp b/src/MsdfLayer.cpp index fa7c5cd..022d211 100644 --- a/src/MsdfLayer.cpp +++ b/src/MsdfLayer.cpp @@ -17,12 +17,6 @@ void MsdfLayer::setup(const LayerSettings & settings){ } void MsdfLayer::update(){ - if(propsBuffer.size() > 0){ - color = glm::vec4(propsBuffer[0].color[0], - propsBuffer[0].color[1], - propsBuffer[0].color[2], - propsBuffer[0].color[3]); - } } void MsdfLayer::draw(glm::vec3 position){ @@ -319,16 +313,23 @@ void MsdfLayer::setProps(const Props & props){ if(propsBuffer.size() == 0 || props.text != propsBuffer[0].text){ setDirtyDirty(true); } - while(propsBuffer.size() > max(0, int(settings.maxBufferSize - 1))){ + int maxPropsBufferSize = max(0, int(props.letterDelay * settings.letterDelayRatio * props.text.size())); + cout << "maxPropsBufferSize: " << ofToString(maxPropsBufferSize) << endl; + if(maxPropsBufferSize > 0){ + propsBuffer.push_front(props); + } + while(propsBuffer.size() > maxPropsBufferSize){ propsBuffer.pop_back(); } - propsBuffer.push_front(props); + lastProps = props; } -const Layer::Props & MsdfLayer::getProps(float delay) const { - return propsBuffer[0]; -} -const glm::vec4 & MsdfLayer::getColor() const { - return color; +const Layer::Props & MsdfLayer::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 + }else{ + return lastProps; + } } void MsdfLayer::clearPropsBuffer(){ propsBuffer.clear(); diff --git a/src/MsdfLayer.h b/src/MsdfLayer.h index 8ac6c28..391fdfb 100644 --- a/src/MsdfLayer.h +++ b/src/MsdfLayer.h @@ -22,7 +22,6 @@ class MsdfLayer : public Layer { ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; void setProps(const Props & props) override; const Props & getProps(float delay = 0) const override; - const glm::vec4 & getColor() const; void clearPropsBuffer() override; void setId(const LayerID & id) override; const LayerID & getId() override; @@ -45,7 +44,6 @@ class MsdfLayer : public Layer { shared_ptr atlas; LayerSettings settings; - std::deque propsBuffer; shared_ptr shader; /// \brief are props updated but not drawn yet bool isDirty = true; @@ -54,10 +52,11 @@ class MsdfLayer : public Layer { VFlipState vFlip = V_FLIP_UNKNOWN; private: + Props lastProps; + std::deque propsBuffer; bool notHappyWithMom = false; ComboIdentifier momsComboIdentifier; LayerType type = MSDFGEN; - glm::vec4 color; ofNode outerNode; ofNode innerNode; };