ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

EventMapper.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/events.h"
00024 
00025 #include "common/system.h"
00026 #include "common/textconsole.h"
00027 
00028 namespace Common {
00029 
00030 List<Event> DefaultEventMapper::mapEvent(const Event &ev, EventSource *source) {
00031     List<Event> events;
00032     Event mappedEvent;
00033 #ifdef ENABLE_VKEYBD
00034     // Trigger virtual keyboard on long press of more than 1 second
00035     // of middle mouse button.
00036     const uint32 vkeybdTime = 1000;
00037 
00038     static uint32 vkeybdThen = 0;
00039 
00040     if (ev.type == EVENT_MBUTTONDOWN) {
00041         vkeybdThen = g_system->getMillis();
00042     }
00043 
00044     if (ev.type == EVENT_MBUTTONUP) {
00045         if ((g_system->getMillis() - vkeybdThen) >= vkeybdTime) {
00046             mappedEvent.type = EVENT_VIRTUAL_KEYBOARD;
00047 
00048             // Avoid blocking event from engine.
00049             addDelayedEvent(100, ev);
00050         }
00051     }
00052 #endif
00053 
00054     if (ev.type == EVENT_KEYDOWN) {
00055         if (ev.kbd.hasFlags(KBD_CTRL) && ev.kbd.keycode == KEYCODE_F5) {
00056             mappedEvent.type = EVENT_MAINMENU;
00057         }
00058 #ifdef ENABLE_VKEYBD
00059         else if (ev.kbd.hasFlags(KBD_CTRL) && ev.kbd.keycode == KEYCODE_F7) {
00060             mappedEvent.type = EVENT_VIRTUAL_KEYBOARD;
00061 
00062             // Avoid blocking CTRL-F7 events from engine.
00063             addDelayedEvent(100, ev);
00064         }
00065 #endif
00066 #ifdef ENABLE_KEYMAPPER
00067         else if (ev.kbd.hasFlags(KBD_CTRL) && ev.kbd.keycode == KEYCODE_F8) {
00068             mappedEvent.type = EVENT_KEYMAPPER_REMAP;
00069 
00070             // Avoid blocking CTRL-F8 events from engine.
00071             addDelayedEvent(100, ev);
00072         }
00073 #endif
00074     }
00075 
00076     // if it didn't get mapped, just pass it through
00077     if (mappedEvent.type == EVENT_INVALID)
00078         mappedEvent = ev;
00079 
00080 #ifdef ENABLE_KEYMAPPER
00081     // TODO: this check is not needed post-split
00082     if (mappedEvent.type == EVENT_CUSTOM_BACKEND_HARDWARE) {
00083         warning("EVENT_CUSTOM_BACKEND_HARDWARE was not mapped");
00084         return List<Event>();
00085     }
00086 #endif
00087 
00088     events.push_back(mappedEvent);
00089     return events;
00090 }
00091 
00092 
00093 void DefaultEventMapper::addDelayedEvent(uint32 millis, Event ev) {
00094     if (_delayedEvents.empty()) {
00095         _delayedEffectiveTime = g_system->getMillis() + millis;
00096         millis = 0;
00097     }
00098     DelayedEventsEntry entry = DelayedEventsEntry(millis, ev);
00099     _delayedEvents.push(entry);
00100 }
00101 
00102 List<Event> DefaultEventMapper::getDelayedEvents() {
00103     List<Event> events;
00104 
00105     if (_delayedEvents.empty())
00106         return events;
00107 
00108     uint32 now = g_system->getMillis();
00109 
00110     while (!_delayedEvents.empty() && now >= _delayedEffectiveTime) {
00111         DelayedEventsEntry entry = _delayedEvents.pop();
00112         if (!_delayedEvents.empty())
00113             _delayedEffectiveTime += _delayedEvents.front().timerOffset;
00114         events.push_back(entry.event);
00115     }
00116     return events;
00117 }
00118 
00119 } // namespace Common


Generated on Sat Mar 16 2019 05:01:30 for ResidualVM by doxygen 1.7.1
curved edge   curved edge