From 036ce8dc0b025d60b36da7d5884ca14e1abe575c Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 7 Apr 2012 17:04:10 +0300 Subject: [PATCH 01/11] Wxwidgets: Move screen scaling into main settings dialog --- include/platform/wxwidgets/platform.hpp | 1 - src/platform/wxwidgets/editor-screen.cpp | 179 ----------------------- src/platform/wxwidgets/mainwindow.cpp | 5 - src/platform/wxwidgets/settings.cpp | 113 ++++++++++++++ 4 files changed, 113 insertions(+), 185 deletions(-) delete mode 100644 src/platform/wxwidgets/editor-screen.cpp diff --git a/include/platform/wxwidgets/platform.hpp b/include/platform/wxwidgets/platform.hpp index 6241aea9..cd99bc10 100644 --- a/include/platform/wxwidgets/platform.hpp +++ b/include/platform/wxwidgets/platform.hpp @@ -37,7 +37,6 @@ void wxeditor_authors_display(wxWindow* parent); void wxeditor_settings_display(wxWindow* parent); void wxeditor_hotkeys_display(wxWindow* parent); std::string wxeditor_keyselect(wxWindow* parent, bool clearable); -void wxeditor_screen_display(wxWindow* parent); void wxsetingsdialog_display(wxWindow* parent); //Auxillary windows. diff --git a/src/platform/wxwidgets/editor-screen.cpp b/src/platform/wxwidgets/editor-screen.cpp deleted file mode 100644 index 3b6f148c..00000000 --- a/src/platform/wxwidgets/editor-screen.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include "platform/wxwidgets/platform.hpp" -#include "library/string.hpp" - -#include -#include -#include -#include -#include -#include - -#include -#include - -extern "C" -{ -#ifndef UINT64_C -#define UINT64_C(val) val##ULL -#endif -#include -} - -const char* algo_choices[] = {"Fast Bilinear", "Bilinear", "Bicubic", "Experimential", "Point", "Area", - "Bicubic-Linear", "Gauss", "Sinc", "Lanczos", "Spline"}; - -class wxeditor_screen : public wxDialog -{ -public: - wxeditor_screen(wxWindow* parent); - ~wxeditor_screen(); - bool ShouldPreventAppExit() const; - void on_value_change(wxCommandEvent& e); - void on_cancel(wxCommandEvent& e); - void on_ok(wxCommandEvent& e); -private: - wxButton* okbutton; - wxButton* cancel; - wxTextCtrl* horizbox; - wxTextCtrl* vertbox; - wxComboBox* algo; -}; - -wxeditor_screen::wxeditor_screen(wxWindow* parent) - : wxDialog(parent, wxID_ANY, wxT("lsnes: Screen scaling"), wxDefaultPosition, wxSize(-1, -1)) -{ - std::set axisnames; - std::string h_x, v_x; - int algoidx; - wxString _algo_choices[sizeof(algo_choices) / sizeof(algo_choices[0])]; - - for(size_t i = 0; i < sizeof(_algo_choices) / sizeof(_algo_choices[0]); i++) - _algo_choices[i] = towxstring(algo_choices[i]); - - h_x = (stringfmt() << horizontal_scale_factor).str(); - v_x = (stringfmt() << vertical_scale_factor).str(); - algoidx = 0; - for(size_t i = 0; i < sizeof(algo_choices) / sizeof(_algo_choices[0]); i++) - if(scaling_flags & (1 << i)) { - algoidx = i; - break; - } - - 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("Horizontal factor:")), 0, wxGROW); - t_s->Add(horizbox = new wxTextCtrl(this, wxID_ANY, towxstring(h_x), wxDefaultPosition, wxSize(100, -1)), 1, - wxGROW); - t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Vertical factor:")), 0, wxGROW); - t_s->Add(vertbox = new wxTextCtrl(this, wxID_ANY, towxstring(v_x), wxDefaultPosition, wxSize(100, -1)), 1, - wxGROW); - t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Method:")), 0, wxGROW); - t_s->Add(algo = new wxComboBox(this, wxID_ANY, _algo_choices[algoidx], wxDefaultPosition, - wxDefaultSize, sizeof(_algo_choices) / sizeof(_algo_choices[0]), _algo_choices, wxCB_READONLY), 1, - wxGROW); - top_s->Add(t_s); - - horizbox->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxeditor_screen::on_value_change), NULL, - this); - vertbox->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxeditor_screen::on_value_change), NULL, - this); - algo->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED, - wxCommandEventHandler(wxeditor_screen::on_value_change), NULL, this); - - 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_screen::on_ok), NULL, this); - cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxeditor_screen::on_cancel), NULL, this); - top_s->Add(pbutton_s, 0, wxGROW); - - t_s->SetSizeHints(this); - top_s->SetSizeHints(this); - Fit(); - -} - -wxeditor_screen::~wxeditor_screen() -{ -} - -bool wxeditor_screen::ShouldPreventAppExit() const -{ - return false; -} - -void wxeditor_screen::on_value_change(wxCommandEvent& e) -{ - double hscale; - double vscale; - int newflags = 0; - bool valid = true; - try { - hscale = parse_value(tostdstring(horizbox->GetValue())); - vscale = parse_value(tostdstring(vertbox->GetValue())); - if(hscale < 0.25 || hscale > 10) - throw std::runtime_error("Specified scale out of range"); - if(vscale < 0.25 || vscale > 10) - throw std::runtime_error("Specified scale out of range"); - std::string a = tostdstring(algo->GetValue()); - for(size_t i = 0; i < sizeof(algo_choices) / sizeof(algo_choices[0]); i++) - if(a == algo_choices[i]) - newflags = (1 << i); - if(newflags == 0) - throw std::runtime_error("Specified algorithm invalid"); - } catch(...) { - valid = false; - } - okbutton->Enable(valid); -} - -void wxeditor_screen::on_cancel(wxCommandEvent& e) -{ - EndModal(wxID_CANCEL); -} - -void wxeditor_screen::on_ok(wxCommandEvent& e) -{ - double hscale; - double vscale; - int newflags = 0; - - try { - hscale = parse_value(tostdstring(horizbox->GetValue())); - vscale = parse_value(tostdstring(vertbox->GetValue())); - if(hscale < 0.25 || hscale > 10) - throw std::runtime_error("Specified scale out of range"); - if(vscale < 0.25 || vscale > 10) - throw std::runtime_error("Specified scale out of range"); - std::string a = tostdstring(algo->GetValue()); - for(size_t i = 0; i < sizeof(algo_choices) / sizeof(algo_choices[0]); i++) - if(a == algo_choices[i]) - newflags = (1 << i); - if(newflags == 0) - throw std::runtime_error("Specified algorithm invalid"); - } catch(...) { - return; - } - - horizontal_scale_factor = hscale; - vertical_scale_factor = vscale; - scaling_flags = newflags; - EndModal(wxID_OK); -} - -void wxeditor_screen_display(wxWindow* parent) -{ - modal_pause_holder hld; - wxDialog* editor; - try { - editor = new wxeditor_screen(parent); - editor->ShowModal(); - } catch(...) { - } - editor->Destroy(); -} diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index a197053f..50077914 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -79,7 +79,6 @@ enum wxID_SHOW_STATUS, wxID_SET_SPEED, wxID_SET_VOLUME, - wxID_SET_SCREEN, wxID_SPEED_5, wxID_SPEED_10, wxID_SPEED_17, @@ -774,7 +773,6 @@ wxwin_mainwindow::wxwin_mainwindow() 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_EDIT_HOTKEYS, wxT("Configure hotkeys...")); } @@ -1123,9 +1121,6 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) runemufn([parsed]() { platform::global_volume = parsed; }); return; } - case wxID_SET_SCREEN: - wxeditor_screen_display(this); - return; case wxID_SPEED_5: set_speed(5); break; diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index 1f8f7113..ea4fea4e 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -240,6 +240,14 @@ namespace return (stringfmt() << name << ": " << formattype(s.ktype) << " low:" << s.cal_left << " mid:" << s.cal_center << " high:" << s.cal_right << " tolerance:" << s.cal_tolerance).str(); } + + std::string getalgo(int flags) + { + for(size_t i = 0; i < sizeof(scalealgo_choices) / sizeof(scalealgo_choices[0]); i++) + if(flags & (1 << i)) + return scalealgo_choices[i]; + return "unknown"; + } } wxeditor_esettings_joystick::wxeditor_esettings_joystick(wxWindow* parent) @@ -389,6 +397,110 @@ void wxeditor_esettings_paths::refresh() Fit(); } +class wxeditor_esettings_screen : public wxPanel +{ +public: + wxeditor_esettings_screen(wxWindow* parent); + ~wxeditor_esettings_screen(); + void on_configure(wxCommandEvent& e); +private: + void refresh(); + wxStaticText* xscale; + wxStaticText* yscale; + wxStaticText* algo; + wxFlexGridSizer* top_s; +}; + +wxeditor_esettings_screen::wxeditor_esettings_screen(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("X scale factor: ")), 0, wxGROW); + top_s->Add(xscale = 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_screen::on_configure), + NULL, this); + top_s->Add(new wxStaticText(this, -1, wxT("Y scale factor: ")), 0, wxGROW); + top_s->Add(yscale = 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_screen::on_configure), + NULL, this); + top_s->Add(new wxStaticText(this, -1, wxT("Scaling type: ")), 0, wxGROW); + top_s->Add(algo = 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_screen::on_configure), + NULL, this); + refresh(); + top_s->SetSizeHints(this); + Fit(); +} +wxeditor_esettings_screen::~wxeditor_esettings_screen() +{ +} + +void wxeditor_esettings_screen::on_configure(wxCommandEvent& e) +{ + if(e.GetId() == wxID_HIGHEST + 1) { + std::string v = (stringfmt() << horizontal_scale_factor).str(); + v = pick_text(this, "Set X scaling factor", "Enter new horizontal scale factor:", v); + double x; + try { + x = parse_value(v); + if(x < 0.25 || x > 10) + throw 42; + } catch(...) { + wxMessageBox(wxT("Bad horizontal scale factor (0.25-10)"), wxT("Input error"), + wxICON_EXCLAMATION | wxOK); + refresh(); + return; + } + horizontal_scale_factor = x; + } else if(e.GetId() == wxID_HIGHEST + 2) { + std::string v = (stringfmt() << vertical_scale_factor).str(); + v = pick_text(this, "Set Y scaling factor", "Enter new vertical scale factor:", v); + double x; + try { + x = parse_value(v); + if(x < 0.25 || x > 10) + throw 42; + } catch(...) { + wxMessageBox(wxT("Bad vertical scale factor (0.25-10)"), wxT("Input error"), + wxICON_EXCLAMATION | wxOK); + refresh(); + return; + } + vertical_scale_factor = x; + } else if(e.GetId() == wxID_HIGHEST + 3) { + std::vector choices; + std::string v; + int newflags = 1; + for(size_t i = 0; i < sizeof(scalealgo_choices) / sizeof(scalealgo_choices[0]); i++) + choices.push_back(scalealgo_choices[i]); + try { + v = pick_among(this, "Select algorithm", "Select scaling algorithm", choices); + } catch(...) { + refresh(); + return; + } + for(size_t i = 0; i < sizeof(scalealgo_choices) / sizeof(scalealgo_choices[0]); i++) + if(v == scalealgo_choices[i]) + newflags = 1 << i; + scaling_flags = newflags; + } + refresh(); +} + +void wxeditor_esettings_screen::refresh() +{ + xscale->SetLabel(towxstring((stringfmt() << horizontal_scale_factor).str())); + yscale->SetLabel(towxstring((stringfmt() << vertical_scale_factor).str())); + algo->SetLabel(towxstring(getalgo(scaling_flags))); + top_s->Layout(); + Fit(); +} + class wxeditor_esettings : public wxDialog { public: @@ -412,6 +524,7 @@ wxeditor_esettings::wxeditor_esettings(wxWindow* parent) 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")); + tabset->AddPage(new wxeditor_esettings_screen(tabset), wxT("Scaling")); top_s->Add(tabset, 1, wxGROW); wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); From 29a1edd3e0dff03526d21de937e17b7223970b0f Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 7 Apr 2012 18:07:33 +0300 Subject: [PATCH 02/11] Internally classify keys This is useful later to split down that massive key list into more logical chunks. --- include/core/keymapper.hpp | 8 +- src/core/keymapper.cpp | 8 +- src/platform/evdev/joystick.cpp | 8 +- src/platform/sdl/graphicsfn.cpp | 10 +- src/platform/sdl/joystick.cpp | 6 +- src/platform/sdl/keyboard.cpp | 467 ++++++++++---------- src/platform/wxwidgets/editor-keyselect.cpp | 2 + src/platform/wxwidgets/keyboard.cpp | 439 +++++++++--------- src/platform/wxwidgets/mainwindow.cpp | 12 +- 9 files changed, 488 insertions(+), 472 deletions(-) diff --git a/include/core/keymapper.hpp b/include/core/keymapper.hpp index 823de52b..6440a4ef 100644 --- a/include/core/keymapper.hpp +++ b/include/core/keymapper.hpp @@ -214,10 +214,11 @@ public: * Create a new key group. * * parameter name: Name of the key group. + * parameter _clazz: The key class. * parameter t: Initial type of the key group. * throws std::bad_alloc: Not enough memory. */ - keygroup(const std::string& name, enum type t) throw(std::bad_alloc); + keygroup(const std::string& name, const std::string& _clazz, enum type t) throw(std::bad_alloc); /** * Destructor */ @@ -331,6 +332,10 @@ public: * Get status value. */ signed get_value(); +/** + * Get class. + */ + const std::string& get_class(); private: signed state; enum type ktype; @@ -343,6 +348,7 @@ private: double compensate2(double value); void run_listeners(const modifier_set& modifiers, unsigned subkey, bool polarity, bool really, double x); std::string keyname; + std::string clazz; bool requests_hook; }; diff --git a/src/core/keymapper.cpp b/src/core/keymapper.cpp index 9af71629..4ddaab4f 100644 --- a/src/core/keymapper.cpp +++ b/src/core/keymapper.cpp @@ -257,6 +257,11 @@ std::string keygroup::name() throw(std::bad_alloc) return keyname; } +const std::string& keygroup::get_class() +{ + return clazz; +} + struct keygroup::parameters keygroup::get_parameters() { parameters p; @@ -277,9 +282,10 @@ std::map keygroup::get_all_parameters( return ret; } -keygroup::keygroup(const std::string& name, enum type t) throw(std::bad_alloc) +keygroup::keygroup(const std::string& name, const std::string& _clazz, enum type t) throw(std::bad_alloc) { keygroups()[keyname = name] = this; + clazz = _clazz; ktype = t; state = 0; last_rawval = 0; diff --git a/src/platform/evdev/joystick.cpp b/src/platform/evdev/joystick.cpp index 9bec41fe..83943484 100644 --- a/src/platform/evdev/joystick.cpp +++ b/src/platform/evdev/joystick.cpp @@ -93,7 +93,7 @@ namespace std::ostringstream _name; _name << "joystick" << joynum << "button" << buttonnum; std::string name = _name.str(); - keygroup* grp = new keygroup(name, keygroup::KT_KEY); + keygroup* grp = new keygroup(name, "joystick", keygroup::KT_KEY); keygroups.insert(grp); struct event_mapping evmap; evmap.joystick = joynum; @@ -115,9 +115,9 @@ namespace std::string name = _name.str(); keygroup* grp; if(min < 0) - grp = new keygroup(name, keygroup::KT_AXIS_PAIR); + grp = new keygroup(name, "joystick", keygroup::KT_AXIS_PAIR); else - grp = new keygroup(name, keygroup::KT_PRESSURE_MP); + grp = new keygroup(name, "joystick", keygroup::KT_PRESSURE_MP); keygroups.insert(grp); struct event_mapping evmap; evmap.joystick = joynum; @@ -138,7 +138,7 @@ namespace std::ostringstream _name; _name << "joystick" << joynum << "hat" << hatnum; std::string name = _name.str(); - keygroup* grp = new keygroup(name, keygroup::KT_HAT); + keygroup* grp = new keygroup(name, "joystick", keygroup::KT_HAT); keygroups.insert(grp); struct event_mapping evmap1; evmap1.joystick = joynum; diff --git a/src/platform/sdl/graphicsfn.cpp b/src/platform/sdl/graphicsfn.cpp index f3e98042..3320db8f 100644 --- a/src/platform/sdl/graphicsfn.cpp +++ b/src/platform/sdl/graphicsfn.cpp @@ -275,11 +275,11 @@ namespace platform::queue(emu_handle_quit_signal, NULL, false); } - keygroup mouse_x("mouse_x", keygroup::KT_MOUSE); - keygroup mouse_y("mouse_y", keygroup::KT_MOUSE); - keygroup mouse_l("mouse_left", keygroup::KT_KEY); - keygroup mouse_m("mouse_center", keygroup::KT_KEY); - keygroup mouse_r("mouse_right", keygroup::KT_KEY); + keygroup mouse_x("mouse_x", "mouse", keygroup::KT_MOUSE); + keygroup mouse_y("mouse_y", "mouse", keygroup::KT_MOUSE); + keygroup mouse_l("mouse_left", "mouse", keygroup::KT_KEY); + keygroup mouse_m("mouse_center", "mouse", keygroup::KT_KEY); + keygroup mouse_r("mouse_right", "mouse", keygroup::KT_KEY); } void notify_emulator_exit() diff --git a/src/platform/sdl/joystick.cpp b/src/platform/sdl/joystick.cpp index 37c4c44b..317e93c3 100644 --- a/src/platform/sdl/joystick.cpp +++ b/src/platform/sdl/joystick.cpp @@ -71,19 +71,19 @@ void joystick_plugin::init() throw() unsigned num = 256 * i + k; std::ostringstream x; x << "joystick" << i << "axis" << k; - joyaxis[num] = new keygroup(x.str(), keygroup::KT_AXIS_PAIR); + joyaxis[num] = new keygroup(x.str(), "joystick", keygroup::KT_AXIS_PAIR); } for(int k = 0; k < SDL_JoystickNumButtons(j); k++) { unsigned num = 256 * i + k; std::ostringstream x; x << "joystick" << i << "button" << k; - joybutton[num] = new keygroup(x.str(), keygroup::KT_KEY); + joybutton[num] = new keygroup(x.str(), "joystick", keygroup::KT_KEY); } for(int k = 0; k < SDL_JoystickNumHats(j); k++) { unsigned num = 256 * i + k; std::ostringstream x; x << "joystick" << i << "hat" << k; - joyhat[num] = new keygroup(x.str(), keygroup::KT_HAT); + joyhat[num] = new keygroup(x.str(), "joystick", keygroup::KT_HAT); } } } diff --git a/src/platform/sdl/keyboard.cpp b/src/platform/sdl/keyboard.cpp index 47b62519..60347772 100644 --- a/src/platform/sdl/keyboard.cpp +++ b/src/platform/sdl/keyboard.cpp @@ -34,239 +34,240 @@ namespace struct sdl_key { const char* name; + const char* clazz; unsigned symbol; } keys_table[] = { - {"backspace", SDLK_BACKSPACE }, - {"tab", SDLK_TAB }, - {"clear", SDLK_CLEAR }, - {"return", SDLK_RETURN }, - {"pause", SDLK_PAUSE }, - {"escape", SDLK_ESCAPE }, - {"space", SDLK_SPACE }, - {"exclaim", SDLK_EXCLAIM }, - {"quotedbl", SDLK_QUOTEDBL }, - {"hash", SDLK_HASH }, - {"dollar", SDLK_DOLLAR }, - {"ampersand", SDLK_AMPERSAND }, - {"quote", SDLK_QUOTE }, - {"leftparen", SDLK_LEFTPAREN }, - {"rightparen", SDLK_RIGHTPAREN }, - {"asterisk", SDLK_ASTERISK }, - {"plus", SDLK_PLUS }, - {"comma", SDLK_COMMA }, - {"minus", SDLK_MINUS }, - {"period", SDLK_PERIOD }, - {"slash", SDLK_SLASH }, - {"0", SDLK_0 }, - {"1", SDLK_1 }, - {"2", SDLK_2 }, - {"3", SDLK_3 }, - {"4", SDLK_4 }, - {"5", SDLK_5 }, - {"6", SDLK_6 }, - {"7", SDLK_7 }, - {"8", SDLK_8 }, - {"9", SDLK_9 }, - {"colon", SDLK_COLON }, - {"semicolon", SDLK_SEMICOLON }, - {"less", SDLK_LESS }, - {"equals", SDLK_EQUALS }, - {"greater", SDLK_GREATER }, - {"question", SDLK_QUESTION }, - {"at", SDLK_AT }, - {"leftbracket", SDLK_LEFTBRACKET }, - {"backslash", SDLK_BACKSLASH }, - {"rightbracket", SDLK_RIGHTBRACKET }, - {"caret", SDLK_CARET }, - {"underscore", SDLK_UNDERSCORE }, - {"backquote", SDLK_BACKQUOTE }, - {"a", SDLK_a }, - {"b", SDLK_b }, - {"c", SDLK_c }, - {"d", SDLK_d }, - {"e", SDLK_e }, - {"f", SDLK_f }, - {"g", SDLK_g }, - {"h", SDLK_h }, - {"i", SDLK_i }, - {"j", SDLK_j }, - {"k", SDLK_k }, - {"l", SDLK_l }, - {"m", SDLK_m }, - {"n", SDLK_n }, - {"o", SDLK_o }, - {"p", SDLK_p }, - {"q", SDLK_q }, - {"r", SDLK_r }, - {"s", SDLK_s }, - {"t", SDLK_t }, - {"u", SDLK_u }, - {"v", SDLK_v }, - {"w", SDLK_w }, - {"x", SDLK_x }, - {"y", SDLK_y }, - {"z", SDLK_z }, - {"delete", SDLK_DELETE }, - {"world_0", SDLK_WORLD_0 }, - {"world_1", SDLK_WORLD_1 }, - {"world_2", SDLK_WORLD_2 }, - {"world_3", SDLK_WORLD_3 }, - {"world_4", SDLK_WORLD_4 }, - {"world_5", SDLK_WORLD_5 }, - {"world_6", SDLK_WORLD_6 }, - {"world_7", SDLK_WORLD_7 }, - {"world_8", SDLK_WORLD_8 }, - {"world_9", SDLK_WORLD_9 }, - {"world_10", SDLK_WORLD_10 }, - {"world_11", SDLK_WORLD_11 }, - {"world_12", SDLK_WORLD_12 }, - {"world_13", SDLK_WORLD_13 }, - {"world_14", SDLK_WORLD_14 }, - {"world_15", SDLK_WORLD_15 }, - {"world_16", SDLK_WORLD_16 }, - {"world_17", SDLK_WORLD_17 }, - {"world_18", SDLK_WORLD_18 }, - {"world_19", SDLK_WORLD_19 }, - {"world_20", SDLK_WORLD_20 }, - {"world_21", SDLK_WORLD_21 }, - {"world_22", SDLK_WORLD_22 }, - {"world_23", SDLK_WORLD_23 }, - {"world_24", SDLK_WORLD_24 }, - {"world_25", SDLK_WORLD_25 }, - {"world_26", SDLK_WORLD_26 }, - {"world_27", SDLK_WORLD_27 }, - {"world_28", SDLK_WORLD_28 }, - {"world_29", SDLK_WORLD_29 }, - {"world_30", SDLK_WORLD_30 }, - {"world_31", SDLK_WORLD_31 }, - {"world_32", SDLK_WORLD_32 }, - {"world_33", SDLK_WORLD_33 }, - {"world_34", SDLK_WORLD_34 }, - {"world_35", SDLK_WORLD_35 }, - {"world_36", SDLK_WORLD_36 }, - {"world_37", SDLK_WORLD_37 }, - {"world_38", SDLK_WORLD_38 }, - {"world_39", SDLK_WORLD_39 }, - {"world_40", SDLK_WORLD_40 }, - {"world_41", SDLK_WORLD_41 }, - {"world_42", SDLK_WORLD_42 }, - {"world_43", SDLK_WORLD_43 }, - {"world_44", SDLK_WORLD_44 }, - {"world_45", SDLK_WORLD_45 }, - {"world_46", SDLK_WORLD_46 }, - {"world_47", SDLK_WORLD_47 }, - {"world_48", SDLK_WORLD_48 }, - {"world_49", SDLK_WORLD_49 }, - {"world_50", SDLK_WORLD_50 }, - {"world_51", SDLK_WORLD_51 }, - {"world_52", SDLK_WORLD_52 }, - {"world_53", SDLK_WORLD_53 }, - {"world_54", SDLK_WORLD_54 }, - {"world_55", SDLK_WORLD_55 }, - {"world_56", SDLK_WORLD_56 }, - {"world_57", SDLK_WORLD_57 }, - {"world_58", SDLK_WORLD_58 }, - {"world_59", SDLK_WORLD_59 }, - {"world_60", SDLK_WORLD_60 }, - {"world_61", SDLK_WORLD_61 }, - {"world_62", SDLK_WORLD_62 }, - {"world_63", SDLK_WORLD_63 }, - {"world_64", SDLK_WORLD_64 }, - {"world_65", SDLK_WORLD_65 }, - {"world_66", SDLK_WORLD_66 }, - {"world_67", SDLK_WORLD_67 }, - {"world_68", SDLK_WORLD_68 }, - {"world_69", SDLK_WORLD_69 }, - {"world_70", SDLK_WORLD_70 }, - {"world_71", SDLK_WORLD_71 }, - {"world_72", SDLK_WORLD_72 }, - {"world_73", SDLK_WORLD_73 }, - {"world_74", SDLK_WORLD_74 }, - {"world_75", SDLK_WORLD_75 }, - {"world_76", SDLK_WORLD_76 }, - {"world_77", SDLK_WORLD_77 }, - {"world_78", SDLK_WORLD_78 }, - {"world_79", SDLK_WORLD_79 }, - {"world_80", SDLK_WORLD_80 }, - {"world_81", SDLK_WORLD_81 }, - {"world_82", SDLK_WORLD_82 }, - {"world_83", SDLK_WORLD_83 }, - {"world_84", SDLK_WORLD_84 }, - {"world_85", SDLK_WORLD_85 }, - {"world_86", SDLK_WORLD_86 }, - {"world_87", SDLK_WORLD_87 }, - {"world_88", SDLK_WORLD_88 }, - {"world_89", SDLK_WORLD_89 }, - {"world_90", SDLK_WORLD_90 }, - {"world_91", SDLK_WORLD_91 }, - {"world_92", SDLK_WORLD_92 }, - {"world_93", SDLK_WORLD_93 }, - {"world_94", SDLK_WORLD_94 }, - {"world_95", SDLK_WORLD_95 }, - {"kp0", SDLK_KP0 }, - {"kp1", SDLK_KP1 }, - {"kp2", SDLK_KP2 }, - {"kp3", SDLK_KP3 }, - {"kp4", SDLK_KP4 }, - {"kp5", SDLK_KP5 }, - {"kp6", SDLK_KP6 }, - {"kp7", SDLK_KP7 }, - {"kp8", SDLK_KP8 }, - {"kp9", SDLK_KP9 }, - {"kp_period", SDLK_KP_PERIOD }, - {"kp_divide", SDLK_KP_DIVIDE }, - {"kp_multiply", SDLK_KP_MULTIPLY }, - {"kp_minus", SDLK_KP_MINUS }, - {"kp_plus", SDLK_KP_PLUS }, - {"kp_enter", SDLK_KP_ENTER }, - {"kp_equals", SDLK_KP_EQUALS }, - {"up", SDLK_UP }, - {"down", SDLK_DOWN }, - {"right", SDLK_RIGHT }, - {"left", SDLK_LEFT }, - {"insert", SDLK_INSERT }, - {"home", SDLK_HOME }, - {"end", SDLK_END }, - {"pageup", SDLK_PAGEUP }, - {"pagedown", SDLK_PAGEDOWN }, - {"f1", SDLK_F1 }, - {"f2", SDLK_F2 }, - {"f3", SDLK_F3 }, - {"f4", SDLK_F4 }, - {"f5", SDLK_F5 }, - {"f6", SDLK_F6 }, - {"f7", SDLK_F7 }, - {"f8", SDLK_F8 }, - {"f9", SDLK_F9 }, - {"f10", SDLK_F10 }, - {"f11", SDLK_F11 }, - {"f12", SDLK_F12 }, - {"f13", SDLK_F13 }, - {"f14", SDLK_F14 }, - {"f15", SDLK_F15 }, - {"numlock", SDLK_NUMLOCK }, - {"capslock", SDLK_CAPSLOCK }, - {"scrollock", SDLK_SCROLLOCK }, - {"rshift", SDLK_RSHIFT }, - {"lshift", SDLK_LSHIFT }, - {"rctrl", SDLK_RCTRL }, - {"lctrl", SDLK_LCTRL }, - {"ralt", SDLK_RALT }, - {"lalt", SDLK_LALT }, - {"rmeta", SDLK_RMETA }, - {"lmeta", SDLK_LMETA }, - {"lsuper", SDLK_LSUPER }, - {"rsuper", SDLK_RSUPER }, - {"mode", SDLK_MODE }, - {"compose", SDLK_COMPOSE }, - {"help", SDLK_HELP }, - {"print", SDLK_PRINT }, - {"sysreq", SDLK_SYSREQ }, - {"break", SDLK_BREAK }, - {"menu", SDLK_MENU }, - {"power", SDLK_POWER }, - {"euro", SDLK_EURO }, - {"undo", SDLK_UNDO }, + {"backspace", "editing", SDLK_BACKSPACE }, + {"tab", "editing", SDLK_TAB }, + {"clear", "editing", SDLK_CLEAR }, + {"return", "editing", SDLK_RETURN }, + {"pause", "special", SDLK_PAUSE }, + {"escape", "editing", SDLK_ESCAPE }, + {"space", "characters", SDLK_SPACE }, + {"exclaim", "characters", SDLK_EXCLAIM }, + {"quotedbl", "characters", SDLK_QUOTEDBL }, + {"hash", "characters", SDLK_HASH }, + {"dollar", "characters", SDLK_DOLLAR }, + {"ampersand", "characters", SDLK_AMPERSAND }, + {"quote", "characters", SDLK_QUOTE }, + {"leftparen", "characters", SDLK_LEFTPAREN }, + {"rightparen", "characters", SDLK_RIGHTPAREN }, + {"asterisk", "characters", SDLK_ASTERISK }, + {"plus", "characters", SDLK_PLUS }, + {"comma", "characters", SDLK_COMMA }, + {"minus", "characters", SDLK_MINUS }, + {"period", "characters", SDLK_PERIOD }, + {"slash", "characters", SDLK_SLASH }, + {"0", "numeric", SDLK_0 }, + {"1", "numeric", SDLK_1 }, + {"2", "numeric", SDLK_2 }, + {"3", "numeric", SDLK_3 }, + {"4", "numeric", SDLK_4 }, + {"5", "numeric", SDLK_5 }, + {"6", "numeric", SDLK_6 }, + {"7", "numeric", SDLK_7 }, + {"8", "numeric", SDLK_8 }, + {"9", "numeric", SDLK_9 }, + {"colon", "characters", SDLK_COLON }, + {"semicolon", "characters", SDLK_SEMICOLON }, + {"less", "characters", SDLK_LESS }, + {"equals", "characters", SDLK_EQUALS }, + {"greater", "characters", SDLK_GREATER }, + {"question", "characters", SDLK_QUESTION }, + {"at", "characters", SDLK_AT }, + {"leftbracket", "characters", SDLK_LEFTBRACKET }, + {"backslash", "characters", SDLK_BACKSLASH }, + {"rightbracket", "characters", SDLK_RIGHTBRACKET }, + {"caret", "characters", SDLK_CARET }, + {"underscore", "characters", SDLK_UNDERSCORE }, + {"backquote", "characters", SDLK_BACKQUOTE }, + {"a", "alphabetic", SDLK_a }, + {"b", "alphabetic", SDLK_b }, + {"c", "alphabetic", SDLK_c }, + {"d", "alphabetic", SDLK_d }, + {"e", "alphabetic", SDLK_e }, + {"f", "alphabetic", SDLK_f }, + {"g", "alphabetic", SDLK_g }, + {"h", "alphabetic", SDLK_h }, + {"i", "alphabetic", SDLK_i }, + {"j", "alphabetic", SDLK_j }, + {"k", "alphabetic", SDLK_k }, + {"l", "alphabetic", SDLK_l }, + {"m", "alphabetic", SDLK_m }, + {"n", "alphabetic", SDLK_n }, + {"o", "alphabetic", SDLK_o }, + {"p", "alphabetic", SDLK_p }, + {"q", "alphabetic", SDLK_q }, + {"r", "alphabetic", SDLK_r }, + {"s", "alphabetic", SDLK_s }, + {"t", "alphabetic", SDLK_t }, + {"u", "alphabetic", SDLK_u }, + {"v", "alphabetic", SDLK_v }, + {"w", "alphabetic", SDLK_w }, + {"x", "alphabetic", SDLK_x }, + {"y", "alphabetic", SDLK_y }, + {"z", "alphabetic", SDLK_z }, + {"delete", "editing", SDLK_DELETE }, + {"world_0", "international",SDLK_WORLD_0 }, + {"world_1", "international",SDLK_WORLD_1 }, + {"world_2", "international",SDLK_WORLD_2 }, + {"world_3", "international",SDLK_WORLD_3 }, + {"world_4", "international",SDLK_WORLD_4 }, + {"world_5", "international",SDLK_WORLD_5 }, + {"world_6", "international",SDLK_WORLD_6 }, + {"world_7", "international",SDLK_WORLD_7 }, + {"world_8", "international",SDLK_WORLD_8 }, + {"world_9", "international",SDLK_WORLD_9 }, + {"world_10", "international",SDLK_WORLD_10 }, + {"world_11", "international",SDLK_WORLD_11 }, + {"world_12", "international",SDLK_WORLD_12 }, + {"world_13", "international",SDLK_WORLD_13 }, + {"world_14", "international",SDLK_WORLD_14 }, + {"world_15", "international",SDLK_WORLD_15 }, + {"world_16", "international",SDLK_WORLD_16 }, + {"world_17", "international",SDLK_WORLD_17 }, + {"world_18", "international",SDLK_WORLD_18 }, + {"world_19", "international",SDLK_WORLD_19 }, + {"world_20", "international",SDLK_WORLD_20 }, + {"world_21", "international",SDLK_WORLD_21 }, + {"world_22", "international",SDLK_WORLD_22 }, + {"world_23", "international",SDLK_WORLD_23 }, + {"world_24", "international",SDLK_WORLD_24 }, + {"world_25", "international",SDLK_WORLD_25 }, + {"world_26", "international",SDLK_WORLD_26 }, + {"world_27", "international",SDLK_WORLD_27 }, + {"world_28", "international",SDLK_WORLD_28 }, + {"world_29", "international",SDLK_WORLD_29 }, + {"world_30", "international",SDLK_WORLD_30 }, + {"world_31", "international",SDLK_WORLD_31 }, + {"world_32", "international",SDLK_WORLD_32 }, + {"world_33", "international",SDLK_WORLD_33 }, + {"world_34", "international",SDLK_WORLD_34 }, + {"world_35", "international",SDLK_WORLD_35 }, + {"world_36", "international",SDLK_WORLD_36 }, + {"world_37", "international",SDLK_WORLD_37 }, + {"world_38", "international",SDLK_WORLD_38 }, + {"world_39", "international",SDLK_WORLD_39 }, + {"world_40", "international",SDLK_WORLD_40 }, + {"world_41", "international",SDLK_WORLD_41 }, + {"world_42", "international",SDLK_WORLD_42 }, + {"world_43", "international",SDLK_WORLD_43 }, + {"world_44", "international",SDLK_WORLD_44 }, + {"world_45", "international",SDLK_WORLD_45 }, + {"world_46", "international",SDLK_WORLD_46 }, + {"world_47", "international",SDLK_WORLD_47 }, + {"world_48", "international",SDLK_WORLD_48 }, + {"world_49", "international",SDLK_WORLD_49 }, + {"world_50", "international",SDLK_WORLD_50 }, + {"world_51", "international",SDLK_WORLD_51 }, + {"world_52", "international",SDLK_WORLD_52 }, + {"world_53", "international",SDLK_WORLD_53 }, + {"world_54", "international",SDLK_WORLD_54 }, + {"world_55", "international",SDLK_WORLD_55 }, + {"world_56", "international",SDLK_WORLD_56 }, + {"world_57", "international",SDLK_WORLD_57 }, + {"world_58", "international",SDLK_WORLD_58 }, + {"world_59", "international",SDLK_WORLD_59 }, + {"world_60", "international",SDLK_WORLD_60 }, + {"world_61", "international",SDLK_WORLD_61 }, + {"world_62", "international",SDLK_WORLD_62 }, + {"world_63", "international",SDLK_WORLD_63 }, + {"world_64", "international",SDLK_WORLD_64 }, + {"world_65", "international",SDLK_WORLD_65 }, + {"world_66", "international",SDLK_WORLD_66 }, + {"world_67", "international",SDLK_WORLD_67 }, + {"world_68", "international",SDLK_WORLD_68 }, + {"world_69", "international",SDLK_WORLD_69 }, + {"world_70", "international",SDLK_WORLD_70 }, + {"world_71", "international",SDLK_WORLD_71 }, + {"world_72", "international",SDLK_WORLD_72 }, + {"world_73", "international",SDLK_WORLD_73 }, + {"world_74", "international",SDLK_WORLD_74 }, + {"world_75", "international",SDLK_WORLD_75 }, + {"world_76", "international",SDLK_WORLD_76 }, + {"world_77", "international",SDLK_WORLD_77 }, + {"world_78", "international",SDLK_WORLD_78 }, + {"world_79", "international",SDLK_WORLD_79 }, + {"world_80", "international",SDLK_WORLD_80 }, + {"world_81", "international",SDLK_WORLD_81 }, + {"world_82", "international",SDLK_WORLD_82 }, + {"world_83", "international",SDLK_WORLD_83 }, + {"world_84", "international",SDLK_WORLD_84 }, + {"world_85", "international",SDLK_WORLD_85 }, + {"world_86", "international",SDLK_WORLD_86 }, + {"world_87", "international",SDLK_WORLD_87 }, + {"world_88", "international",SDLK_WORLD_88 }, + {"world_89", "international",SDLK_WORLD_89 }, + {"world_90", "international",SDLK_WORLD_90 }, + {"world_91", "international",SDLK_WORLD_91 }, + {"world_92", "international",SDLK_WORLD_92 }, + {"world_93", "international",SDLK_WORLD_93 }, + {"world_94", "international",SDLK_WORLD_94 }, + {"world_95", "international",SDLK_WORLD_95 }, + {"kp0", "numeric", SDLK_KP0 }, + {"kp1", "numeric", SDLK_KP1 }, + {"kp2", "numeric", SDLK_KP2 }, + {"kp3", "numeric", SDLK_KP3 }, + {"kp4", "numeric", SDLK_KP4 }, + {"kp5", "numeric", SDLK_KP5 }, + {"kp6", "numeric", SDLK_KP6 }, + {"kp7", "numeric", SDLK_KP7 }, + {"kp8", "numeric", SDLK_KP8 }, + {"kp9", "numeric", SDLK_KP9 }, + {"kp_period", "characters", SDLK_KP_PERIOD }, + {"kp_divide", "characters", SDLK_KP_DIVIDE }, + {"kp_multiply", "characters", SDLK_KP_MULTIPLY }, + {"kp_minus", "characters", SDLK_KP_MINUS }, + {"kp_plus", "characters", SDLK_KP_PLUS }, + {"kp_enter", "characters", SDLK_KP_ENTER }, + {"kp_equals", "characters", SDLK_KP_EQUALS }, + {"up", "editing", SDLK_UP }, + {"down", "editing", SDLK_DOWN }, + {"right", "editing", SDLK_RIGHT }, + {"left", "editing", SDLK_LEFT }, + {"insert", "editing", SDLK_INSERT }, + {"home", "editing", SDLK_HOME }, + {"end", "editing", SDLK_END }, + {"pageup", "editing", SDLK_PAGEUP }, + {"pagedown", "editing", SDLK_PAGEDOWN }, + {"f1", "F-keys", SDLK_F1 }, + {"f2", "F-keys", SDLK_F2 }, + {"f3", "F-keys", SDLK_F3 }, + {"f4", "F-keys", SDLK_F4 }, + {"f5", "F-keys", SDLK_F5 }, + {"f6", "F-keys", SDLK_F6 }, + {"f7", "F-keys", SDLK_F7 }, + {"f8", "F-keys", SDLK_F8 }, + {"f9", "F-keys", SDLK_F9 }, + {"f10", "F-keys", SDLK_F10 }, + {"f11", "F-keys", SDLK_F11 }, + {"f12", "F-keys", SDLK_F12 }, + {"f13", "F-keys", SDLK_F13 }, + {"f14", "F-keys", SDLK_F14 }, + {"f15", "F-keys", SDLK_F15 }, + {"numlock", "locks", SDLK_NUMLOCK }, + {"capslock", "locks", SDLK_CAPSLOCK }, + {"scrollock", "locks", SDLK_SCROLLOCK }, + {"rshift", "modifiers", SDLK_RSHIFT }, + {"lshift", "modifiers", SDLK_LSHIFT }, + {"rctrl", "modifiers", SDLK_RCTRL }, + {"lctrl", "modifiers", SDLK_LCTRL }, + {"ralt", "modifiers", SDLK_RALT }, + {"lalt", "modifiers", SDLK_LALT }, + {"rmeta", "modifiers", SDLK_RMETA }, + {"lmeta", "modifiers", SDLK_LMETA }, + {"lsuper", "modifiers", SDLK_LSUPER }, + {"rsuper", "modifiers", SDLK_RSUPER }, + {"mode", "modifiers", SDLK_MODE }, + {"compose", "modifiers", SDLK_COMPOSE }, + {"help", "special", SDLK_HELP }, + {"print", "special", SDLK_PRINT }, + {"sysreq", "special", SDLK_SYSREQ }, + {"break", "special", SDLK_BREAK }, + {"menu", "special", SDLK_MENU }, + {"power", "special", SDLK_POWER }, + {"euro", "characters", SDLK_EURO }, + {"undo", "special", SDLK_UNDO }, {NULL, 0 } }; @@ -366,13 +367,13 @@ void init_sdl_keys() } struct sdl_key* k = keys_table; while(k->name) { - symbolkeys[k->symbol] = new keygroup(k->name, keygroup::KT_KEY); + symbolkeys[k->symbol] = new keygroup(k->name, k->clazz, keygroup::KT_KEY); k++; } for(unsigned i = 0; i < 256; i++) { std::ostringstream x; x << "key" << i; - scancodekeys[i] = new keygroup(x.str(), keygroup::KT_KEY); + scancodekeys[i] = new keygroup(x.str(), "scancode", keygroup::KT_KEY); } } diff --git a/src/platform/wxwidgets/editor-keyselect.cpp b/src/platform/wxwidgets/editor-keyselect.cpp index 0309c761..3baede8f 100644 --- a/src/platform/wxwidgets/editor-keyselect.cpp +++ b/src/platform/wxwidgets/editor-keyselect.cpp @@ -21,6 +21,7 @@ namespace void on_ok(wxCommandEvent& e); void on_cancel(wxCommandEvent& e); void on_clear(wxCommandEvent& e); + void on_classchange(wxCommandEvent& e); std::string getkey(); private: void set_mask(const std::string& mod); @@ -29,6 +30,7 @@ namespace void (wxdialog_keyentry::*fn)(const std::string& mod)); void load_spec(const std::string& spec); std::map modifiers; + wxComboBox* mainclass; wxComboBox* mainkey; wxButton* ok; wxButton* cancel; diff --git a/src/platform/wxwidgets/keyboard.cpp b/src/platform/wxwidgets/keyboard.cpp index e55cabf2..2642b806 100644 --- a/src/platform/wxwidgets/keyboard.cpp +++ b/src/platform/wxwidgets/keyboard.cpp @@ -33,226 +33,227 @@ namespace { int keynum; const char* name; + const char* clazz; keygroup* allocated; } keys[] = { - { WXK_BACK, "back", NULL }, - { WXK_TAB, "tab", NULL }, - { WXK_RETURN, "return", NULL }, - { WXK_ESCAPE, "escape", NULL }, - { WXK_SPACE, "space", NULL }, - { 33, "exclaim", NULL }, - { 34, "quotedbl", NULL }, - { 35, "hash", NULL }, - { 36, "dollar", NULL }, - { 37, "percent", NULL }, - { 38, "ampersand", NULL }, - { 39, "quote", NULL }, - { 40, "leftparen", NULL }, - { 41, "rightparen", NULL }, - { 42, "asterisk", NULL }, - { 43, "plus", NULL }, - { 44, "comma", NULL }, - { 45, "minus", NULL }, - { 46, "period", NULL }, - { 47, "slash", NULL }, - { 48, "0", NULL }, - { 49, "1", NULL }, - { 50, "2", NULL }, - { 51, "3", NULL }, - { 52, "4", NULL }, - { 53, "5", NULL }, - { 54, "6", NULL }, - { 55, "7", NULL }, - { 56, "8", NULL }, - { 57, "9", NULL }, - { 58, "colon", NULL }, - { 59, "semicolon", NULL }, - { 60, "less", NULL }, - { 61, "equals", NULL }, - { 62, "greater", NULL }, - { 63, "question", NULL }, - { 64, "at", NULL }, - { 65, "a", NULL }, - { 66, "b", NULL }, - { 67, "c", NULL }, - { 68, "d", NULL }, - { 69, "e", NULL }, - { 70, "f", NULL }, - { 71, "g", NULL }, - { 72, "h", NULL }, - { 73, "i", NULL }, - { 74, "j", NULL }, - { 75, "k", NULL }, - { 76, "l", NULL }, - { 77, "m", NULL }, - { 78, "n", NULL }, - { 79, "o", NULL }, - { 80, "p", NULL }, - { 81, "q", NULL }, - { 82, "r", NULL }, - { 83, "s", NULL }, - { 84, "t", NULL }, - { 85, "u", NULL }, - { 86, "v", NULL }, - { 87, "w", NULL }, - { 88, "x", NULL }, - { 89, "y", NULL }, - { 90, "z", NULL }, - { 91, "leftbracket", NULL }, - { 92, "backslash", NULL }, - { 93, "rightbracket", NULL }, - { 94, "caret", NULL }, - { 95, "underscore", NULL }, - { 96, "backquote", NULL }, - { 97, "a", NULL }, - { 98, "b", NULL }, - { 99, "c", NULL }, - { 100, "d", NULL }, - { 101, "e", NULL }, - { 102, "f", NULL }, - { 103, "g", NULL }, - { 104, "h", NULL }, - { 105, "i", NULL }, - { 106, "j", NULL }, - { 107, "k", NULL }, - { 108, "l", NULL }, - { 109, "m", NULL }, - { 110, "n", NULL }, - { 111, "o", NULL }, - { 112, "p", NULL }, - { 113, "q", NULL }, - { 114, "r", NULL }, - { 115, "s", NULL }, - { 116, "t", NULL }, - { 117, "u", NULL }, - { 118, "v", NULL }, - { 119, "w", NULL }, - { 120, "x", NULL }, - { 121, "y", NULL }, - { 122, "z", NULL }, - { 123, "leftcurly", NULL }, - { 124, "pipe", NULL }, - { 125, "rightcurly", NULL }, - { 126, "tilde", NULL }, - { WXK_DELETE, "delete", NULL }, - { WXK_START, "start", NULL }, - { WXK_LBUTTON, "lbutton", NULL }, - { WXK_RBUTTON, "rbutton", NULL }, - { WXK_CANCEL, "cancel", NULL }, - { WXK_MBUTTON, "mbutton", NULL }, - { WXK_CLEAR, "clear", NULL }, - { WXK_SHIFT, "shift", NULL }, - { WXK_ALT, "alt", NULL }, - { WXK_CONTROL, "control", NULL }, - { WXK_MENU, "menu", NULL }, - { WXK_PAUSE, "pause", NULL }, - { WXK_CAPITAL, "capital", NULL }, - { WXK_END, "end", NULL }, - { WXK_HOME, "home", NULL }, - { WXK_LEFT, "lefT", NULL }, - { WXK_UP, "up", NULL }, - { WXK_RIGHT, "right", NULL }, - { WXK_DOWN, "down", NULL }, - { WXK_SELECT, "select", NULL }, - { WXK_PRINT, "print", NULL }, - { WXK_EXECUTE, "execute", NULL }, - { WXK_SNAPSHOT, "snapshot", NULL }, - { WXK_INSERT, "insert", NULL }, - { WXK_HELP, "help", NULL }, - { WXK_NUMPAD0, "numpad0", NULL }, - { WXK_NUMPAD1, "numpad1", NULL }, - { WXK_NUMPAD2, "numpad2", NULL }, - { WXK_NUMPAD3, "numpad3", NULL }, - { WXK_NUMPAD4, "numpad4", NULL }, - { WXK_NUMPAD5, "numpad5", NULL }, - { WXK_NUMPAD6, "numpad6", NULL }, - { WXK_NUMPAD7, "numpad7", NULL }, - { WXK_NUMPAD8, "numpad8", NULL }, - { WXK_NUMPAD9, "numpad9", NULL }, - { WXK_MULTIPLY, "multiply", NULL }, - { WXK_ADD, "add", NULL }, - { WXK_SEPARATOR, "separator", NULL }, - { WXK_SUBTRACT, "subtract", NULL }, - { WXK_DECIMAL, "decimal", NULL }, - { WXK_DIVIDE, "divide", NULL }, - { WXK_F1, "f1", NULL }, - { WXK_F2, "f2", NULL }, - { WXK_F3, "f3", NULL }, - { WXK_F4, "f4", NULL }, - { WXK_F5, "f5", NULL }, - { WXK_F6, "f6", NULL }, - { WXK_F7, "f7", NULL }, - { WXK_F8, "f8", NULL }, - { WXK_F9, "f9", NULL }, - { WXK_F10, "f10", NULL }, - { WXK_F11, "f11", NULL }, - { WXK_F12, "f12", NULL }, - { WXK_F13, "f13", NULL }, - { WXK_F14, "f14", NULL }, - { WXK_F15, "f15", NULL }, - { WXK_F16, "f16", NULL }, - { WXK_F17, "f17", NULL }, - { WXK_F18, "f18", NULL }, - { WXK_F19, "f19", NULL }, - { WXK_F20, "f20", NULL }, - { WXK_F21, "f21", NULL }, - { WXK_F22, "f22", NULL }, - { WXK_F23, "f23", NULL }, - { WXK_F24, "f24", NULL }, - { WXK_NUMLOCK, "numlock", NULL }, - { WXK_SCROLL, "scroll", NULL }, - { WXK_PAGEUP, "pageup", NULL }, - { WXK_PAGEDOWN, "pagedown", NULL }, - { WXK_NUMPAD_SPACE, "numpad_space", NULL }, - { WXK_NUMPAD_TAB, "numpad_tab", NULL }, - { WXK_NUMPAD_ENTER, "numpad_enter", NULL }, - { WXK_NUMPAD_F1, "numpad_f1", NULL }, - { WXK_NUMPAD_F2, "numpad_f2", NULL }, - { WXK_NUMPAD_F3, "numpad_f3", NULL }, - { WXK_NUMPAD_F4, "numpad_f4", NULL }, - { WXK_NUMPAD_HOME, "numpad_home", NULL }, - { WXK_NUMPAD_LEFT, "numpad_left", NULL }, - { WXK_NUMPAD_UP, "numpad_up", NULL }, - { WXK_NUMPAD_RIGHT, "numpad_right", NULL }, - { WXK_NUMPAD_DOWN, "numpad_down", NULL }, - { WXK_NUMPAD_PAGEUP, "numpad_pageup", NULL }, - { WXK_NUMPAD_PAGEDOWN, "numpad_pagedown", NULL }, - { WXK_NUMPAD_END, "numpad_end", NULL }, - { WXK_NUMPAD_BEGIN, "numpad_begin", NULL }, - { WXK_NUMPAD_INSERT, "numpad_insert", NULL }, - { WXK_NUMPAD_DELETE, "numpad_delete", NULL }, - { WXK_NUMPAD_EQUAL, "numpad_equal", NULL }, - { WXK_NUMPAD_MULTIPLY, "numpad_multiply", NULL }, - { WXK_NUMPAD_ADD, "numpad_add", NULL }, - { WXK_NUMPAD_SEPARATOR, "numpad_separator", NULL }, - { WXK_NUMPAD_SUBTRACT, "numpad_subtract", NULL }, - { WXK_NUMPAD_DECIMAL, "numpad_decimal", NULL }, - { WXK_NUMPAD_DIVIDE, "numpad_divide", NULL }, - { WXK_WINDOWS_LEFT, "windows_left", NULL }, - { WXK_WINDOWS_RIGHT, "windows_right", NULL }, - { WXK_WINDOWS_MENU, "windows_menu", NULL }, - { WXK_COMMAND, "command", NULL }, - { WXK_SPECIAL1, "special1", NULL }, - { WXK_SPECIAL2, "special2", NULL }, - { WXK_SPECIAL3, "special3", NULL }, - { WXK_SPECIAL4, "special4", NULL }, - { WXK_SPECIAL5, "special5", NULL }, - { WXK_SPECIAL6, "special6", NULL }, - { WXK_SPECIAL7, "special7", NULL }, - { WXK_SPECIAL8, "special8", NULL }, - { WXK_SPECIAL9, "special9", NULL }, - { WXK_SPECIAL10, "special10", NULL }, - { WXK_SPECIAL11, "special11", NULL }, - { WXK_SPECIAL12, "special12", NULL }, - { WXK_SPECIAL13, "special13", NULL }, - { WXK_SPECIAL14, "special14", NULL }, - { WXK_SPECIAL15, "special15", NULL }, - { WXK_SPECIAL16, "special16", NULL }, - { WXK_SPECIAL17, "special17", NULL }, - { WXK_SPECIAL18, "special18", NULL }, - { WXK_SPECIAL19, "special19", NULL }, - { WXK_SPECIAL20, "special20", NULL }, - { 0, NULL, NULL } + { WXK_BACK, "back", "editing", NULL }, + { WXK_TAB, "tab", "editing", NULL }, + { WXK_RETURN, "return", "editing", NULL }, + { WXK_ESCAPE, "escape", "editing", NULL }, + { WXK_SPACE, "space", "characters", NULL }, + { 33, "exclaim", "characters", NULL }, + { 34, "quotedbl", "characters", NULL }, + { 35, "hash", "characters", NULL }, + { 36, "dollar", "characters", NULL }, + { 37, "percent", "characters", NULL }, + { 38, "ampersand", "characters", NULL }, + { 39, "quote", "characters", NULL }, + { 40, "leftparen", "characters", NULL }, + { 41, "rightparen", "characters", NULL }, + { 42, "asterisk", "characters", NULL }, + { 43, "plus", "characters", NULL }, + { 44, "comma", "characters", NULL }, + { 45, "minus", "characters", NULL }, + { 46, "period", "characters", NULL }, + { 47, "slash", "characters", NULL }, + { 48, "0", "numeric", NULL }, + { 49, "1", "numeric", NULL }, + { 50, "2", "numeric", NULL }, + { 51, "3", "numeric", NULL }, + { 52, "4", "numeric", NULL }, + { 53, "5", "numeric", NULL }, + { 54, "6", "numeric", NULL }, + { 55, "7", "numeric", NULL }, + { 56, "8", "numeric", NULL }, + { 57, "9", "numeric", NULL }, + { 58, "colon", "characters", NULL }, + { 59, "semicolon", "characters", NULL }, + { 60, "less", "characters", NULL }, + { 61, "equals", "characters", NULL }, + { 62, "greater", "characters", NULL }, + { 63, "question", "characters", NULL }, + { 64, "at", "characters", NULL }, + { 65, "a", "alphabetic", NULL }, + { 66, "b", "alphabetic", NULL }, + { 67, "c", "alphabetic", NULL }, + { 68, "d", "alphabetic", NULL }, + { 69, "e", "alphabetic", NULL }, + { 70, "f", "alphabetic", NULL }, + { 71, "g", "alphabetic", NULL }, + { 72, "h", "alphabetic", NULL }, + { 73, "i", "alphabetic", NULL }, + { 74, "j", "alphabetic", NULL }, + { 75, "k", "alphabetic", NULL }, + { 76, "l", "alphabetic", NULL }, + { 77, "m", "alphabetic", NULL }, + { 78, "n", "alphabetic", NULL }, + { 79, "o", "alphabetic", NULL }, + { 80, "p", "alphabetic", NULL }, + { 81, "q", "alphabetic", NULL }, + { 82, "r", "alphabetic", NULL }, + { 83, "s", "alphabetic", NULL }, + { 84, "t", "alphabetic", NULL }, + { 85, "u", "alphabetic", NULL }, + { 86, "v", "alphabetic", NULL }, + { 87, "w", "alphabetic", NULL }, + { 88, "x", "alphabetic", NULL }, + { 89, "y", "alphabetic", NULL }, + { 90, "z", "alphabetic", NULL }, + { 91, "leftbracket", "characters", NULL }, + { 92, "backslash", "characters", NULL }, + { 93, "rightbracket", "characters", NULL }, + { 94, "caret", "characters", NULL }, + { 95, "underscore", "characters", NULL }, + { 96, "backquote", "characters", NULL }, + { 97, "a", "alphabetic", NULL }, + { 98, "b", "alphabetic", NULL }, + { 99, "c", "alphabetic", NULL }, + { 100, "d", "alphabetic", NULL }, + { 101, "e", "alphabetic", NULL }, + { 102, "f", "alphabetic", NULL }, + { 103, "g", "alphabetic", NULL }, + { 104, "h", "alphabetic", NULL }, + { 105, "i", "alphabetic", NULL }, + { 106, "j", "alphabetic", NULL }, + { 107, "k", "alphabetic", NULL }, + { 108, "l", "alphabetic", NULL }, + { 109, "m", "alphabetic", NULL }, + { 110, "n", "alphabetic", NULL }, + { 111, "o", "alphabetic", NULL }, + { 112, "p", "alphabetic", NULL }, + { 113, "q", "alphabetic", NULL }, + { 114, "r", "alphabetic", NULL }, + { 115, "s", "alphabetic", NULL }, + { 116, "t", "alphabetic", NULL }, + { 117, "u", "alphabetic", NULL }, + { 118, "v", "alphabetic", NULL }, + { 119, "w", "alphabetic", NULL }, + { 120, "x", "alphabetic", NULL }, + { 121, "y", "alphabetic", NULL }, + { 122, "z", "alphabetic", NULL }, + { 123, "leftcurly", "characters", NULL }, + { 124, "pipe", "characters", NULL }, + { 125, "rightcurly", "characters", NULL }, + { 126, "tilde", "characters", NULL }, + { WXK_DELETE, "delete", "editing", NULL }, + { WXK_START, "start", "special", NULL }, + { WXK_LBUTTON, "lbutton", "special", NULL }, + { WXK_RBUTTON, "rbutton", "special", NULL }, + { WXK_CANCEL, "cancel", "special", NULL }, + { WXK_MBUTTON, "mbutton", "special", NULL }, + { WXK_CLEAR, "clear", "editing", NULL }, + { WXK_SHIFT, "shift", "modifiers", NULL }, + { WXK_ALT, "alt", "modifiers", NULL }, + { WXK_CONTROL, "control", "modifiers", NULL }, + { WXK_MENU, "menu", "special", NULL }, + { WXK_PAUSE, "pause", "special", NULL }, + { WXK_CAPITAL, "capital", "locks", NULL }, + { WXK_END, "end", "editing", NULL }, + { WXK_HOME, "home", "editing", NULL }, + { WXK_LEFT, "lefT", "editing", NULL }, + { WXK_UP, "up", "editing", NULL }, + { WXK_RIGHT, "right", "editing", NULL }, + { WXK_DOWN, "down", "editing", NULL }, + { WXK_SELECT, "select", "special", NULL }, + { WXK_PRINT, "print", "special", NULL }, + { WXK_EXECUTE, "execute", "special", NULL }, + { WXK_SNAPSHOT, "snapshot", "special", NULL }, + { WXK_INSERT, "insert", "editing", NULL }, + { WXK_HELP, "help", "special", NULL }, + { WXK_NUMPAD0, "numpad0", "numeric", NULL }, + { WXK_NUMPAD1, "numpad1", "numeric", NULL }, + { WXK_NUMPAD2, "numpad2", "numeric", NULL }, + { WXK_NUMPAD3, "numpad3", "numeric", NULL }, + { WXK_NUMPAD4, "numpad4", "numeric", NULL }, + { WXK_NUMPAD5, "numpad5", "numeric", NULL }, + { WXK_NUMPAD6, "numpad6", "numeric", NULL }, + { WXK_NUMPAD7, "numpad7", "numeric", NULL }, + { WXK_NUMPAD8, "numpad8", "numeric", NULL }, + { WXK_NUMPAD9, "numpad9", "numeric", NULL }, + { WXK_MULTIPLY, "multiply", "characters", NULL }, + { WXK_ADD, "add", "characters", NULL }, + { WXK_SEPARATOR, "separator", "characters", NULL }, + { WXK_SUBTRACT, "subtract", "characters", NULL }, + { WXK_DECIMAL, "decimal", "characters", NULL }, + { WXK_DIVIDE, "divide", "characters", NULL }, + { WXK_F1, "f1", "F-keys", NULL }, + { WXK_F2, "f2", "F-keys", NULL }, + { WXK_F3, "f3", "F-keys", NULL }, + { WXK_F4, "f4", "F-keys", NULL }, + { WXK_F5, "f5", "F-keys", NULL }, + { WXK_F6, "f6", "F-keys", NULL }, + { WXK_F7, "f7", "F-keys", NULL }, + { WXK_F8, "f8", "F-keys", NULL }, + { WXK_F9, "f9", "F-keys", NULL }, + { WXK_F10, "f10", "F-keys", NULL }, + { WXK_F11, "f11", "F-keys", NULL }, + { WXK_F12, "f12", "F-keys", NULL }, + { WXK_F13, "f13", "F-keys", NULL }, + { WXK_F14, "f14", "F-keys", NULL }, + { WXK_F15, "f15", "F-keys", NULL }, + { WXK_F16, "f16", "F-keys", NULL }, + { WXK_F17, "f17", "F-keys", NULL }, + { WXK_F18, "f18", "F-keys", NULL }, + { WXK_F19, "f19", "F-keys", NULL }, + { WXK_F20, "f20", "F-keys", NULL }, + { WXK_F21, "f21", "F-keys", NULL }, + { WXK_F22, "f22", "F-keys", NULL }, + { WXK_F23, "f23", "F-keys", NULL }, + { WXK_F24, "f24", "F-keys", NULL }, + { WXK_NUMLOCK, "numlock", "locks", NULL }, + { WXK_SCROLL, "scroll", "locks", NULL }, + { WXK_PAGEUP, "pageup", "editing", NULL }, + { WXK_PAGEDOWN, "pagedown", "editing", NULL }, + { WXK_NUMPAD_SPACE, "numpad_space", "editing", NULL }, + { WXK_NUMPAD_TAB, "numpad_tab", "editing", NULL }, + { WXK_NUMPAD_ENTER, "numpad_enter", "editing", NULL }, + { WXK_NUMPAD_F1, "numpad_f1", "F-keys", NULL }, + { WXK_NUMPAD_F2, "numpad_f2", "F-keys", NULL }, + { WXK_NUMPAD_F3, "numpad_f3", "F-keys", NULL }, + { WXK_NUMPAD_F4, "numpad_f4", "F-keys", NULL }, + { WXK_NUMPAD_HOME, "numpad_home", "editing", NULL }, + { WXK_NUMPAD_LEFT, "numpad_left", "editing", NULL }, + { WXK_NUMPAD_UP, "numpad_up", "editing", NULL }, + { WXK_NUMPAD_RIGHT, "numpad_right", "editing", NULL }, + { WXK_NUMPAD_DOWN, "numpad_down", "editing", NULL }, + { WXK_NUMPAD_PAGEUP, "numpad_pageup", "editing", NULL }, + { WXK_NUMPAD_PAGEDOWN, "numpad_pagedown", "editing", NULL }, + { WXK_NUMPAD_END, "numpad_end", "editing", NULL }, + { WXK_NUMPAD_BEGIN, "numpad_begin", "editing", NULL }, + { WXK_NUMPAD_INSERT, "numpad_insert", "editing", NULL }, + { WXK_NUMPAD_DELETE, "numpad_delete", "editing", NULL }, + { WXK_NUMPAD_EQUAL, "numpad_equal", "characters", NULL }, + { WXK_NUMPAD_MULTIPLY, "numpad_multiply", "characters", NULL }, + { WXK_NUMPAD_ADD, "numpad_add", "characters", NULL }, + { WXK_NUMPAD_SEPARATOR, "numpad_separator", "characters", NULL }, + { WXK_NUMPAD_SUBTRACT, "numpad_subtract", "characters", NULL }, + { WXK_NUMPAD_DECIMAL, "numpad_decimal", "characters", NULL }, + { WXK_NUMPAD_DIVIDE, "numpad_divide", "characters", NULL }, + { WXK_WINDOWS_LEFT, "windows_left", "modifiers", NULL }, + { WXK_WINDOWS_RIGHT, "windows_right", "modifiers", NULL }, + { WXK_WINDOWS_MENU, "windows_menu", "modifiers", NULL }, + { WXK_COMMAND, "command", "special", NULL }, + { WXK_SPECIAL1, "special1", "special", NULL }, + { WXK_SPECIAL2, "special2", "special", NULL }, + { WXK_SPECIAL3, "special3", "special", NULL }, + { WXK_SPECIAL4, "special4", "special", NULL }, + { WXK_SPECIAL5, "special5", "special", NULL }, + { WXK_SPECIAL6, "special6", "special", NULL }, + { WXK_SPECIAL7, "special7", "special", NULL }, + { WXK_SPECIAL8, "special8", "special", NULL }, + { WXK_SPECIAL9, "special9", "special", NULL }, + { WXK_SPECIAL10, "special10", "special", NULL }, + { WXK_SPECIAL11, "special11", "special", NULL }, + { WXK_SPECIAL12, "special12", "special", NULL }, + { WXK_SPECIAL13, "special13", "special", NULL }, + { WXK_SPECIAL14, "special14", "special", NULL }, + { WXK_SPECIAL15, "special15", "special", NULL }, + { WXK_SPECIAL16, "special16", "special", NULL }, + { WXK_SPECIAL17, "special17", "special", NULL }, + { WXK_SPECIAL18, "special18", "special", NULL }, + { WXK_SPECIAL19, "special19", "special", NULL }, + { WXK_SPECIAL20, "special20", "special", NULL }, + { 0, NULL, NULL, NULL } }; std::map modifier_map; @@ -333,7 +334,7 @@ void initialize_wx_keyboard() key_entry* k = keys; while(k->name) { if(!keys_allocated.count(k->name)) { - k->allocated = new keygroup(k->name, keygroup::KT_KEY); + k->allocated = new keygroup(k->name, k->clazz, keygroup::KT_KEY); key_map[k->keynum] = k->allocated; keys_allocated[k->name] = k->keynum; } else diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index 50077914..f845b1ed 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -147,12 +147,12 @@ namespace emulation_thread->join(); } - keygroup mouse_x("mouse_x", keygroup::KT_MOUSE); - keygroup mouse_y("mouse_y", keygroup::KT_MOUSE); - keygroup mouse_l("mouse_left", keygroup::KT_KEY); - keygroup mouse_m("mouse_center", keygroup::KT_KEY); - keygroup mouse_r("mouse_right", keygroup::KT_KEY); - keygroup mouse_i("mouse_inwindow", keygroup::KT_KEY); + keygroup mouse_x("mouse_x", "mouse", keygroup::KT_MOUSE); + keygroup mouse_y("mouse_y", "mouse", keygroup::KT_MOUSE); + keygroup mouse_l("mouse_left", "mouse", keygroup::KT_KEY); + keygroup mouse_m("mouse_center", "mouse", keygroup::KT_KEY); + keygroup mouse_r("mouse_right", "mouse", keygroup::KT_KEY); + keygroup mouse_i("mouse_inwindow", "mouse", keygroup::KT_KEY); void handle_wx_mouse(wxMouseEvent& e) { From b05b31a538db52ab2a0262282125c764e29a53ae Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 7 Apr 2012 19:12:14 +0300 Subject: [PATCH 03/11] Rework jukebox - Remove explicit setting for jukebox names - Add setting for number of saves in jukebox - Add path for save slots. --- include/core/moviedata.hpp | 2 +- manual.lyx | 8 --- manual.txt | 8 +-- src/core/mainloop.cpp | 72 ++++++++++++++------------- src/core/moviedata.cpp | 58 ++++++++++++++++++--- src/platform/win32mm/joystick.cpp | 6 +-- src/platform/wxwidgets/main.cpp | 3 -- src/platform/wxwidgets/mainwindow.cpp | 29 ----------- src/platform/wxwidgets/settings.cpp | 39 ++++++++++++--- 9 files changed, 125 insertions(+), 100 deletions(-) diff --git a/include/core/moviedata.hpp b/include/core/moviedata.hpp index 571d45ff..e17e5856 100644 --- a/include/core/moviedata.hpp +++ b/include/core/moviedata.hpp @@ -28,7 +28,7 @@ void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runti void do_load_beginning() throw(std::bad_alloc, std::runtime_error); void do_load_state(struct moviefile& _movie, int lmode); bool do_load_state(const std::string& filename, int lmode); -std::string translate_name_mprefix(std::string original); +std::string translate_name_mprefix(std::string original, bool forio = false); extern std::string last_save; extern movie_logic movb; diff --git a/manual.lyx b/manual.lyx index a6f9fb54..7a2f3bc1 100644 --- a/manual.lyx +++ b/manual.lyx @@ -1654,14 +1654,6 @@ cycle-jukebox-forward Cycle save jukebox forwards \end_layout -\begin_layout Subsubsection -add-jukebox-save -\end_layout - -\begin_layout Standard -Add to jukebox saves. -\end_layout - \begin_layout Subsubsection load-jukebox \end_layout diff --git a/manual.txt b/manual.txt index 647cda0a..4478743f 100644 --- a/manual.txt +++ b/manual.txt @@ -794,15 +794,11 @@ Cycle save jukebox backwards. Cycle save jukebox forwards -6.8.3 add-jukebox-save - -Add to jukebox saves. - -6.8.4 load-jukebox +6.8.3 load-jukebox Do load from jukebox (current mode). -6.8.5 save-jukebox +6.8.4 save-jukebox Do state save to jukebox. diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index 6cb5abba..e058b415 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -6,6 +6,7 @@ #include "core/framebuffer.hpp" #include "core/framerate.hpp" #include "lua/lua.hpp" +#include "library/string.hpp" #include "core/mainloop.hpp" #include "core/movie.hpp" #include "core/moviedata.hpp" @@ -61,7 +62,7 @@ namespace std::set queued_saves; bool stepping_into_save; //Save jukebox. - std::vector save_jukebox; + numeric_setting jukebox_size("jukebox-size", 0, 999, 12); size_t save_jukebox_pointer; //Pending reset cycles. -1 if no reset pending, otherwise, cycle count for reset. long pending_reset_cycles = -1; @@ -75,6 +76,11 @@ namespace //Last frame params. bool last_hires = false; bool last_interlace = false; + + std::string save_jukebox_name(size_t i) + { + return (stringfmt() << "${project}" << (i + 1) << ".lsmv").str(); + } } class firmware_path_setting : public setting @@ -272,8 +278,8 @@ void update_movie_state() x << "F"; _status.set("Flags", x.str()); } - if(save_jukebox.size() > 0) - _status.set("Saveslot", translate_name_mprefix(save_jukebox[save_jukebox_pointer])); + if(jukebox_size > 0) + _status.set("Saveslot", translate_name_mprefix(save_jukebox_name(save_jukebox_pointer))); else _status.erase("Saveslot"); { @@ -399,6 +405,20 @@ class my_interface : public SNES::Interface namespace { + class jukebox_size_listener : public information_dispatch + { + public: + jukebox_size_listener() : information_dispatch("jukebox-size-listener") {}; + void on_setting_change(const std::string& setting, const std::string& value) + { + if(setting == "jukebox-size") { + if(save_jukebox_pointer >= jukebox_size) + save_jukebox_pointer = 0; + update_movie_state(); + } + } + } _jukebox_size_listener; + function_ptr_command<> count_rerecords("count-rerecords", "Count rerecords", "Syntax: count-rerecords\nCounts rerecords.\n", []() throw(std::bad_alloc, std::runtime_error) { @@ -434,11 +454,13 @@ namespace function_ptr_command<> save_jukebox_prev("cycle-jukebox-backward", "Cycle save jukebox backwards", "Syntax: cycle-jukebox-backward\nCycle save jukebox backwards\n", []() throw(std::bad_alloc, std::runtime_error) { + if(jukebox_size == 0) + return; if(save_jukebox_pointer == 0) - save_jukebox_pointer = save_jukebox.size() - 1; + save_jukebox_pointer = jukebox_size - 1; else save_jukebox_pointer--; - if(save_jukebox_pointer >= save_jukebox.size()) + if(save_jukebox_pointer >= jukebox_size) save_jukebox_pointer = 0; update_movie_state(); information_dispatch::do_status_update(); @@ -447,38 +469,32 @@ namespace function_ptr_command<> save_jukebox_next("cycle-jukebox-forward", "Cycle save jukebox forwards", "Syntax: cycle-jukebox-forward\nCycle save jukebox forwards\n", []() throw(std::bad_alloc, std::runtime_error) { - if(save_jukebox_pointer == save_jukebox.size() - 1) + if(jukebox_size == 0) + return; + if(save_jukebox_pointer == jukebox_size - 1) save_jukebox_pointer = 0; else save_jukebox_pointer++; - if(save_jukebox_pointer >= save_jukebox.size()) + if(save_jukebox_pointer >= jukebox_size) save_jukebox_pointer = 0; update_movie_state(); information_dispatch::do_status_update(); }); - function_ptr_command add_jukebox("add-jukebox-save", "Add save to jukebox", - "Syntax: add-jukebox-save\nAdd save to jukebox\n", - [](arg_filename filename) throw(std::bad_alloc, std::runtime_error) { - save_jukebox.push_back(filename); - update_movie_state(); - information_dispatch::do_status_update(); - }); - function_ptr_command<> load_jukebox("load-jukebox", "Load save from jukebox", "Syntax: load-jukebox\nLoad save from jukebox\n", []() throw(std::bad_alloc, std::runtime_error) { - if(!save_jukebox.size()) - throw std::runtime_error("No saves in jukebox"); - mark_pending_load(save_jukebox[save_jukebox_pointer], LOAD_STATE_CURRENT); + if(jukebox_size == 0) + throw std::runtime_error("No slot selected"); + mark_pending_load(save_jukebox_name(save_jukebox_pointer), LOAD_STATE_CURRENT); }); function_ptr_command<> save_jukebox_c("save-jukebox", "Save save to jukebox", "Syntax: save-jukebox\nSave save to jukebox\n", []() throw(std::bad_alloc, std::runtime_error) { - if(!save_jukebox.size()) - throw std::runtime_error("No saves in jukebox"); - mark_pending_save(save_jukebox[save_jukebox_pointer], SAVE_STATE); + if(jukebox_size == 0) + throw std::runtime_error("No slot selected"); + mark_pending_save(save_jukebox_name(save_jukebox_pointer), SAVE_STATE); }); function_ptr_command<> padvance_frame("+advance-frame", "Advance one frame", @@ -646,7 +662,6 @@ namespace while(1); }); - inverse_key ipause_emulator("pause-emulator", "(Un)pause"); inverse_key ijback("cycle-jukebox-backward", "Cycle slot backwards"); inverse_key ijforward("cycle-jukebox-forward", "Cycle slot forwards"); @@ -853,19 +868,6 @@ namespace } } -std::vector get_jukebox_names() -{ - return save_jukebox; -} - -void set_jukebox_names(const std::vector& newj) -{ - save_jukebox = newj; - if(save_jukebox_pointer >= save_jukebox.size()) - save_jukebox_pointer = 0; - update_movie_state(); -} - void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_to_succeed) throw(std::bad_alloc, std::runtime_error) { diff --git a/src/core/moviedata.cpp b/src/core/moviedata.cpp index 621b73c0..d270c73c 100644 --- a/src/core/moviedata.cpp +++ b/src/core/moviedata.cpp @@ -48,6 +48,44 @@ namespace { numeric_setting savecompression("savecompression", 0, 9, 7); + class slot_path_setting : public setting + { + public: + slot_path_setting() : setting("slotpath") { _slotpath = "."; default_slot = true; } + void blank() throw(std::bad_alloc, std::runtime_error) + { + _slotpath = "."; + default_slot = true; + } + + bool is_set() throw() + { + return !default_slot; + } + + void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) + { + if(value != "") { + _slotpath = value; + default_slot = false; + } else + blank(); + } + + std::string get() throw(std::bad_alloc) + { + return _slotpath; + } + + operator std::string() throw(std::bad_alloc) + { + return _slotpath; + } + private: + std::string _slotpath; + bool default_slot; + } slotpath_setting; + class projectprefix_setting : public setting { public: @@ -168,13 +206,17 @@ namespace } } -std::string translate_name_mprefix(std::string original) +std::string translate_name_mprefix(std::string original, bool forio) { size_t prefixloc = original.find("${project}"); - if(prefixloc < original.length()) - return original.substr(0, prefixloc) + static_cast(mprefix) + - original.substr(prefixloc + 10); - else + if(prefixloc < original.length()) { + std::string pprf = forio ? (slotpath_setting.get() + "/") : std::string(""); + if(prefixloc == 0) + return pprf + static_cast(mprefix) + original.substr(prefixloc + 10); + else + return original.substr(0, prefixloc) + static_cast(mprefix) + + original.substr(prefixloc + 10); + } else return original; } @@ -201,7 +243,7 @@ std::pair split_author(const std::string& author) thro void do_save_state(const std::string& filename) throw(std::bad_alloc, std::runtime_error) { - std::string filename2 = translate_name_mprefix(filename); + std::string filename2 = translate_name_mprefix(filename, true); lua_callback_pre_save(filename2, true); try { uint64_t origtime = get_utime(); @@ -236,7 +278,7 @@ void do_save_state(const std::string& filename) throw(std::bad_alloc, //Save movie. void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runtime_error) { - std::string filename2 = translate_name_mprefix(filename); + std::string filename2 = translate_name_mprefix(filename, true); lua_callback_pre_save(filename2, false); try { uint64_t origtime = get_utime(); @@ -457,7 +499,7 @@ void do_load_state(struct moviefile& _movie, int lmode) //Load state bool do_load_state(const std::string& filename, int lmode) { - std::string filename2 = translate_name_mprefix(filename); + std::string filename2 = translate_name_mprefix(filename, true); uint64_t origtime = get_utime(); lua_callback_pre_load(filename2); struct moviefile mfile; diff --git a/src/platform/win32mm/joystick.cpp b/src/platform/win32mm/joystick.cpp index 67f44606..92c069c8 100644 --- a/src/platform/win32mm/joystick.cpp +++ b/src/platform/win32mm/joystick.cpp @@ -33,14 +33,14 @@ namespace void create_hat(unsigned i) { std::string n = (stringfmt() << "joystick" << i << "hat").str(); - keygroup* k = new keygroup(n, keygroup::KT_HAT); + keygroup* k = new keygroup(n, "joystick", keygroup::KT_HAT); hats[i] = k; } void create_button(unsigned i, unsigned j) { std::string n = (stringfmt() << "joystick" << i << "button" << j).str(); - keygroup* k = new keygroup(n, keygroup::KT_KEY); + keygroup* k = new keygroup(n, "joystick", keygroup::KT_KEY); buttons[std::make_pair(i, j)] = k; } @@ -48,7 +48,7 @@ namespace { std::string n = (stringfmt() << "joystick" << i << "axis" << j).str(); keygroup* k; - k = new keygroup(n, keygroup::KT_AXIS_PAIR); + k = new keygroup(n, "joystick", keygroup::KT_AXIS_PAIR); axes[std::make_pair(i, j)] = k; } diff --git a/src/platform/wxwidgets/main.cpp b/src/platform/wxwidgets/main.cpp index 444809bc..8f0072c1 100644 --- a/src/platform/wxwidgets/main.cpp +++ b/src/platform/wxwidgets/main.cpp @@ -166,9 +166,6 @@ end: { std::string cfg = get_config_path() + "/lsneswxw.rc"; std::ofstream cfgfile(cfg.c_str()); - //Jukebox. - for(auto i : get_jukebox_names()) - cfgfile << "add-jukebox-save " << i << std::endl; //Joystick axis. for(auto i : keygroup::get_axis_set()) { keygroup* k = keygroup::lookup_by_name(i); diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index f845b1ed..fd14cf57 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -72,7 +72,6 @@ enum wxID_DUMP_FIRST, wxID_DUMP_LAST = wxID_DUMP_FIRST + 1023, wxID_REWIND_MOVIE, - wxID_EDIT_JUKEBOX, wxID_MEMORY_SEARCH, wxID_CANCEL_SAVES, wxID_EDIT_HOTKEYS, @@ -771,7 +770,6 @@ wxwin_mainwindow::wxwin_mainwindow() 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_EDIT_HOTKEYS, wxT("Configure hotkeys...")); } @@ -975,33 +973,6 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) runemufn([alias, newcmd]() { command::set_alias_for(alias, newcmd); }); return; } - case wxID_EDIT_JUKEBOX: { - modal_pause_holder hld; - std::vector new_jukebox; - std::string x; - runemufn([&x]() { - for(auto i : get_jukebox_names()) - x = x + i + "\n"; - }); - x = pick_text(this, "Configure jukebox", "List jukebox entries", x, true); - while(x != "") { - size_t split = x.find_first_of("\n"); - std::string l; - if(split < x.length()) { - l = x.substr(0, split); - x = x.substr(split + 1); - } else { - l = x; - x = ""; - } - istrip_CR(l); - if(l != "") - new_jukebox.push_back(l); - } - runemufn([&new_jukebox]() { set_jukebox_names(new_jukebox); }); - notify_update_status(); - return; - } case wxID_EDIT_MEMORYWATCH: { modal_pause_holder hld; std::set bind; diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index ea4fea4e..3978ff7c 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -33,6 +33,8 @@ extern "C" #define FIRMWAREPATH "firmwarepath" #define ROMPATH "rompath" #define MOVIEPATH "moviepath" +#define SLOTPATH "slotpath" +#define SAVESLOTS "jukebox-size" @@ -327,6 +329,8 @@ private: wxStaticText* rompath; wxStaticText* firmpath; wxStaticText* savepath; + wxStaticText* slotpath; + wxStaticText* slots; wxFlexGridSizer* top_s; }; @@ -334,21 +338,31 @@ wxeditor_esettings_paths::wxeditor_esettings_paths(wxWindow* parent) : wxPanel(parent, -1) { wxButton* tmp; - top_s = new wxFlexGridSizer(3, 3, 0, 0); + top_s = new wxFlexGridSizer(5, 3, 0, 0); SetSizer(top_s); - top_s->Add(new wxStaticText(this, -1, wxT("ROM path")), 0, wxGROW); + 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(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(new wxStaticText(this, -1, wxT("Movie 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); + top_s->Add(new wxStaticText(this, -1, wxT("Slot path: ")), 0, wxGROW); + top_s->Add(slotpath = new wxStaticText(this, -1, wxT("")), 1, wxGROW); + top_s->Add(tmp = new wxButton(this, wxID_HIGHEST + 5, 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 slots: ")), 0, wxGROW); + top_s->Add(slots = new wxStaticText(this, -1, wxT("")), 1, wxGROW); + top_s->Add(tmp = new wxButton(this, wxID_HIGHEST + 4, wxT("Change...")), 0, wxGROW); tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_paths::on_configure), NULL, this); refresh(); @@ -368,6 +382,10 @@ void wxeditor_esettings_paths::on_configure(wxCommandEvent& e) name = FIRMWAREPATH; else if(e.GetId() == wxID_HIGHEST + 3) name = MOVIEPATH; + else if(e.GetId() == wxID_HIGHEST + 4) + name = SAVESLOTS; + else if(e.GetId() == wxID_HIGHEST + 5) + name = SLOTPATH; else return; std::string val; @@ -378,21 +396,28 @@ void wxeditor_esettings_paths::on_configure(wxCommandEvent& e) refresh(); return; } - runemufn([val, name]() { setting::set(name, val); }); + std::string err; + runemufn([val, name, &err]() { try { setting::set(name, val); } catch(std::exception& e) { err = e.what(); }}); + if(err != "") + wxMessageBox(wxT("Invalid value"), wxT("Can't change value"), wxICON_EXCLAMATION | wxOK); refresh(); } void wxeditor_esettings_paths::refresh() { - std::string rpath, fpath, spath; - runemufn([&rpath, &fpath, &spath]() { + std::string rpath, fpath, spath, nslot, lpath; + runemufn([&rpath, &fpath, &spath, &nslot, &lpath]() { fpath = setting::get(FIRMWAREPATH); rpath = setting::get(ROMPATH); spath = setting::get(MOVIEPATH); + nslot = setting::get(SAVESLOTS); + lpath = setting::get(SLOTPATH); }); rompath->SetLabel(towxstring(rpath)); firmpath->SetLabel(towxstring(fpath)); savepath->SetLabel(towxstring(spath)); + slots->SetLabel(towxstring(nslot)); + slotpath->SetLabel(towxstring(lpath)); top_s->Layout(); Fit(); } From ae42dc5909ef2da1ec7ce8cc0722f64f3eec7bd8 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 7 Apr 2012 20:02:51 +0300 Subject: [PATCH 04/11] Wxwidgets: Move settings to main configuration dialog --- include/platform/wxwidgets/platform.hpp | 1 - src/platform/wxwidgets/editor-settings.cpp | 267 --------------------- src/platform/wxwidgets/mainwindow.cpp | 5 - src/platform/wxwidgets/settings.cpp | 147 +++++++++++- 4 files changed, 145 insertions(+), 275 deletions(-) delete mode 100644 src/platform/wxwidgets/editor-settings.cpp diff --git a/include/platform/wxwidgets/platform.hpp b/include/platform/wxwidgets/platform.hpp index cd99bc10..b76eb137 100644 --- a/include/platform/wxwidgets/platform.hpp +++ b/include/platform/wxwidgets/platform.hpp @@ -34,7 +34,6 @@ void _runuifun_async(void (*fn)(void*), void* arg); //Editor dialogs. void wxeditor_authors_display(wxWindow* parent); -void wxeditor_settings_display(wxWindow* parent); void wxeditor_hotkeys_display(wxWindow* parent); std::string wxeditor_keyselect(wxWindow* parent, bool clearable); void wxsetingsdialog_display(wxWindow* parent); diff --git a/src/platform/wxwidgets/editor-settings.cpp b/src/platform/wxwidgets/editor-settings.cpp deleted file mode 100644 index dd5d3aac..00000000 --- a/src/platform/wxwidgets/editor-settings.cpp +++ /dev/null @@ -1,267 +0,0 @@ -#include "core/command.hpp" -#include "core/dispatch.hpp" -#include "core/mainloop.hpp" -#include "core/misc.hpp" -#include "core/moviefile.hpp" -#include "core/settings.hpp" -#include "core/window.hpp" - -#include "platform/wxwidgets/platform.hpp" - -#include -#include - - -#include -#include - -#include -#include -#include -#include - -class wxeditor_settings_setting : public wxEvtHandler -{ -public: - wxeditor_settings_setting(wxSizer* sizer, wxWindow* window, const std::string& name); - void on_clear_click(wxCommandEvent& e); - void on_edit_click(wxCommandEvent& e); - void change_setting(const std::string& setting, const std::string& value); - void clear_setting(const std::string& setting); -private: - std::string a_name; - wxWindow* parent; - wxStaticText* label; - wxButton* clear; - wxButton* edit; -}; - -class wxeditor_settings; - -class wxeditor_settings_listener : public information_dispatch -{ -public: - wxeditor_settings_listener(wxeditor_settings* _editor); - ~wxeditor_settings_listener() throw(); - void on_setting_change(const std::string& setting, const std::string& value); - void on_setting_clear(const std::string& setting); -private: - wxeditor_settings* editor; -}; - -class wxeditor_settings : public wxDialog -{ -public: - wxeditor_settings(wxWindow* parent); - ~wxeditor_settings(); - bool ShouldPreventAppExit() const; - void on_close(wxCommandEvent& e); - void change_setting(const std::string& setting, const std::string& value); - void clear_setting(const std::string& setting); -private: - wxeditor_settings_listener listener; - std::vector esettings; - wxScrolledWindow* scrollwin; - wxButton* close; -}; - -wxeditor_settings_setting::wxeditor_settings_setting(wxSizer* sizer, wxWindow* window, const std::string& name) -{ - a_name = name; - parent = window; - std::string pvalue = ""; - runemufn([&pvalue, a_name]() { - try { - if(!setting::is_set(a_name)) - pvalue = ""; - else - pvalue = setting::get(a_name); - } catch(...) { - } - }); - sizer->Add(new wxStaticText(window, wxID_ANY, towxstring(name)), 0, wxGROW); - sizer->Add(label = new wxStaticText(window, wxID_ANY, towxstring(pvalue)), 0, wxGROW); - sizer->Add(edit = new wxButton(window, wxID_ANY, wxT("Edit")), 0, wxGROW); - sizer->Add(clear = new wxButton(window, wxID_ANY, wxT("Clear")), 0, wxGROW); - edit->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxeditor_settings_setting::on_edit_click), NULL, this); - clear->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxeditor_settings_setting::on_clear_click), NULL, this); -} - -void wxeditor_settings_setting::on_clear_click(wxCommandEvent& e) -{ - try { - bool fault = false;; - std::string faulttext; - runemufn([a_name, &fault, &faulttext]() { - try { - setting::blank(a_name); - } catch(std::exception& e) { - fault = true; - faulttext = e.what(); - } - }); - if(fault) { - wxMessageDialog* d = new wxMessageDialog(parent, - towxstring(std::string("Can't clear setting: ") + faulttext), wxT("Error"), wxOK | - wxICON_EXCLAMATION); - d->ShowModal(); - d->Destroy(); - } - }catch(std::exception& e) { - wxMessageDialog* d = new wxMessageDialog(parent, towxstring(std::string("Can't clear setting: ") + - e.what()), wxT("Error"), wxOK | wxICON_EXCLAMATION); - d->ShowModal(); - d->Destroy(); - } -} - -void wxeditor_settings_setting::on_edit_click(wxCommandEvent& e) -{ - try { - std::string newsetting; - std::string oldvalue = setting::get(a_name); - wxTextEntryDialog* d = new wxTextEntryDialog(parent, towxstring("Enter new value for " + a_name), - wxT("Enter new value for setting"), towxstring(oldvalue)); - if(d->ShowModal() == wxID_CANCEL) { - d->Destroy(); - return; - } - newsetting = tostdstring(d->GetValue()); - bool fault = false;; - std::string faulttext; - runemufn([a_name, newsetting, &fault, &faulttext]() { - try { - setting::set(a_name, newsetting); - } catch(std::exception& e) { - fault = true; - faulttext = e.what(); - } - }); - if(fault) { - wxMessageDialog* d = new wxMessageDialog(parent, - towxstring(std::string("Can't set setting: ") + faulttext), wxT("Error"), wxOK | - wxICON_EXCLAMATION); - d->ShowModal(); - d->Destroy(); - } - } catch(std::exception& e) { - wxMessageDialog* d = new wxMessageDialog(parent, towxstring(std::string("Can't set setting: ") + - e.what()), wxT("Error"), wxOK | wxICON_EXCLAMATION); - d->ShowModal(); - d->Destroy(); - } -} - -void wxeditor_settings_setting::change_setting(const std::string& _setting, const std::string& value) -{ - runuifun([_setting, label, a_name, value]() { - if(_setting != a_name) - return; - label->SetLabel(towxstring(value)); - }); -} - -void wxeditor_settings_setting::clear_setting(const std::string& _setting) -{ - runuifun([_setting, label, a_name]() { - if(_setting != a_name) - return; - label->SetLabel(wxT("")); - }); -} - -wxeditor_settings::wxeditor_settings(wxWindow* parent) - : wxDialog(parent, wxID_ANY, wxT("lsnes: Edit settings"), wxDefaultPosition, wxSize(-1, -1)), listener(this) -{ - std::set settings_set; - runemufn([&settings_set]() { settings_set = setting::get_settings_set(); }); - - scrollwin = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxVSCROLL); - scrollwin->SetMinSize(wxSize(-1, 500)); - - Centre(); - wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0); - SetSizer(top_s); - - wxFlexGridSizer* t_s = new wxFlexGridSizer(settings_set.size(), 4, 0, 0); - for(auto i : settings_set) - esettings.push_back(new wxeditor_settings_setting(t_s, scrollwin, i)); - scrollwin->SetSizer(t_s); - top_s->Add(scrollwin); - scrollwin->SetScrollRate(0, 20); - - wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); - pbutton_s->AddStretchSpacer(); - pbutton_s->Add(close = new wxButton(this, wxID_CANCEL, wxT("Close")), 0, wxGROW); - close->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxeditor_settings::on_close), NULL, this); - top_s->Add(pbutton_s, 0, wxGROW); - - t_s->SetSizeHints(this); - top_s->SetSizeHints(this); - t_s->Layout(); - top_s->Layout(); - Fit(); -} - -wxeditor_settings::~wxeditor_settings() -{ - for(auto i : esettings) - delete i; -} - -bool wxeditor_settings::ShouldPreventAppExit() const -{ - return false; -} - -void wxeditor_settings::on_close(wxCommandEvent& e) -{ - EndModal(wxID_OK); -} - -void wxeditor_settings::change_setting(const std::string& _setting, const std::string& value) -{ - for(auto i : esettings) - i->change_setting(_setting, value); -} - -void wxeditor_settings::clear_setting(const std::string& _setting) -{ - for(auto i : esettings) - i->clear_setting(_setting); -} - -wxeditor_settings_listener::wxeditor_settings_listener(wxeditor_settings* _editor) - : information_dispatch("wxeditor_settings-listener") -{ - editor = _editor; -} - -wxeditor_settings_listener::~wxeditor_settings_listener() throw() -{ -} - -void wxeditor_settings_listener::on_setting_change(const std::string& _setting, const std::string& value) -{ - editor->change_setting(_setting, value); -} - -void wxeditor_settings_listener::on_setting_clear(const std::string& _setting) -{ - editor->clear_setting(_setting); -} - -void wxeditor_settings_display(wxWindow* parent) -{ - modal_pause_holder hld; - wxDialog* editor; - try { - editor = new wxeditor_settings(parent); - editor->ShowModal(); - } catch(...) { - } - editor->Destroy(); -} diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index fd14cf57..fadf3c51 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -63,7 +63,6 @@ enum wxID_EDIT_AUTHORS, wxID_AUTOHOLD_FIRST, wxID_AUTOHOLD_LAST = wxID_AUTOHOLD_FIRST + 1023, - wxID_EDIT_SETTINGS, wxID_EDIT_KEYBINDINGS, wxID_EDIT_ALIAS, wxID_EDIT_MEMORYWATCH, @@ -767,7 +766,6 @@ wxwin_mainwindow::wxwin_mainwindow() wxID_DUMP_FIRST, wxID_DUMP_LAST))); menu_start(wxT("Settings")); - 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_separator(); @@ -914,9 +912,6 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) case wxID_EDIT_AUTHORS: wxeditor_authors_display(this); return; - case wxID_EDIT_SETTINGS: - wxeditor_settings_display(this); - return; case wxID_EDIT_HOTKEYS: wxeditor_hotkeys_display(this); return; diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index 3978ff7c..978498aa 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -1,4 +1,5 @@ #include "platform/wxwidgets/platform.hpp" +#include "core/dispatch.hpp" #include "core/settings.hpp" #include "library/string.hpp" @@ -469,7 +470,12 @@ void wxeditor_esettings_screen::on_configure(wxCommandEvent& e) { if(e.GetId() == wxID_HIGHEST + 1) { std::string v = (stringfmt() << horizontal_scale_factor).str(); - v = pick_text(this, "Set X scaling factor", "Enter new horizontal scale factor:", v); + try { + v = pick_text(this, "Set X scaling factor", "Enter new horizontal scale factor:", v); + } catch(...) { + refresh(); + return; + } double x; try { x = parse_value(v); @@ -484,7 +490,12 @@ void wxeditor_esettings_screen::on_configure(wxCommandEvent& e) horizontal_scale_factor = x; } else if(e.GetId() == wxID_HIGHEST + 2) { std::string v = (stringfmt() << vertical_scale_factor).str(); - v = pick_text(this, "Set Y scaling factor", "Enter new vertical scale factor:", v); + try { + v = pick_text(this, "Set Y scaling factor", "Enter new vertical scale factor:", v); + } catch(...) { + refresh(); + return; + } double x; try { x = parse_value(v); @@ -526,6 +537,137 @@ void wxeditor_esettings_screen::refresh() Fit(); } +class wxeditor_esettings_advanced : public wxPanel, information_dispatch +{ +public: + wxeditor_esettings_advanced(wxWindow* parent); + ~wxeditor_esettings_advanced(); + void on_change(wxCommandEvent& e); + void on_clear(wxCommandEvent& e); + void on_setting_change(const std::string& setting, const std::string& value); + void on_setting_clear(const std::string& setting); + void _refresh(); +private: + void refresh(); + std::set settings; + std::map values; + std::map selections; + std::string selected(); + wxListBox* _settings; +}; + +wxeditor_esettings_advanced::wxeditor_esettings_advanced(wxWindow* parent) + : wxPanel(parent, -1), information_dispatch("wxeditor-settings-listener") +{ + wxButton* tmp; + + wxSizer* top_s = new wxBoxSizer(wxVERTICAL); + SetSizer(top_s); + + top_s->Add(_settings = new wxListBox(this, wxID_ANY), 1, wxGROW); + + wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); + pbutton_s->AddStretchSpacer(); + pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Change")), 0, wxGROW); + tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_advanced::on_change), NULL, + this); + pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Clear")), 0, wxGROW); + tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_advanced::on_clear), NULL, + this); + top_s->Add(pbutton_s, 0, wxGROW); + + refresh(); + top_s->SetSizeHints(this); + Fit(); +} + +wxeditor_esettings_advanced::~wxeditor_esettings_advanced() +{ +} + +void wxeditor_esettings_advanced::on_change(wxCommandEvent& e) +{ + std::string name = selected(); + if(name == "") + return; + std::string value; + std::string err; + runemufn([name, &value]() { value = setting::get(name); }); + try { + value = pick_text(this, "Set value to", "Set " + name + " to value:", value); + } catch(...) { + return; + } + runemufn([name, value, &err]() { + try { setting::set(name, value); } catch(std::exception& e) { err = e.what(); } + }); + if(err != "") + wxMessageBox(towxstring(err), wxT("Error setting value"), wxICON_EXCLAMATION | wxOK); +} + +void wxeditor_esettings_advanced::on_clear(wxCommandEvent& e) +{ + std::string name = selected(); + if(name == "") + return; + bool err = false; + runemufn([name, &err]() { try { setting::blank(name); } catch(...) { err = true; }}); + if(err) + wxMessageBox(wxT("This setting can't be cleared"), wxT("Error"), wxICON_EXCLAMATION | wxOK); +} + +void wxeditor_esettings_advanced::on_setting_change(const std::string& setting, const std::string& value) +{ + wxeditor_esettings_advanced* th = this; + runuifun([&settings, &values, setting, value, th]() { + settings.insert(setting); values[setting] = value; th->_refresh(); + }); +} + +void wxeditor_esettings_advanced::on_setting_clear(const std::string& setting) +{ + wxeditor_esettings_advanced* th = this; + runuifun([&settings, &values, setting, th]() { + settings.insert(setting); values.erase(setting); th->_refresh(); + }); +} + +void wxeditor_esettings_advanced::refresh() +{ + runemufn([&settings, &values]() { + settings = setting::get_settings_set(); + for(auto i : settings) { + if(setting::is_set(i)) + values[i] = setting::get(i); + } + }); + _refresh(); +} + +std::string wxeditor_esettings_advanced::selected() +{ + int x = _settings->GetSelection(); + if(selections.count(x)) + return selections[x]; + else + return ""; +} + +void wxeditor_esettings_advanced::_refresh() +{ + std::vector strings; + int k = 0; + for(auto i : settings) { + if(values.count(i)) + strings.push_back(towxstring(i + " (Value: " + values[i] + ")")); + else + strings.push_back(towxstring(i + " (Not set)")); + selections[k++] = i; + } + _settings->Set(strings.size(), &strings[0]); +} + + class wxeditor_esettings : public wxDialog { public: @@ -550,6 +692,7 @@ wxeditor_esettings::wxeditor_esettings(wxWindow* parent) tabset->AddPage(new wxeditor_esettings_joystick(tabset), wxT("Joysticks")); tabset->AddPage(new wxeditor_esettings_paths(tabset), wxT("Paths")); tabset->AddPage(new wxeditor_esettings_screen(tabset), wxT("Scaling")); + tabset->AddPage(new wxeditor_esettings_advanced(tabset), wxT("Advanced")); top_s->Add(tabset, 1, wxGROW); wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); From daa849e16341371a01b0315eb3a63a3d490a0bdc Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 7 Apr 2012 20:03:17 +0300 Subject: [PATCH 05/11] Fix error with settings avi-tscc-keyint and avi-cscd-keyint --- src/video/avi/codec/video/cscd.cpp | 2 +- src/video/avi/codec/video/tscc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video/avi/codec/video/cscd.cpp b/src/video/avi/codec/video/cscd.cpp index 7dcfd487..f7eea0f6 100644 --- a/src/video/avi/codec/video/cscd.cpp +++ b/src/video/avi/codec/video/cscd.cpp @@ -11,7 +11,7 @@ namespace { numeric_setting clvl("avi-cscd-compression", 0, 9, 7); - numeric_setting kint("avi-cscd-keyint", 1, 999999999, 0); + numeric_setting kint("avi-cscd-keyint", 0, 999999999, 0); struct avi_codec_cscd : public avi_video_codec { diff --git a/src/video/avi/codec/video/tscc.cpp b/src/video/avi/codec/video/tscc.cpp index 6adee908..f942ea6d 100644 --- a/src/video/avi/codec/video/tscc.cpp +++ b/src/video/avi/codec/video/tscc.cpp @@ -15,7 +15,7 @@ const void* check; namespace { numeric_setting clvl("avi-tscc-compression", 0, 9, 7); - numeric_setting kint("avi-tscc-keyint", 1, 999999999, 0); + numeric_setting kint("avi-tscc-keyint", 0, 999999999, 0); struct msrle_compressor { From 4eac708596a2067946ebf4996f5891e1a7a47300 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 8 Apr 2012 13:32:01 +0300 Subject: [PATCH 06/11] Wxwidgets: Move the rest of config to main configuration dialog --- src/core/controller.cpp | 4 +- src/core/framerate.cpp | 7 +- src/core/mainloop.cpp | 160 ++--- src/core/window.cpp | 4 +- src/platform/wxwidgets/editor-keyselect.cpp | 430 ------------ src/platform/wxwidgets/mainwindow.cpp | 65 -- src/platform/wxwidgets/settings.cpp | 723 ++++++++++++++++++++ 7 files changed, 810 insertions(+), 583 deletions(-) delete mode 100644 src/platform/wxwidgets/editor-keyselect.cpp diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 5b49754d..7614e50c 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -197,7 +197,7 @@ namespace }; x << (k + 1) << get_logical_button_name(i); y << (k + 1) << get_logical_button_name(i); - expx << "Controller " << (k + 1) << " " << get_logical_button_name(i); + expx << "Controller‣" << (k + 1) << "‣" << get_logical_button_name(i); our_commands.insert(new button_action(x.str(), j, k, y.str())); if(j == 0) our_icommands.insert(new inverse_key(x.str(), expx.str())); @@ -205,7 +205,7 @@ namespace for(unsigned k = 0; k < 8; ++k) { stringfmt x, expx; x << "controller" << (k + 1) << "analog"; - expx << "Controller " << (k + 1) << " analog function"; + expx << "Controller‣" << (k + 1) << "‣Analog function"; our_commands.insert(new analog_action(x.str(), k)); our_icommands.insert(new inverse_key(x.str(), expx.str())); } diff --git a/src/core/framerate.cpp b/src/core/framerate.cpp index bf7a84b0..816f8130 100644 --- a/src/core/framerate.cpp +++ b/src/core/framerate.cpp @@ -12,7 +12,6 @@ #include #include -#define DEFAULT_NOMINAL_RATE 60 #define HISTORY_FRAMES 10 namespace @@ -22,7 +21,7 @@ namespace bool time_frozen = true; uint64_t frame_number = 0; uint64_t frame_start_times[HISTORY_FRAMES]; - double nominal_rate = DEFAULT_NOMINAL_RATE; + double nominal_rate = 100; bool target_nominal = true; double target_fps = 100.0; bool target_infinite = false; @@ -130,8 +129,8 @@ namespace turboed = false; }); - inverse_key turboh("+turbo", "Turbo on hold"); - inverse_key turbot("toggle-turbo", "Toggle turbo"); + inverse_key turboh("+turbo", "Speed‣Turbo hold"); + inverse_key turbot("toggle-turbo", "Speed‣Turbo toggle"); } void freeze_time(uint64_t curtime) diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index e058b415..be107503 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -662,86 +662,86 @@ namespace while(1); }); - inverse_key ipause_emulator("pause-emulator", "(Un)pause"); - inverse_key ijback("cycle-jukebox-backward", "Cycle slot backwards"); - inverse_key ijforward("cycle-jukebox-forward", "Cycle slot forwards"); - inverse_key iloadj("load-jukebox", "load selected slot"); - inverse_key isavej("save-jukebox", "Save selected slot"); - inverse_key iadvframe("+advance-frame", "Advance frame"); - inverse_key iadvsubframe("+advance-poll", "Advance subframe"); - inverse_key iskiplag("advance-skiplag", "Advance to next poll"); - inverse_key ireset("reset", "System reset"); - inverse_key iset_rwmode("set-rwmode", "Switch to read/write"); - inverse_key itoggle_romode("set-romode", "Switch to read-only"); - inverse_key itoggle_rwmode("toggle-rwmode", "Toggle read-only"); - inverse_key irepaint("repaint", "Repaint screen"); - inverse_key itogglepause("toggle-pause-on-end", "Toggle pause-on-end"); - inverse_key irewind_movie("rewind-movie", "Rewind movie"); - inverse_key icancel_saves("cancel-saves", "Cancel pending saves"); - inverse_key iload1("load ${project}1.lsmv", "Load slot 1"); - inverse_key iload2("load ${project}2.lsmv", "Load slot 2"); - inverse_key iload3("load ${project}3.lsmv", "Load slot 3"); - inverse_key iload4("load ${project}4.lsmv", "Load slot 4"); - inverse_key iload5("load ${project}5.lsmv", "Load slot 5"); - inverse_key iload6("load ${project}6.lsmv", "Load slot 6"); - inverse_key iload7("load ${project}7.lsmv", "Load slot 7"); - inverse_key iload8("load ${project}8.lsmv", "Load slot 8"); - inverse_key iload9("load ${project}9.lsmv", "Load slot 9"); - inverse_key iload10("load ${project}10.lsmv", "Load slot 10"); - inverse_key iload11("load ${project}11.lsmv", "Load slot 11"); - inverse_key iload12("load ${project}12.lsmv", "Load slot 12"); - inverse_key iload13("load ${project}13.lsmv", "Load slot 13"); - inverse_key iload14("load ${project}14.lsmv", "Load slot 14"); - inverse_key iload15("load ${project}15.lsmv", "Load slot 15"); - inverse_key iload16("load ${project}16.lsmv", "Load slot 16"); - inverse_key iload17("load ${project}17.lsmv", "Load slot 17"); - inverse_key iload18("load ${project}18.lsmv", "Load slot 18"); - inverse_key iload19("load ${project}19.lsmv", "Load slot 19"); - inverse_key iload20("load ${project}20.lsmv", "Load slot 20"); - inverse_key iload21("load ${project}21.lsmv", "Load slot 21"); - inverse_key iload22("load ${project}22.lsmv", "Load slot 22"); - inverse_key iload23("load ${project}23.lsmv", "Load slot 23"); - inverse_key iload24("load ${project}24.lsmv", "Load slot 24"); - inverse_key iload25("load ${project}25.lsmv", "Load slot 25"); - inverse_key iload26("load ${project}26.lsmv", "Load slot 26"); - inverse_key iload27("load ${project}27.lsmv", "Load slot 27"); - inverse_key iload28("load ${project}28.lsmv", "Load slot 28"); - inverse_key iload29("load ${project}29.lsmv", "Load slot 29"); - inverse_key iload30("load ${project}30.lsmv", "Load slot 30"); - inverse_key iload31("load ${project}31.lsmv", "Load slot 31"); - inverse_key iload32("load ${project}32.lsmv", "Load slot 32"); - inverse_key isave1("save-state ${project}1.lsmv", "Save slot 1"); - inverse_key isave2("save-state ${project}2.lsmv", "Save slot 2"); - inverse_key isave3("save-state ${project}3.lsmv", "Save slot 3"); - inverse_key isave4("save-state ${project}4.lsmv", "Save slot 4"); - inverse_key isave5("save-state ${project}5.lsmv", "Save slot 5"); - inverse_key isave6("save-state ${project}6.lsmv", "Save slot 6"); - inverse_key isave7("save-state ${project}7.lsmv", "Save slot 7"); - inverse_key isave8("save-state ${project}8.lsmv", "Save slot 8"); - inverse_key isave9("save-state ${project}9.lsmv", "Save slot 9"); - inverse_key isave10("save-state ${project}10.lsmv", "Save slot 10"); - inverse_key isave11("save-state ${project}11.lsmv", "Save slot 11"); - inverse_key isave12("save-state ${project}12.lsmv", "Save slot 12"); - inverse_key isave13("save-state ${project}13.lsmv", "Save slot 13"); - inverse_key isave14("save-state ${project}14.lsmv", "Save slot 14"); - inverse_key isave15("save-state ${project}15.lsmv", "Save slot 15"); - inverse_key isave16("save-state ${project}16.lsmv", "Save slot 16"); - inverse_key isave17("save-state ${project}17.lsmv", "Save slot 17"); - inverse_key isave18("save-state ${project}18.lsmv", "Save slot 18"); - inverse_key isave19("save-state ${project}19.lsmv", "Save slot 19"); - inverse_key isave20("save-state ${project}20.lsmv", "Save slot 20"); - inverse_key isave21("save-state ${project}21.lsmv", "Save slot 21"); - inverse_key isave22("save-state ${project}22.lsmv", "Save slot 22"); - inverse_key isave23("save-state ${project}23.lsmv", "Save slot 23"); - inverse_key isave24("save-state ${project}24.lsmv", "Save slot 24"); - inverse_key isave25("save-state ${project}25.lsmv", "Save slot 25"); - inverse_key isave26("save-state ${project}26.lsmv", "Save slot 26"); - inverse_key isave27("save-state ${project}27.lsmv", "Save slot 27"); - inverse_key isave28("save-state ${project}28.lsmv", "Save slot 28"); - inverse_key isave29("save-state ${project}29.lsmv", "Save slot 29"); - inverse_key isave30("save-state ${project}30.lsmv", "Save slot 30"); - inverse_key isave31("save-state ${project}31.lsmv", "Save slot 31"); - inverse_key isave32("save-state ${project}32.lsmv", "Save slot 32"); + inverse_key ipause_emulator("pause-emulator", "Speed‣(Un)pause"); + inverse_key ijback("cycle-jukebox-backward", "Slot select‣Cycle backwards"); + inverse_key ijforward("cycle-jukebox-forward", "Slot select‣Cycle forwards"); + inverse_key iloadj("load-jukebox", "Load‣Selected slot"); + inverse_key isavej("save-jukebox", "Save‣Selected slot"); + inverse_key iadvframe("+advance-frame", "Speed‣Advance frame"); + inverse_key iadvsubframe("+advance-poll", "Speed‣Advance subframe"); + inverse_key iskiplag("advance-skiplag", "Speed‣Advance poll"); + inverse_key ireset("reset", "System‣Reset"); + inverse_key iset_rwmode("set-rwmode", "Movie‣Switch to read/write"); + inverse_key itoggle_romode("set-romode", "Movie‣Switch to read-only"); + inverse_key itoggle_rwmode("toggle-rwmode", "Movie‣Toggle read-only"); + inverse_key irepaint("repaint", "System‣Repaint screen"); + inverse_key itogglepause("toggle-pause-on-end", "Movie‣Toggle pause-on-end"); + inverse_key irewind_movie("rewind-movie", "Movie‣Rewind movie"); + inverse_key icancel_saves("cancel-saves", "Save‣Cancel pending saves"); + inverse_key iload1("load ${project}1.lsmv", "Load‣Slot 1"); + inverse_key iload2("load ${project}2.lsmv", "Load‣Slot 2"); + inverse_key iload3("load ${project}3.lsmv", "Load‣Slot 3"); + inverse_key iload4("load ${project}4.lsmv", "Load‣Slot 4"); + inverse_key iload5("load ${project}5.lsmv", "Load‣Slot 5"); + inverse_key iload6("load ${project}6.lsmv", "Load‣Slot 6"); + inverse_key iload7("load ${project}7.lsmv", "Load‣Slot 7"); + inverse_key iload8("load ${project}8.lsmv", "Load‣Slot 8"); + inverse_key iload9("load ${project}9.lsmv", "Load‣Slot 9"); + inverse_key iload10("load ${project}10.lsmv", "Load‣Slot 10"); + inverse_key iload11("load ${project}11.lsmv", "Load‣Slot 11"); + inverse_key iload12("load ${project}12.lsmv", "Load‣Slot 12"); + inverse_key iload13("load ${project}13.lsmv", "Load‣Slot 13"); + inverse_key iload14("load ${project}14.lsmv", "Load‣Slot 14"); + inverse_key iload15("load ${project}15.lsmv", "Load‣Slot 15"); + inverse_key iload16("load ${project}16.lsmv", "Load‣Slot 16"); + inverse_key iload17("load ${project}17.lsmv", "Load‣Slot 17"); + inverse_key iload18("load ${project}18.lsmv", "Load‣Slot 18"); + inverse_key iload19("load ${project}19.lsmv", "Load‣Slot 19"); + inverse_key iload20("load ${project}20.lsmv", "Load‣Slot 20"); + inverse_key iload21("load ${project}21.lsmv", "Load‣Slot 21"); + inverse_key iload22("load ${project}22.lsmv", "Load‣Slot 22"); + inverse_key iload23("load ${project}23.lsmv", "Load‣Slot 23"); + inverse_key iload24("load ${project}24.lsmv", "Load‣Slot 24"); + inverse_key iload25("load ${project}25.lsmv", "Load‣Slot 25"); + inverse_key iload26("load ${project}26.lsmv", "Load‣Slot 26"); + inverse_key iload27("load ${project}27.lsmv", "Load‣Slot 27"); + inverse_key iload28("load ${project}28.lsmv", "Load‣Slot 28"); + inverse_key iload29("load ${project}29.lsmv", "Load‣Slot 29"); + inverse_key iload30("load ${project}30.lsmv", "Load‣Slot 30"); + inverse_key iload31("load ${project}31.lsmv", "Load‣Slot 31"); + inverse_key iload32("load ${project}32.lsmv", "Load‣Slot 32"); + inverse_key isave1("save-state ${project}1.lsmv", "Save‣Slot 1"); + inverse_key isave2("save-state ${project}2.lsmv", "Save‣Slot 2"); + inverse_key isave3("save-state ${project}3.lsmv", "Save‣Slot 3"); + inverse_key isave4("save-state ${project}4.lsmv", "Save‣Slot 4"); + inverse_key isave5("save-state ${project}5.lsmv", "Save‣Slot 5"); + inverse_key isave6("save-state ${project}6.lsmv", "Save‣Slot 6"); + inverse_key isave7("save-state ${project}7.lsmv", "Save‣Slot 7"); + inverse_key isave8("save-state ${project}8.lsmv", "Save‣Slot 8"); + inverse_key isave9("save-state ${project}9.lsmv", "Save‣Slot 9"); + inverse_key isave10("save-state ${project}10.lsmv", "Save‣Slot 10"); + inverse_key isave11("save-state ${project}11.lsmv", "Save‣Slot 11"); + inverse_key isave12("save-state ${project}12.lsmv", "Save‣Slot 12"); + inverse_key isave13("save-state ${project}13.lsmv", "Save‣Slot 13"); + inverse_key isave14("save-state ${project}14.lsmv", "Save‣Slot 14"); + inverse_key isave15("save-state ${project}15.lsmv", "Save‣Slot 15"); + inverse_key isave16("save-state ${project}16.lsmv", "Save‣Slot 16"); + inverse_key isave17("save-state ${project}17.lsmv", "Save‣Slot 17"); + inverse_key isave18("save-state ${project}18.lsmv", "Save‣Slot 18"); + inverse_key isave19("save-state ${project}19.lsmv", "Save‣Slot 19"); + inverse_key isave20("save-state ${project}20.lsmv", "Save‣Slot 20"); + inverse_key isave21("save-state ${project}21.lsmv", "Save‣Slot 21"); + inverse_key isave22("save-state ${project}22.lsmv", "Save‣Slot 22"); + inverse_key isave23("save-state ${project}23.lsmv", "Save‣Slot 23"); + inverse_key isave24("save-state ${project}24.lsmv", "Save‣Slot 24"); + inverse_key isave25("save-state ${project}25.lsmv", "Save‣Slot 25"); + inverse_key isave26("save-state ${project}26.lsmv", "Save‣Slot 26"); + inverse_key isave27("save-state ${project}27.lsmv", "Save‣Slot 27"); + inverse_key isave28("save-state ${project}28.lsmv", "Save‣Slot 28"); + inverse_key isave29("save-state ${project}29.lsmv", "Save‣Slot 29"); + inverse_key isave30("save-state ${project}30.lsmv", "Save‣Slot 30"); + inverse_key isave31("save-state ${project}31.lsmv", "Save‣Slot 31"); + inverse_key isave32("save-state ${project}32.lsmv", "Save‣Slot 32"); bool on_quit_prompt = false; class mywindowcallbacks : public information_dispatch diff --git a/src/core/window.cpp b/src/core/window.cpp index a9dd01c2..615e66ab 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -148,8 +148,8 @@ namespace } }); - inverse_key ienable_sound("enable-sound on", "Enable sound"); - inverse_key idisable_sound("enable-sound off", "Disable sound"); + inverse_key ienable_sound("enable-sound on", "Sound‣Enable"); + inverse_key idisable_sound("enable-sound off", "Sound‣Disable"); function_ptr_command set_sound_device("set-sound-device", "Set sound device", "Syntax: set-sound-device \nSet sound device to .\n", diff --git a/src/platform/wxwidgets/editor-keyselect.cpp b/src/platform/wxwidgets/editor-keyselect.cpp deleted file mode 100644 index 3baede8f..00000000 --- a/src/platform/wxwidgets/editor-keyselect.cpp +++ /dev/null @@ -1,430 +0,0 @@ -#include "platform/wxwidgets/platform.hpp" -#include "core/keymapper.hpp" - -#include - -namespace -{ - struct keyentry_mod_data - { - wxCheckBox* pressed; - wxCheckBox* unmasked; - unsigned tmpflags; - }; - - class wxdialog_keyentry : public wxDialog - { - public: - wxdialog_keyentry(wxWindow* parent, const std::string& title, const std::string& spec, - bool clearable); - void on_change_setting(wxCommandEvent& e); - void on_ok(wxCommandEvent& e); - void on_cancel(wxCommandEvent& e); - void on_clear(wxCommandEvent& e); - void on_classchange(wxCommandEvent& e); - std::string getkey(); - private: - void set_mask(const std::string& mod); - void set_mod(const std::string& mod); - void set_set(const std::string& mset, - void (wxdialog_keyentry::*fn)(const std::string& mod)); - void load_spec(const std::string& spec); - std::map modifiers; - wxComboBox* mainclass; - wxComboBox* mainkey; - wxButton* ok; - wxButton* cancel; - wxButton* clear; - bool cleared; - }; - - class wxdialog_hotkeys; - - class hotkey - { - public: - hotkey(wxdialog_hotkeys* h, wxWindow* win, wxSizer* s, inverse_key* ikey, unsigned o); - void update(const std::string& primary, const std::string& secondary); - inverse_key* get_associated(); - std::string get_title(); - private: - wxButton* primaryb; - wxButton* secondaryb; - inverse_key* associated; - std::string title; - }; - - class wxdialog_hotkeys : public wxDialog - { - public: - wxdialog_hotkeys(wxWindow* parent); - ~wxdialog_hotkeys(); - void on_close(wxCommandEvent& e); - void on_reconfig(wxCommandEvent& e); - private: - void update(); - wxScrolledWindow* scroll; - wxSizer* scroll_sizer; - std::map hotkeys; - wxButton* close; - }; - - wxdialog_keyentry::wxdialog_keyentry(wxWindow* parent, const std::string& title, const std::string& spec, - bool clearable) - : wxDialog(parent, wxID_ANY, towxstring(title), wxDefaultPosition, wxSize(-1, -1)) - { - std::vector keych; - std::set mods, keys; - - cleared = false; - runemufn([&mods, &keys]() { mods = modifier::get_set(); keys = keygroup::get_keys(); }); - Centre(); - wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0); - SetSizer(top_s); - - wxFlexGridSizer* t_s = new wxFlexGridSizer(mods.size() + 1, 3, 0, 0); - for(auto i : mods) { - t_s->Add(new wxStaticText(this, wxID_ANY, towxstring(i)), 0, wxGROW); - keyentry_mod_data m; - t_s->Add(m.pressed = new wxCheckBox(this, wxID_ANY, wxT("Pressed")), 0, wxGROW); - t_s->Add(m.unmasked = new wxCheckBox(this, wxID_ANY, wxT("Unmasked")), 0, wxGROW); - m.pressed->Disable(); - modifiers[i] = m; - m.pressed->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, - wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); - m.unmasked->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, - wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); - } - for(auto i : keys) - keych.push_back(towxstring(i)); - t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Key")), 0, wxGROW); - t_s->Add(mainkey = new wxComboBox(this, wxID_ANY, keych[0], wxDefaultPosition, wxDefaultSize, - keych.size(), &keych[0], wxCB_READONLY), 1, wxGROW); - mainkey->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED, - wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); - top_s->Add(t_s); - - wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); - if(clearable) - pbutton_s->Add(clear = new wxButton(this, wxID_OK, wxT("Clear")), 0, wxGROW); - 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(wxdialog_keyentry::on_ok), NULL, this); - cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxdialog_keyentry::on_cancel), NULL, this); - if(clearable) - clear->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxdialog_keyentry::on_clear), NULL, this); - top_s->Add(pbutton_s, 0, wxGROW); - - t_s->SetSizeHints(this); - top_s->SetSizeHints(this); - Fit(); - - if(spec != "") - load_spec(spec); - } - -#define TMPFLAG_UNMASKED 65 -#define TMPFLAG_UNMASKED_LINK_CHILD 2 -#define TMPFLAG_UNMASKED_LINK_PARENT 68 -#define TMPFLAG_PRESSED 8 -#define TMPFLAG_PRESSED_LINK_CHILD 16 -#define TMPFLAG_PRESSED_LINK_PARENT 32 - - void wxdialog_keyentry::set_mask(const std::string& mod) - { - if(!modifiers.count(mod)) - return; - if(modifiers[mod].unmasked->IsEnabled()) { - wxCommandEvent e; - modifiers[mod].unmasked->SetValue(true); - on_change_setting(e); - } - } - - void wxdialog_keyentry::set_mod(const std::string& mod) - { - if(!modifiers.count(mod)) - return; - if(modifiers[mod].pressed->IsEnabled()) { - wxCommandEvent e; - modifiers[mod].pressed->SetValue(true); - on_change_setting(e); - } - } - - void wxdialog_keyentry::set_set(const std::string& mset, - void (wxdialog_keyentry::*fn)(const std::string& mod)) - { - std::string rem = mset; - while(rem != "") { - size_t s = rem.find_first_of(","); - if(s >= rem.length()) { - (this->*fn)(rem); - break; - } else { - (this->*fn)(rem.substr(0, s)); - rem = rem.substr(s + 1); - } - } - } - - void wxdialog_keyentry::load_spec(const std::string& spec) - { - std::string _spec = spec; - size_t s1 = _spec.find_first_of("/"); - size_t s2 = _spec.find_first_of("|"); - if(s1 >= _spec.length() || s2 >= _spec.length()) - return; //Bad. - std::string mod = _spec.substr(0, s1); - std::string mask = _spec.substr(s1 + 1, s2 - s1 - 1); - std::string key = _spec.substr(s2 + 1); - set_set(mask, &wxdialog_keyentry::set_mask); - set_set(mod, &wxdialog_keyentry::set_mod); - mainkey->SetValue(towxstring(key)); - } - - void wxdialog_keyentry::on_change_setting(wxCommandEvent& e) - { - for(auto& i : modifiers) - i.second.tmpflags = 0; - for(auto& i : modifiers) { - modifier* m = NULL; - try { - m = &modifier::lookup(i.first); - } catch(...) { - i.second.pressed->Disable(); - i.second.unmasked->Disable(); - continue; - } - std::string j = m->linked_name(); - if(i.second.unmasked->GetValue()) - i.second.tmpflags |= TMPFLAG_UNMASKED; - if(j != "") { - if(modifiers[j].unmasked->GetValue()) - i.second.tmpflags |= TMPFLAG_UNMASKED_LINK_PARENT; - if(i.second.unmasked->GetValue()) - modifiers[j].tmpflags |= TMPFLAG_UNMASKED_LINK_CHILD; - } - if(i.second.pressed->GetValue()) - i.second.tmpflags |= TMPFLAG_PRESSED; - if(j != "") { - if(modifiers[j].pressed->GetValue()) - i.second.tmpflags |= TMPFLAG_PRESSED_LINK_PARENT; - if(i.second.pressed->GetValue()) - modifiers[j].tmpflags |= TMPFLAG_PRESSED_LINK_CHILD; - } - } - for(auto& i : modifiers) { - //Unmasked is to be enabled if neither unmasked link flag is set. - if(i.second.tmpflags & ((TMPFLAG_UNMASKED_LINK_CHILD | TMPFLAG_UNMASKED_LINK_PARENT) & ~64)) { - i.second.unmasked->SetValue(false); - i.second.unmasked->Disable(); - } else - i.second.unmasked->Enable(); - //Pressed is to be enabled if: - //- This modifier is unmasked or parent is unmasked. - //- Parent nor child is not pressed. - if(((i.second.tmpflags & (TMPFLAG_UNMASKED | TMPFLAG_UNMASKED_LINK_PARENT | - TMPFLAG_PRESSED_LINK_CHILD | TMPFLAG_PRESSED_LINK_PARENT)) & 112) == 64) - i.second.pressed->Enable(); - else { - i.second.pressed->SetValue(false); - i.second.pressed->Disable(); - } - } - } - - void wxdialog_keyentry::on_ok(wxCommandEvent& e) - { - EndModal(wxID_OK); - } - - void wxdialog_keyentry::on_clear(wxCommandEvent& e) - { - cleared = true; - EndModal(wxID_OK); - } - - void wxdialog_keyentry::on_cancel(wxCommandEvent& e) - { - EndModal(wxID_CANCEL); - } - - std::string wxdialog_keyentry::getkey() - { - if(cleared) - return ""; - std::string x; - bool f; - f = true; - for(auto i : modifiers) { - if(i.second.pressed->GetValue()) { - if(!f) - x = x + ","; - f = false; - x = x + i.first; - } - } - x = x + "/"; - f = true; - for(auto i : modifiers) { - if(i.second.unmasked->GetValue()) { - if(!f) - x = x + ","; - f = false; - x = x + i.first; - } - } - x = x + "|" + tostdstring(mainkey->GetValue()); - return x; - } - - wxdialog_hotkeys::wxdialog_hotkeys(wxWindow* parent) - : wxDialog(parent, wxID_ANY, wxT("Hotkeys"), wxDefaultPosition, wxSize(-1, -1)) - { - scroll = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1)); - scroll->SetMinSize(wxSize(-1, 500)); - - Centre(); - wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0); - SetSizer(top_s); - scroll_sizer = new wxFlexGridSizer(0, 3, 0, 0); - scroll->SetSizer(scroll_sizer); - - //Obtain all the inverses. - std::set inverses; - runemufn([&inverses]() { - auto x = inverse_key::get_ikeys(); - for(auto y : x) - inverses.insert(y); - }); - unsigned y = 0; - for(auto x : inverses) { - hotkeys[y] = new hotkey(this, scroll, scroll_sizer, x, y); - y++; - } - update(); - - top_s->Add(scroll); - scroll->SetScrollRate(0, 20); - wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); - pbutton_s->AddStretchSpacer(); - pbutton_s->Add(close = new wxButton(this, wxID_CANCEL, wxT("Close")), 0, wxGROW); - close->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxdialog_hotkeys::on_close), NULL, this); - top_s->Add(pbutton_s, 0, wxGROW); - - scroll_sizer->SetSizeHints(this); - top_s->SetSizeHints(this); - scroll_sizer->Layout(); - top_s->Layout(); - Fit(); - } - - void wxdialog_hotkeys::on_reconfig(wxCommandEvent& e) - { - int id = e.GetId(); - if(id <= wxID_HIGHEST) - return; - unsigned button = (id - wxID_HIGHEST - 1) / 2; - bool primflag = (((id - wxID_HIGHEST - 1) % 2) == 0); - if(!hotkeys.count(button)) - return; - wxdialog_keyentry* d = new wxdialog_keyentry(this, "Specify key for " + hotkeys[button]-> - get_title(), hotkeys[button]->get_associated()->get(primflag), true); - if(d->ShowModal() == wxID_CANCEL) { - d->Destroy(); - return; - } - std::string key = d->getkey(); - d->Destroy(); - if(key != "") - hotkeys[button]->get_associated()->set(key, primflag); - else - hotkeys[button]->get_associated()->clear(primflag); - update(); - } - - void wxdialog_hotkeys::update() - { - std::map> data; - runemufn([&data]() { - auto x = inverse_key::get_ikeys(); - for(auto y : x) - data[y] = std::make_pair(y->get(true), y->get(false)); - }); - for(auto i : hotkeys) { - inverse_key* j = i.second->get_associated(); - if(!data.count(j)) - continue; - auto y = data[j]; - i.second->update(y.first, y.second); - } - } - - wxdialog_hotkeys::~wxdialog_hotkeys() - { - for(auto i : hotkeys) - delete i.second; - } - - void wxdialog_hotkeys::on_close(wxCommandEvent& e) - { - EndModal(wxID_OK); - } - - hotkey::hotkey(wxdialog_hotkeys* h, wxWindow* win, wxSizer* s, inverse_key* ikey, unsigned o) - { - title = ikey->getname(); - s->Add(new wxStaticText(win, wxID_ANY, towxstring(title)), 0, wxGROW); - s->Add(primaryb = new wxButton(win, wxID_HIGHEST + 1 + 2 * o, wxT("(none)"), wxDefaultPosition, - wxSize(200, -1)), 0, wxGROW); - s->Add(secondaryb = new wxButton(win, wxID_HIGHEST + 2 + 2 * o, wxT("(none)"), wxDefaultPosition, - wxSize(200, -1)), 0, wxGROW); - primaryb->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxdialog_hotkeys::on_reconfig), NULL, h); - secondaryb->Connect(wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler(wxdialog_hotkeys::on_reconfig), NULL, h); - associated = ikey; - } - - inverse_key* hotkey::get_associated() - { - return associated; - } - - std::string hotkey::get_title() - { - return title; - } - - void hotkey::update(const std::string& primary, const std::string& secondary) - { - primaryb->SetLabel((primary != "") ? towxstring(primary) : towxstring("(none)")); - secondaryb->SetLabel((secondary != "") ? towxstring(secondary) : towxstring("(none)")); - } -} - -std::string wxeditor_keyselect(wxWindow* parent, bool clearable) -{ - wxdialog_keyentry* d = new wxdialog_keyentry(parent, "Specify key", "", clearable); - if(d->ShowModal() == wxID_CANCEL) { - d->Destroy(); - throw canceled_exception(); - } - std::string key = d->getkey(); - d->Destroy(); - return key; -} - -void wxeditor_hotkeys_display(wxWindow* parent) -{ - modal_pause_holder hld; - wxdialog_hotkeys* d = new wxdialog_hotkeys(parent); - d->ShowModal(); - d->Destroy(); -} diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index fadf3c51..53e8b6b5 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -63,8 +63,6 @@ enum wxID_EDIT_AUTHORS, wxID_AUTOHOLD_FIRST, wxID_AUTOHOLD_LAST = wxID_AUTOHOLD_FIRST + 1023, - wxID_EDIT_KEYBINDINGS, - wxID_EDIT_ALIAS, wxID_EDIT_MEMORYWATCH, wxID_SAVE_MEMORYWATCH, wxID_LOAD_MEMORYWATCH, @@ -73,7 +71,6 @@ enum wxID_REWIND_MOVIE, wxID_MEMORY_SEARCH, wxID_CANCEL_SAVES, - wxID_EDIT_HOTKEYS, wxID_SHOW_STATUS, wxID_SET_SPEED, wxID_SET_VOLUME, @@ -764,12 +761,6 @@ wxwin_mainwindow::wxwin_mainwindow() menu_special(wxT("Capture"), reinterpret_cast(dmenu = new dumper_menu(this, wxID_DUMP_FIRST, wxID_DUMP_LAST))); - - menu_start(wxT("Settings")); - menu_entry(wxID_EDIT_KEYBINDINGS, wxT("Configure keybindings...")); - menu_entry(wxID_EDIT_ALIAS, wxT("Configure aliases...")); - menu_separator(); - menu_entry(wxID_EDIT_HOTKEYS, wxT("Configure hotkeys...")); } void wxwin_mainwindow::request_paint() @@ -912,62 +903,6 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) case wxID_EDIT_AUTHORS: wxeditor_authors_display(this); return; - case wxID_EDIT_HOTKEYS: - wxeditor_hotkeys_display(this); - return; - case wxID_EDIT_KEYBINDINGS: { - modal_pause_holder hld; - std::set bind; - runemufn([&bind]() { bind = keymapper::get_bindings(); }); - std::vector choices; - choices.push_back(NEW_KEYBINDING); - for(auto i : bind) - choices.push_back(i); - std::string key = pick_among(this, "Select binding", "Select keybinding to edit", choices); - if(key == NEW_KEYBINDING) - key = wxeditor_keyselect(this, false); - std::string old_command_value; - runemufn([&old_command_value, key]() { old_command_value = keymapper::get_command_for(key); }); - std::string newcommand = pick_text(this, "Edit binding", "Enter new command for binding:", - old_command_value); - bool fault = false; - std::string faulttext; - runemufn([&fault, &faulttext, key, newcommand]() { - try { - keymapper::bind_for(key, newcommand); - } catch(std::exception& e) { - fault = true; - faulttext = e.what(); - } - }); - if(fault) - show_message_ok(this, "Error", "Can't bind key: " + faulttext, wxICON_EXCLAMATION); - return; - } - case wxID_EDIT_ALIAS: { - modal_pause_holder hld; - std::set bind; - runemufn([&bind]() { bind = command::get_aliases(); }); - std::vector choices; - choices.push_back(NEW_ALIAS); - for(auto i : bind) - choices.push_back(i); - std::string alias = pick_among(this, "Select alias", "Select alias to edit", choices); - if(alias == NEW_ALIAS) { - alias = pick_text(this, "Enter alias name", "Enter name for the new alias:"); - if(!command::valid_alias_name(alias)) { - show_message_ok(this, "Error", "Not a valid alias name: " + alias, - wxICON_EXCLAMATION); - throw canceled_exception(); - } - } - std::string old_alias_value; - runemufn([alias, &old_alias_value]() { old_alias_value = command::get_alias_for(alias); }); - std::string newcmd = pick_text(this, "Edit alias", "Enter new commands for alias:", - old_alias_value, true); - runemufn([alias, newcmd]() { command::set_alias_for(alias, newcmd); }); - return; - } case wxID_EDIT_MEMORYWATCH: { modal_pause_holder hld; std::set bind; diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index 978498aa..09eb8472 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -1,10 +1,12 @@ #include "platform/wxwidgets/platform.hpp" +#include "core/command.hpp" #include "core/dispatch.hpp" #include "core/settings.hpp" #include "library/string.hpp" #include #include +#include #include #include #include @@ -42,6 +44,256 @@ extern "C" const char* scalealgo_choices[] = {"Fast Bilinear", "Bilinear", "Bicubic", "Experimential", "Point", "Area", "Bicubic-Linear", "Gauss", "Sinc", "Lanczos", "Spline"}; +namespace +{ + struct keyentry_mod_data + { + wxCheckBox* pressed; + wxCheckBox* unmasked; + unsigned tmpflags; + }; + + class wxdialog_keyentry : public wxDialog + { + public: + wxdialog_keyentry(wxWindow* parent, const std::string& title, const std::string& spec, + bool clearable); + void on_change_setting(wxCommandEvent& e); + void on_ok(wxCommandEvent& e); + void on_cancel(wxCommandEvent& e); + void on_clear(wxCommandEvent& e); + void on_classchange(wxCommandEvent& e); + std::string getkey(); + private: + void set_mask(const std::string& mod); + void set_mod(const std::string& mod); + void set_set(const std::string& mset, + void (wxdialog_keyentry::*fn)(const std::string& mod)); + void load_spec(const std::string& spec); + std::map modifiers; + wxComboBox* mainclass; + wxComboBox* mainkey; + wxButton* ok; + wxButton* cancel; + wxButton* clear; + bool cleared; + }; + + wxdialog_keyentry::wxdialog_keyentry(wxWindow* parent, const std::string& title, const std::string& spec, + bool clearable) + : wxDialog(parent, wxID_ANY, towxstring(title), wxDefaultPosition, wxSize(-1, -1)) + { + std::vector keych; + std::set mods, keys; + + cleared = false; + runemufn([&mods, &keys]() { mods = modifier::get_set(); keys = keygroup::get_keys(); }); + Centre(); + wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0); + SetSizer(top_s); + + wxFlexGridSizer* t_s = new wxFlexGridSizer(mods.size() + 1, 3, 0, 0); + for(auto i : mods) { + t_s->Add(new wxStaticText(this, wxID_ANY, towxstring(i)), 0, wxGROW); + keyentry_mod_data m; + t_s->Add(m.pressed = new wxCheckBox(this, wxID_ANY, wxT("Pressed")), 0, wxGROW); + t_s->Add(m.unmasked = new wxCheckBox(this, wxID_ANY, wxT("Unmasked")), 0, wxGROW); + m.pressed->Disable(); + modifiers[i] = m; + m.pressed->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, + wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); + m.unmasked->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, + wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); + } + for(auto i : keys) + keych.push_back(towxstring(i)); + t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Key")), 0, wxGROW); + t_s->Add(mainkey = new wxComboBox(this, wxID_ANY, keych[0], wxDefaultPosition, wxDefaultSize, + keych.size(), &keych[0], wxCB_READONLY), 1, wxGROW); + mainkey->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED, + wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); + top_s->Add(t_s); + + wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); + if(clearable) + pbutton_s->Add(clear = new wxButton(this, wxID_OK, wxT("Clear")), 0, wxGROW); + 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(wxdialog_keyentry::on_ok), NULL, this); + cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler(wxdialog_keyentry::on_cancel), NULL, this); + if(clearable) + clear->Connect(wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler(wxdialog_keyentry::on_clear), NULL, this); + top_s->Add(pbutton_s, 0, wxGROW); + + t_s->SetSizeHints(this); + top_s->SetSizeHints(this); + Fit(); + + if(spec != "") + load_spec(spec); + } + +#define TMPFLAG_UNMASKED 65 +#define TMPFLAG_UNMASKED_LINK_CHILD 2 +#define TMPFLAG_UNMASKED_LINK_PARENT 68 +#define TMPFLAG_PRESSED 8 +#define TMPFLAG_PRESSED_LINK_CHILD 16 +#define TMPFLAG_PRESSED_LINK_PARENT 32 + + void wxdialog_keyentry::set_mask(const std::string& mod) + { + if(!modifiers.count(mod)) + return; + if(modifiers[mod].unmasked->IsEnabled()) { + wxCommandEvent e; + modifiers[mod].unmasked->SetValue(true); + on_change_setting(e); + } + } + + void wxdialog_keyentry::set_mod(const std::string& mod) + { + if(!modifiers.count(mod)) + return; + if(modifiers[mod].pressed->IsEnabled()) { + wxCommandEvent e; + modifiers[mod].pressed->SetValue(true); + on_change_setting(e); + } + } + + void wxdialog_keyentry::set_set(const std::string& mset, + void (wxdialog_keyentry::*fn)(const std::string& mod)) + { + std::string rem = mset; + while(rem != "") { + size_t s = rem.find_first_of(","); + if(s >= rem.length()) { + (this->*fn)(rem); + break; + } else { + (this->*fn)(rem.substr(0, s)); + rem = rem.substr(s + 1); + } + } + } + + void wxdialog_keyentry::load_spec(const std::string& spec) + { + std::string _spec = spec; + size_t s1 = _spec.find_first_of("/"); + size_t s2 = _spec.find_first_of("|"); + if(s1 >= _spec.length() || s2 >= _spec.length()) + return; //Bad. + std::string mod = _spec.substr(0, s1); + std::string mask = _spec.substr(s1 + 1, s2 - s1 - 1); + std::string key = _spec.substr(s2 + 1); + set_set(mask, &wxdialog_keyentry::set_mask); + set_set(mod, &wxdialog_keyentry::set_mod); + mainkey->SetValue(towxstring(key)); + } + + void wxdialog_keyentry::on_change_setting(wxCommandEvent& e) + { + for(auto& i : modifiers) + i.second.tmpflags = 0; + for(auto& i : modifiers) { + modifier* m = NULL; + try { + m = &modifier::lookup(i.first); + } catch(...) { + i.second.pressed->Disable(); + i.second.unmasked->Disable(); + continue; + } + std::string j = m->linked_name(); + if(i.second.unmasked->GetValue()) + i.second.tmpflags |= TMPFLAG_UNMASKED; + if(j != "") { + if(modifiers[j].unmasked->GetValue()) + i.second.tmpflags |= TMPFLAG_UNMASKED_LINK_PARENT; + if(i.second.unmasked->GetValue()) + modifiers[j].tmpflags |= TMPFLAG_UNMASKED_LINK_CHILD; + } + if(i.second.pressed->GetValue()) + i.second.tmpflags |= TMPFLAG_PRESSED; + if(j != "") { + if(modifiers[j].pressed->GetValue()) + i.second.tmpflags |= TMPFLAG_PRESSED_LINK_PARENT; + if(i.second.pressed->GetValue()) + modifiers[j].tmpflags |= TMPFLAG_PRESSED_LINK_CHILD; + } + } + for(auto& i : modifiers) { + //Unmasked is to be enabled if neither unmasked link flag is set. + if(i.second.tmpflags & ((TMPFLAG_UNMASKED_LINK_CHILD | TMPFLAG_UNMASKED_LINK_PARENT) & ~64)) { + i.second.unmasked->SetValue(false); + i.second.unmasked->Disable(); + } else + i.second.unmasked->Enable(); + //Pressed is to be enabled if: + //- This modifier is unmasked or parent is unmasked. + //- Parent nor child is not pressed. + if(((i.second.tmpflags & (TMPFLAG_UNMASKED | TMPFLAG_UNMASKED_LINK_PARENT | + TMPFLAG_PRESSED_LINK_CHILD | TMPFLAG_PRESSED_LINK_PARENT)) & 112) == 64) + i.second.pressed->Enable(); + else { + i.second.pressed->SetValue(false); + i.second.pressed->Disable(); + } + } + } + + void wxdialog_keyentry::on_ok(wxCommandEvent& e) + { + EndModal(wxID_OK); + } + + void wxdialog_keyentry::on_clear(wxCommandEvent& e) + { + cleared = true; + EndModal(wxID_OK); + } + + void wxdialog_keyentry::on_cancel(wxCommandEvent& e) + { + EndModal(wxID_CANCEL); + } + + std::string wxdialog_keyentry::getkey() + { + if(cleared) + return ""; + std::string x; + bool f; + f = true; + for(auto i : modifiers) { + if(i.second.pressed->GetValue()) { + if(!f) + x = x + ","; + f = false; + x = x + i.first; + } + } + x = x + "/"; + f = true; + for(auto i : modifiers) { + if(i.second.unmasked->GetValue()) { + if(!f) + x = x + ","; + f = false; + x = x + i.first; + } + } + x = x + "|" + tostdstring(mainkey->GetValue()); + return x; + } +} + class wxeditor_esettings_joystick_aconfig : public wxDialog { public: @@ -537,6 +789,474 @@ void wxeditor_esettings_screen::refresh() Fit(); } +class wxeditor_esettings_aliases : public wxPanel +{ +public: + wxeditor_esettings_aliases(wxWindow* parent); + ~wxeditor_esettings_aliases(); + void on_add(wxCommandEvent& e); + void on_edit(wxCommandEvent& e); + void on_delete(wxCommandEvent& e); +private: + std::map numbers; + wxListBox* select; + void refresh(); + std::string selected(); +}; + +wxeditor_esettings_aliases::wxeditor_esettings_aliases(wxWindow* parent) + : wxPanel(parent, -1) +{ + wxButton* tmp; + + wxSizer* top_s = new wxBoxSizer(wxVERTICAL); + SetSizer(top_s); + + top_s->Add(select = new wxListBox(this, wxID_ANY), 1, wxGROW); + + wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); + pbutton_s->AddStretchSpacer(); + pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Add")), 0, wxGROW); + tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_aliases::on_add), NULL, + this); + pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Edit")), 0, wxGROW); + tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_aliases::on_edit), NULL, + this); + pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Delete")), 0, wxGROW); + tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_aliases::on_delete), NULL, + this); + top_s->Add(pbutton_s, 0, wxGROW); + + refresh(); + top_s->SetSizeHints(this); + Fit(); +} + +wxeditor_esettings_aliases::~wxeditor_esettings_aliases() +{ +} + +void wxeditor_esettings_aliases::on_add(wxCommandEvent& e) +{ + try { + std::string name = pick_text(this, "Enter alias name", "Enter name for the new alias:"); + if(!command::valid_alias_name(name)) { + show_message_ok(this, "Error", "Not a valid alias name: " + name, wxICON_EXCLAMATION); + throw canceled_exception(); + } + std::string old_alias_value; + runemufn([name, &old_alias_value]() { old_alias_value = command::get_alias_for(name); }); + std::string newcmd = pick_text(this, "Edit alias", "Enter new commands for '" + name + "':", + old_alias_value, true); + runemufn([name, newcmd]() { command::set_alias_for(name, newcmd); }); + } catch(...) { + } + refresh(); +} + +void wxeditor_esettings_aliases::on_edit(wxCommandEvent& e) +{ + std::string name = selected(); + if(name == "") { + refresh(); + return; + } + try { + std::string old_alias_value; + runemufn([name, &old_alias_value]() { old_alias_value = command::get_alias_for(name); }); + std::string newcmd = pick_text(this, "Edit alias", "Enter new commands for '" + name + "':", + old_alias_value, true); + runemufn([name, newcmd]() { command::set_alias_for(name, newcmd); }); + } catch(...) { + } + refresh(); +} + +void wxeditor_esettings_aliases::on_delete(wxCommandEvent& e) +{ + std::string name = selected(); + if(name == "") { + refresh(); + return; + } + runemufn([name]() { command::set_alias_for(name, ""); }); + refresh(); +} + +void wxeditor_esettings_aliases::refresh() +{ + int n = select->GetSelection(); + std::set bind; + std::vector choices; + runemufn([&bind]() { bind = command::get_aliases(); }); + for(auto i : bind) { + numbers[choices.size()] = i; + choices.push_back(towxstring(i)); + } + select->Set(choices.size(), &choices[0]); + if(n == wxNOT_FOUND && select->GetCount()) + select->SetSelection(0); + else if(n >= select->GetCount()) + select->SetSelection(select->GetCount() ? (select->GetCount() - 1) : wxNOT_FOUND); + else + select->SetSelection(n); +} + +std::string wxeditor_esettings_aliases::selected() +{ + int x = select->GetSelection(); + if(numbers.count(x)) + return numbers[x]; + else + return ""; +} + +class wxeditor_esettings_hotkeys : public wxPanel +{ +public: + wxeditor_esettings_hotkeys(wxWindow* parent); + ~wxeditor_esettings_hotkeys(); + void on_primary(wxCommandEvent& e); + void on_secondary(wxCommandEvent& e); +private: + std::map items; + std::map realitems; + std::map leafname; + wxTreeItemId true_root; + wxTreeCtrl* select; + wxButton* pri_button; + wxButton* sec_button; + void refresh(); + std::string selected(); +}; + +wxeditor_esettings_hotkeys::wxeditor_esettings_hotkeys(wxWindow* parent) + : wxPanel(parent, -1) +{ + wxSizer* top_s = new wxBoxSizer(wxVERTICAL); + SetSizer(top_s); + + top_s->Add(select = new wxTreeCtrl(this, wxID_ANY), 1, wxGROW); + + wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); + pbutton_s->AddStretchSpacer(); + pbutton_s->Add(pri_button = new wxButton(this, wxID_ANY, wxT("Change primary")), 0, wxGROW); + pri_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler(wxeditor_esettings_hotkeys::on_primary), NULL, this); + pbutton_s->Add(sec_button = new wxButton(this, wxID_ANY, wxT("Change secondary")), 0, wxGROW); + sec_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler(wxeditor_esettings_hotkeys::on_secondary), NULL, this); + top_s->Add(pbutton_s, 0, wxGROW); + + items[""] = select->AddRoot(wxT("")); + + refresh(); + top_s->SetSizeHints(this); + Fit(); +} + +wxeditor_esettings_hotkeys::~wxeditor_esettings_hotkeys() +{ +} + +void wxeditor_esettings_hotkeys::on_primary(wxCommandEvent& e) +{ + std::string name = selected(); + if(name == "") { + refresh(); + return; + } + try { + std::string key; + inverse_key* ik = realitems[name]; + if(!ik) { + refresh(); + return; + } + runemufn([&key, ik]() { key = ik->get(true); }); + wxdialog_keyentry* d = new wxdialog_keyentry(this, "Specify key for " + name, key, true); + if(d->ShowModal() == wxID_CANCEL) { + d->Destroy(); + return; + } + key = d->getkey(); + d->Destroy(); + if(key != "") + runemufn([key, ik]() { ik->set(key, true); }); + else + runemufn([key, ik]() { ik->clear(true); }); + refresh(); + } catch(...) { + refresh(); + } +} + +void wxeditor_esettings_hotkeys::on_secondary(wxCommandEvent& e) +{ + std::string name = selected(); + if(name == "") { + refresh(); + return; + } + try { + std::string key; + inverse_key* ik = realitems[name]; + if(!ik) { + refresh(); + return; + } + runemufn([&key, ik]() { key = ik->get(false); }); + wxdialog_keyentry* d = new wxdialog_keyentry(this, "Specify key for " + name, key, true); + if(d->ShowModal() == wxID_CANCEL) { + d->Destroy(); + return; + } + key = d->getkey(); + d->Destroy(); + if(key != "") + runemufn([key, ik]() { ik->set(key, false); }); + else + runemufn([key, ik]() { ik->clear(false); }); + refresh(); + } catch(...) { + refresh(); + } +} + +void wxeditor_esettings_hotkeys::refresh() +{ + std::set closure_additional; + std::map keyorder; + std::map> data; + runemufn([&data, &keyorder]() { + auto x = inverse_key::get_ikeys(); + for(auto y : x) { + keyorder[y->getname()] = y; + data[y] = std::make_pair(y->get(true), y->get(false)); + } + }); + //Close keyorder with respect to parents. + for(auto i : keyorder) { + std::string tmp = i.first; + for(size_t itr = 0; itr < tmp.length() - 2 && itr < tmp.length(); itr++) { + unsigned char ch1 = tmp[itr]; + unsigned char ch2 = tmp[itr + 1]; + unsigned char ch3 = tmp[itr + 2]; + if(ch1 == 0xE2 && ch2 == 0x80 && ch3 == 0xA3) { + closure_additional.insert(tmp.substr(0, itr)); + } + } + } + for(auto i : closure_additional) + if(!keyorder.count(i)) { + keyorder[i] = NULL; + } + //Then add the needed entries to the tree. Thanks to the ordering, presence of parent before child is always + //guaranteed. + for(auto i : keyorder) { + if(!items.count(i.first)) { + //Not found, add. + //Find the parent name. + std::string tmp = i.first; + std::string parent = ""; + std::string leaf = i.first; + for(size_t itr = 0; itr < tmp.length() - 2 && itr < tmp.length(); itr++) { + unsigned char ch1 = tmp[itr]; + unsigned char ch2 = tmp[itr + 1]; + unsigned char ch3 = tmp[itr + 2]; + if(ch1 == 0xE2 && ch2 == 0x80 && ch3 == 0xA3) { + parent = tmp.substr(0, itr); + leaf = tmp.substr(itr + 3); + } + } + items[i.first] = select->AppendItem(items[parent], towxstring(leaf)); + leafname[i.first] = leaf; + } + if(i.second) { + //Real, set the keys. + realitems[i.first] = i.second; + std::string text = leafname[i.first]; + if(data[i.second].first == "") + text = text + " (not set)"; + else if(data[i.second].second == "") + text = text + " (" + data[i.second].first + ")"; + else + text = text + " (" + data[i.second].first + " or " + data[i.second].second + ")"; + select->SetItemText(items[i.first], towxstring(text)); + } + } +} + +std::string wxeditor_esettings_hotkeys::selected() +{ + wxTreeItemId sel = select->GetSelection(); + std::string item; + bool found = false; + for(auto i : items) + if(i.second == sel) { + found = true; + item = i.first; + } + if(!found || !realitems.count(item)) + return ""; + return item; +} + +class wxeditor_esettings_bindings : public wxPanel +{ +public: + wxeditor_esettings_bindings(wxWindow* parent); + ~wxeditor_esettings_bindings(); + void on_add(wxCommandEvent& e); + void on_edit(wxCommandEvent& e); + void on_delete(wxCommandEvent& e); +private: + std::map numbers; + wxListBox* select; + void refresh(); + std::set settings; + std::map values; + std::map selections; + std::string selected(); + wxListBox* _settings; +}; + +wxeditor_esettings_bindings::wxeditor_esettings_bindings(wxWindow* parent) + : wxPanel(parent, -1) +{ + wxButton* tmp; + + wxSizer* top_s = new wxBoxSizer(wxVERTICAL); + SetSizer(top_s); + + top_s->Add(select = new wxListBox(this, wxID_ANY), 1, wxGROW); + + wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); + pbutton_s->AddStretchSpacer(); + pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Add")), 0, wxGROW); + tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_bindings::on_add), NULL, + this); + pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Edit")), 0, wxGROW); + tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_bindings::on_edit), NULL, + this); + pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Delete")), 0, wxGROW); + tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_bindings::on_delete), NULL, + this); + top_s->Add(pbutton_s, 0, wxGROW); + + refresh(); + top_s->SetSizeHints(this); + Fit(); +} + +wxeditor_esettings_bindings::~wxeditor_esettings_bindings() +{ +} + +void wxeditor_esettings_bindings::on_add(wxCommandEvent& e) +{ + try { + std::string name; + wxdialog_keyentry* d = new wxdialog_keyentry(this, "Specify new key", "", false); + if(d->ShowModal() == wxID_CANCEL) { + d->Destroy(); + throw 42; + } + name = d->getkey(); + d->Destroy(); + + std::string newcommand = pick_text(this, "New binding", "Enter command for binding:", ""); + bool fault = false; + std::string faulttext; + runemufn([&fault, &faulttext, name, newcommand]() { + try { + keymapper::bind_for(name, newcommand); + } catch(std::exception& e) { + fault = true; + faulttext = e.what(); + } + }); + if(fault) + wxMessageBox(wxT("Error"), towxstring("Can't bind key: " + faulttext), wxICON_EXCLAMATION); + refresh(); + } catch(...) { + refresh(); + } +} + +void wxeditor_esettings_bindings::on_edit(wxCommandEvent& e) +{ + std::string name = selected(); + if(name == "") { + refresh(); + return; + } + try { + std::string old_command_value; + runemufn([&old_command_value, name]() { old_command_value = keymapper::get_command_for(name); }); + std::string newcommand = pick_text(this, "Edit binding", "Enter new command for binding:", + old_command_value); + bool fault = false; + std::string faulttext; + runemufn([&fault, &faulttext, name, newcommand]() { + try { + keymapper::bind_for(name, newcommand); + } catch(std::exception& e) { + fault = true; + faulttext = e.what(); + } + }); + if(fault) + wxMessageBox(wxT("Error"), towxstring("Can't bind key: " + faulttext), wxICON_EXCLAMATION); + refresh(); + } catch(...) { + refresh(); + } +} + +void wxeditor_esettings_bindings::on_delete(wxCommandEvent& e) +{ + std::string name = selected(); + if(name == "") { + refresh(); + return; + } + runemufn([name]() { try { keymapper::bind_for(name, ""); } catch(...) {} }); + refresh(); +} + +void wxeditor_esettings_bindings::refresh() +{ + int n = select->GetSelection(); + std::map bind; + std::vector choices; + runemufn([&bind]() { + std::set a = keymapper::get_bindings(); + for(auto i : a) + bind[i] = keymapper::get_command_for(i); + }); + for(auto i : bind) { + numbers[choices.size()] = i.first; + choices.push_back(towxstring(i.first + " (" + i.second + ")")); + } + select->Set(choices.size(), &choices[0]); + if(n == wxNOT_FOUND && select->GetCount()) + select->SetSelection(0); + else if(n >= select->GetCount()) + select->SetSelection(select->GetCount() ? (select->GetCount() - 1) : wxNOT_FOUND); + else + select->SetSelection(n); +} + +std::string wxeditor_esettings_bindings::selected() +{ + int x = select->GetSelection(); + if(numbers.count(x)) + return numbers[x]; + else + return ""; +} + class wxeditor_esettings_advanced : public wxPanel, information_dispatch { public: @@ -692,6 +1412,9 @@ wxeditor_esettings::wxeditor_esettings(wxWindow* parent) tabset->AddPage(new wxeditor_esettings_joystick(tabset), wxT("Joysticks")); tabset->AddPage(new wxeditor_esettings_paths(tabset), wxT("Paths")); tabset->AddPage(new wxeditor_esettings_screen(tabset), wxT("Scaling")); + tabset->AddPage(new wxeditor_esettings_hotkeys(tabset), wxT("Hotkeys")); + tabset->AddPage(new wxeditor_esettings_aliases(tabset), wxT("Aliases")); + tabset->AddPage(new wxeditor_esettings_bindings(tabset), wxT("Bindings")); tabset->AddPage(new wxeditor_esettings_advanced(tabset), wxT("Advanced")); top_s->Add(tabset, 1, wxGROW); From 4b07c0f76d796a42c5af8dbc5235634e368afba2 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 8 Apr 2012 13:35:30 +0300 Subject: [PATCH 07/11] Set wxTR_HIDE_ROOT on hotkey tree This makes that three look a bit prettier... --- src/platform/wxwidgets/settings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index 09eb8472..cebdccc4 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -936,7 +936,8 @@ wxeditor_esettings_hotkeys::wxeditor_esettings_hotkeys(wxWindow* parent) wxSizer* top_s = new wxBoxSizer(wxVERTICAL); SetSizer(top_s); - top_s->Add(select = new wxTreeCtrl(this, wxID_ANY), 1, wxGROW); + top_s->Add(select = new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | + wxTR_HIDE_ROOT), 1, wxGROW); wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL); pbutton_s->AddStretchSpacer(); From 2a6e4f715297f80eee7c1426bc58f06d0c5122d0 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 8 Apr 2012 15:18:54 +0300 Subject: [PATCH 08/11] Split keys in classes The full key list is just too large, so break it down. --- src/core/keymapper.cpp | 6 ++- src/platform/wxwidgets/settings.cpp | 58 ++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/core/keymapper.cpp b/src/core/keymapper.cpp index 4ddaab4f..36165a13 100644 --- a/src/core/keymapper.cpp +++ b/src/core/keymapper.cpp @@ -852,11 +852,13 @@ std::string inverse_key::get(bool primary) throw(std::bad_alloc) void inverse_key::clear(bool primary) throw(std::bad_alloc) { if(primary) { - keymapper::bind_for(primary_spec, ""); + if(primary_spec != "") + keymapper::bind_for(primary_spec, ""); primary_spec = secondary_spec; secondary_spec = ""; } else { - keymapper::bind_for(secondary_spec, ""); + if(secondary_spec != "") + keymapper::bind_for(secondary_spec, ""); secondary_spec = ""; } //Search the keybindings for matches. diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index cebdccc4..88a8115e 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -70,7 +70,10 @@ namespace void set_set(const std::string& mset, void (wxdialog_keyentry::*fn)(const std::string& mod)); void load_spec(const std::string& spec); + void set_class(const std::string& _class); std::map modifiers; + std::map> classes; + std::string currentclass; wxComboBox* mainclass; wxComboBox* mainkey; wxButton* ok; @@ -83,11 +86,24 @@ namespace bool clearable) : wxDialog(parent, wxID_ANY, towxstring(title), wxDefaultPosition, wxSize(-1, -1)) { - std::vector keych; + std::vector classeslist; + wxString emptystring; std::set mods, keys; cleared = false; - runemufn([&mods, &keys]() { mods = modifier::get_set(); keys = keygroup::get_keys(); }); + runemufn([&mods, &keys, &classes, &classeslist]() { + std::set x; + mods = modifier::get_set(); + keys = keygroup::get_keys(); + for(auto i : keys) { + std::string kclass = keygroup::lookup(i).first->get_class(); + if(!x.count(kclass)) + classeslist.push_back(towxstring(kclass)); + x.insert(kclass); + classes[kclass].insert(i); + } + }); + Centre(); wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0); SetSizer(top_s); @@ -105,11 +121,13 @@ namespace m.unmasked->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); } - for(auto i : keys) - keych.push_back(towxstring(i)); t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Key")), 0, wxGROW); - t_s->Add(mainkey = new wxComboBox(this, wxID_ANY, keych[0], wxDefaultPosition, wxDefaultSize, - keych.size(), &keych[0], wxCB_READONLY), 1, wxGROW); + t_s->Add(mainclass = new wxComboBox(this, wxID_ANY, classeslist[0], wxDefaultPosition, wxDefaultSize, + classeslist.size(), &classeslist[0], wxCB_READONLY), 1, wxGROW); + mainclass->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED, + wxCommandEventHandler(wxdialog_keyentry::on_classchange), NULL, this); + t_s->Add(mainkey = new wxComboBox(this, wxID_ANY, emptystring, wxDefaultPosition, wxDefaultSize, + 1, &emptystring, wxCB_READONLY), 1, wxGROW); mainkey->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); top_s->Add(t_s); @@ -124,11 +142,15 @@ namespace wxCommandEventHandler(wxdialog_keyentry::on_ok), NULL, this); cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxdialog_keyentry::on_cancel), NULL, this); + mainclass->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED, + wxCommandEventHandler(wxdialog_keyentry::on_classchange), NULL, this); if(clearable) clear->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxdialog_keyentry::on_clear), NULL, this); top_s->Add(pbutton_s, 0, wxGROW); + set_class(tostdstring(classeslist[0])); + t_s->SetSizeHints(this); top_s->SetSizeHints(this); Fit(); @@ -194,6 +216,12 @@ namespace std::string key = _spec.substr(s2 + 1); set_set(mask, &wxdialog_keyentry::set_mask); set_set(mod, &wxdialog_keyentry::set_mod); + std::string _class; + for(auto i : classes) + if(i.second.count(key)) + _class = i.first; + set_class(_class); + mainclass->SetValue(towxstring(_class)); mainkey->SetValue(towxstring(key)); } @@ -264,6 +292,24 @@ namespace EndModal(wxID_CANCEL); } + void wxdialog_keyentry::set_class(const std::string& _class) + { + if(!mainkey) + return; + if(currentclass == _class) + return; + mainkey->Clear(); + for(auto i : classes[_class]) + mainkey->Append(towxstring(i)); + currentclass = _class; + mainkey->SetSelection(0); + } + + void wxdialog_keyentry::on_classchange(wxCommandEvent& e) + { + set_class(tostdstring(mainclass->GetValue())); + } + std::string wxdialog_keyentry::getkey() { if(cleared) From 976ab9a8781dc3ad9873d2409f08f8b446b4d2b5 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 8 Apr 2012 15:44:03 +0300 Subject: [PATCH 09/11] Refactor path handling --- include/core/settings.hpp | 18 ++++++++++++ src/core/mainloop.cpp | 38 +------------------------ src/core/moviedata.cpp | 38 +------------------------ src/core/settings.cpp | 39 ++++++++++++++++++++++++++ src/platform/wxwidgets/mainwindow.cpp | 39 +------------------------- src/platform/wxwidgets/romselect.cpp | 40 ++------------------------- 6 files changed, 62 insertions(+), 150 deletions(-) diff --git a/include/core/settings.hpp b/include/core/settings.hpp index 10849258..96dec847 100644 --- a/include/core/settings.hpp +++ b/include/core/settings.hpp @@ -204,4 +204,22 @@ private: bool value; }; +/** + * Setting having path value. + */ +class path_setting : public setting +{ +public: + path_setting(const std::string& sname) throw(std::bad_alloc); + void blank() throw(std::bad_alloc, std::runtime_error); + bool is_set() throw(); + void set(const std::string& value) throw(std::bad_alloc, std::runtime_error); + std::string get() throw(std::bad_alloc); + operator std::string(); +private: + bool _default; + std::string path; +}; + + #endif diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index be107503..11adc560 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -83,43 +83,7 @@ namespace } } -class firmware_path_setting : public setting -{ -public: - firmware_path_setting() : setting("firmwarepath") { _firmwarepath = "."; default_firmware = true; } - void blank() throw(std::bad_alloc, std::runtime_error) - { - _firmwarepath = "."; - default_firmware = true; - } - - bool is_set() throw() - { - return !default_firmware; - } - - void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) - { - if(value != "") { - _firmwarepath = value; - default_firmware = false; - } else - blank(); - } - - std::string get() throw(std::bad_alloc) - { - return _firmwarepath; - } - - operator std::string() throw(std::bad_alloc) - { - return _firmwarepath; - } -private: - std::string _firmwarepath; - bool default_firmware; -} firmwarepath_setting; +path_setting firmwarepath_setting("firmwarepath"); controller_frame movie_logic::update_controls(bool subframe) throw(std::bad_alloc, std::runtime_error) { diff --git a/src/core/moviedata.cpp b/src/core/moviedata.cpp index d270c73c..2c353133 100644 --- a/src/core/moviedata.cpp +++ b/src/core/moviedata.cpp @@ -48,43 +48,7 @@ namespace { numeric_setting savecompression("savecompression", 0, 9, 7); - class slot_path_setting : public setting - { - public: - slot_path_setting() : setting("slotpath") { _slotpath = "."; default_slot = true; } - void blank() throw(std::bad_alloc, std::runtime_error) - { - _slotpath = "."; - default_slot = true; - } - - bool is_set() throw() - { - return !default_slot; - } - - void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) - { - if(value != "") { - _slotpath = value; - default_slot = false; - } else - blank(); - } - - std::string get() throw(std::bad_alloc) - { - return _slotpath; - } - - operator std::string() throw(std::bad_alloc) - { - return _slotpath; - } - private: - std::string _slotpath; - bool default_slot; - } slotpath_setting; + path_setting slotpath_setting("slotpath"); class projectprefix_setting : public setting { diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 6cc95feb..d800ce4b 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -196,3 +196,42 @@ boolean_setting::operator bool() throw() { return value; } + +path_setting::path_setting(const std::string& sname) throw(std::bad_alloc) + : setting(sname) +{ + path = "."; + _default = true; +} + +void path_setting::blank() throw(std::bad_alloc, std::runtime_error) +{ + path = "."; + _default = true; +} + +bool path_setting::is_set() throw() +{ + return !_default; +} + +void path_setting::set(const std::string& value) throw(std::bad_alloc, std::runtime_error) +{ + if(value == "") { + path = "."; + _default = true; + } else { + path = value; + _default = false; + } +} + +std::string path_setting::get() throw(std::bad_alloc) +{ + return path; +} + +path_setting::operator std::string() +{ + return path; +} \ No newline at end of file diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index 53e8b6b5..de04f8b2 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -442,44 +442,7 @@ namespace runuifun([ahmenu]() { ahmenu->reconfigure(); }); } - - class movie_path_setting : public setting - { - public: - movie_path_setting() : setting("moviepath") { _moviepath = "."; default_movie = true; } - void blank() throw(std::bad_alloc, std::runtime_error) - { - _moviepath = "."; - default_movie = true; - } - - bool is_set() throw() - { - return !default_movie; - } - - void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) - { - if(value != "") { - _moviepath = value; - default_movie = false; - } else - blank(); - } - - std::string get() throw(std::bad_alloc) - { - return _moviepath; - } - - operator std::string() throw(std::bad_alloc) - { - return _moviepath; - } - private: - std::string _moviepath; - bool default_movie; - } moviepath_setting; + path_setting moviepath_setting("moviepath"); std::string movie_path() { diff --git a/src/platform/wxwidgets/romselect.cpp b/src/platform/wxwidgets/romselect.cpp index ae4635f4..af11526b 100644 --- a/src/platform/wxwidgets/romselect.cpp +++ b/src/platform/wxwidgets/romselect.cpp @@ -278,48 +278,12 @@ namespace wxTextCtrl* ctrl; }; - class rom_path_setting : public setting - { - public: - rom_path_setting() : setting("rompath") { _rompath = "."; default_rom = true; } - void blank() throw(std::bad_alloc, std::runtime_error) - { - _rompath = "."; - default_rom = true; - } - - bool is_set() throw() - { - return !default_rom; - } - - void set(const std::string& value) throw(std::bad_alloc, std::runtime_error) - { - if(value != "") { - _rompath = value; - default_rom = false; - } else - blank(); - } - - std::string get() throw(std::bad_alloc) - { - return _rompath; - } - - operator std::string() throw(std::bad_alloc) - { - return _rompath; - } - private: - std::string _rompath; - bool default_rom; - } rompath_setting; + path_setting rompath_setting("rompath"); std::string rom_path() { //This is pre-boot, so read directly. - return setting::get("rompath"); + return rompath_setting; } } From e6bb87a4e0fb511ca42a06484d312a4c7606027c Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 8 Apr 2012 15:44:23 +0300 Subject: [PATCH 10/11] Fix title and prompt in slot count changing --- src/platform/wxwidgets/settings.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index 88a8115e..8fdce721 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -690,7 +690,10 @@ void wxeditor_esettings_paths::on_configure(wxCommandEvent& e) std::string val; runemufn([&val, name]() { val = setting::get(name); }); try { - val = pick_text(this, "Change path to", "Enter new path:", val); + if(e.GetId() == wxID_HIGHEST + 4) + val = pick_text(this, "Change number of slots", "Enter number of slots:", val); + else + val = pick_text(this, "Change path to", "Enter new path:", val); } catch(...) { refresh(); return; From 4f6f88f8cb5176397dc873f3793eabdf165aae62 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 8 Apr 2012 16:02:39 +0300 Subject: [PATCH 11/11] Try to fix the "key does not change" problem with Win32 --- src/platform/wxwidgets/settings.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index 8fdce721..d81fa744 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -614,6 +614,7 @@ void wxeditor_esettings_joystick::refresh() } } jgrid->Layout(); + this->Refresh(); Fit(); } @@ -949,6 +950,7 @@ void wxeditor_esettings_aliases::refresh() select->SetSelection(select->GetCount() ? (select->GetCount() - 1) : wxNOT_FOUND); else select->SetSelection(n); + select->Refresh(); } std::string wxeditor_esettings_aliases::selected() @@ -1135,6 +1137,7 @@ void wxeditor_esettings_hotkeys::refresh() select->SetItemText(items[i.first], towxstring(text)); } } + select->Refresh(); } std::string wxeditor_esettings_hotkeys::selected() @@ -1296,6 +1299,7 @@ void wxeditor_esettings_bindings::refresh() select->SetSelection(select->GetCount() ? (select->GetCount() - 1) : wxNOT_FOUND); else select->SetSelection(n); + select->Refresh(); } std::string wxeditor_esettings_bindings::selected()