Viendo organizacion para ejecucion de eventos desde el control panel u otros elementos de ui,

falta que el uimanager haga de intermediario entre los callbacks?
This commit is contained in:
2025-06-24 01:19:32 -04:00
parent de3b9f6769
commit b186b25a9c
10 changed files with 137 additions and 30 deletions

View File

@@ -3,17 +3,29 @@
#include <format>
#include "imgui.h"
ControlPanel::ControlPanel(
std::shared_ptr<Graphics> graphics,
std::shared_ptr<MachineState> machine_state
): graphics{std::move(graphics)},
machine_state{std::move(machine_state)} {}
void ControlPanel::set_rom_load_callback(const std::function<void(std::string)>& callback) {
this->rom_load_callback = callback;
}
void ControlPanel::set_reset_callback(const std::function<void()>& callback) {
this->reset_callback = callback;
}
void ControlPanel::render() {
constexpr auto full_width = ImVec2(-FLT_MIN, 0.0f);
if (ImGui::Begin("Chip-8 - Controls")) {
ImGui::Button("Load Rom", full_width);
if (ImGui::Button("Load Rom", full_width)) {
this->on_click_load_rom();
}
if (ImGui::Button(run ? "Pause" : "Run", full_width)) {
this->run = !run;
}
@@ -37,10 +49,36 @@ void ControlPanel::render() {
ImGui::SeparatorText("");
ImGui::Button("Reset", full_width);
if (ImGui::Button("Reset", full_width)) {
if (this->reset_callback) {
this->reset_callback();
}
}
ImGui::Button("Reload ROM", full_width);
}
ImGui::End();
}
void ControlPanel::on_click_load_rom() {
constexpr SDL_DialogFileFilter filters[] = {
{"CHIP8 ROMs", "ch8"},
{"All files", "*"}
};
SDL_ShowOpenFileDialog(on_callback_load_rom, this, graphics->get_window().get(), filters, std::size(filters), nullptr, false);
}
void ControlPanel::on_callback_load_rom(void* userdata, const char* const* filelist, int filter) {
const auto control_panel = static_cast<ControlPanel*>(userdata);
if (!control_panel->rom_load_callback) {
return;
}
if (!filelist || !*filelist) {
return;
}
control_panel->rom_load_callback(*filelist);
}