1
0
mirror of synced 2025-01-31 03:53:44 +01:00

fix: Texture loading from romfs

This commit is contained in:
WerWolv 2023-08-26 23:43:35 +02:00
parent 32e05cc62f
commit 550392c8d6
6 changed files with 10 additions and 15 deletions

View File

@ -2,8 +2,10 @@
#include <hex.hpp> #include <hex.hpp>
#include <cstddef>
#include <functional> #include <functional>
#include <string> #include <string>
#include <span>
#include <imgui.h> #include <imgui.h>
#include <imgui_internal.h> #include <imgui_internal.h>

View File

@ -113,10 +113,8 @@ namespace hex::init {
bool WindowSplash::loop() { bool WindowSplash::loop() {
// Load splash screen image from romfs // Load splash screen image from romfs
auto splashBackground = romfs::get("splash_background.png"); ImGui::Texture splashBackgroundTexture = ImGui::Texture(romfs::get("splash_background.png").span());
auto splashText = romfs::get("splash_text.png"); ImGui::Texture splashTextTexture = ImGui::Texture(romfs::get("splash_text.png").span());
ImGui::Texture splashBackgroundTexture = ImGui::Texture(reinterpret_cast<const ImU8 *>(splashBackground.data()), splashBackground.size());
ImGui::Texture splashTextTexture = ImGui::Texture(reinterpret_cast<const ImU8 *>(splashText.data()), splashText.size());
// If the image couldn't be loaded correctly, something went wrong during the build process // If the image couldn't be loaded correctly, something went wrong during the build process
// Close the application since this would lead to errors later on anyway. // Close the application since this would lead to errors later on anyway.

View File

@ -85,8 +85,7 @@ namespace hex {
this->setupNativeWindow(); this->setupNativeWindow();
this->registerEventHandlers(); this->registerEventHandlers();
auto logoData = romfs::get("logo.png"); this->m_logoTexture = ImGui::Texture(romfs::get("logo.png").span());
this->m_logoTexture = ImGui::Texture(reinterpret_cast<const ImU8 *>(logoData.data()), logoData.size());
ContentRegistry::Settings::impl::store(); ContentRegistry::Settings::impl::store();
EventManager::post<EventSettingsChanged>(); EventManager::post<EventSettingsChanged>();

View File

@ -527,10 +527,7 @@ namespace hex::plugin::builtin {
static std::mutex addressMutex; static std::mutex addressMutex;
static TaskHolder addressTask; static TaskHolder addressTask;
static auto mapTexture = [] { static auto mapTexture = ImGui::Texture(romfs::get("assets/common/map.jpg").span());
auto image = romfs::get("assets/common/map.jpg");
return ImGui::Texture(reinterpret_cast<const ImU8 *>(image.data()), image.size());
}();
static ImVec2 mapSize = scaled(ImVec2(500, 500 / mapTexture.getAspectRatio())); static ImVec2 mapSize = scaled(ImVec2(500, 500 / mapTexture.getAspectRatio()));
if (shouldReset) { if (shouldReset) {

View File

@ -33,8 +33,6 @@ namespace hex::plugin::builtin {
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.help", "hex.builtin.menu.help.ask_for_help" }, 4000, CTRLCMD + SHIFT + Keys::D, [] { ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.help", "hex.builtin.menu.help.ask_for_help" }, 4000, CTRLCMD + SHIFT + Keys::D, [] {
PopupDocsQuestion::open(); PopupDocsQuestion::open();
}); });
this->m_logoTexture = ImGui::Texture(romfs::get("assets/common/logo.png").span());
} }
static void link(const std::string &name, const std::string &author, const std::string &url) { static void link(const std::string &name, const std::string &author, const std::string &url) {
@ -63,6 +61,9 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
// Draw the ImHex icon // Draw the ImHex icon
if (!this->m_logoTexture.isValid())
this->m_logoTexture = ImGui::Texture(romfs::get("assets/common/logo.png").span());
ImGui::Image(this->m_logoTexture, scaled({ 64, 64 })); ImGui::Image(this->m_logoTexture, scaled({ 64, 64 }));
ImGui::TableNextColumn(); ImGui::TableNextColumn();

View File

@ -422,9 +422,7 @@ namespace hex::plugin::builtin {
(void)EventManager::subscribe<RequestChangeTheme>([](const std::string &theme) { (void)EventManager::subscribe<RequestChangeTheme>([](const std::string &theme) {
auto changeTexture = [&](const std::string &path) { auto changeTexture = [&](const std::string &path) {
auto textureData = romfs::get(path); return ImGui::Texture(romfs::get(path).span());
return ImGui::Texture(reinterpret_cast<const ImU8*>(textureData.data()), textureData.size());
}; };
ThemeManager::changeTheme(theme); ThemeManager::changeTheme(theme);