diff --git a/src/gtk/joypadconfig.cpp b/src/gtk/joypadconfig.cpp index 738ca9c9..3e048f26 100644 --- a/src/gtk/joypadconfig.cpp +++ b/src/gtk/joypadconfig.cpp @@ -25,45 +25,34 @@ namespace VBA { -const EKey JoypadConfigDialog::m_aeKeys[] = - { - KEY_UP, - KEY_DOWN, - KEY_LEFT, - KEY_RIGHT, - KEY_BUTTON_A, - KEY_BUTTON_B, - KEY_BUTTON_L, - KEY_BUTTON_R, - KEY_BUTTON_SELECT, - KEY_BUTTON_START, - KEY_BUTTON_SPEED, - KEY_BUTTON_CAPTURE - }; +const JoypadConfigDialog::SJoypadKey JoypadConfigDialog::m_astKeys[] = +{ + { KEY_UP, "Up :" }, + { KEY_DOWN, "Down :" }, + { KEY_LEFT, "Left :" }, + { KEY_RIGHT, "Right :" }, + { KEY_BUTTON_A, "Button A :" }, + { KEY_BUTTON_B, "Button B :" }, + { KEY_BUTTON_L, "Button L :" }, + { KEY_BUTTON_R, "Button R :" }, + { KEY_BUTTON_SELECT, "Select :" }, + { KEY_BUTTON_START, "Start :" }, + { KEY_BUTTON_SPEED, "Speed :" }, + { KEY_BUTTON_CAPTURE, "Capture :" } +}; -JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog, - const Glib::RefPtr & _poXml) : - Gtk::Dialog(_pstDialog), +JoypadConfigDialog::JoypadConfigDialog() : + Gtk::Dialog("Joypad config", true, true), + m_oTable(G_N_ELEMENTS(m_astKeys), 2, false), m_ePad(PAD_MAIN) { - m_poOkButton = dynamic_cast(_poXml->get_widget("JoypadOkButton")); - - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadUpEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadDownEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadLeftEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadRightEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadAEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadBEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadLEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadREntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadSelectEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadStartEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadSpeedEntry"))); - m_oEntries.push_back(dynamic_cast(_poXml->get_widget("JoypadCaptureEntry"))); - - for (guint i = 0; i < m_oEntries.size(); i++) + for (guint i = 0; i < G_N_ELEMENTS(m_astKeys); i++) { - Gtk::Entry * poEntry = m_oEntries[i]; + Gtk::Label * poLabel = Gtk::manage( new Gtk::Label(m_astKeys[i].m_csKeyName, Gtk::ALIGN_RIGHT) ); + Gtk::Entry * poEntry = Gtk::manage( new Gtk::Entry() ); + m_oTable.attach(* poLabel, 0, 1, i, i + 1); + m_oTable.attach(* poEntry, 1, 2, i, i + 1); + m_oEntries.push_back(poEntry); poEntry->signal_focus_in_event().connect(sigc::bind( sigc::mem_fun(*this, &JoypadConfigDialog::bOnEntryFocusIn), @@ -71,9 +60,18 @@ JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog, poEntry->signal_focus_out_event().connect(sigc::mem_fun(*this, &JoypadConfigDialog::bOnEntryFocusOut)); } - memset(&m_oPreviousEvent, 0, sizeof(m_oPreviousEvent)); + Gtk::VBox* poVBox = get_vbox(); + poVBox->pack_start(m_oTable); + + m_oTable.set_border_width(5); + m_oTable.set_spacings(5); + + m_poOkButton = add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE); + + show_all(); vEmptyEventQueue(); + memset(&m_oPreviousEvent, 0, sizeof(m_oPreviousEvent)); m_oConfigSig = Glib::signal_idle().connect(sigc::mem_fun(*this, &JoypadConfigDialog::bOnConfigIdle), Glib::PRIORITY_DEFAULT_IDLE); @@ -96,7 +94,7 @@ void JoypadConfigDialog::vUpdateEntries() { const char * csName = 0; - guint uiKeyval = inputGetKeymap(m_ePad, m_aeKeys[i]); + guint uiKeyval = inputGetKeymap(m_ePad, m_astKeys[i].m_eKeyFlag); int dev = uiKeyval >> 16; if (dev == 0) { @@ -182,7 +180,7 @@ void JoypadConfigDialog::vOnInputEvent(const SDL_Event &event) } int code = inputGetEventCode(event); - inputSetKeymap(m_ePad, m_aeKeys[m_iCurrentEntry], code); + inputSetKeymap(m_ePad, m_astKeys[m_iCurrentEntry].m_eKeyFlag, code); vUpdateEntries(); if (m_iCurrentEntry + 1 < (gint)m_oEntries.size()) diff --git a/src/gtk/joypadconfig.h b/src/gtk/joypadconfig.h index 5ca75d0a..d9911bab 100644 --- a/src/gtk/joypadconfig.h +++ b/src/gtk/joypadconfig.h @@ -33,8 +33,7 @@ namespace VBA class JoypadConfigDialog : public Gtk::Dialog { public: - JoypadConfigDialog(GtkDialog * _pstDialog, - const Glib::RefPtr & _poXml); + JoypadConfigDialog(); virtual ~JoypadConfigDialog(); void vInitDialog(EPad _ePad); @@ -46,10 +45,17 @@ protected: bool on_key_press_event(GdkEventKey * _pstEvent); private: + struct SJoypadKey + { + const EKey m_eKeyFlag; + const char * m_csKeyName; + }; + + Gtk::Table m_oTable; Gtk::Button * m_poOkButton; std::vector m_oEntries; gint m_iCurrentEntry; - static const EKey m_aeKeys[]; + static const SJoypadKey m_astKeys[]; sigc::connection m_oConfigSig; SDL_Event m_oPreviousEvent; EPad m_ePad; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 11e1d6e9..5d963e65 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -61,7 +61,7 @@ using Gnome::Glade::Xml; Window * Window::m_poInstance = NULL; -const Window::SJoypadKey Window::m_astJoypad[SDLBUTTONS_NUM] = +const Window::SJoypadKey Window::m_astJoypad[] = { { "left", KEY_LEFT }, { "right", KEY_RIGHT }, @@ -1015,7 +1015,7 @@ void Window::vInitConfig() snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i); std::string sPrefix(csPrefix); - for (int j = 0; j < SDLBUTTONS_NUM; j++) + for (guint j = 0; j < G_N_ELEMENTS(m_astJoypad); j++) { m_poInputConfig->vSetKey(sPrefix + m_astJoypad[j].m_csKey, inputGetKeymap(PAD_DEFAULT, m_astJoypad[j].m_eKeyFlag)); @@ -1220,7 +1220,7 @@ void Window::vLoadJoypadsFromConfig() snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i); std::string sPrefix(csPrefix); - for (int j = 0; j < SDLBUTTONS_NUM; j++) + for (guint j = 0; j < G_N_ELEMENTS(m_astJoypad); j++) { inputSetKeymap((EPad)i, m_astJoypad[j].m_eKeyFlag, m_poInputConfig->oGetKey(sPrefix + m_astJoypad[j].m_csKey)); @@ -1236,7 +1236,7 @@ void Window::vSaveJoypadsToConfig() snprintf(csPrefix, sizeof(csPrefix), "joypadSDL%d_", i); std::string sPrefix(csPrefix); - for (int j = 0; j < SDLBUTTONS_NUM; j++) + for (guint j = 0; j < G_N_ELEMENTS(m_astJoypad); j++) { m_poInputConfig->vSetKey(sPrefix + m_astJoypad[j].m_csKey, inputGetKeymap((EPad)i, m_astJoypad[j].m_eKeyFlag)); diff --git a/src/gtk/window.h b/src/gtk/window.h index be3c40f5..d97b8320 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -243,7 +243,7 @@ private: const EKey m_eKeyFlag; }; - static const SJoypadKey m_astJoypad[SDLBUTTONS_NUM]; + static const SJoypadKey m_astJoypad[]; Gtk::MenuItem * m_apoLoadGameItem[10]; Gtk::MenuItem * m_apoSaveGameItem[10]; diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index bf85ea0e..6a3ed853 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -863,17 +863,11 @@ void Window::vOnFilterIBToggled(Gtk::CheckMenuItem * _poCMI, int _iFilterIB) void Window::vOnJoypadConfigure(EPad _eJoypad) { - Glib::RefPtr poXml; - poXml = Xml::create(PKGDATADIR "/vba.glade", "JoypadConfigDialog"); + JoypadConfigDialog oDialog; + oDialog.set_transient_for(*this); + oDialog.vInitDialog(_eJoypad); - JoypadConfigDialog * poDialog = NULL; - poXml->get_widget_derived("JoypadConfigDialog", poDialog); - poDialog->set_transient_for(*this); - poDialog->vInitDialog(_eJoypad); - - poDialog->run(); - - delete poDialog; + oDialog.run(); } void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, EPad _eJoypad) diff --git a/src/sdl/inputSDL.cpp b/src/sdl/inputSDL.cpp index c7f7e397..a5523aa7 100644 --- a/src/sdl/inputSDL.cpp +++ b/src/sdl/inputSDL.cpp @@ -17,6 +17,8 @@ #include "inputSDL.h" +#define SDLBUTTONS_NUM 14 + static void sdlUpdateKey(uint32_t key, bool down); static void sdlUpdateJoyButton(int which, int button, bool pressed); static void sdlUpdateJoyHat(int which, int hat, int value); diff --git a/src/sdl/inputSDL.h b/src/sdl/inputSDL.h index ef341a7e..9bc5d62f 100644 --- a/src/sdl/inputSDL.h +++ b/src/sdl/inputSDL.h @@ -20,8 +20,6 @@ #include -#define SDLBUTTONS_NUM 14 - enum EKey { KEY_LEFT, KEY_RIGHT,