4#include <SDL3_image/SDL_image.h>
5#include <unordered_map>
20 std::size_t seed = std::hash<asw::Font> {}(key.
font);
21 seed ^= std::hash<std::string> {}(key.
text) + 0x9e3779b9 + ((seed << 6) + (seed >> 2));
33 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Error", message.c_str(),
nullptr);
40 SDL_GetTextureSize(tex.get(), &size.
x, &size.
y);
46 if (font ==
nullptr) {
50 const TextSizeCacheKey cache_key { font, text };
55 TTF_Text* ttf_text = TTF_CreateText(
nullptr, font.get(), text.c_str(), 0);
57 TTF_GetTextSize(ttf_text, &size.
x, &size.
y);
58 TTF_DestroyText(ttf_text);
T y
The y component of the vector.
T x
The x component of the vector.
Structured logging system.
constexpr std::size_t TEXT_SIZE_CACHE_LIMIT
std::unordered_map< TextSizeCacheKey, asw::Vec2< int >, TextSizeCacheKeyHash > text_size_cache
void error(const std::string &message)
Log an error message.
void clear_text_size_cache()
Clear cached text metrics.
asw::Vec2< float > get_texture_size(const asw::Texture &tex)
Get texture size.
asw::Vec2< int > get_text_size(const asw::Font &font, const std::string &text)
Get text size.
void abort_on_error(const std::string &message)
Abort program and display error message.
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
std::size_t operator()(const TextSizeCacheKey &key) const
bool operator==(const TextSizeCacheKey &) const =default
General utility functions.