Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
2
Indexable
Never
struct Fonts
{
public:
    enum class FontList
    {
        arial,
        adobe_Hebrew,

        max_fonts,
    };
    bool isLoaded[static_cast<int>(FontList::max_fonts)] = {false};

    sf::Font loadFont(FontList fontName)
    {
        std::string fontLocation;

        switch(fontName)
        {
            case FontList::arial:
                fontLocation = "arial.ttf";
                isLoaded[static_cast<int>(FontList::arial)] = true;
                break;
            case FontList::adobe_Hebrew:
                fontLocation = "AdobeHebrew-Regular.otf";
                isLoaded[static_cast<int>(FontList::adobe_Hebrew)] = true;
                break;
            default:
                break;
        }

        static sf::Font font;
        if(!font.loadFromFile(fontLocation))
        {
            cout << "Error: Could not load font.\n";
            exit(-1);
        }
        return font;
    }

    void applyFont(sf::Text &text, const FontList &fontName)
    {
        sf::Font font = loadFont(fontName);
        //if(isLoaded[static_cast<int>(fontName)] = false)
        text.setFont(font);
    }
};