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>
|
2010-02-04 13:33:47 +02:00
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
enum ButtonState { PRESSED, RELEASED };
|
|
|
|
struct ButtonEvent {
|
|
|
|
Button button;
|
|
|
|
ButtonState state;
|
|
|
|
};
|
|
|
|
|
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);
|
2012-01-22 22:49:52 +02:00
|
|
|
bool waitForEvent(ButtonEvent *event);
|
2011-10-23 09:57:52 +03:00
|
|
|
Button waitForPressedButton();
|
|
|
|
Button waitForReleasedButton();
|
|
|
|
bool pollEvent(ButtonEvent *event);
|
2010-07-27 22:29:06 +03:00
|
|
|
|
2011-10-23 08:49:43 +03:00
|
|
|
private:
|
2011-10-23 11:38:39 +03:00
|
|
|
enum ButtonSource { UNMAPPED, KEYBOARD, JOYSTICK };
|
2011-10-23 09:57:52 +03:00
|
|
|
struct ButtonMapEntry {
|
|
|
|
ButtonSource source;
|
|
|
|
unsigned int code;
|
|
|
|
};
|
|
|
|
|
2013-07-16 20:36:18 +03:00
|
|
|
Menu *menu;
|
|
|
|
|
2011-10-23 11:38:39 +03:00
|
|
|
void readConfFile(const std::string &conffile);
|
2011-10-23 09:57:52 +03:00
|
|
|
bool getEvent(ButtonEvent *bevent, bool wait);
|
|
|
|
Button waitForButton(ButtonState state);
|
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
|
2011-10-23 10:59:22 +03:00
|
|
|
SDL_Joystick *joystick;
|
2011-10-23 11:12:11 +03:00
|
|
|
#endif
|
2010-02-04 13:33:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|