Debian Codegraph @

xbmc/games/controllers/listproviders/GUIGameControllerProvider.h

raw
1 /*
2 * Copyright (C) 2022-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 "games/controllers/ControllerTypes.h"
12 #include "guilib/listproviders/IListProvider.h"
13
14 #include <memory>
15 #include <stdint.h>
16 #include <string>
17 #include <vector>
18
19 namespace KODI
20 {
21 namespace GAME
22 {
23 /*!
24 * \ingroup games
25 *
26 * \brief Controller list provider for the \ref IAgentList control in the
27 * Player Viewer (<b>`GameAgents`</b>) window
28 *
29 * This list provider populates a game controller list with items that show
30 * which emulator port a player's controller is connected to. Most items are
31 * empty to pad the controller to its correct position in the list.
32 *
33 * The number of list items is determined by \ref MAX_PORT_COUNT, plus an item
34 * for the "disconnected" icon. The list items are updated when the port count
35 * or port index changes.
36 *
37 * An alignment can be specified to align the available ports to the left or
38 * right side of the list.
39 */
40 class CGUIGameControllerProvider : public IListProvider
41 {
42 public:
43 /*!
44 * \brief Construct a game controller provider for the player's controller
45 * list in the Player Viewer dialog
46 *
47 * \param portCount The number of open ports for the emulator
48 * \param portIndex The index of the port the controller is connected to
49 * \param peripheralLocation The location of the underlying peripheral
50 * providing input
51 * \param alignment The alignment of the list items (<b>`XBFONT_LEFT`</b>
52 * or <b>`XBFONT_RIGHT`</b>)
53 * \param parentID The ID of the parent window
54 */
55 CGUIGameControllerProvider(unsigned int portCount,
56 int portIndex,
57 const std::string& peripheralLocation,
58 uint32_t alignment,
59 int parentID);
60 explicit CGUIGameControllerProvider(const CGUIGameControllerProvider& other);
61
62 ~CGUIGameControllerProvider() override;
63
64 // Implementation of IListProvider
65 std::unique_ptr<IListProvider> Clone() override;
66 bool Update(bool forceRefresh) override;
67 void Fetch(std::vector<std::shared_ptr<CGUIListItem>>& items) override;
68 bool OnClick(const std::shared_ptr<CGUIListItem>& item) override { return false; }
69 bool OnInfo(const std::shared_ptr<CGUIListItem>& item) override { return false; }
70 bool OnContextMenu(const std::shared_ptr<CGUIListItem>& item) override { return false; }
71 void SetDefaultItem(int item, bool always) override {}
72 int GetDefaultItem() const override { return -1; }
73 bool AlwaysFocusDefaultItem() const override { return false; }
74
75 // Game functions
76 ControllerPtr GetControllerProfile() const { return m_controllerProfile; }
77 void SetControllerProfile(ControllerPtr controllerProfile);
78 unsigned int GetPortCount() const { return m_portCount; }
79 void SetPortCount(unsigned int portCount);
80 int GetPortIndex() const { return m_portIndex; }
81 void SetPortIndex(int portIndex);
82 const std::string& GetPeripheralLocation() const { return m_peripheralLocation; }
83 void SetPeripheralLocation(const std::string& peripheralLocation);
84
85 private:
86 // GUI functions
87 void InitializeItems();
88 void UpdateItems();
89
90 // Game parameters
91 ControllerPtr m_controllerProfile;
92 unsigned int m_portCount{0};
93 int m_portIndex{-1}; // Not connected
94 std::string m_peripheralLocation;
95
96 // GUI parameters
97 const uint32_t m_alignment;
98 std::vector<std::shared_ptr<CGUIListItem>> m_items;
99 bool m_bDirty{true};
100 };
101 } // namespace GAME
102 } // namespace KODI