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 * Get the command name.
65 * @return The string name of the command for this binding.
67 const std::string &getCommandName () const { return _command_name; }
71 * Get the command itself.
73 * @return The command associated with this binding, or 0 if none
76 SGCommandMgr::command_t getCommand () const { return _command; }
80 * Get the argument that will be passed to the command.
82 * @return A property node that will be passed to the command as its
83 * argument, or 0 if none was supplied.
85 const SGPropertyNode * getArg () { return _arg; }
89 * Read a binding from a property node.
91 * @param node The property node containing the binding.
93 void read (const SGPropertyNode * node, SGPropertyNode* root);
103 * Fire a binding with a scaled movement (rather than absolute position).
105 void fire (double offset, double max) const;
109 * Fire a binding with a setting (i.e. joystick axis).
111 * A double 'setting' property will be added to the arguments.
113 * @param setting The input setting, usually between -1.0 and 1.0.
115 void fire (double setting) const;
120 SGBinding (const SGBinding &binding);
122 std::string _command_name;
123 mutable SGCommandMgr::command_t _command;
124 mutable SGPropertyNode_ptr _arg;
125 mutable SGPropertyNode_ptr _setting;
128 typedef SGSharedPtr<SGBinding> SGBinding_ptr;
130 typedef std::vector<SGBinding_ptr > SGBindingList;
131 typedef std::map<unsigned,SGBindingList> SGBindingMap;
134 * fire every binding in a list, in sequence
137 void fireBindingList(const SGBindingList& aBindings);