Debian Codegraph @

xbmc/games/controllers/input/ControllerActivity.h

raw
1 /*
2 * Copyright (C) 2023 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #pragma once
10
11 #include "input/keyboard/KeyboardTypes.h"
12 #include "input/mouse/MouseTypes.h"
13
14 #include <set>
15
16 namespace KODI
17 {
18 namespace GAME
19 {
20 /*!
21 * \ingroup games
22 *
23 * \brief Class to hold state about the current activity of a controller
24 *
25 * The state is held as a single float value, which is updated by the various
26 * On*() methods. The activity is the maximum value on a single input frame.
27 * The value is saved to m_lastActivity on each call to OnInputFrame().
28 */
29 class CControllerActivity
30 {
31 public:
32 CControllerActivity() = default;
33 ~CControllerActivity() = default;
34
35 float GetActivation() const { return m_lastActivation; }
36 void ClearButtonState();
37
38 void OnButtonPress(bool pressed);
39 void OnButtonMotion(float magnitude);
40 void OnAnalogStickMotion(float x, float y);
41 void OnWheelMotion(float position);
42 void OnThrottleMotion(float position);
43 void OnKeyPress(const KEYBOARD::KeyName& key);
44 void OnKeyRelease(const KEYBOARD::KeyName& key);
45 void OnMouseMotion(const MOUSE::PointerName& relpointer, int differenceX, int differenceY);
46 void OnMouseButtonPress(const MOUSE::ButtonName& button);
47 void OnMouseButtonRelease(const MOUSE::ButtonName& button);
48 void OnInputFrame();
49
50 private:
51 // Input helpers
52 static INPUT::INTERCARDINAL_DIRECTION GetPointerDirection(int differenceX, int differenceY);
53
54 // State parameters
55 float m_lastActivation{0.0f};
56 float m_currentActivation{0.0f};
57 KEYBOARD::KeyName m_activeKey;
58 std::set<MOUSE::PointerName> m_activePointers;
59 std::set<MOUSE::ButtonName> m_activeButtons;
60 bool m_bKeyPressed{false};
61 };
62 } // namespace GAME
63 } // namespace KODI