SuperTuxKart
input_device.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 //
3 // Copyright (C) 2009-2015 Marianne Gagnon
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_INPUT_DEVICE_HPP
20 #define HEADER_INPUT_DEVICE_HPP
21 
22 
23 #include "input/input.hpp"
24 #include "input/input_manager.hpp"
25 #include "states_screens/state_manager.hpp"
26 #include "utils/no_copy.hpp"
27 
28 #include <string>
29 
30 class DeviceConfig;
31 
37 {
38  DT_KEYBOARD,
39  DT_GAMEPAD,
40  DT_MULTITOUCH
41 };
42 
47 class InputDevice: public NoCopy
48 {
49 protected:
52 
55 
58 
61 
64  std::string m_name;
65 
66 public:
67 
68  InputDevice();
69  virtual ~InputDevice();
85  virtual bool processAndMapInput(Input::InputType type, const int id,
86  InputManager::InputDriverMode mode,
87  PlayerAction *action, int* value = NULL
88  ) = 0;
89 
90  // ------------------------------------------------------------------------
93  void setPlayer(StateManager::ActivePlayer* owner) { m_player = owner; }
94 
95  // ------------------------------------------------------------------------
97  void setConfiguration(DeviceConfig *config) {m_configuration = config;}
98 
99  // ------------------------------------------------------------------------
102 
103  // ------------------------------------------------------------------------
105  DeviceType getType() const { return m_type; };
106 
107  // ------------------------------------------------------------------------
110  // ------------------------------------------------------------------------
112  const std::string& getName() const { return m_name; }
113  // ------------------------------------------------------------------------
114  void setConnected(bool val) { m_connected = val; }
115  // ------------------------------------------------------------------------
116  bool isConnected() const { return m_connected; }
117 }; // class InputDevice
118 
119 #endif
DeviceType m_type
Device type (keyboard, gamepad).
Definition: input_device.hpp:54
virtual bool processAndMapInput(Input::InputType type, const int id, InputManager::InputDriverMode mode, PlayerAction *action, int *value=NULL)=0
Invoked when this device it used.
Represents a player that is currently playing.
Definition: state_manager.hpp:75
contains the key bindings information related to one input device
Definition: device_config.hpp:41
DeviceConfig * getConfiguration()
Returns the configuration for this device.
Definition: input_device.hpp:101
void setPlayer(StateManager::ActivePlayer *owner)
Sets which players uses this device; or pass NULL to say no player uses it.
Definition: input_device.hpp:93
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:116
const std::string & getName() const
Returns the name of this device.
Definition: input_device.hpp:112
void setConfiguration(DeviceConfig *config)
Sets the configuration to be used by this input device.
Definition: input_device.hpp:97
bool m_connected
For SDL controller it&#39;s set false when it&#39;s unplugged.
Definition: input_device.hpp:51
StateManager::ActivePlayer * getPlayer()
Returns the player using this device.
Definition: input_device.hpp:109
DeviceType
Input device type.
Definition: input_device.hpp:36
base class for input devices
Definition: input_device.hpp:47
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
DeviceConfig * m_configuration
The configuration for this device.
Definition: input_device.hpp:60
StateManager::ActivePlayer * m_player
Which player is using this device.
Definition: input_device.hpp:57
std::string m_name
If device has a name; unused for keyboards since AFAIK we can&#39;t tell keyboards apart.
Definition: input_device.hpp:64
DeviceType getType() const
Returns the type of this device.
Definition: input_device.hpp:105