From 6ce7b3dc7b5d63234490d3273ac3b3fea82be874 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 1 Jul 2013 11:32:41 +0300 Subject: [PATCH] Oops, Fix compilation of core actions related stuff --- src/emulation/gambatte/core.cpp | 8 +- src/platform/wxwidgets/editor-action.cpp | 223 +++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+), 5 deletions(-) create mode 100644 src/platform/wxwidgets/editor-action.cpp diff --git a/src/emulation/gambatte/core.cpp b/src/emulation/gambatte/core.cpp index 7854a81b..790f74aa 100644 --- a/src/emulation/gambatte/core.cpp +++ b/src/emulation/gambatte/core.cpp @@ -59,7 +59,7 @@ namespace unsigned accumulator_s = 0; bool pflag = false; - interface_action act_reset(gambatte_core, 0, "Soft reset", {}); + interface_action act_reset(gambatte_core, 0, "Soft reset", "reset", {}); //Framebuffer. struct framebuffer_info cover_fbinfo = { @@ -413,7 +413,6 @@ namespace .runtosave = []() -> void {}, .get_pflag = []() -> bool { return pflag; }, .set_pflag = [](bool _pflag) -> void { pflag = _pflag; }, - .request_reset = [](long delay, bool hard) -> void { do_reset_flag = true; }, .port_types = port_types, .draw_cover = []() -> framebuffer_raw& { static framebuffer_raw x(cover_fbinfo); @@ -423,13 +422,12 @@ namespace .get_core_shortname = []() -> std::string { return "gambatte"+gambatte::GB::version(); }, .pre_emulate_frame = [](controller_frame& cf) -> void { cf.axis3(0, 0, 1, do_reset_flag ? 1 : 0); - } + }, .execute_action = [](unsigned id, const std::vector& p) -> void { switch(id) { case 0: //Soft reset. - do_reset_flag = 0; - do_hreset_flag = false; + do_reset_flag = true; break; } } diff --git a/src/platform/wxwidgets/editor-action.cpp b/src/platform/wxwidgets/editor-action.cpp new file mode 100644 index 00000000..878f24b2 --- /dev/null +++ b/src/platform/wxwidgets/editor-action.cpp @@ -0,0 +1,223 @@ +#include "core/command.hpp" +#include "core/dispatch.hpp" +#include "core/mainloop.hpp" +#include "core/moviedata.hpp" +#include "core/project.hpp" +#include "library/zip.hpp" + +#include "platform/wxwidgets/platform.hpp" + +#include +#include +#include +#include +#include + +class wxeditor_action : public wxDialog +{ +public: + wxeditor_action(wxWindow* parent, const std::string& label, const std::list& _params); + std::vector get_results() { return results; } + void on_ok(wxCommandEvent& e); + void on_cancel(wxCommandEvent& e); + void on_change(wxCommandEvent& e); +private: + wxButton* ok; + wxButton* cancel; + std::list params; + std::list controls; + std::vector results; +}; + +wxeditor_action::wxeditor_action(wxWindow* parent, const std::string& label, + const std::list& _params) + : wxDialog(parent, wxID_ANY, towxstring("lsnes: Action " + label), wxDefaultPosition, wxSize(-1, -1)) + +{ + params = _params; + Centre(); + wxBoxSizer* top_s = new wxBoxSizer(wxVERTICAL); + SetSizer(top_s); + + for(auto i : params) { + regex_results r; + if(r = regex("string(:(.*))?", i.model)) { + wxBoxSizer* tmp1 = new wxBoxSizer(wxHORIZONTAL); + tmp1->Add(new wxStaticText(this, wxID_ANY, towxstring(i.name)), 0, wxGROW); + wxTextCtrl* tmp2 = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(200, -1)); + controls.push_back(tmp2); + tmp1->Add(tmp2, 1, wxGROW); + tmp2->Connect(wxEVT_COMMAND_TEXT_UPDATED, + wxCommandEventHandler(wxeditor_action::on_change), NULL, this); + top_s->Add(tmp1, 0, wxGROW); + } else if(r = regex("int:(-?[0-9]+),(-?[0-9]+)", i.model)) { + int64_t low, high, v; + try { + low = parse_value(r[1]); + high = parse_value(r[2]); + } catch(...) { + show_message_ok(this, "Internal error", (stringfmt() << "Unknown limits in '" + << i.model << "'.").str(), wxICON_EXCLAMATION); + return; + } + wxBoxSizer* tmp1 = new wxBoxSizer(wxHORIZONTAL); + tmp1->Add(new wxStaticText(this, wxID_ANY, towxstring(i.name)), 0, wxGROW); + wxSpinCtrl* tmp2 = new wxSpinCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, + wxSP_ARROW_KEYS, low, high, low); + controls.push_back(tmp2); + tmp1->Add(tmp2, 1, wxGROW); + tmp2->Connect(wxEVT_COMMAND_TEXT_UPDATED, + wxCommandEventHandler(wxeditor_action::on_change), NULL, this); + top_s->Add(tmp1, 0, wxGROW); + } else if(i.model == "bool") { + wxCheckBox* tmp2 = new wxCheckBox(this, wxID_ANY, towxstring(i.name)); + controls.push_back(tmp2); + top_s->Add(tmp2, 0, wxGROW); + } else { + show_message_ok(this, "Internal error", (stringfmt() << "Unknown parameter model in '" + << i.model << "'.").str(), wxICON_EXCLAMATION); + return; + } + } + + wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); + pbutton_s->AddStretchSpacer(); + pbutton_s->Add(ok = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW); + pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW); + ok->Connect(wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler(wxeditor_action::on_ok), NULL, this); + cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler(wxeditor_action::on_cancel), NULL, this); + top_s->Add(pbutton_s, 0, wxGROW); + + top_s->SetSizeHints(this); + wxCommandEvent d; + on_change(d); +} + + +void wxeditor_action::on_ok(wxCommandEvent& e) +{ + std::list::iterator i; + std::list::iterator j; + for(i = params.begin(), j = controls.begin(); i != params.end() && j != controls.end(); i++, j++) { + regex_results r; + if(r = regex("string(:(.*))?", i->model)) { + std::string p; + try { + p = tostdstring(reinterpret_cast(*j)->GetValue()); + if(r[2] != "" && !regex_match(r[2], p)) { + show_message_ok(this, "Error in parameters", + (stringfmt() << "String (" << i->name << ") does not satisfy " + << "constraints.").str(), wxICON_EXCLAMATION); + return; + } + } catch(...) { + show_message_ok(this, "Internal error", (stringfmt() << "Bad constraint in '" + << i->model << "'.").str(), wxICON_EXCLAMATION); + return; + } + interface_action_paramval pv; + pv.s = p; + results.push_back(pv); + } else if(r = regex("int:([0-9]+),([0-9]+)", i->model)) { + int64_t low, high, v; + try { + low = parse_value(r[1]); + high = parse_value(r[2]); + } catch(...) { + show_message_ok(this, "Internal error", (stringfmt() << "Unknown limits in '" + << i->model << "'.").str(), wxICON_EXCLAMATION); + return; + } + v = reinterpret_cast(*j)->GetValue(); + if(v < low || v > high) { + show_message_ok(this, "Error in parameters", + (stringfmt() << "Integer (" << i->name << ") out of range.").str(), + wxICON_EXCLAMATION); + return; + } + interface_action_paramval pv; + pv.i = v; + results.push_back(pv); + } else if(i->model == "bool") { + bool b = reinterpret_cast(*j)->GetValue(); + interface_action_paramval pv; + pv.b = b; + results.push_back(pv); + } else { + show_message_ok(this, "Internal error", (stringfmt() << "Unknown parameter model in '" + << i->model << "'.").str(), wxICON_EXCLAMATION); + return; + } + } + EndModal(wxID_OK); +} + +void wxeditor_action::on_cancel(wxCommandEvent& e) +{ + EndModal(wxID_CANCEL); +} + +void wxeditor_action::on_change(wxCommandEvent& e) +{ + std::list::iterator i; + std::list::iterator j; + for(i = params.begin(), j = controls.begin(); i != params.end() && j != controls.end(); i++, j++) { + regex_results r; + if(r = regex("string(:(.*))?", i->model)) { + try { + std::string p = tostdstring(reinterpret_cast(*j)->GetValue()); + if(r[2] != "" && !regex_match(r[2], p)) { + goto bad; + } + } catch(...) { + goto bad; + } + } else if(r = regex("int:([0-9]+),([0-9]+)", i->model)) { + int64_t low, high, v; + try { + low = parse_value(r[1]); + high = parse_value(r[2]); + } catch(...) { + goto bad; + } + v = reinterpret_cast(*j)->GetValue(); + if(v < low || v > high) + goto bad; + } else if(i->model == "bool") { + } else { + goto bad; + } + } + ok->Enable(); + return; +bad: + ok->Disable(); +} + + +std::vector prompt_action_params(wxWindow* parent, const std::string& label, + const std::list& params) +{ + //Empty special case. + if(params.empty()) + return std::vector(); + modal_pause_holder hld; + try { + wxeditor_action* f = new wxeditor_action(parent, label, params); + int r = f->ShowModal(); + if(r == wxID_CANCEL) { + f->Destroy(); + throw canceled_exception(); + } + auto p = f->get_results(); + f->Destroy(); + return p; + } catch(canceled_exception& e) { + throw; + } catch(...) { + throw canceled_exception(); + } +} + -- 2.11.4.GIT