GTK :
- The Joypad config dialog can now display the key associations, but it's read only for now. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@688 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
parent
db486bdb67
commit
3e4b6b354e
|
@ -1,70 +0,0 @@
|
||||||
// -*- C++ -*-
|
|
||||||
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
|
|
||||||
// Copyright (C) 1999-2003 Forgotten
|
|
||||||
// Copyright (C) 2004 Forgotten and the VBA development team
|
|
||||||
|
|
||||||
// This program is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 2, or(at your option)
|
|
||||||
// any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software Foundation,
|
|
||||||
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
|
|
||||||
#ifndef __VBA_INPUT_H__
|
|
||||||
#define __VBA_INPUT_H__
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace VBA
|
|
||||||
{
|
|
||||||
|
|
||||||
enum EKey
|
|
||||||
{
|
|
||||||
KeyNone,
|
|
||||||
// GBA keys
|
|
||||||
KeyA,
|
|
||||||
KeyB,
|
|
||||||
KeySelect,
|
|
||||||
KeyStart,
|
|
||||||
KeyRight,
|
|
||||||
KeyLeft,
|
|
||||||
KeyUp,
|
|
||||||
KeyDown,
|
|
||||||
KeyR,
|
|
||||||
KeyL,
|
|
||||||
// VBA extension
|
|
||||||
KeySpeed,
|
|
||||||
KeyCapture
|
|
||||||
};
|
|
||||||
|
|
||||||
enum EKeyFlag
|
|
||||||
{
|
|
||||||
// GBA keys
|
|
||||||
KeyFlagA = 1 << 0,
|
|
||||||
KeyFlagB = 1 << 1,
|
|
||||||
KeyFlagSelect = 1 << 2,
|
|
||||||
KeyFlagStart = 1 << 3,
|
|
||||||
KeyFlagRight = 1 << 4,
|
|
||||||
KeyFlagLeft = 1 << 5,
|
|
||||||
KeyFlagUp = 1 << 6,
|
|
||||||
KeyFlagDown = 1 << 7,
|
|
||||||
KeyFlagR = 1 << 8,
|
|
||||||
KeyFlagL = 1 << 9,
|
|
||||||
// VBA extension
|
|
||||||
KeyFlagSpeed = 1 << 10,
|
|
||||||
KeyFlagCapture = 1 << 11,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::map<int, EKey> Keymap;
|
|
||||||
|
|
||||||
} // namespace VBA
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __VBA_INPUT_H__
|
|
|
@ -21,142 +21,27 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "intl.h"
|
#include "intl.h"
|
||||||
|
#include "../sdl/inputSDL.h"
|
||||||
|
|
||||||
namespace VBA
|
namespace VBA
|
||||||
{
|
{
|
||||||
|
|
||||||
guint * JoypadConfig::puiAt(int _iIndex)
|
|
||||||
{
|
|
||||||
guint * puiMember;
|
|
||||||
|
|
||||||
switch (_iIndex)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
puiMember = &m_uiUp;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
puiMember = &m_uiDown;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
puiMember = &m_uiLeft;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
puiMember = &m_uiRight;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
puiMember = &m_uiA;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
puiMember = &m_uiB;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
puiMember = &m_uiL;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
puiMember = &m_uiR;
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
puiMember = &m_uiSelect;
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
puiMember = &m_uiStart;
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
puiMember = &m_uiSpeed;
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
puiMember = &m_uiCapture;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
puiMember = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return puiMember;
|
|
||||||
}
|
|
||||||
|
|
||||||
int JoypadConfig::iFind(guint _uiKeycode)
|
|
||||||
{
|
|
||||||
for (guint i = 0; i < 12; i++)
|
|
||||||
{
|
|
||||||
if (*puiAt(i) == _uiKeycode)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JoypadConfig::vSetDefault()
|
|
||||||
{
|
|
||||||
guint auiKeyval[] =
|
|
||||||
{
|
|
||||||
GDK_Up, GDK_Down, GDK_Left, GDK_Right,
|
|
||||||
GDK_z, GDK_x, GDK_a, GDK_s,
|
|
||||||
GDK_BackSpace, GDK_Return,
|
|
||||||
GDK_space, GDK_F12
|
|
||||||
};
|
|
||||||
|
|
||||||
for (guint i = 0; i < G_N_ELEMENTS(auiKeyval); i++)
|
|
||||||
{
|
|
||||||
GdkKeymapKey * pstKeys;
|
|
||||||
int iKeys;
|
|
||||||
|
|
||||||
if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
|
|
||||||
auiKeyval[i],
|
|
||||||
&pstKeys,
|
|
||||||
&iKeys))
|
|
||||||
{
|
|
||||||
*puiAt(i) = pstKeys[0].keycode;
|
|
||||||
g_free(pstKeys);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*puiAt(i) = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Keymap JoypadConfig::oCreateKeymap() const
|
|
||||||
{
|
|
||||||
Keymap oKeymap;
|
|
||||||
|
|
||||||
oKeymap[m_uiUp] = KeyUp;
|
|
||||||
oKeymap[m_uiDown] = KeyDown;
|
|
||||||
oKeymap[m_uiLeft] = KeyLeft;
|
|
||||||
oKeymap[m_uiRight] = KeyRight;
|
|
||||||
oKeymap[m_uiA] = KeyA;
|
|
||||||
oKeymap[m_uiB] = KeyB;
|
|
||||||
oKeymap[m_uiL] = KeyL;
|
|
||||||
oKeymap[m_uiR] = KeyR;
|
|
||||||
oKeymap[m_uiSelect] = KeySelect;
|
|
||||||
oKeymap[m_uiStart] = KeyStart;
|
|
||||||
oKeymap[m_uiSpeed] = KeySpeed;
|
|
||||||
oKeymap[m_uiCapture] = KeyCapture;
|
|
||||||
|
|
||||||
return oKeymap;
|
|
||||||
}
|
|
||||||
|
|
||||||
JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog,
|
JoypadConfigDialog::JoypadConfigDialog(GtkDialog * _pstDialog,
|
||||||
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml) :
|
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml) :
|
||||||
Gtk::Dialog(_pstDialog)
|
Gtk::Dialog(_pstDialog)
|
||||||
{
|
{
|
||||||
m_puiCurrentKeyCode = NULL;
|
|
||||||
|
|
||||||
memset(&m_oConfig, 0, sizeof(m_oConfig));
|
|
||||||
|
|
||||||
m_poOkButton = dynamic_cast<Gtk::Button *>(_poXml->get_widget("JoypadOkButton"));
|
m_poOkButton = dynamic_cast<Gtk::Button *>(_poXml->get_widget("JoypadOkButton"));
|
||||||
|
|
||||||
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("JoypadLeftEntry")));
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadRightEntry")));
|
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("JoypadAEntry")));
|
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("JoypadBEntry")));
|
||||||
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("JoypadSelectEntry")));
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadStartEntry")));
|
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("JoypadSpeedEntry")));
|
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadSpeedEntry")));
|
||||||
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadCaptureEntry")));
|
m_oEntries.push_back(dynamic_cast<Gtk::Entry *>(_poXml->get_widget("JoypadCaptureEntry")));
|
||||||
|
|
||||||
|
@ -177,27 +62,48 @@ JoypadConfigDialog::~JoypadConfigDialog()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoypadConfigDialog::vSetConfig(const JoypadConfig & _roConfig)
|
|
||||||
{
|
|
||||||
m_oConfig = _roConfig;
|
|
||||||
vUpdateEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JoypadConfigDialog::vUpdateEntries()
|
void JoypadConfigDialog::vUpdateEntries()
|
||||||
{
|
{
|
||||||
for (guint i = 0; i < m_oEntries.size(); i++)
|
for (guint i = 0; i < m_oEntries.size(); i++)
|
||||||
{
|
{
|
||||||
guint uiKeyval = 0;
|
const char * csName = 0;
|
||||||
gdk_keymap_translate_keyboard_state(gdk_keymap_get_default(),
|
|
||||||
*m_oConfig.puiAt(i),
|
guint uiKeyval = inputGetKeymap(PAD_MAIN, (EKey)i);
|
||||||
(GdkModifierType)0,
|
int dev = uiKeyval >> 16;
|
||||||
0,
|
if (dev == 0)
|
||||||
&uiKeyval,
|
{
|
||||||
NULL,
|
csName = gdk_keyval_name(uiKeyval);
|
||||||
NULL,
|
}
|
||||||
NULL);
|
else
|
||||||
const char * csName = gdk_keyval_name(uiKeyval);
|
{
|
||||||
if (csName == NULL)
|
int what = uiKeyval & 0xffff;
|
||||||
|
std::stringstream os;
|
||||||
|
os << "Joy " << dev;
|
||||||
|
|
||||||
|
if(what >= 128)
|
||||||
|
{
|
||||||
|
// joystick button
|
||||||
|
int button = what - 128;
|
||||||
|
os << " Button " << button;
|
||||||
|
}
|
||||||
|
else if (what < 0x20)
|
||||||
|
{
|
||||||
|
// joystick axis
|
||||||
|
what >>= 1;
|
||||||
|
os << " Axis " << what;
|
||||||
|
}
|
||||||
|
else if (what < 0x30)
|
||||||
|
{
|
||||||
|
// joystick hat
|
||||||
|
what = (what & 15);
|
||||||
|
what >>= 2;
|
||||||
|
os << " Hat " << what;
|
||||||
|
}
|
||||||
|
|
||||||
|
csName = os.str().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (csName == 0)
|
||||||
{
|
{
|
||||||
m_oEntries[i]->set_text(_("<Undefined>"));
|
m_oEntries[i]->set_text(_("<Undefined>"));
|
||||||
}
|
}
|
||||||
|
@ -212,21 +118,19 @@ bool JoypadConfigDialog::bOnEntryFocusIn(GdkEventFocus * _pstEvent,
|
||||||
guint _uiEntry)
|
guint _uiEntry)
|
||||||
{
|
{
|
||||||
m_uiCurrentEntry = _uiEntry;
|
m_uiCurrentEntry = _uiEntry;
|
||||||
m_puiCurrentKeyCode = m_oConfig.puiAt(_uiEntry);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JoypadConfigDialog::bOnEntryFocusOut(GdkEventFocus * _pstEvent)
|
bool JoypadConfigDialog::bOnEntryFocusOut(GdkEventFocus * _pstEvent)
|
||||||
{
|
{
|
||||||
m_puiCurrentKeyCode = NULL;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent)
|
bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent)
|
||||||
{
|
{
|
||||||
if (m_puiCurrentKeyCode == NULL)
|
/* if (m_puiCurrentKeyCode == NULL)
|
||||||
{
|
{
|
||||||
return Gtk::Dialog::on_key_press_event(_pstEvent);
|
return Gtk::Dialog::on_key_press_event(_pstEvent);
|
||||||
}
|
}
|
||||||
|
@ -268,7 +172,7 @@ bool JoypadConfigDialog::on_key_press_event(GdkEventKey * _pstEvent)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_poOkButton->grab_focus();
|
m_poOkButton->grab_focus();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,33 +25,9 @@
|
||||||
#include <libglademm.h>
|
#include <libglademm.h>
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
|
|
||||||
#include "input.h"
|
|
||||||
|
|
||||||
namespace VBA
|
namespace VBA
|
||||||
{
|
{
|
||||||
|
|
||||||
class JoypadConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
guint m_uiUp;
|
|
||||||
guint m_uiDown;
|
|
||||||
guint m_uiLeft;
|
|
||||||
guint m_uiRight;
|
|
||||||
guint m_uiA;
|
|
||||||
guint m_uiB;
|
|
||||||
guint m_uiL;
|
|
||||||
guint m_uiR;
|
|
||||||
guint m_uiSelect;
|
|
||||||
guint m_uiStart;
|
|
||||||
guint m_uiSpeed;
|
|
||||||
guint m_uiCapture;
|
|
||||||
|
|
||||||
guint * puiAt(int _iIndex);
|
|
||||||
int iFind(guint _uiKeycode);
|
|
||||||
void vSetDefault();
|
|
||||||
Keymap oCreateKeymap() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class JoypadConfigDialog : public Gtk::Dialog
|
class JoypadConfigDialog : public Gtk::Dialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -59,9 +35,6 @@ public:
|
||||||
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml);
|
const Glib::RefPtr<Gnome::Glade::Xml> & _poXml);
|
||||||
virtual ~JoypadConfigDialog();
|
virtual ~JoypadConfigDialog();
|
||||||
|
|
||||||
void vSetConfig(const JoypadConfig & _roConfig);
|
|
||||||
inline JoypadConfig stGetConfig() const { return m_oConfig; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool bOnEntryFocusIn(GdkEventFocus * _pstEvent, guint _uiEntry);
|
bool bOnEntryFocusIn(GdkEventFocus * _pstEvent, guint _uiEntry);
|
||||||
bool bOnEntryFocusOut(GdkEventFocus * _pstEvent);
|
bool bOnEntryFocusOut(GdkEventFocus * _pstEvent);
|
||||||
|
@ -69,10 +42,8 @@ protected:
|
||||||
bool on_key_press_event(GdkEventKey * _pstEvent);
|
bool on_key_press_event(GdkEventKey * _pstEvent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JoypadConfig m_oConfig;
|
|
||||||
Gtk::Button * m_poOkButton;
|
Gtk::Button * m_poOkButton;
|
||||||
std::vector<Gtk::Entry *> m_oEntries;
|
std::vector<Gtk::Entry *> m_oEntries;
|
||||||
guint * m_puiCurrentKeyCode;
|
|
||||||
guint m_uiCurrentEntry;
|
guint m_uiCurrentEntry;
|
||||||
|
|
||||||
void vUpdateEntries();
|
void vUpdateEntries();
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
#include "configfile.h"
|
#include "configfile.h"
|
||||||
#include "screenarea.h"
|
#include "screenarea.h"
|
||||||
#include "filters.h"
|
#include "filters.h"
|
||||||
//#include "joypadconfig.h"
|
|
||||||
|
|
||||||
namespace VBA
|
namespace VBA
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "intl.h"
|
#include "intl.h"
|
||||||
|
#include "joypadconfig.h"
|
||||||
|
|
||||||
extern int systemRenderedFrames;
|
extern int systemRenderedFrames;
|
||||||
extern int systemFPS;
|
extern int systemFPS;
|
||||||
|
@ -861,24 +862,23 @@ void Window::vOnFilterIBToggled(Gtk::CheckMenuItem * _poCMI, int _iFilterIB)
|
||||||
|
|
||||||
void Window::vOnJoypadConfigure(int _iJoypad)
|
void Window::vOnJoypadConfigure(int _iJoypad)
|
||||||
{
|
{
|
||||||
/* Glib::RefPtr<Xml> poXml;
|
Glib::RefPtr<Xml> poXml;
|
||||||
poXml = Xml::create(PKGDATADIR "/vba.glade", "JoypadConfigDialog");
|
poXml = Xml::create(PKGDATADIR "/vba.glade", "JoypadConfigDialog");
|
||||||
|
|
||||||
JoypadConfigDialog * poDialog = NULL;
|
JoypadConfigDialog * poDialog = NULL;
|
||||||
poXml->get_widget_derived<JoypadConfigDialog>("JoypadConfigDialog", poDialog);
|
poXml->get_widget_derived<JoypadConfigDialog>("JoypadConfigDialog", poDialog);
|
||||||
poDialog->set_transient_for(*this);
|
poDialog->set_transient_for(*this);
|
||||||
poDialog->vSetConfig(m_oJoypads[_iJoypad - 1]);
|
|
||||||
|
|
||||||
if (poDialog->run() == Gtk::RESPONSE_OK)
|
if (poDialog->run() == Gtk::RESPONSE_OK)
|
||||||
{
|
{
|
||||||
m_oJoypads[_iJoypad - 1] = poDialog->stGetConfig();
|
/*m_oJoypads[_iJoypad - 1] = poDialog->stGetConfig();
|
||||||
if (_iJoypad == m_poInputConfig->oGetKey<int>("active_joypad"))
|
if (_iJoypad == m_poInputConfig->oGetKey<int>("active_joypad"))
|
||||||
{
|
{
|
||||||
m_oKeymap = m_oJoypads[_iJoypad - 1].oCreateKeymap();
|
m_oKeymap = m_oJoypads[_iJoypad - 1].oCreateKeymap();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
delete poDialog;*/
|
delete poDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, int _iJoypad)
|
void Window::vOnJoypadToggled(Gtk::CheckMenuItem * _poCMI, int _iJoypad)
|
||||||
|
|
Loading…
Reference in New Issue