2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
2011-10-23 08:49:43 +03:00
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
2010-02-04 13:33:47 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
2011-10-23 08:49:43 +03:00
|
|
|
|
|
|
|
#ifndef INPUTMANAGER_H
|
|
|
|
#define INPUTMANAGER_H
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-10-23 08:54:10 +03:00
|
|
|
#include <SDL.h>
|
2010-09-17 23:34:26 +03:00
|
|
|
#include <sstream>
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-09-17 23:34:26 +03:00
|
|
|
using namespace std;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-09-17 23:34:26 +03:00
|
|
|
typedef enum buttontype_e {
|
2011-10-23 08:49:43 +03:00
|
|
|
UP, DOWN, LEFT, RIGHT,
|
|
|
|
ACCEPT, CANCEL,
|
|
|
|
CLEAR, MANUAL,
|
|
|
|
ALTLEFT, ALTRIGHT,
|
|
|
|
MENU, SETTINGS,
|
|
|
|
VOLUP, VOLDOWN,
|
|
|
|
POWER, LOCK
|
2010-09-17 23:34:26 +03:00
|
|
|
} buttontype_t;
|
|
|
|
#define BUTTONTYPE_T_SIZE 16
|
|
|
|
|
|
|
|
enum source_type_e {KEYBOARD, JOYSTICK};
|
|
|
|
enum state_e {PRESSED, RELEASED};
|
|
|
|
|
|
|
|
typedef struct {
|
2011-10-23 08:49:43 +03:00
|
|
|
source_type_e source;
|
|
|
|
Uint32 code;
|
2010-09-17 23:34:26 +03:00
|
|
|
} input_t;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
typedef struct {
|
2011-10-23 08:49:43 +03:00
|
|
|
buttontype_t button;
|
|
|
|
state_e state;
|
2010-09-17 23:34:26 +03:00
|
|
|
} bevent_t;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
class InputManager {
|
2011-10-23 08:49:43 +03:00
|
|
|
public:
|
|
|
|
InputManager();
|
|
|
|
~InputManager();
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-10-23 08:49:43 +03:00
|
|
|
void init(const string &conffile);
|
|
|
|
void waitForEvent(bevent_t *event);
|
|
|
|
buttontype_t waitForPressedButton();
|
|
|
|
buttontype_t waitForReleasedButton();
|
|
|
|
bool pollEvent(bevent_t *event);
|
2010-07-27 22:29:06 +03:00
|
|
|
|
2011-10-23 08:49:43 +03:00
|
|
|
private:
|
|
|
|
input_t ButtonMap[BUTTONTYPE_T_SIZE];
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-10-23 08:49:43 +03:00
|
|
|
bool readConfFile(const string &conffile);
|
|
|
|
void initJoystick();
|
|
|
|
bool getEvent(bevent_t *bevent, bool wait);
|
|
|
|
buttontype_t waitForButton(enum state_e state);
|
2010-02-04 13:33:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|