2017-02-09 03:15:43 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "Common/Common.h"
|
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
2017-02-26 20:00:24 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2017-02-25 05:35:02 +00:00
|
|
|
Triggers::Triggers(const std::string& name_) : ControlGroup(name_, GroupType::Triggers)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
AddDeadzoneSetting(&m_deadzone_setting, 50);
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 20:47:55 +00:00
|
|
|
Triggers::StateData Triggers::GetState() const
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
const size_t trigger_count = controls.size();
|
2019-03-27 00:31:03 +00:00
|
|
|
const ControlState deadzone = m_deadzone_setting.GetValue() / 100;
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2018-07-13 16:06:49 +00:00
|
|
|
StateData result(trigger_count);
|
|
|
|
for (size_t i = 0; i < trigger_count; ++i)
|
2020-02-09 02:36:26 +00:00
|
|
|
result.data[i] = std::min(ApplyDeadzone(controls[i]->GetState(), deadzone), 1.0);
|
2018-07-13 16:06:49 +00:00
|
|
|
|
|
|
|
return result;
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
} // namespace ControllerEmu
|