3
* Copyright (C) 2004-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
#include "inputevent.h"
37
* Number of buttons we can handle.
45
* Directions, to be used as bitmask values.
56
* Initializes the joystick subsystem.
61
* Returns the number of available joysticks.
63
static int getNumberOfJoysticks() A_WARN_UNUSED
64
{ return joystickCount; }
67
* Constructor, pass the number of the joystick the new object
70
explicit Joystick(const int no);
72
A_DELETE_COPY(Joystick)
80
bool isEnabled() const A_WARN_UNUSED
83
void setNumber(const int n);
85
static void setEnabled(const bool enabled)
86
{ mEnabled = enabled; }
88
static void getNames(std::vector <std::string> &names);
91
* Updates the direction and button information.
95
void startCalibration();
97
void finishCalibration();
99
bool isCalibrating() const A_WARN_UNUSED
100
{ return mCalibrating; }
102
bool buttonPressed(const unsigned char no) const A_WARN_UNUSED;
104
bool isUp() const A_WARN_UNUSED
105
{ return mEnabled && (mDirection & UP); }
107
bool isDown() const A_WARN_UNUSED
108
{ return mEnabled && (mDirection & DOWN); }
110
bool isLeft() const A_WARN_UNUSED
111
{ return mEnabled && (mDirection & LEFT); }
113
bool isRight() const A_WARN_UNUSED
114
{ return mEnabled && (mDirection & RIGHT); }
116
int getNumber() const A_WARN_UNUSED
119
void setUseInactive(const bool b)
120
{ mUseInactive = b; }
124
KeysVector *getActionVector(const SDL_Event &event) A_WARN_UNUSED;
126
KeysVector *getActionVectorByKey(const int i) A_WARN_UNUSED;
128
int getButtonFromEvent(const SDL_Event &event) const A_WARN_UNUSED;
130
bool isActionActive(const int index) const A_WARN_UNUSED;
132
bool validate() const A_WARN_UNUSED;
134
void handleRepeat(const int time);
136
void resetRepeat(const int key);
141
unsigned char mDirection;
143
bool mActiveButtons[MAX_BUTTONS];
145
SDL_Joystick *mJoystick;
158
KeyToActionMap mKeyToAction;
162
KeyTimeMap mKeyTimeMap;
165
* Is joystick support enabled.
167
static bool mEnabled;
168
static int joystickCount;
170
void doCalibration();
173
extern Joystick *joystick;