mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-03 09:23:37 +00:00
- Adapt DefaultEventManager to use Common::ArtificialEventSource
- Adapt Keymapper to implement EventMapper interface svn-id: r42727
This commit is contained in:
parent
eeaafdf4ee
commit
ef71667403
@ -206,14 +206,13 @@ DefaultEventManager::DefaultEventManager(Common::EventSource *boss) :
|
||||
#endif
|
||||
#ifdef ENABLE_KEYMAPPER
|
||||
_keymapper = new Common::Keymapper(this);
|
||||
// EventDispatcher will automatically free the keymapper
|
||||
g_eventDispatcher.registerMapper(_keymapper);
|
||||
_remap = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
DefaultEventManager::~DefaultEventManager() {
|
||||
#ifdef ENABLE_KEYMAPPER
|
||||
delete _keymapper;
|
||||
#endif
|
||||
#ifdef ENABLE_VKEYBD
|
||||
delete _vk;
|
||||
#endif
|
||||
@ -388,21 +387,6 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||
if (!_eventQueue.empty()) {
|
||||
event = _eventQueue.pop();
|
||||
result = true;
|
||||
|
||||
#ifdef ENABLE_KEYMAPPER
|
||||
if (result) {
|
||||
// send key press events to keymapper
|
||||
if (event.type == Common::EVENT_KEYDOWN) {
|
||||
if (_keymapper->mapKeyDown(event.kbd)) {
|
||||
result = false;
|
||||
}
|
||||
} else if (event.type == Common::EVENT_KEYUP) {
|
||||
if (_keymapper->mapKeyUp(event.kbd)) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_recordMode != kPassthrough) {
|
||||
|
@ -51,26 +51,7 @@ class DefaultEventManager : public Common::EventManager, Common::EventObserver {
|
||||
bool _remap;
|
||||
#endif
|
||||
|
||||
// TODO: Maybe move this to common/events.h, when other code uses something similar
|
||||
class ArtificialEventSource : public Common::EventSource {
|
||||
private:
|
||||
Common::Queue<Common::Event> _artificialEventQueue;
|
||||
public:
|
||||
void addEvent(const Common::Event &ev) {
|
||||
_artificialEventQueue.push(ev);
|
||||
}
|
||||
|
||||
bool pollEvent(Common::Event &ev) {
|
||||
if (!_artificialEventQueue.empty()) {
|
||||
ev = _artificialEventQueue.pop();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool allowMapping() const { return false; }
|
||||
} _artificialEventSource;
|
||||
Common::ArtificialEventSource _artificialEventSource;
|
||||
|
||||
Common::Queue<Common::Event> _eventQueue;
|
||||
bool notifyEvent(const Common::Event &ev) {
|
||||
|
@ -168,6 +168,15 @@ void Keymapper::popKeymap() {
|
||||
_activeMaps.pop();
|
||||
}
|
||||
|
||||
bool Keymapper::notifyEvent(const Common::Event &ev) {
|
||||
if (ev.type == Common::EVENT_KEYDOWN)
|
||||
return mapKeyDown(ev.kbd);
|
||||
else if (ev.type == Common::EVENT_KEYUP)
|
||||
return mapKeyUp(ev.kbd);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Keymapper::mapKeyDown(const KeyState& key) {
|
||||
return mapKey(key, true);
|
||||
}
|
||||
@ -255,7 +264,7 @@ void Keymapper::executeAction(const Action *action, bool keyDown) {
|
||||
}
|
||||
|
||||
evt.mouse = _eventMan->getMousePos();
|
||||
_eventMan->pushEvent(evt);
|
||||
addEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
namespace Common {
|
||||
|
||||
class Keymapper {
|
||||
class Keymapper : public Common::EventMapper, private Common::ArtificialEventSource {
|
||||
public:
|
||||
|
||||
struct MapRecord {
|
||||
@ -134,6 +134,10 @@ public:
|
||||
*/
|
||||
void popKeymap();
|
||||
|
||||
// Implementation of the EventMapper interface
|
||||
bool notifyEvent(const Common::Event &ev);
|
||||
bool pollEvent(Common::Event &ev) { return Common::ArtificialEventSource::pollEvent(ev); }
|
||||
|
||||
/**
|
||||
* @brief Map a key press event.
|
||||
* If the active keymap contains a Action mapped to the given key, then
|
||||
|
Loading…
x
Reference in New Issue
Block a user