layer combos without children are erased

This commit is contained in:
jrkb 2023-04-18 13:19:28 +02:00
parent 8fe23edc1f
commit e357a7f4a2
6 changed files with 13 additions and 0 deletions

View file

@ -27,6 +27,7 @@ class AtlasLayerCombo {
virtual void setup(const ComboIdentifier & identifier, virtual void setup(const ComboIdentifier & identifier,
AtlasLayerComboSettings settings) = 0; AtlasLayerComboSettings settings) = 0;
virtual void update() = 0; virtual void update() = 0;
virtual bool hasChildren() = 0;
virtual void careForChild(shared_ptr <Layer> layer) = 0; virtual void careForChild(shared_ptr <Layer> layer) = 0;
virtual void abandonChild(shared_ptr <Layer> layer) = 0; virtual void abandonChild(shared_ptr <Layer> layer) = 0;
virtual const ComboIdentifier & getIdentifier() const = 0; virtual const ComboIdentifier & getIdentifier() const = 0;

View file

@ -139,6 +139,9 @@ const ComboIdentifier & GPUFontAtlasLayerCombo::getIdentifier() const {
void GPUFontAtlasLayerCombo::setVFlip(VFlipState vFlipState){ void GPUFontAtlasLayerCombo::setVFlip(VFlipState vFlipState){
vFlip = vFlipState; vFlip = vFlipState;
} }
bool GPUFontAtlasLayerCombo::hasChildren(){
return layers.size() > 0;
}
const vector <shared_ptr <GPUFontLayer> > & GPUFontAtlasLayerCombo::getLayers(){ const vector <shared_ptr <GPUFontLayer> > & GPUFontAtlasLayerCombo::getLayers(){
return layers; return layers;
} }

View file

@ -63,6 +63,7 @@ class GPUFontAtlasLayerCombo : public AtlasLayerCombo {
void abandonChild(shared_ptr <Layer> layer) override; void abandonChild(shared_ptr <Layer> layer) override;
const ComboIdentifier & getIdentifier() const override; const ComboIdentifier & getIdentifier() const override;
void setVFlip(VFlipState vFlipState) override; void setVFlip(VFlipState vFlipState) override;
bool hasChildren() override;
const vector <shared_ptr <GPUFontLayer> > & getLayers(); const vector <shared_ptr <GPUFontLayer> > & getLayers();
void draw(); void draw();

View file

@ -20,6 +20,9 @@ void LayerComposition::update(){
if(l.second->wantsNewMom()){ if(l.second->wantsNewMom()){
const auto momIdentifier = l.second->getMomsComboIdentifier(); const auto momIdentifier = l.second->getMomsComboIdentifier();
atlasLayerCombos[momIdentifier]->abandonChild(l.second); atlasLayerCombos[momIdentifier]->abandonChild(l.second);
if(!atlasLayerCombos[momIdentifier]->hasChildren()){
atlasLayerCombos.erase(momIdentifier);
}
ComboIdentifier idealMom{ ComboIdentifier idealMom{
l.second->getProps().fontPath, l.second->getProps().fontPath,
momIdentifier.type momIdentifier.type

View file

@ -74,6 +74,10 @@ void MsdfAtlasLayerCombo::setVFlip(VFlipState vFlipState){
} }
} }
bool MsdfAtlasLayerCombo::hasChildren(){
return layers.size() > 0;
}
const ofImage & MsdfAtlasLayerCombo::getAtlasImage(){ const ofImage & MsdfAtlasLayerCombo::getAtlasImage(){
return atlas->getAtlasImage(); return atlas->getAtlasImage();
} }

View file

@ -19,6 +19,7 @@ class MsdfAtlasLayerCombo : public AtlasLayerCombo {
void abandonChild(shared_ptr <Layer> layer) override; void abandonChild(shared_ptr <Layer> layer) override;
const ComboIdentifier & getIdentifier() const override; const ComboIdentifier & getIdentifier() const override;
void setVFlip(VFlipState vFlipState) override; void setVFlip(VFlipState vFlipState) override;
bool hasChildren() override;
const ofImage & getAtlasImage(); const ofImage & getAtlasImage();
string getAtlasImagePath(); string getAtlasImagePath();
shared_ptr <Layer> getLayer(); // TODO: is this used shared_ptr <Layer> getLayer(); // TODO: is this used