Files
kaizen/lib/source/gainput/gestures/GainputSimultaneouslyDownGesture.cpp
Simone 4e42229bdd Squashed 'external/gainput/' content from commit 2be0a50
git-subtree-dir: external/gainput
git-subtree-split: 2be0a50089eafcc6fccb66142180082e48f27f4c
2024-01-22 08:51:55 +01:00

64 lines
1.5 KiB
C++

#include <gainput/gainput.h>
#include <gainput/gestures/GainputSimultaneouslyDownGesture.h>
#ifdef GAINPUT_ENABLE_SIMULTANEOUSLY_DOWN_GESTURE
#include <gainput/GainputInputDeltaState.h>
#include <gainput/GainputHelpers.h>
namespace gainput
{
SimultaneouslyDownGesture::SimultaneouslyDownGesture(InputManager& manager, DeviceId device, unsigned index, DeviceVariant /*variant*/) :
InputGesture(manager, device, index),
buttons_(manager.GetAllocator())
{
state_ = manager_.GetAllocator().New<InputState>(manager.GetAllocator(), 1);
GAINPUT_ASSERT(state_);
previousState_ = manager_.GetAllocator().New<InputState>(manager.GetAllocator(), 1);
GAINPUT_ASSERT(previousState_);
}
SimultaneouslyDownGesture::~SimultaneouslyDownGesture()
{
manager_.GetAllocator().Delete(state_);
manager_.GetAllocator().Delete(previousState_);
}
void
SimultaneouslyDownGesture::AddButton(DeviceId device, DeviceButtonId button)
{
DeviceButtonSpec spec;
spec.deviceId = device;
spec.buttonId = button;
buttons_.push_back(spec);
}
void
SimultaneouslyDownGesture::ClearButtons()
{
buttons_.clear();
}
void
SimultaneouslyDownGesture::InternalUpdate(InputDeltaState* delta)
{
bool allDown = !buttons_.empty();
for (Array<DeviceButtonSpec>::const_iterator it = buttons_.begin();
it != buttons_.end() && allDown;
++it)
{
const InputDevice* device = manager_.GetDevice(it->deviceId);
GAINPUT_ASSERT(device);
allDown = allDown && device->GetBool(it->buttonId);
}
HandleButton(*this, *state_, delta, SimultaneouslyDownTriggered, allDown);
}
}
#endif