individual letterDelays on cpp side

This commit is contained in:
jrkb 2023-05-16 18:48:34 +02:00
parent 012987c11b
commit 840dbce493
5 changed files with 34 additions and 25 deletions

View file

@ -74,6 +74,7 @@ void GPUFontLayer::setMomsComboIdentifier(const ComboIdentifier & identifier){
void GPUFontLayer::setProps(const Props & props){ void GPUFontLayer::setProps(const Props & props){
OFX_PROFILER_FUNCTION(); OFX_PROFILER_FUNCTION();
delayProps = props;
bool propsBufferEmpty = propsBuffer.size() == 0; bool propsBufferEmpty = propsBuffer.size() == 0;
bool setAppearanceAlready = false; bool setAppearanceAlready = false;
if(propsBufferEmpty || lastProps.text != props.text if(propsBufferEmpty || lastProps.text != props.text
@ -88,7 +89,7 @@ void GPUFontLayer::setProps(const Props & props){
int i = 0; int i = 0;
for(const char c : props.text){ for(const char c : props.text){
OFX_PROFILER_SCOPE("char"); OFX_PROFILER_SCOPE("char");
const Props & vProps = propsBufferEmpty ? props : getProps(i * props.letterDelay); const Props & vProps = propsBufferEmpty ? props : getProps(i);
ofxGPUFont::GlyphIdentity glyphIdentity; ofxGPUFont::GlyphIdentity glyphIdentity;
ofxGPUFont::GlyphAppearance glyphAppearance; ofxGPUFont::GlyphAppearance glyphAppearance;
glyphIdentity.charcode = ofxGPUFont::decodeCharcode(&c); glyphIdentity.charcode = ofxGPUFont::decodeCharcode(&c);
@ -124,7 +125,11 @@ void GPUFontLayer::setProps(const Props & props){
notHappyWithMom = true; 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){ if(maxPropsBufferSize > 0){
propsBuffer.push_front(props); propsBuffer.push_front(props);
} }
@ -133,10 +138,28 @@ void GPUFontLayer::setProps(const Props & props){
} }
lastProps = props; lastProps = props;
} }
const Layer::Props & GPUFontLayer::getProps(float delay_seconds) const { const Layer::Props & GPUFontLayer::getProps(float i){
if(delay_seconds != 0 && propsBuffer.size() > 0){ if(i != 0 && propsBuffer.size() > 0){
int index = max(0, min(int(propsBuffer.size() - 1), int(delay_seconds * settings.letterDelayRatio))); for(const auto & ld : lastProps.letterDelays){
return propsBuffer[index]; // gets newest 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{ }else{
return lastProps; return lastProps;
} }

View file

@ -23,7 +23,7 @@ class GPUFontLayer : public Layer {
float scale = 1, float scale = 1,
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override;
void setProps(const Props & props) 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 clearPropsBuffer() override;
void setId(const LayerID & id) override; void setId(const LayerID & id) override;
const LayerID & getId() override; const LayerID & getId() override;
@ -64,6 +64,7 @@ class GPUFontLayer : public Layer {
private: private:
std::deque <Props> propsBuffer; std::deque <Props> propsBuffer;
Props lastProps; Props lastProps;
Props delayProps;
ComboIdentifier momsComboIdentifier; ComboIdentifier momsComboIdentifier;
bool notHappyWithMom = false; bool notHappyWithMom = false;
LayerType type = GPUFONT; LayerType type = GPUFONT;

View file

@ -48,21 +48,6 @@ class Layer {
std::map <string, float> letterDelays; std::map <string, float> letterDelays;
string text = "abc"; string text = "abc";
string fontPath = "data/celines-fonts/Version-2-var.ttf"; 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 { struct BoundingBox {
float x; float x;
@ -109,7 +94,7 @@ class Layer {
float scale = 1, float scale = 1,
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) = 0; ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) = 0;
virtual void setProps(const Props & props) = 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 clearPropsBuffer() = 0;
virtual void setId(const LayerID & id) = 0; virtual void setId(const LayerID & id) = 0;
virtual const LayerID & getId() = 0; virtual const LayerID & getId() = 0;

View file

@ -329,7 +329,7 @@ void MsdfLayer::setProps(const Props & props){
} }
lastProps = 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){ if(delay_seconds != 0 && propsBuffer.size() > 0){
int index = max(0, min(int(propsBuffer.size() - 1), int(delay_seconds * settings.letterDelayRatio))); int index = max(0, min(int(propsBuffer.size() - 1), int(delay_seconds * settings.letterDelayRatio)));
return propsBuffer[index]; // gets newest return propsBuffer[index]; // gets newest

View file

@ -21,7 +21,7 @@ class MsdfLayer : public Layer {
float scale = 1, float scale = 1,
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override;
void setProps(const Props & props) 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 clearPropsBuffer() override;
void setId(const LayerID & id) override; void setId(const LayerID & id) override;
const LayerID & getId() override; const LayerID & getId() override;