Change Character postiion/size to uint, add Font size
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "inferno/io/file.h"
|
||||
#include "inferno/render/font.h"
|
||||
#include "inferno/render/texture.h"
|
||||
#include "inferno/util/string.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -24,21 +25,28 @@ namespace Inferno {
|
||||
std::istringstream iss(font);
|
||||
for (std::string line; std::getline(iss, line);) {
|
||||
|
||||
if (findAction(line).compare("char") != 0) {
|
||||
if (findAction(line).compare("info") != 0 &&
|
||||
findAction(line).compare("char") != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::vector<std::string> data = findColumns(line);
|
||||
const std::vector<std::string> columns = findColumns(line);
|
||||
|
||||
unsigned char id = std::stoi(findValue("id", data));
|
||||
unsigned long advance = std::stoul(findValue("xadvance", data));
|
||||
ASSERT(advance <= std::numeric_limits<uint32_t>::max(), "Font file xadvance is not in uint32_t range on line \n'{}'", line);
|
||||
// Info
|
||||
|
||||
if (findAction(line).compare("info") == 0) {
|
||||
m_size = std::stou(findValue("size", columns));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Character
|
||||
|
||||
unsigned char id = std::stoi(findValue("id", columns));
|
||||
Character character = {
|
||||
{ std::stoi(findValue("x", data)), std::stoi(findValue("y", data)) },
|
||||
{ std::stoi(findValue("width", data)), std::stoi(findValue("height", data)) },
|
||||
{ std::stoi(findValue("xoffset", data)), std::stoi(findValue("yoffset", data)) },
|
||||
static_cast<uint32_t>(advance)
|
||||
{ std::stou(findValue("x", columns)), std::stou(findValue("y", columns)) },
|
||||
{ std::stou(findValue("width", columns)), std::stou(findValue("height", columns)) },
|
||||
{ std::stoi(findValue("xoffset", columns)), std::stoi(findValue("yoffset", columns)) },
|
||||
std::stou(findValue("xadvance", columns))
|
||||
};
|
||||
m_characterList.emplace(id, std::make_shared<Character>(character));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include <unordered_map> // std::unordered_map
|
||||
#include <vector> // std::vector
|
||||
|
||||
#include "glm/ext/vector_int2.hpp" // glm::ivec2
|
||||
#include "glm/ext/vector_uint2.hpp" // glm::uvec2
|
||||
#include "glm/ext/vector_int2.hpp" // glm::ivec2
|
||||
|
||||
#include "inferno/io/log.h"
|
||||
|
||||
@@ -16,8 +17,8 @@ namespace Inferno {
|
||||
class Texture;
|
||||
|
||||
struct Character {
|
||||
glm::ivec2 position; // Position
|
||||
glm::ivec2 size; // Width/height
|
||||
glm::uvec2 position; // Position
|
||||
glm::uvec2 size; // Width/height
|
||||
glm::ivec2 offset; // Offset from baseline to left / top of glyph
|
||||
uint32_t advance; // Amount to advance to next glyph
|
||||
};
|
||||
@@ -29,6 +30,7 @@ class Texture;
|
||||
Font(const std::string& name);
|
||||
virtual ~Font() {}
|
||||
|
||||
inline uint32_t size() const { return m_size; }
|
||||
inline const std::shared_ptr<Character>& get(unsigned char c) const { return m_characterList.at(c); }
|
||||
inline const std::shared_ptr<Character>& operator[](unsigned char c) const { return m_characterList.at(c); }
|
||||
|
||||
@@ -41,9 +43,10 @@ class Texture;
|
||||
const std::vector<std::string> findColumns(const std::string& line);
|
||||
const std::string findValue(const std::string& key, const std::vector<std::string>& columns);
|
||||
|
||||
uint32_t m_size;
|
||||
std::unordered_map<unsigned char, std::shared_ptr<Character>> m_characterList;
|
||||
std::string m_name;
|
||||
std::shared_ptr<Texture> m_texture;
|
||||
std::unordered_map<unsigned char, std::shared_ptr<Character>> m_characterList;
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user