mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 17:34:40 +02:00
Change API of InputManager: we don't care about key release events
This commit is contained in:
parent
ba5ef51269
commit
dba6c32109
@ -628,17 +628,15 @@ void GMenu2X::main() {
|
||||
}
|
||||
|
||||
// Handle other input events.
|
||||
InputManager::ButtonEvent event;
|
||||
InputManager::Button button;
|
||||
bool gotEvent;
|
||||
const bool wait = !animating;
|
||||
do {
|
||||
do {
|
||||
gotEvent = input.getEvent(&event, wait);
|
||||
} while (gotEvent && event.state != InputManager::PRESSED);
|
||||
gotEvent = input.getButton(&button, wait);
|
||||
} while (wait && !gotEvent);
|
||||
if (gotEvent) {
|
||||
for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
|
||||
if ((*it)->handleButtonPress(event.button)) {
|
||||
if ((*it)->handleButtonPress(button)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -117,20 +117,16 @@ void InputManager::readConfFile(const string &conffile) {
|
||||
}
|
||||
|
||||
InputManager::Button InputManager::waitForPressedButton() {
|
||||
ButtonEvent event;
|
||||
while (!waitForEvent(&event) || event.state != PRESSED);
|
||||
return event.button;
|
||||
Button button;
|
||||
while (!getButton(&button, true));
|
||||
return button;
|
||||
}
|
||||
|
||||
bool InputManager::waitForEvent(ButtonEvent *event) {
|
||||
return getEvent(event, true);
|
||||
bool InputManager::pollButton(Button *button) {
|
||||
return getButton(button, false);
|
||||
}
|
||||
|
||||
bool InputManager::pollEvent(ButtonEvent *event) {
|
||||
return getEvent(event, false);
|
||||
}
|
||||
|
||||
bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
|
||||
bool InputManager::getButton(Button *button, bool wait) {
|
||||
//TODO: when an event is processed, program a new event
|
||||
//in some time, and when it occurs, do a key repeat
|
||||
|
||||
@ -142,32 +138,18 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
|
||||
#endif
|
||||
|
||||
SDL_Event event;
|
||||
if (wait) {
|
||||
if (wait)
|
||||
SDL_WaitEvent(&event);
|
||||
} else {
|
||||
bevent->state = RELEASED;
|
||||
if (!SDL_PollEvent(&event)) {
|
||||
else if (!SDL_PollEvent(&event))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ButtonSource source;
|
||||
switch(event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
bevent->state = PRESSED;
|
||||
source = KEYBOARD;
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
bevent->state = RELEASED;
|
||||
source = KEYBOARD;
|
||||
break;
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
bevent->state = PRESSED;
|
||||
source = JOYSTICK;
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
bevent->state = RELEASED;
|
||||
source = JOYSTICK;
|
||||
break;
|
||||
#endif
|
||||
@ -191,8 +173,7 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
|
||||
|
||||
if (event.user.data1)
|
||||
free(event.user.data1);
|
||||
bevent->state = PRESSED;
|
||||
bevent->button = REPAINT;
|
||||
*button = REPAINT;
|
||||
return true;
|
||||
|
||||
default:
|
||||
@ -203,7 +184,7 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
|
||||
for (i = 0; i < BUTTON_TYPE_SIZE; i++) {
|
||||
if (buttonMap[i].source == KEYBOARD
|
||||
&& (unsigned int)event.key.keysym.sym == buttonMap[i].code) {
|
||||
bevent->button = static_cast<Button>(i);
|
||||
*button = static_cast<Button>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -212,7 +193,7 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
|
||||
for (i = 0; i < BUTTON_TYPE_SIZE; i++) {
|
||||
if (buttonMap[i].source == JOYSTICK
|
||||
&& (unsigned int)event.jbutton.button == buttonMap[i].code) {
|
||||
bevent->button = static_cast<Button>(i);
|
||||
*button = static_cast<Button>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -45,22 +45,17 @@ public:
|
||||
};
|
||||
#define BUTTON_TYPE_SIZE 10
|
||||
|
||||
enum ButtonState { PRESSED, RELEASED };
|
||||
struct ButtonEvent {
|
||||
Button button;
|
||||
ButtonState state;
|
||||
};
|
||||
|
||||
InputManager();
|
||||
~InputManager();
|
||||
|
||||
void init(const std::string &conffile, Menu *menu);
|
||||
bool waitForEvent(ButtonEvent *event);
|
||||
Button waitForPressedButton();
|
||||
bool pollEvent(ButtonEvent *event);
|
||||
bool getEvent(ButtonEvent *bevent, bool wait);
|
||||
bool pollButton(Button *button);
|
||||
bool getButton(Button *button, bool wait);
|
||||
|
||||
private:
|
||||
void readConfFile(const std::string &conffile);
|
||||
|
||||
enum ButtonSource { UNMAPPED, KEYBOARD, JOYSTICK };
|
||||
struct ButtonMapEntry {
|
||||
ButtonSource source;
|
||||
@ -69,8 +64,6 @@ private:
|
||||
|
||||
Menu *menu;
|
||||
|
||||
void readConfFile(const std::string &conffile);
|
||||
|
||||
ButtonMapEntry buttonMap[BUTTON_TYPE_SIZE];
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
std::vector<SDL_Joystick *> joysticks;
|
||||
|
@ -99,11 +99,10 @@ int MessageBox::exec() {
|
||||
|
||||
int result = -1;
|
||||
while (result < 0) {
|
||||
InputManager::ButtonEvent event;
|
||||
if (gmenu2x->input.pollEvent(&event)
|
||||
&& event.state == InputManager::PRESSED
|
||||
&& !buttons[event.button].empty()) {
|
||||
result = event.button;
|
||||
InputManager::Button button;
|
||||
if (gmenu2x->input.pollButton(&button)
|
||||
&& !buttons[button].empty()) {
|
||||
result = button;
|
||||
}
|
||||
|
||||
usleep(LOOP_DELAY);
|
||||
|
Loading…
Reference in New Issue
Block a user