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 MsdfAtlasLayerCombo::setup(const ComboIdentifier & layerIdentifier){
|
|
|
|
this->identifier = layerIdentifier;
|
|
|
|
ofxMsdfgen::AtlasSettings atlasSettings;
|
2023-03-26 21:19:37 +02:00
|
|
|
//settings.characters = "ABCDEFGHIJKL";
|
2023-04-06 11:17:22 +02:00
|
|
|
atlasSettings.scale = 64;
|
|
|
|
atlasSettings.minimumScale = 64;
|
|
|
|
atlasSettings.characters = "";
|
2023-04-07 09:48:37 +02:00
|
|
|
atlasSettings.maxInterpolationStepSize = 50.0;
|
2023-04-06 11:17:22 +02:00
|
|
|
|
2023-03-25 18:59:58 +01:00
|
|
|
//string fontName = "RobotoFlex.ttf";
|
|
|
|
//string fontPath = "data/fonts/" + fontName;
|
|
|
|
//string fontPath = "data/celines-fonts/testing2VF.ttf";
|
|
|
|
string fontPath = "data/celines-fonts/Version-2-var.ttf";
|
2023-04-06 11:17:22 +02:00
|
|
|
//string fontPath = "data/celines-fonts/Version-2-var.ttf";
|
|
|
|
//string fontPath = "data/celines-fonts/Version-3-var.ttf";
|
|
|
|
//string fontPath = "data/celines-fonts/Version-4-var.ttf";
|
2023-03-28 17:48:18 +02:00
|
|
|
//string fontPath = "data/celines-fonts/Alfarn2.otf";
|
2023-03-25 18:59:58 +01:00
|
|
|
//string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
2023-03-26 21:19:37 +02:00
|
|
|
atlas = make_shared <ofxMsdfgen::Atlas>();
|
2023-03-25 18:59:58 +01:00
|
|
|
|
|
|
|
msdfShader = make_shared <ofShader>();
|
|
|
|
#ifdef TARGET_EMSCRIPTEN
|
2023-03-30 16:22:35 +02:00
|
|
|
msdfShader->load("ofxMsdfgen/shaders/mix/ES3/shader");
|
2023-03-25 18:59:58 +01:00
|
|
|
#else
|
2023-03-30 16:22:35 +02:00
|
|
|
msdfShader->load("ofxMsdfgen/shaders/mix/GL3/shader");
|
2023-03-25 18:59:58 +01:00
|
|
|
#endif
|
|
|
|
|
2023-04-07 09:48:37 +02:00
|
|
|
cout << "settings scale before " << atlasSettings.scale << endl
|
|
|
|
<< "minimum scale before " << atlasSettings.minimumScale << endl;
|
2023-04-06 11:17:22 +02:00
|
|
|
atlas->setup(fontPath, atlasSettings);
|
|
|
|
}
|
2023-03-26 21:19:37 +02:00
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
void MsdfAtlasLayerCombo::update(){
|
|
|
|
if(isDirty){
|
|
|
|
atlas->generate();
|
|
|
|
isDirty = false;
|
|
|
|
}
|
|
|
|
}
|
2023-03-25 18:59:58 +01:00
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
void MsdfAtlasLayerCombo::careForChild(shared_ptr <Layer> layer){
|
|
|
|
shared_ptr <MsdfLayer> msdfLayer = dynamic_pointer_cast <MsdfLayer>(layer);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-26 21:19:37 +02:00
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
const ComboIdentifier & MsdfAtlasLayerCombo::getIdentifier() const {
|
|
|
|
return identifier;
|
|
|
|
}
|
2023-03-29 20:47:48 +02:00
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
void LayerComposition::setup(){
|
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-06 11:17:22 +02:00
|
|
|
void LayerComposition::addLayer(const ComboIdentifier & identifier,
|
|
|
|
const string & text,
|
|
|
|
const std::vector <FontVariation> & variations){
|
|
|
|
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>();
|
|
|
|
auto props = Layer::Props();
|
|
|
|
props.text = text;
|
|
|
|
layer->setProps(props);
|
|
|
|
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);
|
|
|
|
layers.push_back(layer);
|
|
|
|
atlasLayerCombos[identifier] = std::move(combo);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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){
|
|
|
|
layer_it->draw(glm::vec3(0, 0, 0));
|
|
|
|
}
|
2023-03-25 18:59:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|