Font: move Glyph to it's own header.
This commit is contained in:
parent
5c4eea4ae1
commit
2dd1187ff2
7 changed files with 31 additions and 19 deletions
|
|
@ -6,9 +6,9 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <Spectre/Math/Vector4.h>
|
|
||||||
#include <Spectre/Math/Vector2.h>
|
#include <Spectre/Math/Vector2.h>
|
||||||
#include <Spectre/Graphics/Texture.h>
|
#include <Spectre/Graphics/Texture.h>
|
||||||
|
#include <Spectre/Graphics/Font/Glyph.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
|
@ -24,16 +24,6 @@ public :
|
||||||
std::string name;
|
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();
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
|
|
|
||||||
21
include/Spectre/Graphics/Font/Glyph.h
Normal file
21
include/Spectre/Graphics/Font/Glyph.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_GRAPHICS_FONT_GLYPH_H
|
||||||
|
#define SPECTRE_GRAPHICS_FONT_GLYPH_H
|
||||||
|
|
||||||
|
#include <Spectre/Math/Vector2.h>
|
||||||
|
#include <Spectre/Graphics/Texture.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
struct Glyph {
|
||||||
|
vec2b size; // Width, Height of bounding box.
|
||||||
|
vec2b offset; // Offset from cursor where the box begins.
|
||||||
|
unsigned char advance;
|
||||||
|
|
||||||
|
vec2u texture_origin;
|
||||||
|
const Texture* texture; // Texture atlas.
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif // SPECTRE_GRAPHICS_FONT_GLYPH_H
|
||||||
|
|
@ -42,7 +42,7 @@ bool Font::loadFromMemory(const void *data)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::Glyph Font::getGlyph(unsigned int code) const
|
Glyph Font::getGlyph(unsigned int code) const
|
||||||
{
|
{
|
||||||
if (m_charset.find(code) == m_charset.end()) {
|
if (m_charset.find(code) == m_charset.end()) {
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ Font::Glyph Font::getGlyph(unsigned int code) const
|
||||||
void Font::loadChar(unsigned char code) const
|
void Font::loadChar(unsigned char code) const
|
||||||
{
|
{
|
||||||
Image img;
|
Image img;
|
||||||
Font::Glyph glyph;
|
Glyph glyph;
|
||||||
|
|
||||||
if (!m_engine) {
|
if (!m_engine) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Spectre/Graphics/Image.h>
|
#include <Spectre/Graphics/Image.h>
|
||||||
|
#include <Spectre/Graphics/Font/Glyph.h>
|
||||||
#include <Spectre/Graphics/Font.h>
|
#include <Spectre/Graphics/Font.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
@ -20,7 +21,7 @@ public :
|
||||||
|
|
||||||
virtual bool loadFromFile(const std::string& filename) = 0;
|
virtual bool loadFromFile(const std::string& filename) = 0;
|
||||||
|
|
||||||
virtual Font::Glyph loadGlyph(unsigned int codepoint, Image& img, unsigned int outlineSize = 0) = 0;
|
virtual Glyph loadGlyph(unsigned int codepoint, Image& img, unsigned int outlineSize = 0) = 0;
|
||||||
|
|
||||||
virtual std::string getName() = 0;
|
virtual std::string getName() = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,9 @@ bool FreeTypeEngine::loadFromFile(const std::string& filename)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::Glyph FreeTypeEngine::loadGlyph(unsigned int codepoint, Image& img, unsigned int outlineSize)
|
Glyph FreeTypeEngine::loadGlyph(unsigned int codepoint, Image& img, unsigned int outlineSize)
|
||||||
{
|
{
|
||||||
Font::Glyph glyph;
|
Glyph glyph;
|
||||||
FT_Glyph glyph_info;
|
FT_Glyph glyph_info;
|
||||||
FT_Int32 flags = FT_LOAD_TARGET_NORMAL;
|
FT_Int32 flags = FT_LOAD_TARGET_NORMAL;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public:
|
||||||
|
|
||||||
virtual bool loadFromFile(const std::string& filename);
|
virtual bool loadFromFile(const std::string& filename);
|
||||||
|
|
||||||
virtual Font::Glyph loadGlyph(unsigned int codepoint, Image& img, unsigned int outlineSize = 0);
|
virtual Glyph loadGlyph(unsigned int codepoint, Image& img, unsigned int outlineSize = 0);
|
||||||
|
|
||||||
virtual std::string getName();
|
virtual std::string getName();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ Vector2f Text::getSize() const
|
||||||
|
|
||||||
for(size_t i = 0; i < m_string.size(); i++) {
|
for(size_t i = 0; i < m_string.size(); i++) {
|
||||||
|
|
||||||
Font::Glyph glyph = m_font->getGlyph(m_string[i]);
|
Glyph glyph = m_font->getGlyph(m_string[i]);
|
||||||
|
|
||||||
float h = glyph.size.y;
|
float h = glyph.size.y;
|
||||||
float w = glyph.advance;
|
float w = glyph.advance;
|
||||||
|
|
@ -142,7 +142,7 @@ void Text::updateGeometry() const
|
||||||
|
|
||||||
Vertex2D v1, v2, v3, v4;
|
Vertex2D v1, v2, v3, v4;
|
||||||
|
|
||||||
Font::Glyph glyph = m_font->getGlyph(m_string[i]);
|
Glyph glyph = m_font->getGlyph(m_string[i]);
|
||||||
|
|
||||||
if (glyph.texture) {
|
if (glyph.texture) {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue