Wxwidgets: New settings dialog: Axes and paths

This commit is contained in:
Ilari Liusvaara 2012-04-07 15:33:49 +03:00
parent 73d58b5402
commit 0491f97e0d
5 changed files with 460 additions and 417 deletions

View file

@ -33,13 +33,12 @@ void signal_resize_needed();
void _runuifun_async(void (*fn)(void*), void* arg);
//Editor dialogs.
void wxeditor_axes_display(wxWindow* parent);
void wxeditor_authors_display(wxWindow* parent);
void wxeditor_settings_display(wxWindow* parent);
void wxeditor_hotkeys_display(wxWindow* parent);
void wxeditor_paths_display(wxWindow* parent);
std::string wxeditor_keyselect(wxWindow* parent, bool clearable);
void wxeditor_screen_display(wxWindow* parent);
void wxsetingsdialog_display(wxWindow* parent);
//Auxillary windows.
void wxwindow_memorysearch_display();

View file

@ -1,292 +0,0 @@
#include "core/keymapper.hpp"
#include "platform/wxwidgets/platform.hpp"
#include <boost/lexical_cast.hpp>
#include <sstream>
#define AMODE_DISABLED "Disabled"
#define AMODE_AXIS_PAIR "Axis"
#define AMODE_AXIS_PAIR_INVERSE "Axis (inverted)"
#define AMODE_PRESSURE_M0 "Pressure - to 0"
#define AMODE_PRESSURE_MP "Pressure - to +"
#define AMODE_PRESSURE_0M "Pressure 0 to -"
#define AMODE_PRESSURE_0P "Pressure 0 to +"
#define AMODE_PRESSURE_PM "Pressure + to -"
#define AMODE_PRESSURE_P0 "Pressure + to 0"
#include <wx/wx.h>
#include <wx/event.h>
#include <wx/control.h>
#include <wx/combobox.h>
#include <vector>
#include <string>
class wxeditor_axes_axis
{
public:
wxeditor_axes_axis(wxSizer* sizer, wxWindow* window, const std::string& name);
bool is_ok();
void apply();
private:
std::string a_name;
wxComboBox* a_type;
wxTextCtrl* a_low;
wxTextCtrl* a_mid;
wxTextCtrl* a_high;
wxTextCtrl* a_tolerance;
};
class wxeditor_axes : public wxDialog
{
public:
wxeditor_axes(wxWindow* parent);
~wxeditor_axes();
bool ShouldPreventAppExit() const;
void on_value_change(wxCommandEvent& e);
void on_cancel(wxCommandEvent& e);
void on_ok(wxCommandEvent& e);
bool has_axes();
private:
std::vector<wxeditor_axes_axis*> axes;
wxButton* okbutton;
wxButton* cancel;
};
//Should be called in modal pause mode.
wxeditor_axes_axis::wxeditor_axes_axis(wxSizer* sizer, wxWindow* window, const std::string& name)
{
wxString choices[9];
choices[0] = wxT(AMODE_DISABLED);
choices[1] = wxT(AMODE_AXIS_PAIR);
choices[2] = wxT(AMODE_AXIS_PAIR_INVERSE);
choices[3] = wxT(AMODE_PRESSURE_M0);
choices[4] = wxT(AMODE_PRESSURE_MP);
choices[5] = wxT(AMODE_PRESSURE_0M);
choices[6] = wxT(AMODE_PRESSURE_0P);
choices[7] = wxT(AMODE_PRESSURE_PM);
choices[8] = wxT(AMODE_PRESSURE_P0);
size_t defaultidx = 0;
std::string low;
std::string mid;
std::string high;
std::string tolerance;
keygroup* k;
runemufn([&k, name]() { k = keygroup::lookup_by_name(name); });
if(!k) {
return;
}
struct keygroup::parameters p = k->get_parameters();
{
switch(p.ktype) {
case keygroup::KT_DISABLED: defaultidx = 0; break;
case keygroup::KT_AXIS_PAIR: defaultidx = 1; break;
case keygroup::KT_AXIS_PAIR_INVERSE: defaultidx = 2; break;
case keygroup::KT_PRESSURE_M0: defaultidx = 3; break;
case keygroup::KT_PRESSURE_MP: defaultidx = 4; break;
case keygroup::KT_PRESSURE_0M: defaultidx = 5; break;
case keygroup::KT_PRESSURE_0P: defaultidx = 6; break;
case keygroup::KT_PRESSURE_PM: defaultidx = 7; break;
case keygroup::KT_PRESSURE_P0: defaultidx = 8; break;
};
std::ostringstream x1;
std::ostringstream x2;
std::ostringstream x3;
std::ostringstream x4;
x1 << p.cal_left;
x2 << p.cal_center;
x3 << p.cal_right;
x4 << p.cal_tolerance;
low = x1.str();
mid = x2.str();
high = x3.str();
tolerance = x4.str();
}
a_name = name;
sizer->Add(new wxStaticText(window, wxID_ANY, towxstring(name)), 0, wxGROW);
sizer->Add(a_type = new wxComboBox(window, wxID_ANY, choices[defaultidx], wxDefaultPosition, wxDefaultSize,
9, choices, wxCB_READONLY), 0, wxGROW);
sizer->Add(a_low = new wxTextCtrl(window, wxID_ANY, towxstring(low)), 0, wxGROW);
sizer->Add(a_mid = new wxTextCtrl(window, wxID_ANY, towxstring(mid)), 0, wxGROW);
sizer->Add(a_high = new wxTextCtrl(window, wxID_ANY, towxstring(high)), 0, wxGROW);
sizer->Add(a_tolerance = new wxTextCtrl(window, wxID_ANY, towxstring(tolerance)), 0, wxGROW);
a_low->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxeditor_axes::on_value_change), NULL,
window);
a_mid->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxeditor_axes::on_value_change), NULL,
window);
a_high->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxeditor_axes::on_value_change), NULL,
window);
a_tolerance->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxeditor_axes::on_value_change), NULL,
window);
}
bool wxeditor_axes_axis::is_ok()
{
int32_t low, mid, high;
double tolerance;
try {
low = boost::lexical_cast<int32_t>(tostdstring(a_low->GetValue()));
mid = boost::lexical_cast<int32_t>(tostdstring(a_mid->GetValue()));
high = boost::lexical_cast<int32_t>(tostdstring(a_high->GetValue()));
tolerance = boost::lexical_cast<double>(tostdstring(a_tolerance->GetValue()));
} catch(...) {
return false;
}
if(low < -32768 || low > 32767 || low > mid)
return false;
if(mid < -32768 || mid > 32767 || mid > high)
return false;
if(high < -32768 || high > 32767)
return false;
if(tolerance <= 0 || tolerance >= 1)
return false;
return true;
}
//Should be called in modal pause mode.
void wxeditor_axes_axis::apply()
{
keygroup* k;
runemufn([&k, a_name]() { k = keygroup::lookup_by_name(a_name); });
if(!k)
return;
int32_t low, mid, high;
double tolerance;
enum keygroup::type ntype;
enum keygroup::type ctype;
runemufn([&ctype, k]() { ctype = k->get_parameters().ktype; });
std::string amode = tostdstring(a_type->GetValue());
if(amode == AMODE_AXIS_PAIR)
ntype = keygroup::KT_AXIS_PAIR;
if(amode == AMODE_AXIS_PAIR_INVERSE)
ntype = keygroup::KT_AXIS_PAIR_INVERSE;
if(amode == AMODE_DISABLED)
ntype = keygroup::KT_DISABLED;
if(amode == AMODE_PRESSURE_0M)
ntype = keygroup::KT_PRESSURE_0M;
if(amode == AMODE_PRESSURE_0P)
ntype = keygroup::KT_PRESSURE_0P;
if(amode == AMODE_PRESSURE_M0)
ntype = keygroup::KT_PRESSURE_M0;
if(amode == AMODE_PRESSURE_MP)
ntype = keygroup::KT_PRESSURE_MP;
if(amode == AMODE_PRESSURE_PM)
ntype = keygroup::KT_PRESSURE_PM;
if(amode == AMODE_PRESSURE_P0)
ntype = keygroup::KT_PRESSURE_P0;
try {
low = boost::lexical_cast<int32_t>(tostdstring(a_low->GetValue()));
mid = boost::lexical_cast<int32_t>(tostdstring(a_mid->GetValue()));
high = boost::lexical_cast<int32_t>(tostdstring(a_high->GetValue()));
tolerance = boost::lexical_cast<double>(tostdstring(a_tolerance->GetValue()));
} catch(...) {
return;
}
if(low < -32768 || low > 32767 || low > mid)
return;
if(mid < -32768 || mid > 32767 || mid > high)
return;
if(high < -32768 || high > 32767)
return;
if(tolerance <= 0 || tolerance >= 1)
return;
runemufn([k, ctype, ntype, low, mid, high, tolerance]() {
if(ctype != ntype)
k->change_type(ntype);
k->change_calibration(low, mid, high, tolerance);
});
}
wxeditor_axes::wxeditor_axes(wxWindow* parent)
: wxDialog(parent, wxID_ANY, wxT("lsnes: Edit axes"), wxDefaultPosition, wxSize(-1, -1))
{
std::set<std::string> axisnames;
runemufn([&axisnames]() { axisnames = keygroup::get_axis_set(); });
Centre();
wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0);
SetSizer(top_s);
wxFlexGridSizer* t_s = new wxFlexGridSizer(axisnames.size() + 1, 6, 0, 0);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Name")), 0, wxGROW);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Type")), 0, wxGROW);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Low")), 0, wxGROW);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Mid")), 0, wxGROW);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("High")), 0, wxGROW);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Tolerance")), 0, wxGROW);
for(auto i : axisnames)
axes.push_back(new wxeditor_axes_axis(t_s, this, i));
top_s->Add(t_s);
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->AddStretchSpacer();
pbutton_s->Add(okbutton = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW);
pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW);
okbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_axes::on_ok), NULL, this);
cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_axes::on_cancel), NULL, this);
top_s->Add(pbutton_s, 0, wxGROW);
t_s->SetSizeHints(this);
top_s->SetSizeHints(this);
Fit();
}
wxeditor_axes::~wxeditor_axes()
{
for(auto i : axes)
delete i;
}
bool wxeditor_axes::has_axes()
{
return (axes.size() != 0);
}
bool wxeditor_axes::ShouldPreventAppExit() const
{
return false;
}
void wxeditor_axes::on_value_change(wxCommandEvent& e)
{
bool all_ok = true;
for(auto i : axes)
all_ok = all_ok && i->is_ok();
okbutton->Enable(all_ok);
}
void wxeditor_axes::on_cancel(wxCommandEvent& e)
{
EndModal(wxID_CANCEL);
}
void wxeditor_axes::on_ok(wxCommandEvent& e)
{
for(auto i : axes)
i->apply();
EndModal(wxID_OK);
}
void wxeditor_axes_display(wxWindow* parent)
{
modal_pause_holder hld;
wxDialog* editor;
try {
editor = new wxeditor_axes(parent);
if(dynamic_cast<wxeditor_axes*>(editor)->has_axes())
editor->ShowModal();
else {
wxMessageBox(_T("You don't have joysticks to configure!"), _T("Warning"), wxICON_WARNING |
wxOK);
}
} catch(...) {
}
editor->Destroy();
}

View file

@ -1,112 +0,0 @@
#include "platform/wxwidgets/platform.hpp"
#include "core/settings.hpp"
#include "library/string.hpp"
#include <wx/wx.h>
#include <wx/event.h>
#include <wx/control.h>
#include <wx/combobox.h>
#include <vector>
#include <string>
#include <boost/lexical_cast.hpp>
#include <sstream>
#define FIRMWAREPATH "firmwarepath"
#define ROMPATH "rompath"
#define MOVIEPATH "moviepath"
class wxeditor_paths : public wxDialog
{
public:
wxeditor_paths(wxWindow* parent);
~wxeditor_paths();
bool ShouldPreventAppExit() const;
void on_cancel(wxCommandEvent& e);
void on_ok(wxCommandEvent& e);
private:
wxButton* okbutton;
wxButton* cancel;
wxTextCtrl* rompath;
wxTextCtrl* moviepath;
wxTextCtrl* firmwarepath;
};
wxeditor_paths::wxeditor_paths(wxWindow* parent)
: wxDialog(parent, wxID_ANY, wxT("lsnes: Paths"), wxDefaultPosition, wxSize(-1, -1))
{
std::string cur_rompath, cur_moviepath, cur_firmwarepath;
runemufn([&cur_firmwarepath, &cur_moviepath, &cur_rompath]() {
cur_firmwarepath = setting::get(FIRMWAREPATH);
cur_rompath = setting::get(ROMPATH);
cur_moviepath = setting::get(MOVIEPATH);
});
Centre();
wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0);
SetSizer(top_s);
wxFlexGridSizer* t_s = new wxFlexGridSizer(3, 2, 0, 0);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("ROMs:")), 0, wxGROW);
t_s->Add(rompath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_rompath), wxDefaultPosition, wxSize(400, -1)),
1, wxGROW);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Movies:")), 0, wxGROW);
t_s->Add(moviepath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_moviepath), wxDefaultPosition,
wxSize(400, -1)), 1, wxGROW);
t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Firmware:")), 0, wxGROW);
t_s->Add(firmwarepath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_firmwarepath), wxDefaultPosition,
wxSize(400, -1)), 1, wxGROW);
top_s->Add(t_s);
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->AddStretchSpacer();
pbutton_s->Add(okbutton = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW);
pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW);
okbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_paths::on_ok), NULL, this);
cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_paths::on_cancel), NULL, this);
top_s->Add(pbutton_s, 0, wxGROW);
t_s->SetSizeHints(this);
top_s->SetSizeHints(this);
Fit();
}
wxeditor_paths::~wxeditor_paths()
{
}
bool wxeditor_paths::ShouldPreventAppExit() const
{
return false;
}
void wxeditor_paths::on_cancel(wxCommandEvent& e)
{
EndModal(wxID_CANCEL);
}
void wxeditor_paths::on_ok(wxCommandEvent& e)
{
std::string cur_rompath = tostdstring(rompath->GetValue());
std::string cur_moviepath = tostdstring(moviepath->GetValue());
std::string cur_firmwarepath = tostdstring(firmwarepath->GetValue());
runemufn([cur_firmwarepath, cur_moviepath, cur_rompath]() {
setting::set(ROMPATH, cur_rompath);
setting::set(MOVIEPATH, cur_moviepath);
setting::set(FIRMWAREPATH, cur_firmwarepath);
});
EndModal(wxID_OK);
}
void wxeditor_paths_display(wxWindow* parent)
{
modal_pause_holder hld;
wxDialog* editor;
try {
editor = new wxeditor_paths(parent);
editor->ShowModal();
} catch(...) {
}
editor->Destroy();
}

View file

@ -63,7 +63,6 @@ enum
wxID_EDIT_AUTHORS,
wxID_AUTOHOLD_FIRST,
wxID_AUTOHOLD_LAST = wxID_AUTOHOLD_FIRST + 1023,
wxID_EDIT_AXES,
wxID_EDIT_SETTINGS,
wxID_EDIT_KEYBINDINGS,
wxID_EDIT_ALIAS,
@ -81,7 +80,6 @@ enum
wxID_SET_SPEED,
wxID_SET_VOLUME,
wxID_SET_SCREEN,
wxID_SET_PATHS,
wxID_SPEED_5,
wxID_SPEED_10,
wxID_SPEED_17,
@ -94,7 +92,8 @@ enum
wxID_SPEED_200,
wxID_SPEED_300,
wxID_SPEED_TURBO,
wxID_LOAD_LIBRARY
wxID_LOAD_LIBRARY,
wxID_SETTINGS,
};
@ -710,6 +709,7 @@ wxwin_mainwindow::wxwin_mainwindow()
}
menu_special_sub(wxT("Dump video"), reinterpret_cast<dumper_menu*>(dmenu = new dumper_menu(this,
wxID_DUMP_FIRST, wxID_DUMP_LAST)));
menu_entry(wxID_SETTINGS, wxT("Configure emulator..."));
if(platform::sound_initialized()) {
menu_separator();
menu_entry_check(wxID_AUDIO_ENABLED, wxT("Sounds enabled"));
@ -766,14 +766,12 @@ wxwin_mainwindow::wxwin_mainwindow()
menu_entry(wxID_MEMORY_SEARCH, wxT("Memory Search..."));
//Settings menu: (ACFOS)
menu_start(wxT("Settings"));
menu_entry(wxID_EDIT_AXES, wxT("Configure axes..."));
menu_entry(wxID_EDIT_SETTINGS, wxT("Configure settings..."));
menu_entry(wxID_EDIT_KEYBINDINGS, wxT("Configure keybindings..."));
menu_entry(wxID_EDIT_ALIAS, wxT("Configure aliases..."));
menu_entry(wxID_EDIT_JUKEBOX, wxT("Configure jukebox..."));
menu_separator();
menu_entry(wxID_SET_SCREEN, wxT("Set screen scaling..."));
menu_entry(wxID_SET_PATHS, wxT("Set paths..."));
menu_entry(wxID_EDIT_HOTKEYS, wxT("Configure hotkeys..."));
}
@ -914,9 +912,6 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
update_movie_state();
});
return;
case wxID_EDIT_AXES:
wxeditor_axes_display(this);
return;
case wxID_EDIT_AUTHORS:
wxeditor_authors_display(this);
return;
@ -1126,9 +1121,6 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
case wxID_SET_SCREEN:
wxeditor_screen_display(this);
return;
case wxID_SET_PATHS:
wxeditor_paths_display(this);
return;
case wxID_SPEED_5:
set_speed(5);
break;
@ -1168,6 +1160,10 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
case wxID_LOAD_LIBRARY: {
std::string name = std::string("load ") + library_is_called;
load_library(pick_file(this, name, "."));
break;
}
case wxID_SETTINGS:
wxsetingsdialog_display(this);
break;
};
}

