1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #if !defined(BACKEND_EVENTS_DEFAULT_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) 24 #define BACKEND_EVENTS_DEFAULT_H 25 26 #include "common/events.h" 27 #include "common/queue.h" 28 29 namespace Common { 30 #ifdef ENABLE_KEYMAPPER 31 class Keymapper; 32 #endif 33 #ifdef ENABLE_VKEYBD 34 class VirtualKeyboard; 35 #endif 36 } 37 38 39 class DefaultEventManager : public Common::EventManager, Common::EventObserver { 40 #ifdef ENABLE_VKEYBD 41 Common::VirtualKeyboard *_vk; 42 #endif 43 44 #ifdef ENABLE_KEYMAPPER 45 Common::Keymapper *_keymapper; 46 bool _remap; 47 #endif 48 49 Common::ArtificialEventSource _artificialEventSource; 50 51 Common::Queue<Common::Event> _eventQueue; notifyEvent(const Common::Event & ev)52 bool notifyEvent(const Common::Event &ev) override { 53 _eventQueue.push(ev); 54 return true; 55 } 56 57 Common::Point _mousePos; 58 int _buttonState; 59 int _modifierState; 60 bool _shouldQuit; 61 bool _shouldRTL; 62 bool _confirmExitDialogActive; 63 64 // for continuous events (keyDown) 65 enum { 66 kKeyRepeatInitialDelay = 400, 67 kKeyRepeatSustainDelay = 100 68 }; 69 70 bool _shouldGenerateKeyRepeatEvents; 71 Common::KeyState _currentKeyDown; 72 uint32 _keyRepeatTime; 73 74 void handleKeyRepeat(); 75 public: 76 DefaultEventManager(Common::EventSource *boss); 77 ~DefaultEventManager(); 78 79 virtual void init() override; 80 virtual bool pollEvent(Common::Event &event) override; 81 virtual void pushEvent(const Common::Event &event) override; 82 virtual void purgeMouseEvents() override; 83 getMousePos()84 virtual Common::Point getMousePos() const override { return _mousePos; } getButtonState()85 virtual int getButtonState() const override { return _buttonState; } getModifierState()86 virtual int getModifierState() const override { return _modifierState; } shouldQuit()87 virtual int shouldQuit() const override { return _shouldQuit; } shouldRTL()88 virtual int shouldRTL() const override { return _shouldRTL; } resetRTL()89 virtual void resetRTL() override { _shouldRTL = false; } 90 #ifdef FORCE_RTL resetQuit()91 virtual void resetQuit() override { _shouldQuit = false; } 92 #endif 93 94 #ifdef ENABLE_KEYMAPPER 95 // IMPORTANT NOTE: This is part of the WIP Keymapper. If you plan to use 96 // this, please talk to tsoliman and/or LordHoto. getKeymapper()97 virtual Common::Keymapper *getKeymapper() override { return _keymapper; } 98 #endif 99 100 /** 101 * Controls whether repeated key down events are generated while a key is pressed 102 * 103 * Backends that generate their own keyboard repeat events should disable this. 104 * 105 * @param generateKeyRepeatEvents 106 */ setGenerateKeyRepeatEvents(bool generateKeyRepeatEvents)107 void setGenerateKeyRepeatEvents(bool generateKeyRepeatEvents) { 108 _shouldGenerateKeyRepeatEvents = generateKeyRepeatEvents; 109 } 110 }; 111 112 #endif 113