2023-03-25 18:59:58 +01:00
|
|
|
#include "LayerComposition.h"
|
2023-04-06 11:17:22 +02:00
|
|
|
#include "Atlas.h"
|
|
|
|
#include "MsdfLayer.h"
|
2023-04-07 09:48:37 +02:00
|
|
|
#include "Utils.h"
|
2023-03-26 19:42:57 +02:00
|
|
|
#include "ofUtils.h"
|
2023-03-26 21:19:37 +02:00
|
|
|
#include <memory>
|
2023-03-25 18:59:58 +01:00
|
|
|
|
|
|
|
namespace ofxVariableLab {
|
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
void LayerComposition::setup(){
|
2023-04-12 13:59:09 +02:00
|
|
|
auto combo = make_shared <GPUFontAtlasLayerCombo>();
|
|
|
|
ComboIdentifier comboIdentifier = {"lol", Layer::GPUFONT};
|
|
|
|
combo->setup(comboIdentifier);
|
|
|
|
atlasLayerCombos[comboIdentifier] = combo;
|
2023-03-25 18:59:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerComposition::update(){
|
2023-04-06 11:17:22 +02:00
|
|
|
for(const auto & atlasLayerCombo : atlasLayerCombos){
|
|
|
|
atlasLayerCombo.second->update();
|
|
|
|
}
|
2023-03-25 18:59:58 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 16:17:07 +02:00
|
|
|
LayerID LayerComposition::addLayer(const ComboIdentifier & identifier,
|
|
|
|
const string & text,
|
|
|
|
const std::vector <FontVariation> & variations){
|
2023-04-11 12:23:14 +02:00
|
|
|
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){
|
2023-04-07 16:17:07 +02:00
|
|
|
string layerID = "";
|
2023-04-06 11:17:22 +02:00
|
|
|
if(atlasLayerCombos.count(identifier) <= 0){
|
|
|
|
switch(identifier.type){
|
|
|
|
case Layer::GPUFONT: {
|
|
|
|
ofLogError("LayerComposition::addLayer")
|
|
|
|
<< "GPUFont not implemented" << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
case Layer::MSDFGEN: {
|
|
|
|
// TODO: put most stuff in combo setup
|
|
|
|
auto combo = make_shared <MsdfAtlasLayerCombo>();
|
|
|
|
combo->setup(identifier); // TODO: add here text and variations
|
|
|
|
auto layer = make_shared <MsdfLayer>();
|
2023-04-11 13:17:30 +02:00
|
|
|
layer->vFlip = vFlipState;
|
2023-04-06 11:17:22 +02:00
|
|
|
layer->setProps(props);
|
2023-04-07 16:17:07 +02:00
|
|
|
layer->setup();
|
2023-04-06 11:17:22 +02:00
|
|
|
std::vector <ofxMsdfgen::FontVariation> 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);
|
2023-04-07 16:17:07 +02:00
|
|
|
layers[layer->getId()] = layer;
|
2023-04-06 11:17:22 +02:00
|
|
|
atlasLayerCombos[identifier] = std::move(combo);
|
2023-04-07 16:17:07 +02:00
|
|
|
layerID = layer->getId();
|
2023-04-06 11:17:22 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-25 18:59:58 +01:00
|
|
|
}
|
2023-04-07 16:17:07 +02:00
|
|
|
return layerID;
|
|
|
|
}
|
|
|
|
|
|
|
|
shared_ptr <Layer> LayerComposition::getLayer(const LayerID & layerID){
|
|
|
|
return layers[layerID];
|
2023-03-25 18:59:58 +01:00
|
|
|
}
|
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
void LayerComposition::draw() const {
|
|
|
|
for(const auto & layer_it : layers){
|
2023-04-12 13:59:09 +02:00
|
|
|
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 <GPUFontAtlasLayerCombo>(combo_it.second);
|
|
|
|
combo->draw();
|
|
|
|
}
|
2023-04-06 11:17:22 +02:00
|
|
|
}
|
2023-03-25 18:59:58 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 12:23:14 +02:00
|
|
|
const unordered_map <ComboIdentifier, shared_ptr <AtlasLayerCombo> > & LayerComposition::getAtlasLayerCombos() const {
|
|
|
|
return atlasLayerCombos;
|
|
|
|
}
|
|
|
|
|
2023-04-11 13:17:30 +02:00
|
|
|
void LayerComposition::setVFlip(bool vFlip){
|
|
|
|
vFlipState = vFlip ? V_FLIP_ON : V_FLIP_OFF;
|
|
|
|
for(auto & layer : layers){
|
|
|
|
layer.second->setVFlip(vFlipState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-25 18:59:58 +01:00
|
|
|
}
|