diff options
author | Tarek Soliman | 2012-02-17 17:08:58 -0600 |
---|---|---|
committer | Tarek Soliman | 2012-02-20 06:49:22 -0600 |
commit | a0ba4eb569ae9ec0e05a7ba8532ab304e6852f84 (patch) | |
tree | 8512ff77abea1150250712ab1cb1b872c32b2f67 /common | |
parent | c0b04fdcaa0d357a0565a16ea7be74994e55da07 (diff) | |
download | scummvm-rg350-a0ba4eb569ae9ec0e05a7ba8532ab304e6852f84.tar.gz scummvm-rg350-a0ba4eb569ae9ec0e05a7ba8532ab304e6852f84.tar.bz2 scummvm-rg350-a0ba4eb569ae9ec0e05a7ba8532ab304e6852f84.zip |
KEYMAPPER: Rewrite the EventMapper API
Diffstat (limited to 'common')
-rw-r--r-- | common/EventDispatcher.cpp | 22 | ||||
-rw-r--r-- | common/events.h | 22 |
2 files changed, 21 insertions, 23 deletions
diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp index 6f36ee5f0f..4c7286bbb5 100644 --- a/common/EventDispatcher.cpp +++ b/common/EventDispatcher.cpp @@ -21,7 +21,6 @@ */ #include "common/events.h" -#include "common/textconsole.h" namespace Common { @@ -49,26 +48,15 @@ void EventDispatcher::dispatch() { dispatchPoll(); for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) { - const bool allowMapping = i->source->allowMapping(); - while (i->source->pollEvent(event)) { // 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. assert(_mapper); - if (allowMapping) { - 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; - } else { - dispatchEvent(Event(event)); + List<Event> mappedEvents = _mapper->mapEvent(event, i->source); + + for (List<Event>::iterator j = mappedEvents.begin(); j != mappedEvents.end(); ++j) { + const Event mappedEvent = *j; + dispatchEvent(mappedEvent); } } } diff --git a/common/events.h b/common/events.h index 48854b2abf..fec4d37d34 100644 --- a/common/events.h +++ b/common/events.h @@ -213,15 +213,25 @@ public: * * An example for this is the Keymapper. */ -class EventMapper : public EventSource, public EventObserver { +class EventMapper { public: - /** For event mappers resulting events should never be mapped */ - bool allowMapping() const { return false; } + virtual ~EventMapper() {} + + /** + * Map an incoming event to one or more action events + */ + virtual List<Event> mapEvent(const Event &ev, EventSource *source) = 0; }; -class DefaultEventMapper : public EventMapper, private ArtificialEventSource { - bool notifyEvent(const Event &ev) { ArtificialEventSource::addEvent(Event(ev)); return true; } - bool pollEvent(Event &ev) { return ArtificialEventSource::pollEvent(ev); } +class DefaultEventMapper : public EventMapper { +public: + // EventMapper interface + virtual List<Event> mapEvent(const Event &ev, EventSource *source) { + List<Event> events; + // just pass it through + events.push_back(ev); + return events; + } }; /** |