JKSV/source/gfxutil.cpp
2025-08-06 19:35:23 -04:00

29 lines
999 B
C++

#include "gfxutil.hpp"
namespace
{
/// @brief Width of generic icons in pixels.
constexpr int SIZE_ICON_WIDTH = 256;
/// @brief Height of generic icons in pixels.
constexpr int SIZE_ICON_HEIGHT = 256;
} // namespace
sdl::SharedTexture gfxutil::create_generic_icon(std::string_view text,
int fontSize,
sdl::Color background,
sdl::Color foreground)
{
// Create base icon texture.
sdl::SharedTexture icon = sdl::TextureManager::create_load_texture(text, 256, 256, SDL_TEXTUREACCESS_TARGET);
// Get the centered X and Y coordinates.
const int textX = (SIZE_ICON_WIDTH / 2) - (sdl::text::get_width(fontSize, text) / 2);
const int textY = (SIZE_ICON_HEIGHT / 2) - (fontSize / 2);
icon->clear(background);
sdl::text::render(icon, textX, textY, fontSize, sdl::text::NO_WRAP, foreground, text);
return icon;
}