2 #ifndef GAINPUTHELPERS_H_ 3 #define GAINPUTHELPERS_H_ 5 #include <gainput/GainputLog.h> 10 inline void HandleButton(InputDevice& device, InputState& state, InputDeltaState* delta,
DeviceButtonId buttonId,
bool value)
13 if (value != state.GetBool(buttonId))
15 GAINPUT_LOG(
"Button changed: %d, %i\n", buttonId, value);
21 const bool oldValue = state.GetBool(buttonId);
22 if (value != oldValue)
24 delta->AddChange(device.GetDeviceId(), buttonId, oldValue, value);
28 state.Set(buttonId, value);
31 inline void HandleAxis(InputDevice& device, InputState& state, InputDeltaState* delta,
DeviceButtonId buttonId,
float value)
33 const float deadZone = device.GetDeadZone(buttonId);
36 const float absValue = Abs(value);
37 const float sign = value < 0.0f ? -1.0f : 1.0f;
38 if (absValue < deadZone)
44 value -= sign*deadZone;
45 value *= 1.0f / (1.0f - deadZone);
49 if (value != state.GetFloat(buttonId))
51 GAINPUT_LOG(
"Axis changed: %d, %f\n", buttonId, value);
57 const float oldValue = state.GetFloat(buttonId);
58 if (value != oldValue)
60 delta->AddChange(device.GetDeviceId(), buttonId, oldValue, value);
64 state.Set(buttonId, value);