[Qt] Set application icon from the game

This commit is contained in:
Dr. Chat 2018-05-15 16:47:15 -05:00
parent b56296007c
commit ed5810e205
3 changed files with 29 additions and 9 deletions

View File

@ -136,6 +136,19 @@ EmulatorWindow::EmulatorWindow() {
if (!InitializeVulkan()) { if (!InitializeVulkan()) {
return; 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() { bool EmulatorWindow::InitializeVulkan() {

View File

@ -49,7 +49,7 @@ DEFINE_double(time_scalar, 1.0,
namespace xe { namespace xe {
Emulator::Emulator(const std::wstring& command_line) Emulator::Emulator(const std::wstring& command_line)
: command_line_(command_line) {} : command_line_(command_line), title_data_(nullptr, 0) {}
Emulator::~Emulator() { Emulator::~Emulator() {
// Note that we delete things in the reverse order they were initialized. // 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; uint32_t resource_size = 0;
if (XSUCCEEDED( if (XSUCCEEDED(
module->GetSection(title_id, &resource_data, &resource_size))) { module->GetSection(title_id, &resource_data, &resource_size))) {
kernel::util::XdbfGameData db( title_data_ = kernel::util::XdbfGameData(
module->memory()->TranslateVirtual(resource_data), resource_size); module->memory()->TranslateVirtual(resource_data), resource_size);
if (db.is_valid()) { if (title_data_.is_valid()) {
game_title_ = xe::to_wstring(db.title()); game_title_ = xe::to_wstring(title_data_.title());
auto icon_block = db.icon();
if (icon_block) {
// display_window_->SetIcon(icon_block.buffer, icon_block.size);
}
} }
} }
} }

View File

@ -16,6 +16,7 @@
#include "xenia/base/delegate.h" #include "xenia/base/delegate.h"
#include "xenia/base/exception_handler.h" #include "xenia/base/exception_handler.h"
#include "xenia/kernel/kernel_state.h" #include "xenia/kernel/kernel_state.h"
#include "xenia/kernel/util/xdbf_utils.h"
#include "xenia/memory.h" #include "xenia/memory.h"
#include "xenia/vfs/virtual_file_system.h" #include "xenia/vfs/virtual_file_system.h"
#include "xenia/xbox.h" #include "xenia/xbox.h"
@ -92,6 +93,15 @@ class Emulator {
// This is effectively the guest operating system. // This is effectively the guest operating system.
kernel::KernelState* kernel_state() const { return kernel_state_.get(); } 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. // Initializes the emulator and configures all components.
// The given window is used for display and the provided functions are used // The given window is used for display and the provided functions are used
// to create subsystems as required. // to create subsystems as required.
@ -166,6 +176,7 @@ class Emulator {
std::unique_ptr<kernel::KernelState> kernel_state_; std::unique_ptr<kernel::KernelState> kernel_state_;
threading::Thread* main_thread_ = nullptr; threading::Thread* main_thread_ = nullptr;
kernel::util::XdbfGameData title_data_; // Currently running title DB
uint32_t title_id_ = 0; // Currently running title ID uint32_t title_id_ = 0; // Currently running title ID
bool paused_ = false; bool paused_ = false;