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 node The binding will be built from this node.
46 SGBinding(const std::string& commandName);
49 * Convenience constructor.
51 * @param node The binding will be built from this node.
53 SGBinding (const SGPropertyNode * node, SGPropertyNode* root);
59 virtual ~SGBinding ();
63 * clear internal state of the binding back to empty. This is useful
64 * if you don't want the 'remove on delete' behaviour of the
71 * Get the command name.
73 * @return The string name of the command for this binding.
75 const std::string &getCommandName () const { return _command_name; }
79 * Get the command itself.
81 * @return The command associated with this binding, or 0 if none
84 SGCommandMgr::Command* getCommand () const { return _command; }
88 * Get the argument that will be passed to the command.
90 * @return A property node that will be passed to the command as its
91 * argument, or 0 if none was supplied.
93 const SGPropertyNode * getArg () { return _arg; }
97 * Read a binding from a property node.
99 * @param node The property node containing the binding.
101 void read (const SGPropertyNode * node, SGPropertyNode* root);
111 * Fire a binding with a scaled movement (rather than absolute position).
113 void fire (double offset, double max) const;
117 * Fire a binding with a setting (i.e. joystick axis).
119 * A double 'setting' property will be added to the arguments.
121 * @param setting The input setting, usually between -1.0 and 1.0.
123 void fire (double setting) const;
126 * Fire a binding with a number of additional parameters
128 * The children of params will be merged with the fixed arguments.
130 void fire (SGPropertyNode* params) const;
133 void innerFire() const;
135 SGBinding (const SGBinding &binding);
137 std::string _command_name;
138 mutable SGCommandMgr::Command* _command;
139 mutable SGPropertyNode_ptr _arg;
140 mutable SGPropertyNode_ptr _setting;
143 typedef SGSharedPtr<SGBinding> SGBinding_ptr;
145 typedef std::vector<SGBinding_ptr > SGBindingList;
146 typedef std::map<unsigned,SGBindingList> SGBindingMap;
149 * fire every binding in a list, in sequence
152 void fireBindingList(const SGBindingList& aBindings, SGPropertyNode* params = NULL);
155 * fire every binding in a list with a setting value
158 void fireBindingListWithOffset(const SGBindingList& aBindings, double offset, double max);
161 * read multiple bindings from property-list format
163 SGBindingList readBindingList(const simgear::PropertyList& aNodes, SGPropertyNode* aRoot);
166 * call clear() on every binding in a list
168 void clearBindingList(const SGBindingList& aBindings);