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/props.hxx>
35 #include <Main/fgfs.hxx>
36 #include <Main/globals.hxx>
45 * An input binding of some sort.
47 * <p>This class represents a binding that can be assigned to a
48 * keyboard key, a joystick button or axis, or even a panel
63 FGBinding (const SGPropertyNode * node);
64 virtual ~FGBinding ();
66 virtual Action getAction () const { return _action; }
67 virtual SGPropertyNode * getProperty () { return _node; }
68 virtual const SGPropertyNode * getProperty () const { return _node; }
69 virtual const SGValue * getAdjustStep () const { return _adjust_step; }
70 virtual const SGValue * getAssignValue () const { return _assign_value; }
72 virtual void setAction (Action action);
73 virtual void setProperty (SGPropertyNode * node);
74 virtual void setAdjustStep (const SGValue * step);
75 virtual void setAssignValue (const SGValue * value);
77 virtual void read (const SGPropertyNode * node);
79 virtual void fire () const;
80 // virtual void fire (double value);
81 // virtual void fire (int xdelta, int ydelta);
85 SGPropertyNode * _node;
86 const SGValue * _adjust_step;
87 const SGValue * _assign_value;
92 * Generic input module.
94 * <p>This module is designed to handle input from multiple sources --
95 * keyboard, joystick, mouse, or even panel switches -- in a consistent
96 * way, and to allow users to rebind any of the actions at runtime.</p>
98 class FGInput : public FGSubsystem
107 MOD_MAX = 8 // one past all modifiers
114 // Implementation of FGSubsystem.
116 virtual void init ();
117 virtual void bind ();
118 virtual void unbind ();
119 virtual void update ();
123 * Handle a single keystroke.
125 * <p>Note: for special keys, the integer key code will be the Glut
128 * @param k The integer key code, as returned by glut.
129 * @param modifiers Modifier keys pressed (bitfield).
130 * @param x The mouse x position at the time of keypress.
131 * @param y The mouse y position at the time of keypress.
136 virtual void doKey (int k, int modifiers, int x, int y);
140 * Fire off a single-trigger action.
142 * <p>This method fires an action triggered by a key or button
143 * press, with no additional quantity information.</p>
145 * @param binding The property node with the binding.
147 virtual void action (const SGPropertyNode * binding);
151 * Fire off a quantity action.
153 * <p>This method fires an action triggered by a change in value,
154 * such as a slider or axis.</p>
156 * @param action The property node with the binding.
157 * @param value The new value.
159 // virtual void action (const SGPropertyNode * binding, double value);
163 * Fire off a movement action.
165 * <p>This method fires an action triggered by relative movement
166 * rather than an absolute value; it is especially applicable to
167 * mouse-movement bindings.</p>
169 * @param binding The property node containing the binding.
170 * @param xdelta The amount of X movement.
171 * @param ydelta The amount of Y movement.
173 // virtual void action (const SGPropertyNode * binding, int xdelta, int ydelta);
177 typedef map<int,vector<FGBinding> > keyboard_map;
178 keyboard_map _key_bindings[MOD_MAX];
182 extern FGInput current_input;
184 #endif // _CONTROLS_HXX