UI for rom info
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "RomInfo.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
RomInfo::RomInfo(
|
||||
@@ -10,11 +12,33 @@ RomInfo::RomInfo(
|
||||
machine_state{std::move(machine_state)},
|
||||
callback_manager{std::move(callback_manager)}
|
||||
{
|
||||
this->callback_manager->rom_load_callback.push_back(std::bind(
|
||||
&RomInfo::on_rom_load,
|
||||
this,
|
||||
std::placeholders::_1
|
||||
));
|
||||
}
|
||||
|
||||
void RomInfo::render()
|
||||
{
|
||||
if (ImGui::Begin("Chip-8 - ROM Info"))
|
||||
{
|
||||
if (!this->rom_path.empty())
|
||||
{
|
||||
ImGui::Text("ROM: %s", this->rom_path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Text("ROM: None");
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void RomInfo::on_rom_load(const std::string& rom_path)
|
||||
{
|
||||
std::filesystem::path home = SDL_GetUserFolder(SDL_FOLDER_HOME);
|
||||
std::filesystem::path path = rom_path;
|
||||
|
||||
this->rom_path = std::filesystem::relative(path, home).string();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class RomInfo
|
||||
std::shared_ptr<Graphics> graphics;
|
||||
std::shared_ptr<MachineState> machine_state;
|
||||
std::shared_ptr<CallbackManager> callback_manager;
|
||||
std::string rom_path;
|
||||
|
||||
public:
|
||||
RomInfo(
|
||||
@@ -20,6 +21,7 @@ public:
|
||||
);
|
||||
|
||||
void render();
|
||||
void on_rom_load(const std::string& rom_path);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -21,4 +21,5 @@ void UIManager::render()
|
||||
{
|
||||
this->display->render();
|
||||
this->control_panel->render();
|
||||
this->rom_info->render();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user