]> git.mxchange.org Git - simgear.git/blob - simgear/structure/SGBinding.hxx
Remove stray ';'
[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   /**
43    * Convenience constructor.
44    *
45    * @param node The binding will be built from this node.
46    */
47   SGBinding (const SGPropertyNode * node, SGPropertyNode* root);
48
49
50   /**
51    * Destructor.
52    */
53   virtual ~SGBinding ();
54
55
56   /**
57    * Get the command name.
58    *
59    * @return The string name of the command for this binding.
60    */
61   const std::string &getCommandName () const { return _command_name; }
62
63
64   /**
65    * Get the command itself.
66    *
67    * @return The command associated with this binding, or 0 if none
68    * is present.
69    */
70   SGCommandMgr::command_t getCommand () const { return _command; }
71
72
73   /**
74    * Get the argument that will be passed to the command.
75    *
76    * @return A property node that will be passed to the command as its
77    * argument, or 0 if none was supplied.
78    */
79   const SGPropertyNode * getArg () { return _arg; }
80   
81
82   /**
83    * Read a binding from a property node.
84    *
85    * @param node The property node containing the binding.
86    */
87   void read (const SGPropertyNode * node, SGPropertyNode* root);
88
89
90   /**
91    * Fire a binding.
92    */
93   void fire () const;
94
95
96   /**
97    * Fire a binding with a scaled movement (rather than absolute position).
98    */
99   void fire (double offset, double max) const;
100
101
102   /**
103    * Fire a binding with a setting (i.e. joystick axis).
104    *
105    * A double 'setting' property will be added to the arguments.
106    *
107    * @param setting The input setting, usually between -1.0 and 1.0.
108    */
109   void fire (double setting) const;
110
111
112 private:
113                                 // just to be safe.
114   SGBinding (const SGBinding &binding);
115
116   std::string _command_name;
117   mutable SGCommandMgr::command_t _command;
118   mutable SGPropertyNode_ptr _arg;
119   mutable SGPropertyNode_ptr _setting;
120 };
121
122 typedef std::vector<SGSharedPtr<SGBinding> > SGBindingList;
123 typedef std::map<unsigned,SGBindingList> SGBindingMap;
124
125 #endif