Gainput  v1.0.0
GainputHelpers.h
1 
2 #ifndef GAINPUTHELPERS_H_
3 #define GAINPUTHELPERS_H_
4 
5 #include <gainput/GainputLog.h>
6 
7 namespace gainput
8 {
9 
10  inline void HandleButton(InputDevice& device, InputState& state, InputDeltaState* delta, DeviceButtonId buttonId, bool value)
11  {
12 #ifdef GAINPUT_DEBUG
13  if (value != state.GetBool(buttonId))
14  {
15  GAINPUT_LOG("Button changed: %d, %i\n", buttonId, value);
16  }
17 #endif
18 
19  if (delta)
20  {
21  const bool oldValue = state.GetBool(buttonId);
22  if (value != oldValue)
23  {
24  delta->AddChange(device.GetDeviceId(), buttonId, oldValue, value);
25  }
26  }
27 
28  state.Set(buttonId, value);
29  }
30 
31  inline void HandleAxis(InputDevice& device, InputState& state, InputDeltaState* delta, DeviceButtonId buttonId, float value)
32  {
33  const float deadZone = device.GetDeadZone(buttonId);
34  if (deadZone > 0.0f)
35  {
36  const float absValue = Abs(value);
37  const float sign = value < 0.0f ? -1.0f : 1.0f;
38  if (absValue < deadZone)
39  {
40  value = 0.0f;
41  }
42  else
43  {
44  value -= sign*deadZone;
45  value *= 1.0f / (1.0f - deadZone);
46  }
47  }
48 #ifdef GAINPUT_DEBUG
49  if (value != state.GetFloat(buttonId))
50  {
51  GAINPUT_LOG("Axis changed: %d, %f\n", buttonId, value);
52  }
53 #endif
54 
55  if (delta)
56  {
57  const float oldValue = state.GetFloat(buttonId);
58  if (value != oldValue)
59  {
60  delta->AddChange(device.GetDeviceId(), buttonId, oldValue, value);
61  }
62  }
63 
64  state.Set(buttonId, value);
65  }
66 
67 }
68 
69 #endif
70 
71 
unsigned int DeviceButtonId
ID of a specific button unique to an input device.
Definition: gainput.h:109
Contains all Gainput related classes, types, and functions.
Definition: gainput.h:103