Mana
Loading...
Searching...
No Matches
joystick.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <SDL.h>
25
27{
28 public:
32 enum
33 {
34 MAX_BUTTONS = 6
35 };
36
40 enum
41 {
42 UP = 1,
43 DOWN = 2,
44 LEFT = 4,
45 RIGHT = 8
46 };
47
51 static void init();
52
56 static int getNumberOfJoysticks() { return joystickCount; }
57
62 Joystick(int no);
63
64 ~Joystick();
65
66 bool isEnabled() const { return mEnabled; }
67
68 void setEnabled(bool enabled) { mEnabled = enabled; }
69
73 void update();
74
75 void startCalibration();
76
77 void finishCalibration();
78
79 bool isCalibrating() const { return mCalibrating; }
80
81 bool buttonPressed(unsigned char no) const;
82
83 bool isUp() const { return mEnabled && (mDirection & UP); };
84 bool isDown() const { return mEnabled && (mDirection & DOWN); };
85 bool isLeft() const { return mEnabled && (mDirection & LEFT); };
86 bool isRight() const { return mEnabled && (mDirection & RIGHT); };
87
88 protected:
89 unsigned char mDirection;
91 SDL_Joystick *mJoystick;
92
96
97 static int joystickCount;
98
99 void doCalibration();
100};
SDL_Joystick * mJoystick
Definition joystick.h:91
bool mEnabled
Definition joystick.h:95
void finishCalibration()
Definition joystick.cpp:134
static void init()
Initializes the joystick subsystem.
Definition joystick.cpp:31
int mUpTolerance
Definition joystick.h:93
bool isCalibrating() const
Definition joystick.h:79
int mLeftTolerance
Definition joystick.h:93
bool isRight() const
Definition joystick.h:86
static int joystickCount
Definition joystick.h:97
bool isEnabled() const
Definition joystick.h:66
void startCalibration()
Definition joystick.cpp:108
bool isDown() const
Definition joystick.h:84
void update()
Updates the direction and button information.
Definition joystick.cpp:75
bool mButtons[MAX_BUTTONS]
Definition joystick.h:90
static int getNumberOfJoysticks()
Returns the number of available joysticks.
Definition joystick.h:56
bool isLeft() const
Definition joystick.h:85
void doCalibration()
Definition joystick.cpp:117
@ MAX_BUTTONS
Definition joystick.h:34
unsigned char mDirection
Definition joystick.h:89
bool isUp() const
Definition joystick.h:83
int mRightTolerance
Definition joystick.h:93
void setEnabled(bool enabled)
Definition joystick.h:68
bool mCalibrating
Definition joystick.h:94
bool buttonPressed(unsigned char no) const
Definition joystick.cpp:143
int mDownTolerance
Definition joystick.h:93