]> git.mxchange.org Git - flightgear.git/blob - src/Input/input.hxx
8358412da4130775b234359b0c501090338b926f
[flightgear.git] / src / Input / input.hxx
1 // input.hxx -- handle user input from various sources.
2 //
3 // Written by David Megginson, started May 2001.
4 //
5 // Copyright (C) 2001 David Megginson, david@megginson.com
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifndef _INPUT_HXX
25 #define _INPUT_HXX
26
27 #ifndef __cplusplus                                                          
28 # error This library requires C++
29 #endif
30
31 #include <simgear/compiler.h>
32
33 #include <simgear/misc/commands.hxx>
34 #include <simgear/misc/props.hxx>
35
36 #include <Main/fgfs.hxx>
37 #include <Main/globals.hxx>
38
39 #include <map>
40 #include <vector>
41
42 SG_USING_STD(map);
43 SG_USING_STD(vector);
44
45 /**
46  * An input binding of some sort.
47  *
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
50  * instrument.</p>
51  */
52 class FGBinding
53 {
54 public:
55
56   FGBinding ();
57   FGBinding (const SGPropertyNode * node);
58   virtual ~FGBinding ();
59
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; }
63   
64   virtual void read (const SGPropertyNode * node);
65
66   virtual void fire () const;
67 //   virtual void fire (double value);
68 //   virtual void fire (int xdelta, int ydelta);
69
70 private:
71   string _command_name;
72   SGCommandMgr::command_t _command;
73   const SGPropertyNode * _arg;
74 };
75
76
77 /**
78  * Generic input module.
79  *
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>
83  */
84 class FGInput : public FGSubsystem
85 {
86 public:
87
88   enum {
89     FG_MOD_NONE = 0,
90     FG_MOD_SHIFT = 1,
91     FG_MOD_CTRL = 2,
92     FG_MOD_ALT = 4,
93     FG_MOD_MAX = 8                      // one past all modifiers
94   };
95
96   FGInput();
97   virtual ~FGInput();
98
99   //
100   // Implementation of FGSubsystem.
101   //
102   virtual void init ();
103   virtual void bind ();
104   virtual void unbind ();
105   virtual void update ();
106
107
108   /**
109    * Handle a single keystroke.
110    *
111    * <p>Note: for special keys, the integer key code will be the Glut
112    * code + 256.</p>
113    *
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.
118    * @see #FG_MOD_SHIFT
119    * @see #FG_MOD_CTRL
120    * @see #FG_MOD_ALT
121    */
122   virtual void doKey (int k, int modifiers, int x, int y);
123
124
125 private:
126
127   /**
128    * Look up the bindings for a key code.
129    */
130   const vector<FGBinding> * _find_bindings (int k, int modifiers);
131
132   typedef map<int,vector<FGBinding> > keyboard_map;
133   keyboard_map _key_bindings[FG_MOD_MAX];
134
135 };
136
137 extern FGInput current_input;
138
139 #endif // _CONTROLS_HXX