GTK : The joypad config dialog now works again for keyboards events.

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@689 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2008-09-03 18:57:21 +00:00
parent 3e4b6b354e
commit bbc6ca50a8
3 changed files with 47 additions and 17 deletions

View File

@ -21,27 +21,42 @@
#include <string.h>
#include "intl.h"
#include "../sdl/inputSDL.h"
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
};
JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog,
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml) :
Gtk::Dialog(_pstDialog)
{
m_poOkButton = dynamic_cast<Gtk::Button *>(_poXml->get_widget("JoypadOkButton"));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadLeftEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadRightEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadUpEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadDownEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadLeftEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadRightEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadAEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadBEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSelectEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadStartEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadLEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadREntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSelectEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadStartEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSpeedEntry")));
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadCaptureEntry")));
@ -68,7 +83,7 @@ void JoypadConfigDialog::vUpdateEntries()
{
const char * csName = 0;
guint uiKeyval = inputGetKeymap(PAD_MAIN, (EKey)i);
guint uiKeyval = inputGetKeymap(PAD_MAIN, m_aeKeys[i]);
int dev = uiKeyval >> 16;
if (dev == 0)
{
@ -130,6 +145,11 @@ bool JoypadConfigDialog::bOnEntryFocusOut(GdkEventFocus * _pstEvent)
bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent)
{
// Forward the keyboard event to the input module by faking a SDL event
SDL_Event event;
event.type = SDL_KEYDOWN;
event.key.keysym.sym = (SDLKey)_pstEvent->keyval;
vOnInputEvent(event);
/* if (m_puiCurrentKeyCode == NULL)
{
return Gtk::Dialog::on_key_press_event(_pstEvent);
@ -177,4 +197,20 @@ bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent)
return true;
}
void JoypadConfigDialog::vOnInputEvent(const SDL_Event &event)
{
int code = inputGetEventCode(event);
inputSetKeymap(PAD_MAIN, m_aeKeys[m_uiCurrentEntry], code);
vUpdateEntries();
if (m_uiCurrentEntry + 1 < m_oEntries.size())
{
m_oEntries[m_uiCurrentEntry + 1]->grab_focus();
}
else
{
m_poOkButton->grab_focus();
}
}
} // namespace VBA

View File

@ -25,6 +25,8 @@
#include <libglademm.h>
#include <gtkmm.h>
#include "../sdl/inputSDL.h"
namespace VBA
{
@ -39,12 +41,14 @@ protected:
bool bOnEntryFocusIn(GdkEventFocus * _pstEvent, guint _uiEntry);
bool bOnEntryFocusOut(GdkEventFocus * _pstEvent);
void vOnInputEvent(const SDL_Event &event);
bool on_key_press_event(GdkEventKey * _pstEvent);
private:
Gtk::Button * m_poOkButton;
std::vector<Gtk::Entry *> m_oEntries;
guint m_uiCurrentEntry;
static const EKey m_aeKeys[];
void vUpdateEntries();
};

View File

@ -2086,22 +2086,12 @@
<widget class="GtkHButtonBox" id="dialog-action_area4">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="cancelbutton3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="JoypadOkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="label">gtk-ok</property>
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="response_id">-5</property>
</widget>