letterDelay for variations

This commit is contained in:
jrkb 2023-04-18 18:05:33 +02:00
parent 24c52521e4
commit 297542abc9
5 changed files with 13 additions and 9 deletions

View file

@ -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;

View file

@ -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;
};
}

View file

@ -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;

View file

@ -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 {

View file

@ -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;