xbmc
ControllerGrid.h
1 /*
2  * Copyright (C) 2017-2018 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 "ControllerTree.h"
12 #include "games/controllers/ControllerTypes.h"
13 
14 #include <string>
15 #include <vector>
16 
17 namespace KODI
18 {
19 namespace GAME
20 {
27 {
28  bool bVisible = true;
29  bool bConnected = false;
30  ControllerPtr controller; // Mandatory if connected
31  PORT_TYPE portType = PORT_TYPE::UNKNOWN; // Optional
32  std::string address; // Optional
33  ControllerVector compatible; // Compatible controllers
34 };
35 
42 {
43  std::vector<ControllerVertex> vertices;
44 };
45 
51 using ControllerGrid = std::vector<ControllerColumn>;
52 
59 {
60 public:
61  CControllerGrid() = default;
62  CControllerGrid(const CControllerGrid& other) = default;
63  ~CControllerGrid();
64 
68  void SetControllerTree(const CControllerTree& controllerTree);
69 
73  unsigned int GetWidth() const { return static_cast<unsigned int>(m_grid.size()); }
74 
81  unsigned int GetHeight() const { return m_height; }
82 
86  const ControllerGrid& GetGrid() const { return m_grid; }
87 
93  ControllerVector GetControllers(unsigned int playerIndex) const;
94 
95 private:
99  enum class GRID_DIRECTION
100  {
101  RIGHT,
102  DOWN,
103  };
104 
113  static unsigned int AddPorts(const PortVec& ports, ControllerGrid& grid);
114 
125  static unsigned int AddController(const CPortNode& port,
126  unsigned int height,
127  std::vector<ControllerVertex>& column,
128  ControllerGrid& grid);
129 
141  static unsigned int AddHub(const PortVec& ports,
142  unsigned int height,
143  bool bSkipFirst,
144  ControllerGrid& grid);
145 
151  static void AddInvisible(std::vector<ControllerVertex>& column);
152 
159  static void SetHeight(unsigned int height, ControllerGrid& grid);
160 
169  static GRID_DIRECTION GetDirection(const CControllerNode& node);
170 
171  ControllerGrid m_grid;
172  unsigned int m_height = 0;
173 };
174 } // namespace GAME
175 } // namespace KODI
unsigned int GetHeight() const
Get the height (deepest controller) of the controller grid.
Definition: ControllerGrid.h:81
Node in the controller tree.
Definition: ControllerNode.h:31
std::vector< ControllerColumn > ControllerGrid
Collection of controllers in a grid layout.
Definition: ControllerGrid.h:51
Column of controllers in the grid.
Definition: ControllerGrid.h:41
const ControllerGrid & GetGrid() const
Access the controller grid.
Definition: ControllerGrid.h:86
Collection of nodes that can be connected to this port.
Definition: PortNode.h:28
unsigned int GetWidth() const
Get the width of the controller grid.
Definition: ControllerGrid.h:73
Definition: AudioDecoder.h:18
std::shared_ptr< CController > ControllerPtr
Smart pointer to a game controller (CController)
Definition: ControllerTypes.h:25
A branch in the controller tree.
Definition: ControllerHub.h:25
Class to encapsulate grid operations.
Definition: ControllerGrid.h:58
Vertex in the grid of controllers.
Definition: ControllerGrid.h:26
PORT_TYPE
Type of input provided by a hardware or controller port.
Definition: ControllerTypes.h:39
std::vector< ControllerPtr > ControllerVector
Vector of smart pointers to a game controller (CController)
Definition: ControllerTypes.h:32