Debian Codegraph @

Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h

raw symbols SCIP
1 // Copyright 2017 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <cmath>
7 #include <string>
8
9 #include "InputCommon/ControllerEmu/Control/Control.h"
10 #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
11
12 namespace ControllerEmu
13 {
14 class Buttons : public ControlGroup
15 {
16 public:
17 explicit Buttons(const std::string& name_);
18 Buttons(std::string ini_name, std::string group_name);
19
20 template <typename C>
21 void GetState(C* const buttons, const C* bitmasks) const
22 {
23 for (auto& control : controls)
24 *buttons |= *(bitmasks++) * control->GetState<bool>();
25 }
26
27 template <typename C>
28 void GetState(C* const buttons, const C* bitmasks,
29 const InputOverrideFunction& override_func) const
30 {
31 if (!override_func)
32 return GetState(buttons, bitmasks);
33
34 for (auto& control : controls)
35 {
36 ControlState state = control->GetState();
37 if (std::optional<ControlState> state_override = override_func(name, control->name, state))
38 state = *state_override;
39 *buttons |= *(bitmasks++) * (std::lround(state) > 0);
40 }
41 }
42 };
43 } // namespace ControllerEmu