adding multiple font support

This commit is contained in:
Kbz-8
2023-12-14 19:13:41 +01:00
parent c013237219
commit d08a97f55c
20 changed files with 131 additions and 86 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 21:17:04 by kbz_8 #+# #+# */
/* Updated: 2023/12/13 00:25:30 by kbz_8 ### ########.fr */
/* Updated: 2023/12/14 17:51:40 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,24 +17,29 @@
#include <stb_truetype.h>
#include <utils/non_copyable.h>
#include <renderer/images/texture_atlas.h>
#include <utils/combine_hash.h>
namespace mlx
{
class Font : public non_copyable
{
public:
Font() = delete;
Font(class Renderer& renderer, const std::filesystem::path& path, float scale);
Font(class Renderer& renderer, const std::string& name, const std::vector<uint8_t>& ttf_data, float scale);
inline const std::string& getName() const { return _name; }
inline float getScale() const noexcept { return _scale; }
inline const std::array<stbtt_packedchar, 96>& getCharData() const { return _cdata; }
inline VkDescriptorSet getDescriptorSet() noexcept { return _atlas.getSet(); }
inline bool operator==(const Font& rhs) { return rhs._name == _name; }
inline const TextureAtlas& getAtlas() const noexcept { return _atlas; }
inline bool operator==(const Font& rhs) const { return rhs._name == _name; }
inline bool operator!=(const Font& rhs) const { return rhs._name != _name; }
~Font();
private:
std::array<stbtt_packedchar, 96> _cdata;
TextureAtlas _atlas;
std::string _name;
float _scale = 0;
};
}
@@ -45,7 +50,9 @@ namespace std
{
std::size_t operator()(const mlx::Font& f) const noexcept
{
return std::hash<std::string>()(f.getName());
std::size_t hash = 0;
mlx::hashCombine(hash, f.getName(), f.getScale());
return hash;
}
};
}