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

events.h

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 #ifndef COMMON_EVENTS_H
00024 #define COMMON_EVENTS_H
00025 
00026 #include "common/keyboard.h"
00027 #include "common/queue.h"
00028 #include "common/rect.h"
00029 #include "common/noncopyable.h"
00030 
00031 #include "common/list.h"
00032 #include "common/singleton.h"
00033 
00034 namespace Common {
00035 
00045 enum EventType {
00046     EVENT_INVALID = 0,
00048     EVENT_KEYDOWN = 1,
00050     EVENT_KEYUP = 2,
00052     EVENT_MOUSEMOVE = 3,
00053     EVENT_LBUTTONDOWN = 4,
00054     EVENT_LBUTTONUP = 5,
00055     EVENT_RBUTTONDOWN = 6,
00056     EVENT_RBUTTONUP = 7,
00057     EVENT_WHEELUP = 8,
00058     EVENT_WHEELDOWN = 9,
00059     EVENT_MBUTTONDOWN = 13,
00060     EVENT_MBUTTONUP = 14,
00061 
00062     EVENT_MAINMENU = 15,
00063     EVENT_RTL = 16,
00064     EVENT_MUTE = 17,
00065 
00066     EVENT_QUIT = 10,
00067     EVENT_SCREEN_CHANGED = 11,
00075     EVENT_PREDICTIVE_DIALOG = 12,
00076 
00077 #ifdef ENABLE_KEYMAPPER
00078     // IMPORTANT NOTE: This is part of the WIP Keymapper. If you plan to use
00079     // this, please talk to tsoliman and/or LordHoto.
00080     EVENT_CUSTOM_BACKEND_ACTION = 18,
00081     EVENT_CUSTOM_BACKEND_HARDWARE = 21,
00082     EVENT_GUI_REMAP_COMPLETE_ACTION = 22,
00083     EVENT_KEYMAPPER_REMAP = 19,
00084 #endif
00085 #ifdef ENABLE_VKEYBD
00086     EVENT_VIRTUAL_KEYBOARD = 20,
00087 #endif
00088 
00089     EVENT_DROP_FILE = 23,
00090     EVENT_CLIPBOARD_UPDATE = 27
00091 
00092 /* START of ResidualVM-specific code */
00093     ,
00094     EVENT_JOYAXIS_MOTION = 24,
00095     EVENT_JOYBUTTON_DOWN = 25,
00096     EVENT_JOYBUTTON_UP = 26
00097 };
00098 
00099 const int16 JOYAXIS_MIN = -32768;
00100 const int16 JOYAXIS_MAX = 32767;
00101 
00105 struct JoystickState {
00107     byte axis;
00109     int16 position;
00116     byte button;
00117 };
00118 
00122 enum JoystickButton {
00123     JOYSTICK_BUTTON_A,
00124     JOYSTICK_BUTTON_B,
00125     JOYSTICK_BUTTON_X,
00126     JOYSTICK_BUTTON_Y,
00127     JOYSTICK_BUTTON_BACK,
00128     JOYSTICK_BUTTON_GUIDE,
00129     JOYSTICK_BUTTON_START,
00130     JOYSTICK_BUTTON_LEFT_STICK,
00131     JOYSTICK_BUTTON_RIGHT_STICK,
00132     JOYSTICK_BUTTON_LEFT_SHOULDER,
00133     JOYSTICK_BUTTON_RIGHT_SHOULDER,
00134     JOYSTICK_BUTTON_DPAD_UP,
00135     JOYSTICK_BUTTON_DPAD_DOWN,
00136     JOYSTICK_BUTTON_DPAD_LEFT,
00137     JOYSTICK_BUTTON_DPAD_RIGHT,
00138     // Left and right trigger button events are generated in place of the axis events for now
00139     JOYSTICK_BUTTON_LEFT_TRIGGER,
00140     JOYSTICK_BUTTON_RIGHT_TRIGGER
00141 };
00142 
00143 /* END of ResidualVM-specific code */
00144 
00145 typedef uint32 CustomEventType;
00146 
00151 struct Event {
00152 
00154     EventType type;
00155 
00161     bool kbdRepeat;
00162 
00167     KeyState kbd;
00168 
00175     Point mouse;
00176 
00177 #ifdef ENABLE_KEYMAPPER
00178     // IMPORTANT NOTE: This is part of the WIP Keymapper. If you plan to use
00179     // this, please talk to tsoliman and/or LordHoto.
00180     CustomEventType customType;
00181 #endif
00182 
00183     /* The path of the file or directory dragged to the ScummVM window */
00184     Common::String path;
00185 
00191     Common::Point relMouse;
00192 
00199     JoystickState joystick;
00200 
00201     Event() : type(EVENT_INVALID), kbdRepeat(false) {
00202 #ifdef ENABLE_KEYMAPPER
00203         customType = 0;
00204 #endif
00205     }
00206 };
00207 
00214 class EventSource {
00215 public:
00216     virtual ~EventSource() {}
00217 
00224     virtual bool pollEvent(Event &event) = 0;
00225 
00234     virtual bool allowMapping() const { return true; }
00235 };
00236 
00243 class ArtificialEventSource : public EventSource {
00244 protected:
00245     Queue<Event> _artificialEventQueue;
00246 public:
00247     void addEvent(const Event &ev) {
00248         _artificialEventQueue.push(ev);
00249     }
00250 
00251     bool pollEvent(Event &ev) {
00252     if (!_artificialEventQueue.empty()) {
00253             ev = _artificialEventQueue.pop();
00254             return true;
00255         } else {
00256             return false;
00257         }
00258     }
00259 
00264     virtual bool allowMapping() const { return false; }
00265 };
00266 
00272 class EventObserver {
00273 public:
00274     virtual ~EventObserver() {}
00275 
00289     virtual bool notifyEvent(const Event &event) = 0;
00290 
00297     virtual bool notifyPoll() { return false; }
00298 };
00299 
00305 class EventMapper {
00306 public:
00307     virtual ~EventMapper() {}
00308 
00312     virtual List<Event> mapEvent(const Event &ev, EventSource *source) = 0;
00313 
00314     virtual List<Event> getDelayedEvents() = 0;
00315 };
00316 
00317 class DefaultEventMapper : public EventMapper {
00318 public:
00319     DefaultEventMapper() : _delayedEvents(), _delayedEffectiveTime(0) {}
00320     // EventMapper interface
00321     virtual List<Event> mapEvent(const Event &ev, EventSource *source);
00322     virtual List<Event> getDelayedEvents();
00323 protected:
00324     virtual void addDelayedEvent(uint32 millis, Event ev);
00325 
00326     struct DelayedEventsEntry {
00327         const uint32 timerOffset;
00328         const Event event;
00329         DelayedEventsEntry(const uint32 offset, const Event ev) : timerOffset(offset), event(ev) { }
00330     };
00331 
00332     Queue<DelayedEventsEntry> _delayedEvents;
00333     uint32 _delayedEffectiveTime;
00334 };
00335 
00349 class EventDispatcher {
00350 public:
00351     EventDispatcher();
00352     ~EventDispatcher();
00353 
00360     void dispatch();
00361 
00366     void clearEvents();
00367 
00382     void registerMapper(EventMapper *mapper, bool autoFree = true);
00383 
00387     EventMapper *queryMapper() const { return _mapper; }
00388 
00392     void registerSource(EventSource *source, bool autoFree);
00393 
00399     void unregisterSource(EventSource *source);
00400 
00407     void registerObserver(EventObserver *obs, uint priority, bool autoFree, bool listenPolls = false);
00408 
00414     void unregisterObserver(EventObserver *obs);
00415 private:
00416     bool _autoFreeMapper;
00417     EventMapper *_mapper;
00418 
00419     struct Entry {
00420         bool autoFree;
00421     };
00422 
00423     struct SourceEntry : public Entry {
00424         EventSource *source;
00425     };
00426 
00427     List<SourceEntry> _sources;
00428 
00429     struct ObserverEntry : public Entry {
00430         uint priority;
00431         EventObserver *observer;
00432         bool poll;
00433     };
00434 
00435     List<ObserverEntry> _observers;
00436 
00437     void dispatchEvent(const Event &event);
00438     void dispatchPoll();
00439 };
00440 
00441 class Keymapper;
00442 
00448 class EventManager : NonCopyable {
00449 public:
00450     EventManager() {}
00451     virtual ~EventManager() {}
00452 
00453     enum {
00454         LBUTTON = 1 << 0,
00455         RBUTTON = 1 << 1
00456     };
00457 
00458 
00463     virtual void init() {}
00464 
00470     virtual bool pollEvent(Event &event) = 0;
00471 
00475     virtual void pushEvent(const Event &event) = 0;
00476 
00480     virtual void purgeMouseEvents() = 0;
00481 
00483     virtual Point getMousePos() const = 0;
00484 
00490     virtual int getButtonState() const = 0;
00491 
00493     virtual int getModifierState() const = 0;
00494 
00499     virtual int shouldQuit() const = 0;
00500 
00504     virtual int shouldRTL() const = 0;
00505 
00510     virtual void resetRTL() = 0;
00511 #ifdef FORCE_RTL
00512     virtual void resetQuit() = 0;
00513 #endif
00514     // Optional: check whether a given key is currently pressed ????
00515     //virtual bool isKeyPressed(int keycode) = 0;
00516 
00517     // TODO: Keyboard repeat support?
00518 
00519     // TODO: Consider removing OSystem::getScreenChangeID and
00520     // replacing it by a generic getScreenChangeID method here
00521 #ifdef ENABLE_KEYMAPPER
00522     virtual Keymapper *getKeymapper() = 0;
00523 #endif
00524 
00525     enum {
00530         kEventManPriority = 0,
00535         kEventRecorderPriority = 1
00536     };
00537 
00541     EventDispatcher *getEventDispatcher() { return &_dispatcher; }
00542 
00543 protected:
00544     EventDispatcher _dispatcher;
00545 };
00546 
00547 } // End of namespace Common
00548 
00549 #endif


Generated on Sat Feb 22 2020 05:00:42 for ResidualVM by doxygen 1.7.1
curved edge   curved edge