| 1 | /* |
| 2 | =========================================================================== |
| 3 | blockattack - Block Attack - Rise of the Blocks |
| 4 | Copyright (C) 2005-2016 Poul Sander |
| 5 | |
| 6 | This program is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program. If not, see http://www.gnu.org/licenses/ |
| 18 | |
| 19 | Source information and contacts persons can be found at |
| 20 | http://www.blockattack.net |
| 21 | =========================================================================== |
| 22 | */ |
| 23 | |
| 24 | #ifndef GAMECONTROLLER_H |
| 25 | #define GAMECONTROLLER_H |
| 26 | |
| 27 | #include "SDL.h" |
| 28 | #include <vector> |
| 29 | #include <string> |
| 30 | |
| 31 | const int deadZoneLimit = 20000; |
| 32 | |
| 33 | void InitGameControllers(); |
| 34 | void UnInitGameControllers(); |
| 35 | |
| 36 | bool GameControllerIsDownEvent(const SDL_Event& event); |
| 37 | bool GameControllerIsUpEvent(const SDL_Event& event); |
| 38 | bool GameControllerIsLeftEvent(const SDL_Event& event); |
| 39 | bool GameControllerIsRightEvent(const SDL_Event& event); |
| 40 | |
| 41 | bool GameControllerExtIsPlayerDownEvent(int playerNumber, const SDL_Event& event); |
| 42 | bool GameControllerExtIsPlayerUpEvent(int playerNumber, const SDL_Event& event); |
| 43 | bool GameControllerExtIsPlayerLeftEvent(int playerNumber, const SDL_Event& event); |
| 44 | bool GameControllerExtIsPlayerRightEvent(int playerNumber, const SDL_Event& event); |
| 45 | bool GameControllerExtIsPlayerSwitchEvent(int playerNumber, const SDL_Event& event); |
| 46 | bool GameControllerExtIsPlayerPushEvent(int playerNumber, const SDL_Event& event); |
| 47 | bool GameControllerIsConnectionEvent(const SDL_Event& event); |
| 48 | void GameControllerSetVerbose(bool value); |
| 49 | const std::vector<std::string>& GetSupportedControllerNames(); |
| 50 | |
| 51 | /** |
| 52 | * Checks that the given event is in the dead zone. |
| 53 | * If it is in the dead zone. Then the dead zone variable for that axis will be set to true; |
| 54 | * Otherwise nothing is done |
| 55 | * @param event An SDL |
| 56 | */ |
| 57 | void GameControllerCheckDeadZone(const SDL_Event& event); |
| 58 | |
| 59 | /** |
| 60 | * Checks that the given axis on a given gamepad was in a dead zone last time checked. |
| 61 | * @param id The gamepad |
| 62 | * @param axis The axis on the gamepad |
| 63 | * @return true if the axis has been in the dead zone |
| 64 | */ |
| 65 | bool GameControllerIsInDeadZone(SDL_JoystickID id, int axis); |
| 66 | |
| 67 | /** |
| 68 | * Sets dead zone status on a given axis on a given gamepad |
| 69 | * @param id The gamepad |
| 70 | * @param axis The axis on the gamepad |
| 71 | * @param value Value to set. Should normally be false as true will be set by checkDeadZone |
| 72 | */ |
| 73 | void GameControllerSetIsInDeadZone(SDL_JoystickID id, int axis, bool value); |
| 74 | |
| 75 | #endif //GAMECONTROLLER |