KEYMAPPER: EventMapper must now eat all events

This commit is contained in:
Tarek Soliman 2012-02-17 12:17:51 -06:00
parent ae992bebe3
commit e7ade8ae05
3 changed files with 34 additions and 13 deletions

View File

@ -181,12 +181,24 @@ void Keymapper::popKeymap(const char *name) {
}
bool Keymapper::notifyEvent(const Common::Event &ev) {
bool mapped = false;
if (ev.type == Common::EVENT_KEYDOWN)
return mapKeyDown(ev.kbd);
mapped = mapKeyDown(ev.kbd);
else if (ev.type == Common::EVENT_KEYUP)
return mapKeyUp(ev.kbd);
mapped = mapKeyUp(ev.kbd);
if (mapped)
return true;
else
return false;
return mapEvent(ev);
}
bool Keymapper::mapEvent(const Common::Event &ev) {
// pass through - copy the event
Event evt = ev;
addEvent(evt);
return true;
}
bool Keymapper::mapKeyDown(const KeyState& key) {

View File

@ -163,6 +163,12 @@ public:
*/
bool mapKeyUp(const KeyState& key);
/**
* Map non-key incoming events
* @param ev incoming event
*/
bool mapEvent(const Common::Event &ev);
/**
* Enable/disable the keymapper
*/

View File

@ -21,6 +21,7 @@
*/
#include "common/events.h"
#include "common/textconsole.h"
namespace Common {
@ -54,18 +55,20 @@ void EventDispatcher::dispatch() {
// We only try to process the events via the setup event mapper, when
// we have a setup mapper and when the event source allows mapping.
if (_mapper && allowMapping) {
if (_mapper->notifyEvent(event)) {
// We allow the event mapper to create multiple events, when
// eating an event.
while (_mapper->pollEvent(event))
dispatchEvent(event);
bool mapped = _mapper->notifyEvent(event);
// EventMappers must map all events
if (!mapped)
error("Event [%u] was not mapped by the EventMapper!", event.type);
// We allow the event mapper to create multiple events, when
// eating an event.
while (_mapper->pollEvent(event))
dispatchEvent(event);
// Try getting another event from the current EventSource.
continue;
}
// Try getting another event from the current EventSource.
continue;
} else {
dispatchEvent(event);
}
dispatchEvent(event);
}
}
}