2023-03-25 18:59:58 +01:00
|
|
|
#pragma once
|
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
#include "Utils.h"
|
2023-03-25 18:59:58 +01:00
|
|
|
#include "ofMain.h"
|
|
|
|
#include "ofxMsdfgen.h"
|
|
|
|
#include "Layer.h"
|
2023-04-06 11:17:22 +02:00
|
|
|
#include "MsdfLayer.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
#include <type_traits>
|
2023-03-25 18:59:58 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace ofxVariableLab {
|
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
struct ComboIdentifier {
|
|
|
|
std::string fontPath = "data/celines-fonts/Version-2-var.ttf";
|
|
|
|
Layer::Type type = Layer::MSDFGEN;
|
|
|
|
|
|
|
|
bool operator==(const ComboIdentifier & other) const {
|
|
|
|
return (this->fontPath == other.fontPath
|
|
|
|
&& this->type == other.type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class AtlasLayerCombo {
|
|
|
|
public:
|
|
|
|
virtual void setup(const ComboIdentifier & identifier) = 0;
|
|
|
|
virtual void update() = 0;
|
|
|
|
virtual void careForChild(shared_ptr <Layer> layer) = 0;
|
|
|
|
virtual const ComboIdentifier & getIdentifier() const = 0;
|
|
|
|
|
|
|
|
bool operator==(const AtlasLayerCombo & other) const {
|
|
|
|
return (this->getIdentifier() == other.getIdentifier());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct hash <ofxVariableLab::ComboIdentifier> {
|
|
|
|
std::size_t operator()(const ofxVariableLab::ComboIdentifier & k) const {
|
|
|
|
using std::size_t;
|
|
|
|
using std::hash;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
size_t seed = 0;
|
|
|
|
ofxVariableLab::hash_combine(seed, k.fontPath);
|
|
|
|
ofxVariableLab::hash_combine(seed, k.type);
|
|
|
|
|
|
|
|
return seed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct hash <ofxVariableLab::AtlasLayerCombo> {
|
|
|
|
std::size_t operator()(const ofxVariableLab::AtlasLayerCombo & k) const {
|
|
|
|
using std::size_t;
|
|
|
|
using std::hash;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
size_t seed = 0;
|
|
|
|
ofxVariableLab::hash_combine(seed, k.getIdentifier());
|
|
|
|
|
|
|
|
return seed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
namespace ofxVariableLab {
|
|
|
|
|
|
|
|
class MsdfAtlasLayerCombo : public AtlasLayerCombo {
|
|
|
|
public:
|
|
|
|
void setup(const ComboIdentifier & identifier) override;
|
|
|
|
void update() override;
|
|
|
|
void careForChild(shared_ptr <Layer> layer) override;
|
|
|
|
const ComboIdentifier & getIdentifier() const override;
|
|
|
|
shared_ptr <ofxMsdfgen::Atlas> atlas;
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector <ofxMsdfgen::GlyphGeometry> glyphGeometries;
|
|
|
|
shared_ptr <ofShader> msdfShader;
|
|
|
|
ComboIdentifier identifier;
|
|
|
|
bool isDirty = false;
|
|
|
|
};
|
|
|
|
|
2023-03-25 18:59:58 +01:00
|
|
|
class LayerComposition {
|
|
|
|
public:
|
|
|
|
void setup();
|
|
|
|
void update();
|
|
|
|
void draw() const;
|
2023-04-06 11:17:22 +02:00
|
|
|
void addLayer(const ComboIdentifier & identifier,
|
|
|
|
const string & text,
|
|
|
|
const std::vector <FontVariation> & variations);
|
2023-03-25 18:59:58 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2023-04-06 11:17:22 +02:00
|
|
|
vector <shared_ptr <ofxVariableLab::Layer> > layers;
|
|
|
|
unordered_map <ComboIdentifier, shared_ptr <AtlasLayerCombo> > atlasLayerCombos;
|
|
|
|
//unordered_map <LayerIdentifier, shared_ptr <ofxVariableLab::Layer> > layers;
|
2023-03-25 18:59:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|