View file

@ -0,0 +1,452 @@
#include "platform/wxwidgets/platform.hpp"
#include "core/settings.hpp"
#include "library/string.hpp"
#include <wx/wx.h>
#include <wx/notebook.h>
#include <wx/event.h>
#include <wx/control.h>
#include <wx/combobox.h>
#include <vector>
#include <string>
#include <boost/lexical_cast.hpp>
#include <sstream>
extern "C"
{
#ifndef UINT64_C
#define UINT64_C(val) val##ULL
#endif
#include <libswscale/swscale.h>
}
#define AMODE_DISABLED "Disabled"
#define AMODE_AXIS_PAIR "Axis"
#define AMODE_AXIS_PAIR_INVERSE "Axis (inverted)"
#define AMODE_PRESSURE_M0 "Pressure - to 0"
#define AMODE_PRESSURE_MP "Pressure - to +"
#define AMODE_PRESSURE_0M "Pressure 0 to -"
#define AMODE_PRESSURE_0P "Pressure 0 to +"
#define AMODE_PRESSURE_PM "Pressure + to -"
#define AMODE_PRESSURE_P0 "Pressure + to 0"
#define FIRMWAREPATH "firmwarepath"
#define ROMPATH "rompath"
#define MOVIEPATH "moviepath"
const char* scalealgo_choices[] = {"Fast Bilinear", "Bilinear", "Bicubic", "Experimential", "Point", "Area",
"Bicubic-Linear", "Gauss", "Sinc", "Lanczos", "Spline"};
class wxeditor_esettings_joystick_aconfig : public wxDialog
{
public:
wxeditor_esettings_joystick_aconfig(wxWindow* parent, const std::string& _aname);
~wxeditor_esettings_joystick_aconfig();
void on_ok(wxCommandEvent& e);
void on_cancel(wxCommandEvent& e);
private:
std::string aname;
wxComboBox* type;
wxTextCtrl* low;
wxTextCtrl* mid;
wxTextCtrl* hi;
wxTextCtrl* tol;
wxButton* okbutton;
wxButton* cancel;
};
wxeditor_esettings_joystick_aconfig::wxeditor_esettings_joystick_aconfig(wxWindow* parent, const std::string& _aname)
: wxDialog(parent, -1, towxstring("Configure axis " + _aname))
{
wxString choices[9];
int didx = 1;
choices[0] = wxT(AMODE_DISABLED);
choices[1] = wxT(AMODE_AXIS_PAIR);
choices[2] = wxT(AMODE_AXIS_PAIR_INVERSE);
choices[3] = wxT(AMODE_PRESSURE_M0);
choices[4] = wxT(AMODE_PRESSURE_MP);
choices[5] = wxT(AMODE_PRESSURE_0M);
choices[6] = wxT(AMODE_PRESSURE_0P);
choices[7] = wxT(AMODE_PRESSURE_PM);
choices[8] = wxT(AMODE_PRESSURE_P0);
aname = _aname;
keygroup::parameters params;
runemufn([aname, &params]() {
auto k = keygroup::lookup_by_name(aname);
if(k)
params = k->get_parameters();
});
switch(params.ktype) {
case keygroup::KT_DISABLED: didx = 0; break;
case keygroup::KT_AXIS_PAIR: didx = 1; break;
case keygroup::KT_AXIS_PAIR_INVERSE: didx = 2; break;
case keygroup::KT_PRESSURE_M0: didx = 3; break;
case keygroup::KT_PRESSURE_MP: didx = 4; break;
case keygroup::KT_PRESSURE_0M: didx = 5; break;
case keygroup::KT_PRESSURE_0P: didx = 6; break;
case keygroup::KT_PRESSURE_PM: didx = 7; break;
case keygroup::KT_PRESSURE_P0: didx = 8; break;
};
Centre();
wxSizer* top_s = new wxBoxSizer(wxVERTICAL);
SetSizer(top_s);
wxFlexGridSizer* t_s = new wxFlexGridSizer(5, 2, 0, 0);
t_s->Add(new wxStaticText(this, -1, wxT("Type: ")), 0, wxGROW);
t_s->Add(type = new wxComboBox(this, wxID_ANY, choices[didx], wxDefaultPosition, wxDefaultSize,
9, choices, wxCB_READONLY), 1, wxGROW);
t_s->Add(new wxStaticText(this, -1, wxT("Low: ")), 0, wxGROW);
t_s->Add(low = new wxTextCtrl(this, -1, towxstring((stringfmt() << params.cal_left).str()), wxDefaultPosition,
wxSize(100, -1)), 1, wxGROW);
t_s->Add(new wxStaticText(this, -1, wxT("Middle: ")), 0, wxGROW);
t_s->Add(mid = new wxTextCtrl(this, -1, towxstring((stringfmt() << params.cal_center).str()),
wxDefaultPosition, wxSize(100, -1)), 1, wxGROW);
t_s->Add(new wxStaticText(this, -1, wxT("High: ")), 0, wxGROW);
t_s->Add(hi = new wxTextCtrl(this, -1, towxstring((stringfmt() << params.cal_right).str()),
wxDefaultPosition, wxSize(100, -1)), 1, wxGROW);
t_s->Add(new wxStaticText(this, -1, wxT("Tolerance: ")), 0, wxGROW);
t_s->Add(tol = new wxTextCtrl(this, -1, towxstring((stringfmt() << params.cal_tolerance).str()),
wxDefaultPosition, wxSize(100, -1)), 1, wxGROW);
top_s->Add(t_s);
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->AddStretchSpacer();
pbutton_s->Add(okbutton = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW);
pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW);
okbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_esettings_joystick_aconfig::on_ok), NULL, this);
cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_esettings_joystick_aconfig::on_cancel), NULL, this);
top_s->Add(pbutton_s, 0, wxGROW);
t_s->SetSizeHints(this);
top_s->SetSizeHints(this);
Fit();
}
wxeditor_esettings_joystick_aconfig::~wxeditor_esettings_joystick_aconfig()
{
}
void wxeditor_esettings_joystick_aconfig::on_ok(wxCommandEvent& e)
{
std::string _type = tostdstring(type->GetValue());
std::string _low = tostdstring(low->GetValue());
std::string _mid = tostdstring(mid->GetValue());
std::string _hi = tostdstring(hi->GetValue());
std::string _tol = tostdstring(tol->GetValue());
enum keygroup::type _ctype = keygroup::KT_DISABLED;
enum keygroup::type _ntype = keygroup::KT_AXIS_PAIR;
int32_t nlow, nmid, nhi;
double ntol;
keygroup* k;
runemufn([&k, aname, &_ctype]() {
k = keygroup::lookup_by_name(aname);
if(k)
_ctype = k->get_parameters().ktype;
});
if(!k) {
//Axis gone away?
EndModal(wxID_OK);
return;
}
const char* bad_what = NULL;
try {
bad_what = "Bad axis type";
if(_type == AMODE_AXIS_PAIR) _ntype = keygroup::KT_AXIS_PAIR;
else if(_type == AMODE_AXIS_PAIR_INVERSE) _ntype = keygroup::KT_AXIS_PAIR_INVERSE;
else if(_type == AMODE_DISABLED) _ntype = keygroup::KT_DISABLED;
else if(_type == AMODE_PRESSURE_0M) _ntype = keygroup::KT_PRESSURE_0M;
else if(_type == AMODE_PRESSURE_0P) _ntype = keygroup::KT_PRESSURE_0P;
else if(_type == AMODE_PRESSURE_M0) _ntype = keygroup::KT_PRESSURE_M0;
else if(_type == AMODE_PRESSURE_MP) _ntype = keygroup::KT_PRESSURE_MP;
else if(_type == AMODE_PRESSURE_P0) _ntype = keygroup::KT_PRESSURE_P0;
else if(_type == AMODE_PRESSURE_PM) _ntype = keygroup::KT_PRESSURE_PM;
else
throw 42;
bad_what = "Bad low calibration value (range is -32768 - 32767)";
nlow = boost::lexical_cast<int32_t>(_low);
if(nlow < -32768 || nlow > 32767)
throw 42;
bad_what = "Bad middle calibration value (range is -32768 - 32767)";
nmid = boost::lexical_cast<int32_t>(_mid);
if(nmid < -32768 || nmid > 32767)
throw 42;
bad_what = "Bad high calibration value (range is -32768 - 32767)";
nhi = boost::lexical_cast<int32_t>(_hi);
if(nhi < -32768 || nhi > 32767)
throw 42;
bad_what = "Bad tolerance (range is 0 - 1)";
ntol = boost::lexical_cast<double>(_tol);
if(ntol <= 0 || ntol >= 1)
throw 42;
} catch(...) {
wxMessageBox(towxstring(bad_what), _T("Error"), wxICON_EXCLAMATION | wxOK);
return;
}
runemufn([&k, _ctype, _ntype, nlow, nmid, nhi, ntol]() {
if(_ctype != _ntype)
k->change_type(_ntype);
k->change_calibration(nlow, nmid, nhi, ntol);
});
EndModal(wxID_OK);
}
void wxeditor_esettings_joystick_aconfig::on_cancel(wxCommandEvent& e)
{
EndModal(wxID_CANCEL);
}
class wxeditor_esettings_joystick : public wxPanel
{
public:
wxeditor_esettings_joystick(wxWindow* parent);
~wxeditor_esettings_joystick();
void on_configure(wxCommandEvent& e);
private:
void refresh();
wxSizer* jgrid;
std::map<std::string, wxButton*> buttons;
std::map<int, std::string> ids;
int last_id;
};
namespace
{
std::string formattype(keygroup::type t)
{
if(t == keygroup::KT_AXIS_PAIR) return AMODE_AXIS_PAIR;
else if(t == keygroup::KT_AXIS_PAIR_INVERSE) return AMODE_AXIS_PAIR_INVERSE;
else if(t == keygroup::KT_PRESSURE_0M) return AMODE_PRESSURE_0M;
else if(t == keygroup::KT_PRESSURE_0P) return AMODE_PRESSURE_0P;
else if(t == keygroup::KT_PRESSURE_M0) return AMODE_PRESSURE_M0;
else if(t == keygroup::KT_PRESSURE_MP) return AMODE_PRESSURE_MP;
else if(t == keygroup::KT_PRESSURE_P0) return AMODE_PRESSURE_P0;
else if(t == keygroup::KT_PRESSURE_PM) return AMODE_PRESSURE_PM;
else return "Unknown";
}
std::string formatsettings(const std::string& name, const keygroup::parameters& s)
{
return (stringfmt() << name << ": " << formattype(s.ktype) << " low:" << s.cal_left << " mid:"
<< s.cal_center << " high:" << s.cal_right << " tolerance:" << s.cal_tolerance).str();
}
}
wxeditor_esettings_joystick::wxeditor_esettings_joystick(wxWindow* parent)
: wxPanel(parent, -1)
{
last_id = wxID_HIGHEST + 1;
SetSizer(jgrid = new wxBoxSizer(wxVERTICAL));
refresh();
jgrid->SetSizeHints(this);
Fit();
}
wxeditor_esettings_joystick::~wxeditor_esettings_joystick()
{
}
void wxeditor_esettings_joystick::on_configure(wxCommandEvent& e)
{
if(!ids.count(e.GetId()))
return;
wxDialog* d = new wxeditor_esettings_joystick_aconfig(this, ids[e.GetId()]);
d->ShowModal();
d->Destroy();
refresh();
}
void wxeditor_esettings_joystick::refresh()
{
//Collect the new settings.
std::map<std::string, keygroup::parameters> x;
runemufn([&x]() {
auto axisnames = keygroup::get_axis_set();
for(auto i : axisnames) {
keygroup* k = keygroup::lookup_by_name(i);
if(k)
x[i] = k->get_parameters();
}
});
for(auto i : x) {
if(buttons.count(i.first)) {
//Okay, this already exists. Update.
buttons[i.first]->SetLabel(towxstring(formatsettings(i.first, i.second)));
if(!buttons[i.first]->IsShown()) {
jgrid->Add(buttons[i.first], 1, wxGROW);
buttons[i.first]->Show();
}
} else {
//New button.
ids[last_id] = i.first;
buttons[i.first] = new wxButton(this, last_id++, towxstring(formatsettings(i.first,
i.second)));
buttons[i.first]->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_esettings_joystick::on_configure), NULL, this);
jgrid->Add(buttons[i.first], 1, wxGROW);
}
}
for(auto i : buttons) {
if(!x.count(i.first)) {
//Removed button.
i.second->Hide();
jgrid->Detach(i.second);
}
}
jgrid->Layout();
Fit();
}
class wxeditor_esettings_paths : public wxPanel
{
public:
wxeditor_esettings_paths(wxWindow* parent);
~wxeditor_esettings_paths();
void on_configure(wxCommandEvent& e);
private:
void refresh();
wxStaticText* rompath;
wxStaticText* firmpath;
wxStaticText* savepath;
wxFlexGridSizer* top_s;
};
wxeditor_esettings_paths::wxeditor_esettings_paths(wxWindow* parent)
: wxPanel(parent, -1)
{
wxButton* tmp;
top_s = new wxFlexGridSizer(3, 3, 0, 0);
SetSizer(top_s);
top_s->Add(new wxStaticText(this, -1, wxT("ROM path")), 0, wxGROW);
top_s->Add(rompath = new wxStaticText(this, -1, wxT("")), 1, wxGROW);
top_s->Add(tmp = new wxButton(this, wxID_HIGHEST + 1, wxT("Change...")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_paths::on_configure), NULL,
this);
top_s->Add(new wxStaticText(this, -1, wxT("Firmware path")), 0, wxGROW);
top_s->Add(firmpath = new wxStaticText(this, -1, wxT("")), 1, wxGROW);
top_s->Add(tmp = new wxButton(this, wxID_HIGHEST + 2, wxT("Change...")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_paths::on_configure), NULL,
this);
top_s->Add(new wxStaticText(this, -1, wxT("Save path")), 0, wxGROW);
top_s->Add(savepath = new wxStaticText(this, -1, wxT("")), 1, wxGROW);
top_s->Add(tmp = new wxButton(this, wxID_HIGHEST + 3, wxT("Change...")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_paths::on_configure), NULL,
this);
refresh();
top_s->SetSizeHints(this);
Fit();
}
wxeditor_esettings_paths::~wxeditor_esettings_paths()
{
}
void wxeditor_esettings_paths::on_configure(wxCommandEvent& e)
{
std::string name;
if(e.GetId() == wxID_HIGHEST + 1)
name = ROMPATH;
else if(e.GetId() == wxID_HIGHEST + 2)
name = FIRMWAREPATH;
else if(e.GetId() == wxID_HIGHEST + 3)
name = MOVIEPATH;
else
return;
std::string val;
runemufn([&val, name]() { val = setting::get(name); });
try {
val = pick_text(this, "Change path to", "Enter new path:", val);
} catch(...) {
refresh();
return;
}
runemufn([val, name]() { setting::set(name, val); });
refresh();
}
void wxeditor_esettings_paths::refresh()
{
std::string rpath, fpath, spath;
runemufn([&rpath, &fpath, &spath]() {
fpath = setting::get(FIRMWAREPATH);
rpath = setting::get(ROMPATH);
spath = setting::get(MOVIEPATH);
});
rompath->SetLabel(towxstring(rpath));
firmpath->SetLabel(towxstring(fpath));
savepath->SetLabel(towxstring(spath));
top_s->Layout();
Fit();
}
class wxeditor_esettings : public wxDialog
{
public:
wxeditor_esettings(wxWindow* parent);
~wxeditor_esettings();
bool ShouldPreventAppExit() const;
void on_close(wxCommandEvent& e);
private:
wxWindow* joystick_window;
wxNotebook* tabset;
wxButton* closebutton;
};
wxeditor_esettings::wxeditor_esettings(wxWindow* parent)
: wxDialog(parent, wxID_ANY, wxT("lsnes: Configure emulator"), wxDefaultPosition, wxSize(-1, -1))
{
Centre();
wxSizer* top_s = new wxBoxSizer(wxVERTICAL);
SetSizer(top_s);
tabset = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP);
tabset->AddPage(new wxeditor_esettings_joystick(tabset), wxT("Joysticks"));
tabset->AddPage(new wxeditor_esettings_paths(tabset), wxT("Paths"));
top_s->Add(tabset, 1, wxGROW);
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->AddStretchSpacer();
pbutton_s->Add(closebutton = new wxButton(this, wxID_ANY, wxT("Close")), 0, wxGROW);
closebutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_esettings::on_close), NULL, this);
top_s->Add(pbutton_s, 0, wxGROW);
top_s->SetSizeHints(this);
Fit();
}
wxeditor_esettings::~wxeditor_esettings()
{
}
bool wxeditor_esettings::ShouldPreventAppExit() const
{
return false;
}
void wxeditor_esettings::on_close(wxCommandEvent& e)
{
EndModal(wxID_OK);
}
void wxsetingsdialog_display(wxWindow* parent)
{
modal_pause_holder hld;
wxDialog* editor;
try {
editor = new wxeditor_esettings(parent);
editor->ShowModal();
} catch(...) {
}
editor->Destroy();
}