diff --git a/src/Input/FGButton.cxx b/src/Input/FGButton.cxx
new file mode 100644
index 000000000..ee5953aca
--- /dev/null
+++ b/src/Input/FGButton.cxx
@@ -0,0 +1,75 @@
+// FGButton.cxx -- a simple button/key wrapper class
+//
+// Written by Torsten Dreyer, started August 2009
+// Based on work from David Megginson, started May 2001.
+//
+// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
+// Copyright (C) 2001 David Megginson, david@megginson.com
+//
+// 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 of the
+// License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#include "FGButton.hxx"
+
+FGButton::FGButton ()
+ : is_repeatable(false),
+ interval_sec(0),
+ last_dt(0),
+ last_state(0)
+{
+}
+
+FGButton::~FGButton ()
+{
+ // bindings is a list of SGSharedPtr
+ // no cleanup required
+}
+
+
+void FGButton::init( const SGPropertyNode * node, const string name, string & module )
+{
+ if (node == 0) {
+ SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for button " << name);
+ } else {
+ is_repeatable = node->getBoolValue("repeatable", is_repeatable);
+ // Get the bindings for the button
+ read_bindings( node, bindings, KEYMOD_NONE, module );
+ }
+}
+
+void FGButton::update( int modifiers, bool pressed, int x, int y)
+{
+ if (pressed) {
+ // The press event may be repeated.
+ if (!last_state || is_repeatable) {
+ SG_LOG( SG_INPUT, SG_DEBUG, "Button has been pressed" );
+ for (unsigned int k = 0; k < bindings[modifiers].size(); k++) {
+ bindings[modifiers][k]->fire(x, y);
+ }
+ }
+ } else {
+ // The release event is never repeated.
+ if (last_state) {
+ SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
+ for (unsigned int k = 0; k < bindings[modifiers|KEYMOD_RELEASED].size(); k++)
+ bindings[modifiers|KEYMOD_RELEASED][k]->fire(x, y);
+ }
+ }
+
+ last_state = pressed;
+}
+
+
diff --git a/src/Input/FGButton.hxx b/src/Input/FGButton.hxx
new file mode 100644
index 000000000..6ab5347a0
--- /dev/null
+++ b/src/Input/FGButton.hxx
@@ -0,0 +1,44 @@
+// FGButton.hxx -- a simple button/key wrapper class
+//
+// Written by Torsten Dreyer, started August 2009
+// Based on work from David Megginson, started May 2001.
+//
+// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
+// Copyright (C) 2001 David Megginson, david@megginson.com
+//
+// 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 of the
+// License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#ifndef FGBUTTON_H
+#define FGBUTTON_H
+
+#include "FGCommonInput.hxx"
+#include
+
+class FGButton : public FGCommonInput {
+public:
+ FGButton();
+ virtual ~FGButton();
+ void init( const SGPropertyNode * node, const string name, string & module );
+ void update( int modifiers, bool pressed, int x = -1, int y = -1);
+ bool is_repeatable;
+ float interval_sec;
+ float last_dt;
+ int last_state;
+ binding_list_t bindings[KEYMOD_MAX];
+};
+
+#endif
diff --git a/src/Input/FGCommonInput.cxx b/src/Input/FGCommonInput.cxx
new file mode 100644
index 000000000..513e9a640
--- /dev/null
+++ b/src/Input/FGCommonInput.cxx
@@ -0,0 +1,71 @@
+// FGCommonInput.cxx -- common functions for all Input subsystems
+//
+// Written by Torsten Dreyer, started August 2009
+// Based on work from David Megginson, started May 2001.
+//
+// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
+// Copyright (C) 2001 David Megginson, david@megginson.com
+//
+// 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 of the
+// License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#include "FGCommonInput.hxx"
+#include
+#include
+
+void FGCommonInput::read_bindings (const SGPropertyNode * node, binding_list_t * binding_list, int modifiers, string & module )
+{
+ SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
+ vector bindings = node->getChildren("binding");
+ string nasal = "nasal";
+ for (unsigned int i = 0; i < bindings.size(); i++) {
+ const char *cmd = bindings[i]->getStringValue("command");
+ SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding " << cmd);
+ if (nasal.compare(cmd) == 0 && !module.empty())
+ bindings[i]->setStringValue("module", module.c_str());
+ binding_list[modifiers].push_back(new SGBinding(bindings[i], globals->get_props()));
+ }
+
+ // Read nested bindings for modifiers
+ if (node->getChild("mod-up") != 0)
+ read_bindings(node->getChild("mod-up"), binding_list,
+ modifiers|KEYMOD_RELEASED, module);
+
+ if (node->getChild("mod-shift") != 0)
+ read_bindings(node->getChild("mod-shift"), binding_list,
+ modifiers|KEYMOD_SHIFT, module);
+
+ if (node->getChild("mod-ctrl") != 0)
+ read_bindings(node->getChild("mod-ctrl"), binding_list,
+ modifiers|KEYMOD_CTRL, module);
+
+ if (node->getChild("mod-alt") != 0)
+ read_bindings(node->getChild("mod-alt"), binding_list,
+ modifiers|KEYMOD_ALT, module);
+
+ if (node->getChild("mod-meta") != 0)
+ read_bindings(node->getChild("mod-meta"), binding_list,
+ modifiers|KEYMOD_META, module);
+
+ if (node->getChild("mod-super") != 0)
+ read_bindings(node->getChild("mod-super"), binding_list,
+ modifiers|KEYMOD_SUPER, module);
+
+ if (node->getChild("mod-hyper") != 0)
+ read_bindings(node->getChild("mod-hyper"), binding_list,
+ modifiers|KEYMOD_HYPER, module);
+}
+
diff --git a/src/Input/FGCommonInput.hxx b/src/Input/FGCommonInput.hxx
new file mode 100644
index 000000000..7eee91526
--- /dev/null
+++ b/src/Input/FGCommonInput.hxx
@@ -0,0 +1,51 @@
+// FGCommonInput.hxx -- common functions for all Input subsystems
+//
+// Written by Torsten Dreyer, started August 2009
+// Based on work from David Megginson, started May 2001.
+//
+// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
+// Copyright (C) 2001 David Megginson, david@megginson.com
+//
+// 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 of the
+// License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#ifndef FGCOMMONINPUT_H
+#define FGCOMMONINPUT_H
+
+#include
+#include
+
+#if defined( UL_WIN32 )
+#define TGT_PLATFORM "windows"
+#elif defined ( UL_MAC_OSX )
+#define TGT_PLATFORM "mac"
+#else
+#define TGT_PLATFORM "unix"
+#endif
+
+class FGCommonInput {
+public:
+ typedef vector > binding_list_t;
+
+ /*
+ read all "binding" nodes directly under the specified base node and fill the
+ vector of SGBinding supplied in binding_list. Reads all the mod-xxx bindings and
+ add the corresponding SGBindings.
+ */
+ static void read_bindings (const SGPropertyNode * base, binding_list_t * binding_list, int modifiers, string & module );
+};
+
+#endif
diff --git a/src/Input/FGDeviceConfigurationMap.cxx b/src/Input/FGDeviceConfigurationMap.cxx
new file mode 100644
index 000000000..e54860dfe
--- /dev/null
+++ b/src/Input/FGDeviceConfigurationMap.cxx
@@ -0,0 +1,77 @@
+// FGDeviceConfigurationMap.cxx -- a map to access xml device configuration
+//
+// Written by Torsten Dreyer, started August 2009
+// Based on work from David Megginson, started May 2001.
+//
+// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
+// Copyright (C) 2001 David Megginson, david@megginson.com
+//
+// 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 of the
+// License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#include "FGDeviceConfigurationMap.hxx"
+#include
+#include
+
+FGDeviceConfigurationMap::FGDeviceConfigurationMap( const char * relative_path, SGPropertyNode_ptr aBase, const char * aChildname ) :
+ base(aBase),
+ childname(aChildname)
+{
+ SGPath path(globals->get_fg_root());
+ path.append( relative_path );
+
+ int index = 1000;
+ scan_dir( path, &index);
+
+ vector childNodes = base->getChildren(childname);
+ for (int k = (int)childNodes.size() - 1; k >= 0; k--) {
+ SGPropertyNode *n = childNodes[k];
+ vector names = n->getChildren("name");
+ if (names.size() ) // && (n->getChildren("axis").size() || n->getChildren("button").size()))
+ for (unsigned int j = 0; j < names.size(); j++)
+ (*this)[names[j]->getStringValue()] = n;
+ }
+}
+
+FGDeviceConfigurationMap::~FGDeviceConfigurationMap()
+{
+ base->removeChildren( childname );
+}
+
+void FGDeviceConfigurationMap::scan_dir( SGPath & path, int *index)
+{
+ ulDir *dir = ulOpenDir(path.c_str());
+ if (dir) {
+ ulDirEnt* dent;
+ while ((dent = ulReadDir(dir)) != 0) {
+ if (dent->d_name[0] == '.')
+ continue;
+
+ SGPath p(path.str());
+ p.append(dent->d_name);
+ scan_dir(p, index);
+ }
+ ulCloseDir(dir);
+
+ } else if (path.extension() == "xml") {
+ SG_LOG(SG_INPUT, SG_DEBUG, "Reading joystick file " << path.str());
+ SGPropertyNode_ptr n = base->getChild(childname, (*index)++, true);
+ readProperties(path.str(), n);
+ n->setStringValue("source", path.c_str());
+ }
+}
+
+
diff --git a/src/Input/FGDeviceConfigurationMap.hxx b/src/Input/FGDeviceConfigurationMap.hxx
new file mode 100644
index 000000000..27a3a8a14
--- /dev/null
+++ b/src/Input/FGDeviceConfigurationMap.hxx
@@ -0,0 +1,48 @@
+// FGDeviceConfigurationMap.hxx -- a map to access xml device configuration
+//
+// Written by Torsten Dreyer, started August 2009
+// Based on work from David Megginson, started May 2001.
+//
+// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
+// Copyright (C) 2001 David Megginson, david@megginson.com
+//
+// 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 of the
+// License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// $Id$
+
+#ifndef _FGDEVICECONFIGURATIONMAP_HXX
+#define _FGDEVICECONFIGURATIONMAP_HXX
+
+#ifndef __cplusplus
+# error This library requires C++
+#endif
+
+#include
+#include
+
+#include
*/
-class FGInput : public SGSubsystem
+class FGInput : public SGSubsystemGroup
{
public:
/**
@@ -89,259 +61,6 @@ public:
*/
virtual ~FGInput();
- //
- // Implementation of SGSubsystem.
- //
- virtual void init ();
- virtual void reinit ();
- virtual void postinit ();
- virtual void bind ();
- virtual void unbind ();
- virtual void update (double dt);
- virtual void suspend ();
- virtual void resume ();
- virtual bool is_suspended () const;
-
-
- /**
- * Control whether this is the default module to receive events.
- *
- * The first input module created will set itself as the default
- * automatically.
- *
- * @param status true if this should be the default module for
- * events, false otherwise.
- */
- virtual void makeDefault (bool status = true);
-
-
- /**
- * Handle a single keystroke.
- *
- * @param k The integer key code, see Main/fg_os.hxx
- * @param modifiers Modifier keys pressed (bitfield).
- * @param x The mouse x position at the time of keypress.
- * @param y The mouse y position at the time of keypress.
- */
- virtual void doKey (int k, int modifiers, int x, int y);
-
-
- /**
- * Handle a mouse click event.
- *
- * @param button The mouse button selected.
- * @param updown Button status.
- * @param x The X position of the mouse event, in screen coordinates.
- * @param y The Y position of the mouse event, in screen coordinates.
- */
- virtual void doMouseClick (int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter*);
-
-
- /**
- * Handle mouse motion.
- *
- * @param x The new mouse x position, in screen coordinates.
- * @param y The new mouse y position, in screen coordinates.
- */
- virtual void doMouseMotion (int x, int y);
-
-
-private:
- // Constants
- enum
- {
- MAX_KEYS = 1024,
- MAX_JOYSTICKS = 10,
- MAX_JOYSTICK_AXES = _JS_MAX_AXES,
- MAX_JOYSTICK_BUTTONS = 32,
-
- MAX_MICE = 1,
- MAX_MOUSE_BUTTONS = 8
- };
- struct mouse;
- friend struct mouse;
-
- typedef vector > binding_list_t;
-
- /**
- * Settings for a key or button.
- */
- struct button {
- button ();
- virtual ~button ();
- bool is_repeatable;
- float interval_sec;
- float last_dt;
- int last_state;
- binding_list_t bindings[KEYMOD_MAX];
- };
-
-
- /**
- * Settings for a single joystick axis.
- */
- struct axis {
- axis ();
- virtual ~axis ();
- float last_value;
- float tolerance;
- binding_list_t bindings[KEYMOD_MAX];
- float low_threshold;
- float high_threshold;
- struct button low;
- struct button high;
- float interval_sec;
- double last_dt;
- };
-
-
- /**
- * Settings for a joystick.
- */
- struct joystick {
- joystick ();
- virtual ~joystick ();
- int jsnum;
- jsJoystick * js;
- int naxes;
- int nbuttons;
- axis * axes;
- button * buttons;
- };
-
-
- /**
- * Settings for a mouse mode.
- */
- struct mouse_mode {
- mouse_mode ();
- virtual ~mouse_mode ();
- int cursor;
- bool constrained;
- bool pass_through;
- button * buttons;
- binding_list_t x_bindings[KEYMOD_MAX];
- binding_list_t y_bindings[KEYMOD_MAX];
- };
-
-
- /**
- * Settings for a mouse.
- */
- struct mouse {
- mouse ();
- virtual ~mouse ();
- int x;
- int y;
- int save_x;
- int save_y;
- SGPropertyNode_ptr mode_node;
- SGPropertyNode_ptr mouse_button_nodes[MAX_MOUSE_BUTTONS];
- int nModes;
- int current_mode;
- double timeout;
- mouse_mode * modes;
- };
-
-
- /**
- * Initialize joystick bindings.
- */
- void _init_joystick ();
-
-
- /**
- * Scan directory recursively for "named joystick" configuration files,
- * and read them into /input/joysticks/js-named[index]++.
- */
- void _scan_joystick_dir (SGPath *path, SGPropertyNode* node, int *index);
-
-
- /**
- * Initialize mouse bindings.
- */
- void _init_mouse ();
-
-
- /**
- * Initialize a single button.
- */
- inline void _init_button (const SGPropertyNode * node,
- button &b,
- const string name);
-
- /**
- * Initialize key bindings, as well as those joystick parts that
- * depend on a working Nasal subsystem.
- */
- void _postinit_keyboard ();
- void _postinit_joystick ();
-
- /**
- * Update the keyboard.
- */
- void _update_keyboard ();
-
-
- /**
- * Update the joystick.
- */
- void _update_joystick (double dt);
-
-
- /**
- * Update the mouse.
- */
- void _update_mouse (double dt);
-
-
- /**
- * Update a single button.
- */
- inline void _update_button (button &b, int modifiers, bool pressed,
- int x, int y);
-
-
- /**
- * Read bindings and modifiers.
- */
- void _read_bindings (const SGPropertyNode * node,
- binding_list_t * binding_list,
- int modifiers);
-
- /**
- * Look up the bindings for a key code.
- */
- const binding_list_t& _find_key_bindings (unsigned int k,
- int modifiers);
-
- button _key_bindings[MAX_KEYS];
- joystick _joystick_bindings[MAX_JOYSTICKS];
- mouse _mouse_bindings[MAX_MICE];
-
- /**
- * Nasal module name/namespace.
- */
- string _module;
-
- /**
- * List of currently pressed mouse button events
- */
- std::map > > _activePickCallbacks;
-
- /**
- * Key listener interface.
- */
- SGPropertyNode_ptr _key_event;
- int _key_code;
- int _key_modifiers;
- bool _key_pressed;
- bool _key_shift;
- bool _key_ctrl;
- bool _key_alt;
- bool _key_meta;
- bool _key_super;
- bool _key_hyper;
};
#endif // _INPUT_HXX