#include "LayerComposition.h" #include "Atlas.h" #include "GPUFontAtlasLayerCombo.h" #include "MsdfLayer.h" #include "Utils.h" #include "ofUtils.h" #include namespace ofxVariableLab { void LayerComposition::setup(){ //auto combo = make_shared (); //ComboIdentifier comboIdentifier = {"lol", Layer::GPUFONT}; //combo->setup(comboIdentifier); //atlasLayerCombos[comboIdentifier] = combo; } void LayerComposition::update(){ for(const auto & atlasLayerCombo : atlasLayerCombos){ atlasLayerCombo.second->update(); } } LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, const string & text, const std::vector & variations){ auto props = Layer::Props(); props.text = text; props.fontPath = identifier.fontPath; return addLayer(identifier, props, variations); } LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, const Layer::Props & props, const std::vector & variations){ string layerID = ""; switch(identifier.type){ case Layer::GPUFONT: { shared_ptr combo; auto comboIterator = atlasLayerCombos.find(identifier); if(comboIterator == atlasLayerCombos.end()){ // we don't have one yet // so let's create it combo = make_shared (); GPUFontAtlasLayerComboSettings settings; settings.gpuTextureOffset = nextGpuTextureOffset; combo->setup(identifier, settings); nextGpuTextureOffset++; atlasLayerCombos[identifier] = combo; }else{ // use existing combo combo = dynamic_pointer_cast (comboIterator->second); } auto layer = make_shared (); layer->setProps(props); combo->careForChild(layer); layerID = layer->getId(); layers[layerID] = layer; break; } default: case Layer::MSDFGEN: { // TODO: put most stuff in combo setup auto combo = make_shared (); combo->setup(identifier); // TODO: add here text and variations auto layer = make_shared (); layer->vFlip = vFlipState; layer->setProps(props); layer->setup(); std::vector msdfVariations; for(const auto & v : variations){ msdfVariations.push_back({v.name, v.value}); } // TODO: do not add Variation to atlas, but to combo, // so we know it's dirty combo->atlas->addVariations(msdfVariations); combo->careForChild(layer); layers[layer->getId()] = layer; atlasLayerCombos[identifier] = std::move(combo); layerID = layer->getId(); } } return layerID; } void LayerComposition::removeLayer(const LayerID & id){ auto layer = getLayer(id); for(auto & it : atlasLayerCombos){ it.second->abandonChild(layer); } layers.erase(id); } shared_ptr LayerComposition::getLayer(const LayerID & layerID){ return layers[layerID]; } void LayerComposition::draw() const { for(const auto & layer_it : layers){ if(layer_it.second->getType() == Layer::MSDFGEN){ layer_it.second->draw(glm::vec3(200, 200, 0)); } } for(const auto & combo_it : atlasLayerCombos){ if(combo_it.first.type == Layer::GPUFONT){ auto combo = static_pointer_cast (combo_it.second); combo->draw(); } } } const unordered_map > & LayerComposition::getAtlasLayerCombos() const { return atlasLayerCombos; } void LayerComposition::setVFlip(bool vFlip){ vFlipState = vFlip ? V_FLIP_ON : V_FLIP_OFF; for(auto & layer : layers){ layer.second->setVFlip(vFlipState); } for(const auto & combo_it : atlasLayerCombos){ combo_it.second->setVFlip(vFlipState); } } }