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 11:12:11 +03:00
|
|
|
#include <SDL.h>
|
2011-10-23 09:15:23 +03:00
|
|
|
#include <string>
|
2013-07-29 08:28:52 +03:00
|
|
|
#include <vector>
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-02-23 18:00:12 +02:00
|
|
|
#define INPUT_KEY_REPEAT_DELAY 250
|
|
|
|
#define INPUT_KEY_REPEAT_RATE 150
|
|
|
|
|
2013-07-16 20:36:18 +03:00
|
|
|
class Menu;
|
|
|
|
|
2013-07-22 06:52:35 +03:00
|
|
|
enum EventCode {
|
|
|
|
REMOVE_LINKS,
|
|
|
|
OPEN_PACKAGE,
|
|
|
|
OPEN_PACKAGES_FROM_DIR,
|
|
|
|
REPAINT_MENU,
|
|
|
|
};
|
|
|
|
|
2014-02-23 18:00:12 +02:00
|
|
|
#ifndef SDL_JOYSTICK_DISABLED
|
|
|
|
#define AXIS_STATE_POSITIVE 0
|
|
|
|
#define AXIS_STATE_NEGATIVE 1
|
|
|
|
struct Joystick {
|
|
|
|
SDL_Joystick *joystick;
|
|
|
|
bool axisState[2][2];
|
|
|
|
Uint8 hatState;
|
|
|
|
SDL_TimerID timer;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
class InputManager {
|
2011-10-23 08:49:43 +03:00
|
|
|
public:
|
2011-10-23 09:57:52 +03:00
|
|
|
enum Button {
|
|
|
|
UP, DOWN, LEFT, RIGHT,
|
|
|
|
ACCEPT, CANCEL,
|
|
|
|
ALTLEFT, ALTRIGHT,
|
|
|
|
MENU, SETTINGS,
|
2013-07-16 20:36:18 +03:00
|
|
|
REPAINT,
|
2011-10-23 09:57:52 +03:00
|
|
|
};
|
2013-07-29 08:33:48 +03:00
|
|
|
#define BUTTON_TYPE_SIZE 10
|
2011-10-23 09:57:52 +03:00
|
|
|
|
2011-10-23 08:49:43 +03:00
|
|
|
InputManager();
|
|
|
|
~InputManager();
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2013-07-16 20:36:18 +03:00
|
|
|
void init(const std::string &conffile, Menu *menu);
|
2011-10-23 09:57:52 +03:00
|
|
|
Button waitForPressedButton();
|
2013-09-07 18:00:57 +03:00
|
|
|
bool pollButton(Button *button);
|
|
|
|
bool getButton(Button *button, bool wait);
|
2010-07-27 22:29:06 +03:00
|
|
|
|
2011-10-23 08:49:43 +03:00
|
|
|
private:
|
2013-09-07 18:00:57 +03:00
|
|
|
void readConfFile(const std::string &conffile);
|
|
|
|
|
2011-10-23 09:57:52 +03:00
|
|
|
struct ButtonMapEntry {
|
2014-04-20 17:08:17 +03:00
|
|
|
bool kb_mapped, js_mapped;
|
|
|
|
unsigned int kb_code, js_code;
|
2011-10-23 09:57:52 +03:00
|
|
|
};
|
|
|
|
|
2013-07-16 20:36:18 +03:00
|
|
|
Menu *menu;
|
|
|
|
|
2011-10-23 10:59:22 +03:00
|
|
|
ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
|
2011-10-23 11:12:11 +03:00
|
|
|
#ifndef SDL_JOYSTICK_DISABLED
|
2013-09-07 18:09:56 +03:00
|
|
|
std::vector<Joystick> joysticks;
|
2014-02-23 18:00:12 +02:00
|
|
|
|
|
|
|
void startTimer(Joystick *joystick);
|
|
|
|
void stopTimer(Joystick *joystick);
|
2011-10-23 11:12:11 +03:00
|
|
|
#endif
|
2010-02-04 13:33:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|