]> git.mxchange.org Git - simgear.git/blob - simgear/structure/SGBinding.hxx
State-machine structure, initial work.
[simgear.git] / simgear / structure / SGBinding.hxx
1 /**
2  * \file commands.hxx
3  * Interface definition for encapsulated commands.
4  * Started Spring 2001 by David Megginson, david@megginson.com
5  * This code is released into the Public Domain.
6  *
7  * $Id$
8  */
9
10 #ifndef __SGBINDING_HXX
11 #define __SGBINDING_HXX
12
13
14 #include <simgear/compiler.h>
15
16 #include <string>
17 #include <map>
18 #include <vector>
19
20 #include <simgear/props/props.hxx>
21 #include <simgear/props/condition.hxx>
22
23 #include "commands.hxx"
24
25 /**
26  * An input binding of some sort.
27  *
28  * <p>This class represents a binding that can be assigned to a
29  * keyboard key, a joystick button or axis, or even a panel
30  * instrument.</p>
31  */
32 class SGBinding : public SGConditional
33 {
34 public:
35
36   /**
37    * Default constructor.
38    */
39   SGBinding ();
40
41     /**
42      * Convenience constructor.
43      *
44      * @param node The binding will be built from this node.
45      */
46     SGBinding(const std::string& commandName);
47
48   /**
49    * Convenience constructor.
50    *
51    * @param node The binding will be built from this node.
52    */
53   SGBinding (const SGPropertyNode * node, SGPropertyNode* root);
54
55
56   /**
57    * Destructor.
58    */
59   virtual ~SGBinding ();
60
61
62   /**
63    * Get the command name.
64    *
65    * @return The string name of the command for this binding.
66    */
67   const std::string &getCommandName () const { return _command_name; }
68
69
70   /**
71    * Get the command itself.
72    *
73    * @return The command associated with this binding, or 0 if none
74    * is present.
75    */
76   SGCommandMgr::command_t getCommand () const { return _command; }
77
78
79   /**
80    * Get the argument that will be passed to the command.
81    *
82    * @return A property node that will be passed to the command as its
83    * argument, or 0 if none was supplied.
84    */
85   const SGPropertyNode * getArg () { return _arg; }
86   
87
88   /**
89    * Read a binding from a property node.
90    *
91    * @param node The property node containing the binding.
92    */
93   void read (const SGPropertyNode * node, SGPropertyNode* root);
94
95
96   /**
97    * Fire a binding.
98    */
99   void fire () const;
100
101
102   /**
103    * Fire a binding with a scaled movement (rather than absolute position).
104    */
105   void fire (double offset, double max) const;
106
107
108   /**
109    * Fire a binding with a setting (i.e. joystick axis).
110    *
111    * A double 'setting' property will be added to the arguments.
112    *
113    * @param setting The input setting, usually between -1.0 and 1.0.
114    */
115   void fire (double setting) const;
116
117
118 private:
119                                 // just to be safe.
120   SGBinding (const SGBinding &binding);
121
122   std::string _command_name;
123   mutable SGCommandMgr::command_t _command;
124   mutable SGPropertyNode_ptr _arg;
125   mutable SGPropertyNode_ptr _setting;
126 };
127
128 typedef SGSharedPtr<SGBinding> SGBinding_ptr;
129
130 typedef std::vector<SGBinding_ptr > SGBindingList;
131 typedef std::map<unsigned,SGBindingList> SGBindingMap;
132
133 /**
134  * fire every binding in a list, in sequence
135  
136  */
137 void fireBindingList(const SGBindingList& aBindings);
138
139 #endif