Gainput  v1.0.0
GainputInputMap.h
1 
2 #ifndef GAINPUTINPUTMAP_H_
3 #define GAINPUTINPUTMAP_H_
4 
5 namespace gainput
6 {
7 
8 class UserButton;
9 
11 typedef float (*FilterFunc_T)(float const value, void* userData);
12 
14 
26 class GAINPUT_LIBEXPORT InputMap
27 {
28 public:
30 
35  InputMap(InputManager& manager, const char* name = 0, Allocator& allocator = GetDefaultAllocator());
37  ~InputMap();
38 
40  void Clear();
41 
43  const InputManager& GetManager() const { return manager_; }
45 
48  const char* GetName() const { return name_; }
50  unsigned GetId() const { return id_; }
51 
53 
59  bool MapBool(UserButtonId userButton, DeviceId device, DeviceButtonId deviceButton);
61 
71  bool MapFloat(UserButtonId userButton, DeviceId device, DeviceButtonId deviceButton,
72  float min = 0.0f, float max = 1.0f,
73  FilterFunc_T filterFunc = 0, void* filterUserData = 0);
75  void Unmap(UserButtonId userButton);
77  bool IsMapped(UserButtonId userButton) const;
78 
80 
86  size_t GetMappings(UserButtonId userButton, DeviceButtonSpec* outButtons, size_t maxButtonCount) const;
87 
90  {
94  UBP_AVERAGE
95  };
97 
100  bool SetUserButtonPolicy(UserButtonId userButton, UserButtonPolicy policy);
101 
103 
112  bool SetDeadZone(UserButtonId userButton, float deadZone);
113 
115  bool GetBool(UserButtonId userButton) const;
117  bool GetBoolIsNew(UserButtonId userButton) const;
119  bool GetBoolPrevious(UserButtonId userButton) const;
121  bool GetBoolWasDown(UserButtonId userButton) const;
122 
124  float GetFloat(UserButtonId userButton) const;
126  float GetFloatPrevious(UserButtonId userButton) const;
128  float GetFloatDelta(UserButtonId userButton) const;
129 
131 
137  size_t GetUserButtonName(UserButtonId userButton, char* buffer, size_t bufferLength) const;
138 
140 
148  UserButtonId GetUserButtonId(DeviceId device, DeviceButtonId deviceButton) const;
149 
151 
154  ListenerId AddListener(MappedInputListener* listener);
156  void RemoveListener(ListenerId listenerId);
158 
163  void ReorderListeners();
164 
165 private:
166  InputManager& manager_;
167  char* name_;
168  unsigned id_;
169  Allocator& allocator_;
170 
172  UserButtonMap userButtons_;
173  UserButtonId nextUserButtonId_;
174 
176  Array<MappedInputListener*> sortedListeners_;
177  unsigned nextListenerId_;
178  InputListener* managerListener_;
179  ListenerId managerListenerId_;
180 
181  float GetFloatState(UserButtonId userButton, bool previous) const;
182 
183  UserButton* GetUserButton(UserButtonId userButton);
184  const UserButton* GetUserButton(UserButtonId userButton) const;
185 
186  // Do not copy.
187  InputMap(const InputMap &);
188  InputMap& operator=(const InputMap &);
189 
190 };
191 
192 }
193 
194 #endif
195 
The maximum of all device button states is the result.
Definition: GainputInputMap.h:92
Maps user buttons to device buttons.
Definition: GainputInputMap.h:26
A std::vector-like data container for POD-types.
Definition: GainputContainers.h:96
Listener interface that allows to receive notifications when user button states change.
Definition: GainputInputListener.h:43
const InputManager & GetManager() const
Returns the input manager this input map uses.
Definition: GainputInputMap.h:43
Manages all input devices and some other helpful stuff.
Definition: GainputInputManager.h:24
float(* FilterFunc_T)(float const value, void *userData)
Type for filter functions that can be used to filter mapped float inputs.
Definition: GainputInputMap.h:11
UserButtonPolicy
Policy for how multiple device buttons are summarized in one user button.
Definition: GainputInputMap.h:89
GAINPUT_LIBEXPORT DefaultAllocator & GetDefaultAllocator()
Returns the default instance of the default allocator.
unsigned int UserButtonId
ID of a user-defined, mapped button.
Definition: gainput.h:121
Listener interface that allows to receive notifications when device button states change...
Definition: GainputInputListener.h:9
Describes a device button on a specific device.
Definition: gainput.h:112
unsigned int DeviceId
ID of an input device.
Definition: gainput.h:107
unsigned int ListenerId
ID of an input listener.
Definition: gainput.h:123
The first device buttons that is down (or not 0.0f) determines the result.
Definition: GainputInputMap.h:91
unsigned GetId() const
Returns the map&#39;s auto-generated ID (that should not be used outside of the library).
Definition: GainputInputMap.h:50
const char * GetName() const
Returns the map&#39;s name, if any.
Definition: GainputInputMap.h:48
unsigned int DeviceButtonId
ID of a specific button unique to an input device.
Definition: gainput.h:109
Interface used to pass custom allocators to the library.
Definition: GainputAllocator.h:16
The minimum of all device button states is the result.
Definition: GainputInputMap.h:93
Contains all Gainput related classes, types, and functions.
Definition: gainput.h:103