From e8b08761c9f97ee6012990c1b5c54140d2410b8f Mon Sep 17 00:00:00 2001 From: bgk Date: Sat, 13 Sep 2008 15:51:06 +0000 Subject: [PATCH] GTK : Moved default joypad selection to the joypad config dialog. --- src/gtk/joypadconfig.cpp | 22 +++++++++++++++++-- src/gtk/joypadconfig.h | 3 +++ src/gtk/vba.glade | 42 ------------------------------------- src/gtk/window.cpp | 18 ++-------------- src/gtk/window.h | 1 - src/gtk/windowcallbacks.cpp | 12 +---------- src/sdl/inputSDL.cpp | 5 +++++ src/sdl/inputSDL.h | 8 ++++++- 8 files changed, 38 insertions(+), 73 deletions(-) diff --git a/src/gtk/joypadconfig.cpp b/src/gtk/joypadconfig.cpp index fd84f351..a306ac81 100644 --- a/src/gtk/joypadconfig.cpp +++ b/src/gtk/joypadconfig.cpp @@ -45,6 +45,7 @@ JoypadConfigDialog::JoypadConfigDialog() : Gtk::Dialog("Joypad config", true, true), m_oTitleHBox(false, 5), m_oTitleLabel("Joypad :", Gtk::ALIGN_RIGHT), + m_oDefaultJoypad("Default joypad"), m_oTable(G_N_ELEMENTS(m_astKeys), 2, false), m_ePad(PAD_MAIN) { @@ -78,14 +79,17 @@ JoypadConfigDialog::JoypadConfigDialog() : m_oTitleHBox.set_border_width(5); m_oTable.set_border_width(5); m_oTable.set_spacings(5); + get_vbox()->set_spacing(5); get_vbox()->pack_start(m_oTitleHBox); get_vbox()->pack_start(m_oSeparator); + get_vbox()->pack_start(m_oDefaultJoypad); get_vbox()->pack_start(m_oTable); // Signals and default values m_oConfigSig = Glib::signal_idle().connect(sigc::mem_fun(*this, &JoypadConfigDialog::bOnConfigIdle), Glib::PRIORITY_DEFAULT_IDLE); - + m_oDefaultJoypad.signal_toggled().connect(sigc::mem_fun(*this, + &JoypadConfigDialog::vOnDefaultJoypadSelect) ); m_oTitleCombo.signal_changed().connect(sigc::mem_fun(*this, &JoypadConfigDialog::vOnJoypadSelect) ); m_oTitleCombo.set_active_text("1"); @@ -100,9 +104,11 @@ JoypadConfigDialog::~JoypadConfigDialog() void JoypadConfigDialog::vUpdateEntries() { + m_oDefaultJoypad.set_active(inputGetDefaultJoypad() == m_ePad); + for (guint i = 0; i < m_oEntries.size(); i++) { - const char * csName = 0; + const char * csName = 0; guint uiKeyval = inputGetKeymap(m_ePad, m_astKeys[i].m_eKeyFlag); int dev = uiKeyval >> 16; @@ -267,4 +273,16 @@ void JoypadConfigDialog::vOnJoypadSelect() vUpdateEntries(); } +void JoypadConfigDialog::vOnDefaultJoypadSelect() +{ + if (m_oDefaultJoypad.get_active()) + { + inputSetDefaultJoypad(m_ePad); + } + else + { + inputSetDefaultJoypad(PAD_MAIN); + } +} + } // namespace VBA diff --git a/src/gtk/joypadconfig.h b/src/gtk/joypadconfig.h index bbea347e..0e34bc6d 100644 --- a/src/gtk/joypadconfig.h +++ b/src/gtk/joypadconfig.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "../sdl/inputSDL.h" @@ -58,6 +59,7 @@ private: Gtk::Label m_oTitleLabel; Gtk::ComboBoxText m_oTitleCombo; Gtk::HSeparator m_oSeparator; + Gtk::CheckButton m_oDefaultJoypad; Gtk::Table m_oTable; Gtk::Button * m_poOkButton; std::vector m_oEntries; @@ -69,6 +71,7 @@ private: bool bOnConfigIdle(); void vOnJoypadSelect(); + void vOnDefaultJoypadSelect(); void vUpdateEntries(); void vEmptyEventQueue(); }; diff --git a/src/gtk/vba.glade b/src/gtk/vba.glade index 72358192..39f56f0e 100644 --- a/src/gtk/vba.glade +++ b/src/gtk/vba.glade @@ -1044,48 +1044,6 @@ True - - - True - - - - - True - _1 - True - True - - - - - True - _2 - True - Joypad1 - - - - - True - _3 - True - Joypad1 - - - - - True - _4 - True - Joypad1 - - - - - True - - True diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index c71a9113..01c8f919 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -614,22 +614,8 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : poMI = dynamic_cast(_poXml->get_widget("JoypadConfigure")); poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnJoypadConfigure)); - int iDefaultJoypad = m_poInputConfig->oGetKey("active_joypad"); - for (int i = m_iJoypadMin; i <= m_iJoypadMax; i++) - { - char csName[20]; - snprintf(csName, sizeof(csName), "Joypad%d", i + 1); - - poCMI = dynamic_cast(_poXml->get_widget(csName)); - if (i == iDefaultJoypad) - { - poCMI->set_active(); - vOnJoypadToggled(poCMI, (EPad)iDefaultJoypad); - } - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnJoypadToggled), - poCMI, (EPad)i)); - } + EPad eDefaultJoypad = (EPad)m_poInputConfig->oGetKey("active_joypad"); + inputSetDefaultJoypad(eDefaultJoypad); // Autofire menu // diff --git a/src/gtk/window.h b/src/gtk/window.h index 2b1977a4..ada35768 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -160,7 +160,6 @@ protected: virtual void vOnFilter2xToggled(Gtk::CheckMenuItem * _poCMI, int _iFilter2x); virtual void vOnFilterIBToggled(Gtk::CheckMenuItem * _poCMI, int _iFilterIB); virtual void vOnJoypadConfigure(); - virtual void vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, EPad _eJoypad); virtual void vOnAutofireToggled(Gtk::CheckMenuItem * _poCMI, EKey _eKey); virtual void vOnHelpAbout(); virtual bool bOnEmuIdle(); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 1442cd21..c5cea31c 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -641,18 +641,8 @@ void Window::vOnJoypadConfigure() JoypadConfigDialog oDialog; oDialog.set_transient_for(*this); oDialog.run(); -} -void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, EPad _eJoypad) -{ - if (! _poCMI->get_active()) - { - return; - } - - inputSetDefaultJoypad(_eJoypad); - - m_poInputConfig->vSetKey("active_joypad", _eJoypad); + m_poInputConfig->vSetKey("active_joypad", inputGetDefaultJoypad()); } void Window::vOnAutofireToggled(Gtk::CheckMenuItem * _poCMI, EKey _eKey) diff --git a/src/sdl/inputSDL.cpp b/src/sdl/inputSDL.cpp index a5523aa7..1d8c78a0 100644 --- a/src/sdl/inputSDL.cpp +++ b/src/sdl/inputSDL.cpp @@ -600,3 +600,8 @@ void inputSetDefaultJoypad(EPad pad) { sdlDefaultJoypad = pad; } + +EPad inputGetDefaultJoypad() +{ + return sdlDefaultJoypad; +} diff --git a/src/sdl/inputSDL.h b/src/sdl/inputSDL.h index 9bc5d62f..c70b42e7 100644 --- a/src/sdl/inputSDL.h +++ b/src/sdl/inputSDL.h @@ -128,8 +128,14 @@ int inputGetSensorY(); /** * Set which joypad configuration use when the core doesn't ask for a specific - * pad + * @param pad Default pad */ void inputSetDefaultJoypad(EPad pad); +/** + * Get the default joypad + * pad + */ +EPad inputGetDefaultJoypad(); + #endif // VBAM_SDL_INPUT_H