74 lines
1.3 KiB
C++
74 lines
1.3 KiB
C++
|
|
#ifndef SPECTRE_GRAPHCIS_FONT_H
|
|
#define SPECTRE_GRAPHCIS_FONT_H
|
|
|
|
#include <map>
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
#include <Spectre/Math/Vector4.h>
|
|
#include <Spectre/Math/Vector2.h>
|
|
#include <Spectre/Graphics/Texture.h>
|
|
|
|
class FontDriver;
|
|
|
|
// TODO: Fixup this api :)
|
|
|
|
class Font
|
|
{
|
|
public :
|
|
|
|
struct Info {
|
|
std::string name;
|
|
};
|
|
|
|
struct Glyph {
|
|
vec2b size; // Width, Height of bounding box.
|
|
vec2b offset; // Offset from cursor where the box begins.
|
|
unsigned char advance;
|
|
|
|
//vec4u tex_coords;
|
|
vec2u texture_origin;
|
|
const Texture* texture; // Texture atlas.
|
|
};
|
|
|
|
Font();
|
|
~Font();
|
|
|
|
bool loadFromFile(const std::string& filename, unsigned int size = 22);
|
|
|
|
bool loadFromMemory(const void *data, unsigned int size);
|
|
|
|
Glyph getGlyph(unsigned int code) const;
|
|
|
|
const Texture* getTexture() const;
|
|
|
|
protected :
|
|
|
|
bool loadData();
|
|
|
|
void loadChar(unsigned char code) const;
|
|
|
|
void createTexture();
|
|
|
|
void resizeTexture() const;
|
|
|
|
Vector2u findTextureRegion(const Image& img) const;
|
|
|
|
protected :
|
|
|
|
FontDriver *m_driver;
|
|
|
|
mutable std::map<unsigned char, Glyph> m_charset;
|
|
|
|
unsigned int m_size; // font size, in pixels. not points.
|
|
|
|
// Texture atlas used by the font.
|
|
mutable Texture m_texture;
|
|
mutable vec2u m_texpos;
|
|
mutable unsigned m_shelf;
|
|
|
|
std::vector<unsigned char> m_rawData;
|
|
};
|
|
|
|
#endif /* SPECTRE_GRAPHCIS_FONT_H */
|