Root/src/inputmanager.h

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
28class Menu;
29
30enum EventCode {
31    REMOVE_LINKS,
32    OPEN_PACKAGE,
33    OPEN_PACKAGES_FROM_DIR,
34    REPAINT_MENU,
35};
36
37class InputManager {
38public:
39    enum Button {
40        UP, DOWN, LEFT, RIGHT,
41        ACCEPT, CANCEL,
42        ALTLEFT, ALTRIGHT,
43        MENU, SETTINGS,
44        REPAINT,
45    };
46    #define BUTTON_TYPE_SIZE 10
47
48    InputManager();
49    ~InputManager();
50
51    void init(const std::string &conffile, Menu *menu);
52    Button waitForPressedButton();
53    bool pollButton(Button *button);
54    bool getButton(Button *button, bool wait);
55
56private:
57    void readConfFile(const std::string &conffile);
58
59    enum ButtonSource { UNMAPPED, KEYBOARD, JOYSTICK };
60    struct ButtonMapEntry {
61        ButtonSource source;
62        unsigned int code;
63    };
64
65    Menu *menu;
66
67    ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
68#ifndef SDL_JOYSTICK_DISABLED
69#define AXIS_STATE_POSITIVE 0
70#define AXIS_STATE_NEGATIVE 1
71    struct Joystick {
72        SDL_Joystick *joystick;
73        bool axisState[2][2];
74    };
75
76    std::vector<Joystick> joysticks;
77#endif
78};
79
80#endif
81

Archive Download this file



interactive