Root/
| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2006 by Massimiliano Torromeo * |
| 3 | * massimiliano.torromeo@gmail.com * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (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 * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | #ifndef INPUTMANAGER_H |
| 22 | #define INPUTMANAGER_H |
| 23 | |
| 24 | #include <SDL.h> |
| 25 | #include <string> |
| 26 | #include <vector> |
| 27 | |
| 28 | #define INPUT_KEY_REPEAT_DELAY 250 |
| 29 | |
| 30 | class GMenu2X; |
| 31 | class Menu; |
| 32 | class PowerSaver; |
| 33 | class InputManager; |
| 34 | |
| 35 | enum EventCode { |
| 36 | REMOVE_LINKS, |
| 37 | OPEN_PACKAGE, |
| 38 | OPEN_PACKAGES_FROM_DIR, |
| 39 | REPAINT_MENU, |
| 40 | }; |
| 41 | |
| 42 | #ifndef SDL_JOYSTICK_DISABLED |
| 43 | #define AXIS_STATE_POSITIVE 0 |
| 44 | #define AXIS_STATE_NEGATIVE 1 |
| 45 | struct Joystick { |
| 46 | SDL_Joystick *joystick; |
| 47 | bool axisState[2][2]; |
| 48 | Uint8 hatState; |
| 49 | SDL_TimerID timer; |
| 50 | InputManager *inputManager; |
| 51 | }; |
| 52 | #endif |
| 53 | |
| 54 | class InputManager { |
| 55 | public: |
| 56 | enum Button { |
| 57 | UP, DOWN, LEFT, RIGHT, |
| 58 | ACCEPT, CANCEL, |
| 59 | ALTLEFT, ALTRIGHT, |
| 60 | MENU, SETTINGS, |
| 61 | // Events that are not actually buttons: |
| 62 | // (not included in BUTTON_TYPE_SIZE) |
| 63 | REPAINT, QUIT, |
| 64 | }; |
| 65 | #define BUTTON_TYPE_SIZE 10 |
| 66 | |
| 67 | InputManager(GMenu2X& gmenu2x, PowerSaver& powerSaver); |
| 68 | ~InputManager(); |
| 69 | |
| 70 | bool init(Menu *menu); |
| 71 | Button waitForPressedButton(); |
| 72 | void repeatRateChanged(); |
| 73 | Uint32 joystickRepeatCallback(Uint32 timeout, struct Joystick *joystick); |
| 74 | bool pollButton(Button *button); |
| 75 | bool getButton(Button *button, bool wait); |
| 76 | |
| 77 | private: |
| 78 | bool readConfFile(const std::string &conffile); |
| 79 | |
| 80 | struct ButtonMapEntry { |
| 81 | bool kb_mapped, js_mapped; |
| 82 | unsigned int kb_code, js_code; |
| 83 | }; |
| 84 | |
| 85 | GMenu2X& gmenu2x; |
| 86 | Menu *menu; |
| 87 | PowerSaver& powerSaver; |
| 88 | |
| 89 | ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE]; |
| 90 | #ifndef SDL_JOYSTICK_DISABLED |
| 91 | std::vector<Joystick> joysticks; |
| 92 | |
| 93 | void startTimer(Joystick *joystick); |
| 94 | void stopTimer(Joystick *joystick); |
| 95 | #endif |
| 96 | }; |
| 97 | |
| 98 | #endif |
| 99 |
Branches:
install_locations
master
opkrun
packages
