feat: added fonts
parent
b294a76cc9
commit
ed3e91aead
|
@ -42,6 +42,14 @@ void AssetDB::index_assets() {
|
||||||
} else {
|
} else {
|
||||||
this->assets.insert({name, std::make_shared<Texture>(itr.path())});
|
this->assets.insert({name, std::make_shared<Texture>(itr.path())});
|
||||||
}
|
}
|
||||||
|
} else if(itr.path().extension() == ".ttf") {
|
||||||
|
std::filesystem::path name{itr.path().filename()};
|
||||||
|
name.replace_extension();
|
||||||
|
if(this->assets.contains(name)) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to add asset %s, asset by that name is already indexed", name.c_str());
|
||||||
|
} else {
|
||||||
|
this->assets.insert({name, std::make_shared<Font>(itr.path())});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "core/canvas_engine.hpp"
|
#include "core/canvas_engine.hpp"
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_render.h>
|
#include <SDL2/SDL_render.h>
|
||||||
|
#include <SDL2/SDL_ttf.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
namespace ce {
|
namespace ce {
|
||||||
|
@ -30,4 +31,23 @@ bool Texture::is_loaded() const {
|
||||||
SDL_Texture *Texture::get() {
|
SDL_Texture *Texture::get() {
|
||||||
return this->texture;
|
return this->texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Font::Font(std::filesystem::path const &path) : Asset(path) {}
|
||||||
|
|
||||||
|
Font::~Font() {
|
||||||
|
this->unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Font::load() {
|
||||||
|
this->font = TTF_OpenFont(this->path.c_str(), 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Font::unload() {
|
||||||
|
TTF_CloseFont(this->font);
|
||||||
|
this->font = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Font::is_loaded() const {
|
||||||
|
return this->font != nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
typedef struct SDL_Texture SDL_Texture;
|
typedef struct SDL_Texture SDL_Texture;
|
||||||
|
typedef struct _TTF_Font TTF_Font;
|
||||||
|
|
||||||
namespace ce {
|
namespace ce {
|
||||||
class Asset {
|
class Asset {
|
||||||
|
@ -28,6 +29,17 @@ public:
|
||||||
virtual bool is_loaded() const override;
|
virtual bool is_loaded() const override;
|
||||||
SDL_Texture *get();
|
SDL_Texture *get();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Font : public Asset {
|
||||||
|
TTF_Font *font{nullptr};
|
||||||
|
public:
|
||||||
|
Font(std::filesystem::path const &path);
|
||||||
|
~Font();
|
||||||
|
virtual void load() override;
|
||||||
|
virtual void unload() override;
|
||||||
|
virtual bool is_loaded() const override;
|
||||||
|
TTF_Font *get();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !CANVAS_ASSET_WRAPPER_HPP
|
#endif // !CANVAS_ASSET_WRAPPER_HPP
|
||||||
|
|
Loading…
Reference in New Issue