Skip to content

Commit

Permalink
fix: Texture loading from romfs
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Aug 26, 2023
1 parent 32e05cc commit 550392c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
2 changes: 2 additions & 0 deletions lib/libimhex/include/hex/ui/imgui_imhex_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include <hex.hpp>

#include <cstddef>
#include <functional>
#include <string>
#include <span>

#include <imgui.h>
#include <imgui_internal.h>
Expand Down
6 changes: 2 additions & 4 deletions main/source/init/splash_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ namespace hex::init {

bool WindowSplash::loop() {
// Load splash screen image from romfs
auto splashBackground = romfs::get("splash_background.png");
auto splashText = romfs::get("splash_text.png");
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());
ImGui::Texture splashBackgroundTexture = ImGui::Texture(romfs::get("splash_background.png").span());
ImGui::Texture splashTextTexture = ImGui::Texture(romfs::get("splash_text.png").span());

// 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.
Expand Down
3 changes: 1 addition & 2 deletions main/source/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ namespace hex {
this->setupNativeWindow();
this->registerEventHandlers();

auto logoData = romfs::get("logo.png");
this->m_logoTexture = ImGui::Texture(reinterpret_cast<const ImU8 *>(logoData.data()), logoData.size());
this->m_logoTexture = ImGui::Texture(romfs::get("logo.png").span());

ContentRegistry::Settings::impl::store();
EventManager::post<EventSettingsChanged>();
Expand Down
5 changes: 1 addition & 4 deletions plugins/builtin/source/content/pl_visualizers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,7 @@ namespace hex::plugin::builtin {
static std::mutex addressMutex;
static TaskHolder addressTask;

static auto mapTexture = [] {
auto image = romfs::get("assets/common/map.jpg");
return ImGui::Texture(reinterpret_cast<const ImU8 *>(image.data()), image.size());
}();
static auto mapTexture = ImGui::Texture(romfs::get("assets/common/map.jpg").span());
static ImVec2 mapSize = scaled(ImVec2(500, 500 / mapTexture.getAspectRatio()));

if (shouldReset) {
Expand Down
5 changes: 3 additions & 2 deletions plugins/builtin/source/content/views/view_about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, [] {
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) {
Expand Down Expand Up @@ -63,6 +61,9 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();

// 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::TableNextColumn();

Expand Down
4 changes: 1 addition & 3 deletions plugins/builtin/source/content/welcome_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,7 @@ namespace hex::plugin::builtin {

(void)EventManager::subscribe<RequestChangeTheme>([](const std::string &theme) {
auto changeTexture = [&](const std::string &path) {
auto textureData = romfs::get(path);

return ImGui::Texture(reinterpret_cast<const ImU8*>(textureData.data()), textureData.size());
return ImGui::Texture(romfs::get(path).span());
};

ThemeManager::changeTheme(theme);
Expand Down

0 comments on commit 550392c

Please sign in to comment.