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#ifndef NEWINPUT_H
21#define NEWINPUT_H
22
23#include <SDL/SDL.h>
24#include <sstream>
25
26using namespace std;
27
28typedef enum buttontype_e {
29    UP, DOWN, LEFT, RIGHT,
30    ACCEPT, CANCEL,
31    CLEAR, MANUAL,
32    ALTLEFT, ALTRIGHT,
33    MENU, SETTINGS,
34    VOLUP, VOLDOWN,
35    POWER, LOCK
36} buttontype_t;
37#define BUTTONTYPE_T_SIZE 16
38
39enum source_type_e {KEYBOARD, JOYSTICK};
40enum state_e {PRESSED, RELEASED};
41
42typedef struct {
43    source_type_e source;
44    Uint32 code;
45} input_t;
46
47typedef struct {
48    buttontype_t button;
49    state_e state;
50} bevent_t;
51
52
53class InputManager {
54private:
55    input_t ButtonMap[BUTTONTYPE_T_SIZE];
56
57    bool readConfFile(const string &conffile);
58    void initJoystick();
59    bool getEvent(bevent_t *bevent, bool wait);
60    buttontype_t waitForButton(enum state_e state);
61
62public:
63    InputManager();
64    ~InputManager();
65
66    void init(const string &conffile);
67    void waitForEvent(bevent_t *event);
68    buttontype_t waitForPressedButton();
69    buttontype_t waitForReleasedButton();
70    bool pollEvent(bevent_t *event);
71};
72
73#endif
74

Archive Download this file



interactive