2013-11-15 06:43:21 -05:00
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
//
|
2015-03-29 20:31:42 -04:00
|
|
|
// Copyright (C) 2009-2015 Marianne Gagnon
|
2013-11-15 06:43:21 -05:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2014-10-27 19:14:04 -04:00
|
|
|
#ifndef HEADER_INPUT_DEVICE_HPP
|
|
|
|
#define HEADER_INPUT_DEVICE_HPP
|
2009-03-23 14:38:06 -04:00
|
|
|
|
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
#include "input/input.hpp"
|
2010-05-03 14:56:55 -04:00
|
|
|
#include "input/input_manager.hpp"
|
2010-02-18 16:28:32 -05:00
|
|
|
#include "states_screens/state_manager.hpp"
|
2010-09-09 01:28:18 -04:00
|
|
|
#include "utils/no_copy.hpp"
|
2014-10-27 19:14:04 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2014-10-29 01:41:04 -04:00
|
|
|
class DeviceConfig;
|
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \brief Input device type
|
|
|
|
* \ingroup input
|
|
|
|
*/
|
2009-03-23 14:38:06 -04:00
|
|
|
enum DeviceType
|
|
|
|
{
|
|
|
|
DT_KEYBOARD,
|
2016-11-09 20:42:56 -05:00
|
|
|
DT_GAMEPAD,
|
|
|
|
DT_MULTITOUCH
|
2009-03-23 14:38:06 -04:00
|
|
|
};
|
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \brief base class for input devices
|
|
|
|
* \ingroup input
|
|
|
|
*/
|
2010-09-09 01:28:18 -04:00
|
|
|
class InputDevice: public NoCopy
|
2009-03-23 14:38:06 -04:00
|
|
|
{
|
|
|
|
protected:
|
2020-04-20 12:14:32 -04:00
|
|
|
/** For SDL controller it's set false when it's unplugged. */
|
|
|
|
bool m_connected;
|
|
|
|
|
2014-10-27 18:00:22 -04:00
|
|
|
/** Device type (keyboard, gamepad). */
|
2009-03-23 14:38:06 -04:00
|
|
|
DeviceType m_type;
|
2014-10-27 18:00:22 -04:00
|
|
|
|
|
|
|
/** Which player is using this device. */
|
2010-02-18 16:28:32 -05:00
|
|
|
StateManager::ActivePlayer* m_player;
|
2014-10-27 18:00:22 -04:00
|
|
|
|
|
|
|
/** The configuration for this device. */
|
2009-08-06 15:05:26 -04:00
|
|
|
DeviceConfig* m_configuration;
|
2009-07-04 16:00:18 -04:00
|
|
|
|
2014-10-27 18:00:22 -04:00
|
|
|
/** If device has a name; unused for keyboards since AFAIK we
|
|
|
|
* can't tell keyboards apart. */
|
2011-10-05 00:12:00 -04:00
|
|
|
std::string m_name;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-10-27 18:00:22 -04:00
|
|
|
public:
|
|
|
|
|
|
|
|
InputDevice();
|
|
|
|
virtual ~InputDevice();
|
2014-10-28 02:04:00 -04:00
|
|
|
/** Invoked when this device it used. Verifies if the key/button that was
|
|
|
|
* pressed is associated with a binding. If yes, sets action and returns
|
|
|
|
* true; otherwise returns false. It can also modify the value used.
|
|
|
|
* \param type Type of input (e.g. IT_STICKMOTION, ...).
|
|
|
|
* \param id ID of the key that was pressed or of the axis that was
|
|
|
|
* triggered (depending on the value of the 'type' parameter).
|
|
|
|
* \param mode Used to determine whether to map menu actions or
|
|
|
|
* game actions
|
|
|
|
* \param[out] action The action associated to this input (only check
|
|
|
|
* this value if method returned true)
|
|
|
|
* \param[in,out] value The value associated with this type (typically
|
|
|
|
* how far a gamepad axis is moved).
|
|
|
|
*
|
|
|
|
* \return Whether the pressed key/button is bound with an action
|
|
|
|
*/
|
|
|
|
virtual bool processAndMapInput(Input::InputType type, const int id,
|
2014-10-27 18:00:22 -04:00
|
|
|
InputManager::InputDriverMode mode,
|
2014-10-28 02:04:00 -04:00
|
|
|
PlayerAction *action, int* value = NULL
|
|
|
|
) = 0;
|
2014-10-27 19:14:04 -04:00
|
|
|
|
2014-10-27 18:00:22 -04:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Sets which players uses this device; or pass NULL to say no player
|
|
|
|
* uses it. */
|
|
|
|
void setPlayer(StateManager::ActivePlayer* owner) { m_player = owner; }
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Sets the configuration to be used by this input device. */
|
2009-08-06 15:05:26 -04:00
|
|
|
void setConfiguration(DeviceConfig *config) {m_configuration = config;}
|
2014-10-27 18:00:22 -04:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns the configuration for this device. */
|
2009-08-06 15:05:26 -04:00
|
|
|
DeviceConfig *getConfiguration() {return m_configuration;}
|
|
|
|
|
2014-10-27 18:00:22 -04:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns the type of this device. */
|
2009-03-23 14:38:06 -04:00
|
|
|
DeviceType getType() const { return m_type; };
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-10-27 18:00:22 -04:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns the player using this device. */
|
2010-02-18 16:28:32 -05:00
|
|
|
StateManager::ActivePlayer *getPlayer() { return m_player; }
|
2014-10-27 18:00:22 -04:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns the name of this device. */
|
|
|
|
const std::string& getName() const { return m_name; }
|
2020-04-20 12:14:32 -04:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
void setConnected(bool val) { m_connected = val; }
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
bool isConnected() const { return m_connected; }
|
2014-10-27 18:00:22 -04:00
|
|
|
}; // class InputDevice
|
2009-03-23 14:38:06 -04:00
|
|
|
|
2009-03-30 23:15:41 -04:00
|
|
|
#endif
|