/**
 * @file Font.h
 * @author Petr Egert (egertpet@fel.cvut.cz)
 * @brief Contains Font class declaration
 */

#ifndef FONT_H
#define FONT_H

#include "Vector.h"
#include "Error.h"

#include <string>

namespace RD
{
    /**
     * @brief Class used to load bitmap fonts in BFF format and use them to render text in OpenGL
     *
     * Fonts in BFF format can be generated using the freely available CodeHead's Bitmap Font Generator (http://www.codehead.co.uk/cbfg/)
     */
    class Font
    {
        public:
            ///Default constructor, sets the font oolor to white
            Font() : color(1.0, 1.0, 1.0){};

            ///Default destructor, currently does nothing
            ~Font(){};

            Result Init(const char *fileName);
            Result Release();

            void DrawString(const std::string &text);

            vec3 color;     ///< Font color (RGB, 0.0 - 1.0 scale)

        protected:

        private:
            ///Structure representing information contained in BFF file header
            struct FontHeader
            {
                unsigned short id;          ///< File ID (must be 0xF2BF)
                int imgWidth;               ///< Total width of the font image in pixels
                int imgHeight;              ///< Total height of the font image in pixels
                int cellWidth;              ///< Width of a single character cell in pixels
                int cellHeight;             ///< Height of a single character cell in pixels
                unsigned char bpp;          ///< Image bits per pixel (8, 24 or 32)
                unsigned char startChar;    ///< Code of the character, which the first cell in the image represents
            };

            Result Load(const char *fileName);

            FontHeader header;      ///< BFF file header

            int cellsPerRow;        ///< Number of cells per image row
            float cellWidth;        ///< Width of a single cell in 0.0-1.0 range
            float cellHeight;       ///< Height of a single cell in 0.0-1.0 range

            float widths[255];      ///< Real width of individual glyphs
            unsigned int texID;     ///< OpenGL texture id of the font image
    };
}

#endif // FONT_H

