From ed5810e20531b859a09788af80a240d80387385e Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Tue, 15 May 2018 16:47:15 -0500 Subject: [PATCH] [Qt] Set application icon from the game --- src/xenia/app/emulator_window.cc | 13 +++++++++++++ src/xenia/emulator.cc | 12 ++++-------- src/xenia/emulator.h | 13 ++++++++++++- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/xenia/app/emulator_window.cc b/src/xenia/app/emulator_window.cc index 75b364b16..ca4217b80 100644 --- a/src/xenia/app/emulator_window.cc +++ b/src/xenia/app/emulator_window.cc @@ -136,6 +136,19 @@ EmulatorWindow::EmulatorWindow() { if (!InitializeVulkan()) { return; } + + // Set a callback on launch + emulator_->on_launch.AddListener([this]() { + auto title_db = this->emulator()->game_data(); + if (title_db) { + QPixmap p; + auto icon_block = title_db->icon(); + if (icon_block.buffer && + p.loadFromData(icon_block.buffer, uint(icon_block.size), "PNG")) { + this->setWindowIcon(QIcon(p)); + } + } + }); } bool EmulatorWindow::InitializeVulkan() { diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index 83130da4a..b64d2b2a5 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -49,7 +49,7 @@ DEFINE_double(time_scalar, 1.0, namespace xe { Emulator::Emulator(const std::wstring& command_line) - : command_line_(command_line) {} + : command_line_(command_line), title_data_(nullptr, 0) {} Emulator::~Emulator() { // Note that we delete things in the reverse order they were initialized. @@ -597,14 +597,10 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path, uint32_t resource_size = 0; if (XSUCCEEDED( module->GetSection(title_id, &resource_data, &resource_size))) { - kernel::util::XdbfGameData db( + title_data_ = kernel::util::XdbfGameData( module->memory()->TranslateVirtual(resource_data), resource_size); - if (db.is_valid()) { - game_title_ = xe::to_wstring(db.title()); - auto icon_block = db.icon(); - if (icon_block) { - // display_window_->SetIcon(icon_block.buffer, icon_block.size); - } + if (title_data_.is_valid()) { + game_title_ = xe::to_wstring(title_data_.title()); } } } diff --git a/src/xenia/emulator.h b/src/xenia/emulator.h index c04ce89a9..e5861b008 100644 --- a/src/xenia/emulator.h +++ b/src/xenia/emulator.h @@ -16,6 +16,7 @@ #include "xenia/base/delegate.h" #include "xenia/base/exception_handler.h" #include "xenia/kernel/kernel_state.h" +#include "xenia/kernel/util/xdbf_utils.h" #include "xenia/memory.h" #include "xenia/vfs/virtual_file_system.h" #include "xenia/xbox.h" @@ -92,6 +93,15 @@ class Emulator { // This is effectively the guest operating system. kernel::KernelState* kernel_state() const { return kernel_state_.get(); } + // Get the database with information about the running game. + const kernel::util::XdbfGameData* game_data() const { + if (title_data_.is_valid()) { + return &title_data_; + } + + return nullptr; + } + // Initializes the emulator and configures all components. // The given window is used for display and the provided functions are used // to create subsystems as required. @@ -166,7 +176,8 @@ class Emulator { std::unique_ptr kernel_state_; threading::Thread* main_thread_ = nullptr; - uint32_t title_id_ = 0; // Currently running title ID + kernel::util::XdbfGameData title_data_; // Currently running title DB + uint32_t title_id_ = 0; // Currently running title ID bool paused_ = false; bool restoring_ = false;