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.
10 #ifndef __SGBINDING_HXX
11 #define __SGBINDING_HXX
14 #include <simgear/compiler.h>
20 #include <simgear/props/props.hxx>
21 #include <simgear/props/condition.hxx>
23 #include "commands.hxx"
26 * An input binding of some sort.
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
32 class SGBinding : public SGConditional
37 * Default constructor.
42 * Convenience constructor.
44 * @param commandName TODO
46 SGBinding(const std::string& commandName);
49 * Convenience constructor.
51 * @param node The binding will be built from this node.
52 * @param root Property root used while building binding.
54 SGBinding( const SGPropertyNode *node,
55 SGPropertyNode *root );
61 virtual ~SGBinding ();
65 * clear internal state of the binding back to empty. This is useful
66 * if you don't want the 'remove on delete' behaviour of the
73 * Get the command name.
75 * @return The string name of the command for this binding.
77 const std::string &getCommandName () const { return _command_name; }
81 * Get the command itself.
83 * @return The command associated with this binding, or 0 if none
86 SGCommandMgr::Command* getCommand () const { return _command; }
90 * Get the argument that will be passed to the command.
92 * @return A property node that will be passed to the command as its
93 * argument, or 0 if none was supplied.
95 const SGPropertyNode * getArg () { return _arg; }
99 * Read a binding from a property node.
101 * @param node The property node containing the binding.
102 * @param root The property root node used while building the binding from
105 void read (const SGPropertyNode * node, SGPropertyNode* root);
115 * Fire a binding with a scaled movement (rather than absolute position).
117 void fire (double offset, double max) const;
121 * Fire a binding with a setting (i.e. joystick axis).
123 * A double 'setting' property will be added to the arguments.
125 * @param setting The input setting, usually between -1.0 and 1.0.
127 void fire (double setting) const;
130 * Fire a binding with a number of additional parameters
132 * The children of params will be merged with the fixed arguments.
134 void fire (SGPropertyNode* params) const;
137 void innerFire() const;
139 SGBinding (const SGBinding &binding);
141 std::string _command_name;
142 mutable SGCommandMgr::Command* _command;
143 mutable SGPropertyNode_ptr _arg;
144 mutable SGPropertyNode_ptr _setting;
147 typedef SGSharedPtr<SGBinding> SGBinding_ptr;
149 typedef std::vector<SGBinding_ptr > SGBindingList;
150 typedef std::map<unsigned,SGBindingList> SGBindingMap;
153 * fire every binding in a list, in sequence
156 void fireBindingList(const SGBindingList& aBindings, SGPropertyNode* params = NULL);
159 * fire every binding in a list with a setting value
162 void fireBindingListWithOffset(const SGBindingList& aBindings, double offset, double max);
165 * read multiple bindings from property-list format
167 SGBindingList readBindingList(const simgear::PropertyList& aNodes, SGPropertyNode* aRoot);
170 * call clear() on every binding in a list
172 void clearBindingList(const SGBindingList& aBindings);