Simplificando callback manager
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#include "ControlPanel.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <ranges>
|
||||
|
||||
#include "CallbackManager.h"
|
||||
#include "imgui.h"
|
||||
|
||||
|
||||
@@ -14,6 +16,11 @@ ControlPanel::ControlPanel(
|
||||
machine_state{std::move(machine_state)},
|
||||
callback_manager{std::move(callback_manager)}
|
||||
{
|
||||
this->callback_manager->ips_callback.push_back(std::bind(
|
||||
&ControlPanel::initial_ips_load,
|
||||
this,
|
||||
std::placeholders::_1
|
||||
));
|
||||
}
|
||||
|
||||
void ControlPanel::render()
|
||||
@@ -34,11 +41,11 @@ void ControlPanel::render()
|
||||
this->run = !run;
|
||||
if (this->run)
|
||||
{
|
||||
this->callback_manager->trigger_resume();
|
||||
this->callback_manager->trigger(this->callback_manager->resume_callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->callback_manager->trigger_stop();
|
||||
this->callback_manager->trigger(this->callback_manager->stop_callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +56,12 @@ void ControlPanel::render()
|
||||
|
||||
if (ImGui::Button("Step One", full_width))
|
||||
{
|
||||
this->callback_manager->trigger_step(1);
|
||||
this->callback_manager->trigger(this->callback_manager->step_callback, 1);
|
||||
}
|
||||
|
||||
if (ImGui::Button(std::format("Step +{}", steps).data(), full_width))
|
||||
{
|
||||
this->callback_manager->trigger_step(steps);
|
||||
this->callback_manager->trigger(this->callback_manager->step_callback, steps);
|
||||
}
|
||||
|
||||
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
|
||||
@@ -72,17 +79,26 @@ void ControlPanel::render()
|
||||
|
||||
if (ImGui::Button("Reset", full_width))
|
||||
{
|
||||
this->callback_manager->trigger_reset();
|
||||
this->callback_manager->trigger(this->callback_manager->reset_callback);
|
||||
}
|
||||
if (ImGui::Button("Reload ROM", full_width))
|
||||
{
|
||||
this->callback_manager->trigger_reload();
|
||||
this->callback_manager->trigger(this->callback_manager->reload_callback);
|
||||
}
|
||||
}
|
||||
|
||||
if (starting_speed != this->ips)
|
||||
if (ips < 0)
|
||||
{
|
||||
this->callback_manager->trigger_ips(this->ips);
|
||||
ips = 0;
|
||||
}
|
||||
if (steps < 1)
|
||||
{
|
||||
steps = 1;
|
||||
}
|
||||
|
||||
if (starting_speed != ips)
|
||||
{
|
||||
this->callback_manager->trigger(this->callback_manager->ips_callback, ips);
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
@@ -115,5 +131,13 @@ void ControlPanel::on_callback_load_rom(void* self, const char* const* filelist,
|
||||
return;
|
||||
}
|
||||
|
||||
control_panel->callback_manager->trigger_rom_load(filelist[0]);
|
||||
control_panel->callback_manager->trigger(
|
||||
control_panel->callback_manager->rom_load_callback,
|
||||
std::string(filelist[0])
|
||||
);
|
||||
}
|
||||
|
||||
void ControlPanel::initial_ips_load(int ips)
|
||||
{
|
||||
this->ips = ips;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user