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:
parent
452160cd00
commit
1214a1d4a6
4 changed files with 23 additions and 21 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue