#pragma once

#include "Atlas.h"
#include "conversion.h"
#include "ofMain.h"
#include "ofQuaternion.h"
#include "ofxMsdfgen.h"
#include <unordered_map>

using namespace msdfgen;

struct AtlasLetter {
    int x, y, w, h;
    glm::vec2 unitRange;
    void draw(const ofImage & image,
              const ofShader & shader){
        shader.setUniform2f("unitRange", unitRange);
        image.drawSubsection(0, 0, w, h, x, y, w, h);
    }
};
struct DrawnLetter {
    glm::vec3 position;
    glm::quat orientation;
};

class ofApp : public ofBaseApp {

    public:
        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y);
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased(int x, int y, int button);
        void mouseEntered(int x, int y);
        void mouseExited(int x, int y);
        void windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);

        ofxMsdfgen::Atlas atlas;
        ofImage atlasImage;
        vector <ofxMsdfgen::GlyphGeometry> glyphGeometries;
        ofShader shader;
        ofEasyCam cam;
        unordered_map <char *, AtlasLetter> atlasLetters;
        std::vector <DrawnLetter> drawnLetters;
        std::vector <int> drawOrder;
};
