1 // input.hxx -- handle user input from various sources.
3 // Written by David Megginson, started May 2001.
5 // Copyright (C) 2001 David Megginson, david@megginson.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 # error This library requires C++
31 #include <simgear/compiler.h>
33 #include <simgear/misc/commands.hxx>
34 #include <simgear/misc/props.hxx>
36 #include <Main/fgfs.hxx>
37 #include <Main/globals.hxx>
46 * An input binding of some sort.
48 * <p>This class represents a binding that can be assigned to a
49 * keyboard key, a joystick button or axis, or even a panel
57 FGBinding (const SGPropertyNode * node);
58 virtual ~FGBinding ();
60 virtual const string &getCommandName () const { return _command_name; }
61 virtual SGCommandMgr::command_t getCommand () const { return _command; }
62 virtual const SGPropertyNode * getArg () { return _arg; }
64 virtual void read (const SGPropertyNode * node);
66 virtual void fire () const;
67 // virtual void fire (double value);
68 // virtual void fire (int xdelta, int ydelta);
72 SGCommandMgr::command_t _command;
73 const SGPropertyNode * _arg;
78 * Generic input module.
80 * <p>This module is designed to handle input from multiple sources --
81 * keyboard, joystick, mouse, or even panel switches -- in a consistent
82 * way, and to allow users to rebind any of the actions at runtime.</p>
84 class FGInput : public FGSubsystem
93 FG_MOD_MAX = 8 // one past all modifiers
100 // Implementation of FGSubsystem.
102 virtual void init ();
103 virtual void bind ();
104 virtual void unbind ();
105 virtual void update ();
109 * Handle a single keystroke.
111 * <p>Note: for special keys, the integer key code will be the Glut
114 * @param k The integer key code, as returned by glut.
115 * @param modifiers Modifier keys pressed (bitfield).
116 * @param x The mouse x position at the time of keypress.
117 * @param y The mouse y position at the time of keypress.
122 virtual void doKey (int k, int modifiers, int x, int y);
128 * Look up the bindings for a key code.
130 const vector<FGBinding> * _find_bindings (int k, int modifiers);
132 typedef map<int,vector<FGBinding> > keyboard_map;
133 keyboard_map _key_bindings[FG_MOD_MAX];
137 extern FGInput current_input;
139 #endif // _CONTROLS_HXX