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 
00091 /* START of ResidualVM-specific code */
00092     ,
00093     EVENT_JOYAXIS_MOTION = 24,
00094     EVENT_JOYBUTTON_DOWN = 25,
00095     EVENT_JOYBUTTON_UP = 26
00096 };
00097 
00098 const int16 JOYAXIS_MIN = -32768;
00099 const int16 JOYAXIS_MAX = 32767;
00100 
00104 struct JoystickState {
00106     byte axis;
00108     int16 position;
00115     byte button;
00116 };
00117 
00121 enum JoystickButton {
00122     JOYSTICK_BUTTON_A,
00123     JOYSTICK_BUTTON_B,
00124     JOYSTICK_BUTTON_X,
00125     JOYSTICK_BUTTON_Y,
00126     JOYSTICK_BUTTON_BACK,
00127     JOYSTICK_BUTTON_GUIDE,
00128     JOYSTICK_BUTTON_START,
00129     JOYSTICK_BUTTON_LEFT_STICK,
00130     JOYSTICK_BUTTON_RIGHT_STICK,
00131     JOYSTICK_BUTTON_LEFT_SHOULDER,
00132     JOYSTICK_BUTTON_RIGHT_SHOULDER,
00133     JOYSTICK_BUTTON_DPAD_UP,
00134     JOYSTICK_BUTTON_DPAD_DOWN,
00135     JOYSTICK_BUTTON_DPAD_LEFT,
00136     JOYSTICK_BUTTON_DPAD_RIGHT,
00137     // Left and right trigger button events are generated in place of the axis events for now
00138     JOYSTICK_BUTTON_LEFT_TRIGGER,
00139     JOYSTICK_BUTTON_RIGHT_TRIGGER
00140 };
00141 
00142 /* END of ResidualVM-specific code */
00143 
00144 typedef uint32 CustomEventType;
00145 
00150 struct Event {
00151 
00153     EventType type;
00154 
00160     bool kbdRepeat;
00161 
00166     KeyState kbd;
00167 
00174     Point mouse;
00175 
00176 #ifdef ENABLE_KEYMAPPER
00177     // IMPORTANT NOTE: This is part of the WIP Keymapper. If you plan to use
00178     // this, please talk to tsoliman and/or LordHoto.
00179     CustomEventType customType;
00180 #endif
00181 
00182     /* The path of the file or directory dragged to the ScummVM window */
00183     Common::String path;
00184 
00190     Common::Point relMouse;
00191 
00198     JoystickState joystick;
00199 
00200     Event() : type(EVENT_INVALID), kbdRepeat(false) {
00201 #ifdef ENABLE_KEYMAPPER
00202         customType = 0;
00203 #endif
00204     }
00205 };
00206 
00213 class EventSource {
00214 public:
00215     virtual ~EventSource() {}
00216 
00223     virtual bool pollEvent(Event &event) = 0;
00224 
00233     virtual bool allowMapping() const { return true; }
00234 };
00235 
00242 class ArtificialEventSource : public EventSource {
00243 protected:
00244     Queue<Event> _artificialEventQueue;
00245 public:
00246     void addEvent(const Event &ev) {
00247         _artificialEventQueue.push(ev);
00248     }
00249 
00250     bool pollEvent(Event &ev) {
00251     if (!_artificialEventQueue.empty()) {
00252             ev = _artificialEventQueue.pop();
00253             return true;
00254         } else {
00255             return false;
00256         }
00257     }
00258 
00263     virtual bool allowMapping() const { return false; }
00264 };
00265 
00271 class EventObserver {
00272 public:
00273     virtual ~EventObserver() {}
00274 
00288     virtual bool notifyEvent(const Event &event) = 0;
00289 
00296     virtual bool notifyPoll() { return false; }
00297 };
00298 
00304 class EventMapper {
00305 public:
00306     virtual ~EventMapper() {}
00307 
00311     virtual List<Event> mapEvent(const Event &ev, EventSource *source) = 0;
00312 
00313     virtual List<Event> getDelayedEvents() = 0;
00314 };
00315 
00316 class DefaultEventMapper : public EventMapper {
00317 public:
00318     DefaultEventMapper() : _delayedEvents(), _delayedEffectiveTime(0) {}
00319     // EventMapper interface
00320     virtual List<Event> mapEvent(const Event &ev, EventSource *source);
00321     virtual List<Event> getDelayedEvents();
00322 protected:
00323     virtual void addDelayedEvent(uint32 millis, Event ev);
00324 
00325     struct DelayedEventsEntry {
00326         const uint32 timerOffset;
00327         const Event event;
00328         DelayedEventsEntry(const uint32 offset, const Event ev) : timerOffset(offset), event(ev) { }
00329     };
00330 
00331     Queue<DelayedEventsEntry> _delayedEvents;
00332     uint32 _delayedEffectiveTime;
00333 };
00334 
00348 class EventDispatcher {
00349 public:
00350     EventDispatcher();
00351     ~EventDispatcher();
00352 
00359     void dispatch();
00360 
00365     void clearEvents();
00366 
00381     void registerMapper(EventMapper *mapper, bool autoFree = true);
00382 
00386     EventMapper *queryMapper() const { return _mapper; }
00387 
00391     void registerSource(EventSource *source, bool autoFree);
00392 
00398     void unregisterSource(EventSource *source);
00399 
00406     void registerObserver(EventObserver *obs, uint priority, bool autoFree, bool listenPolls = false);
00407 
00413     void unregisterObserver(EventObserver *obs);
00414 private:
00415     bool _autoFreeMapper;
00416     EventMapper *_mapper;
00417 
00418     struct Entry {
00419         bool autoFree;
00420     };
00421 
00422     struct SourceEntry : public Entry {
00423         EventSource *source;
00424     };
00425 
00426     List<SourceEntry> _sources;
00427 
00428     struct ObserverEntry : public Entry {
00429         uint priority;
00430         EventObserver *observer;
00431         bool poll;
00432     };
00433 
00434     List<ObserverEntry> _observers;
00435 
00436     void dispatchEvent(const Event &event);
00437     void dispatchPoll();
00438 };
00439 
00440 class Keymapper;
00441 
00447 class EventManager : NonCopyable {
00448 public:
00449     EventManager() {}
00450     virtual ~EventManager() {}
00451 
00452     enum {
00453         LBUTTON = 1 << 0,
00454         RBUTTON = 1 << 1
00455     };
00456 
00457 
00462     virtual void init() {}
00463 
00469     virtual bool pollEvent(Event &event) = 0;
00470 
00474     virtual void pushEvent(const Event &event) = 0;
00475 
00479     virtual void purgeMouseEvents() = 0;
00480 
00482     virtual Point getMousePos() const = 0;
00483 
00489     virtual int getButtonState() const = 0;
00490 
00492     virtual int getModifierState() const = 0;
00493 
00498     virtual int shouldQuit() const = 0;
00499 
00503     virtual int shouldRTL() const = 0;
00504 
00509     virtual void resetRTL() = 0;
00510 #ifdef FORCE_RTL
00511     virtual void resetQuit() = 0;
00512 #endif
00513     // Optional: check whether a given key is currently pressed ????
00514     //virtual bool isKeyPressed(int keycode) = 0;
00515 
00516     // TODO: Keyboard repeat support?
00517 
00518     // TODO: Consider removing OSystem::getScreenChangeID and
00519     // replacing it by a generic getScreenChangeID method here
00520 #ifdef ENABLE_KEYMAPPER
00521     virtual Keymapper *getKeymapper() = 0;
00522 #endif
00523 
00524     enum {
00529         kEventManPriority = 0,
00534         kEventRecorderPriority = 1
00535     };
00536 
00540     EventDispatcher *getEventDispatcher() { return &_dispatcher; }
00541 
00542 protected:
00543     EventDispatcher _dispatcher;
00544 };
00545 
00546 } // End of namespace Common
00547 
00548 #endif


Generated on Sat Sep 14 2019 05:01:00 for ResidualVM by doxygen 1.7.1
curved edge   curved edge