1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Refactor ITextureSource use in main menu (#16135)

This commit is contained in:
sfan5 2025-05-24 22:49:29 +02:00 committed by GitHub
parent 452160cd00
commit 1214a1d4a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 21 deletions

View file

@ -326,6 +326,18 @@ void ClientLauncher::setting_changed_callback(const std::string &name, void *dat
static_cast<ClientLauncher*>(data)->config_guienv();
}
static video::ITexture *loadTexture(video::IVideoDriver *driver, const char *path)
{
// FIXME?: it would be cleaner to do this through a ITextureSource, but we don't have one
video::ITexture *texture = nullptr;
verbosestream << "Loading texture " << path << std::endl;
if (auto *image = driver->createImageFromFile(path); image) {
texture = driver->addTexture(fs::GetFilenameFromPath(path), image);
image->drop();
}
return texture;
}
void ClientLauncher::config_guienv()
{
gui::IGUISkin *skin = guienv->getSkin();
@ -364,10 +376,9 @@ void ClientLauncher::config_guienv()
if (cached_id != sprite_ids.end()) {
skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, cached_id->second);
} else {
gui::IGUISpriteBank *sprites = skin->getSpriteBank();
video::IVideoDriver *driver = m_rendering_engine->get_video_driver();
video::ITexture *texture = driver->getTexture(path.c_str());
s32 id = sprites->addTextureAsSprite(texture);
auto *driver = m_rendering_engine->get_video_driver();
auto *texture = loadTexture(driver, path.c_str());
s32 id = skin->getSpriteBank()->addTextureAsSprite(texture);
if (id != -1) {
skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, id);
sprite_ids.emplace(path, id);