#pragma once #include "Utils.h" #include "ofMain.h" #include "ofxMsdfgen.h" #include "Layer.h" #include "MsdfLayer.h" #include "Utils.h" #include #include namespace ofxVariableLab { 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) = 0; virtual const ComboIdentifier & getIdentifier() const = 0; bool operator==(const AtlasLayerCombo & other) const { return (this->getIdentifier() == other.getIdentifier()); } }; } namespace std { template <> struct hash { 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 { 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) override; const ComboIdentifier & getIdentifier() const override; shared_ptr atlas; private: vector glyphGeometries; shared_ptr msdfShader; ComboIdentifier identifier; bool isDirty = false; }; class LayerComposition { public: void setup(); void update(); void draw() const; void addLayer(const ComboIdentifier & identifier, const string & text, const std::vector & variations); private: vector > layers; unordered_map > atlasLayerCombos; //unordered_map > layers; }; }