ofxVariableLab/src/MsdfAtlasLayerCombo.cpp

84 lines
2.5 KiB
C++

#include "MsdfAtlasLayerCombo.h"
#include "AtlasLayerCombo.h"
#include "Utils.h"
namespace ofxVariableLab {
void MsdfAtlasLayerCombo::setup(const ComboIdentifier & layerIdentifier,
AtlasLayerComboSettings settings){
this->identifier = layerIdentifier;
this->settings = static_cast <MsdfAtlasLayerComboSettings &>(settings);
ofxMsdfgen::AtlasSettings atlasSettings;
//settings.characters = "ABCDEFGHIJKL";
atlasSettings.scale = this->settings.scale;
atlasSettings.minimumScale = this->settings.minimumScale;
atlasSettings.characters = "";
atlasSettings.maxInterpolationStepSize = this->settings.maxInterpolationStepSize;
atlas = make_shared <ofxMsdfgen::Atlas>();
msdfShader = make_shared <ofShader>();
#ifdef TARGET_EMSCRIPTEN
msdfShader->load("ofxMsdfgen/shaders/mix/ES3/shader");
#else
msdfShader->load("ofxMsdfgen/shaders/mix/GL3/shader");
#endif
atlas->setup(this->identifier.fontPath, atlasSettings);
}
void MsdfAtlasLayerCombo::update(){
if(isDirty){
atlas->generate();
isDirty = false;
}
}
void MsdfAtlasLayerCombo::careForChild(shared_ptr <Layer> layer){
shared_ptr <MsdfLayer> msdfLayer = dynamic_pointer_cast <MsdfLayer>(layer);
msdfLayer->setMomsComboIdentifier(identifier);
msdfLayer->isWithNewMom();
msdfLayer->setDirtyDirty(true);
msdfLayer->setAtlas(this->atlas);
msdfLayer->setShader(msdfShader);
auto & as = atlas->settings;
for(const char c : layer->getProps().text){
if(as.characters.find(c) == std::string::npos){
// not found
as.characters += c;
isDirty = true;
}
}
layers.push_back(std::move(msdfLayer));
}
void MsdfAtlasLayerCombo::abandonChild(shared_ptr <Layer> layer){
shared_ptr <MsdfLayer> msdfLayer = dynamic_pointer_cast <MsdfLayer>(layer);
layers.erase(
std::remove_if(
layers.begin(),
layers.end(),
[msdfLayer](shared_ptr <MsdfLayer> const & l)
{
return l == msdfLayer;
}), layers.end());
}
const ComboIdentifier & MsdfAtlasLayerCombo::getIdentifier() const {
return identifier;
}
void MsdfAtlasLayerCombo::setVFlip(VFlipState vFlipState){
vFlip = vFlipState;
for(const auto & layer : layers){
layer->setVFlip(vFlip);
}
}
const ofImage & MsdfAtlasLayerCombo::getAtlasImage(){
return atlas->getAtlasImage();
}
string MsdfAtlasLayerCombo::getAtlasImagePath(){
return atlas->getAtlasPath();
}
}