get atlas image and add layer with props

This commit is contained in:
jrkb 2023-04-11 12:23:14 +02:00
parent 1ed1210d29
commit 9f6fba0281
2 changed files with 46 additions and 3 deletions

View file

@ -54,6 +54,14 @@ const ComboIdentifier & MsdfAtlasLayerCombo::getIdentifier() const {
return identifier;
}
const ofImage & MsdfAtlasLayerCombo::getAtlasImage(){
return atlas->getAtlasImage();
}
string MsdfAtlasLayerCombo::getAtlasImagePath(){
return atlas->getAtlasPath();
}
void LayerComposition::setup(){
}
@ -66,6 +74,17 @@ void LayerComposition::update(){
LayerID LayerComposition::addLayer(const ComboIdentifier & identifier,
const string & text,
const std::vector <FontVariation> & 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 <FontVariation> & variations){
string layerID = "";
if(atlasLayerCombos.count(identifier) <= 0){
switch(identifier.type){
@ -81,9 +100,6 @@ LayerID LayerComposition::addLayer(const ComboIdentifier & identifier,
auto combo = make_shared <MsdfAtlasLayerCombo>();
combo->setup(identifier); // TODO: add here text and variations
auto layer = make_shared <MsdfLayer>();
auto props = Layer::Props();
props.text = text;
props.fontPath = identifier.fontPath;
layer->setProps(props);
layer->setup();
std::vector <ofxMsdfgen::FontVariation> msdfVariations;
@ -107,10 +123,26 @@ shared_ptr <Layer> LayerComposition::getLayer(const LayerID & layerID){
return layers[layerID];
}
const ofImage & LayerComposition::getAtlasImage(const ComboIdentifier & identifier){
return atlasLayerCombos[identifier]->getAtlasImage();
}
void LayerComposition::draw() const {
for(const auto & layer_it : layers){
layer_it.second->draw(glm::vec3(0, 0, 0));
}
}
const std::vector <ComboIdentifier> LayerComposition::getAvailableComboIdentifiers() const {
std::vector <ComboIdentifier> combos;
for(const auto & combo : atlasLayerCombos){
combos.push_back(combo.first);
}
return combos;
}
const unordered_map <ComboIdentifier, shared_ptr <AtlasLayerCombo> > & LayerComposition::getAtlasLayerCombos() const {
return atlasLayerCombos;
}
}

View file

@ -27,6 +27,8 @@ class AtlasLayerCombo {
virtual void update() = 0;
virtual void careForChild(shared_ptr <Layer> layer) = 0;
virtual const ComboIdentifier & getIdentifier() const = 0;
virtual const ofImage & getAtlasImage() = 0;
virtual string getAtlasImagePath() = 0;
bool operator==(const AtlasLayerCombo & other) const {
return (this->getIdentifier() == other.getIdentifier());
@ -70,6 +72,8 @@ class MsdfAtlasLayerCombo : public AtlasLayerCombo {
void update() override;
void careForChild(shared_ptr <Layer> layer) override;
const ComboIdentifier & getIdentifier() const override;
const ofImage & getAtlasImage() override;
string getAtlasImagePath() override;
shared_ptr <Layer> getLayer();
shared_ptr <ofxMsdfgen::Atlas> atlas;
@ -86,10 +90,17 @@ class LayerComposition {
void setup();
void update();
void draw() const;
const ofImage & getAtlasImage(const ComboIdentifier & identifier);
LayerID addLayer(const ComboIdentifier & identifier,
const string & text,
const std::vector <FontVariation> & variations);
LayerID addLayer(const ComboIdentifier & identifier,
const Layer::Props & props,
const std::vector <FontVariation> & variations);
shared_ptr <ofxVariableLab::Layer> getLayer(const LayerID & layerID);
const std::vector <ComboIdentifier> getAvailableComboIdentifiers() const;
const unordered_map <ComboIdentifier, shared_ptr <AtlasLayerCombo> > & getAtlasLayerCombos() const;
private: