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_RETURN_TO_LAUNCHER = 16,
00064     EVENT_MUTE = 17,
00065 
00066     EVENT_QUIT = 10,
00067     EVENT_SCREEN_CHANGED = 11,
00068 
00070     EVENT_INPUT_CHANGED  = 35,
00071 
00079     EVENT_PREDICTIVE_DIALOG = 12,
00080 
00081     EVENT_CUSTOM_BACKEND_ACTION_START = 18,
00082     EVENT_CUSTOM_BACKEND_ACTION_END   = 19,
00083     EVENT_CUSTOM_BACKEND_ACTION_AXIS  = 34,
00084     EVENT_CUSTOM_ENGINE_ACTION_START  = 20,
00085     EVENT_CUSTOM_ENGINE_ACTION_END    = 21,
00086 
00087 #ifdef ENABLE_VKEYBD
00088     EVENT_VIRTUAL_KEYBOARD = 22,
00089 #endif
00090 
00091     EVENT_DROP_FILE = 23,
00092 
00093     EVENT_JOYAXIS_MOTION = 24,
00094     EVENT_JOYBUTTON_DOWN = 25,
00095     EVENT_JOYBUTTON_UP = 26,
00096 
00097     EVENT_CLIPBOARD_UPDATE = 27,
00098 
00099     EVENT_CUSTOM_BACKEND_HARDWARE = 28,
00100     EVENT_DEBUGGER = 29,
00101 
00108     EVENT_X1BUTTONDOWN = 30,
00109     EVENT_X1BUTTONUP = 31,
00110     EVENT_X2BUTTONDOWN = 32,
00111     EVENT_X2BUTTONUP = 33,
00112 
00114     EVENT_FOCUS_GAINED = 36,
00115     EVENT_FOCUS_LOST = 37
00116 };
00117 
00118 const int16 JOYAXIS_MIN = -32768;
00119 const int16 JOYAXIS_MAX = 32767;
00120 
00124 struct JoystickState {
00126     byte axis;
00128     int16 position;
00135     uint8 button;
00136 
00137     JoystickState() : axis(0), position(0), button(0) {}
00138 };
00139 
00143 enum JoystickButton {
00144     JOYSTICK_BUTTON_A,
00145     JOYSTICK_BUTTON_B,
00146     JOYSTICK_BUTTON_X,
00147     JOYSTICK_BUTTON_Y,
00148     JOYSTICK_BUTTON_BACK,
00149     JOYSTICK_BUTTON_GUIDE,
00150     JOYSTICK_BUTTON_START,
00151     JOYSTICK_BUTTON_LEFT_STICK,
00152     JOYSTICK_BUTTON_RIGHT_STICK,
00153     JOYSTICK_BUTTON_LEFT_SHOULDER,
00154     JOYSTICK_BUTTON_RIGHT_SHOULDER,
00155     JOYSTICK_BUTTON_DPAD_UP,
00156     JOYSTICK_BUTTON_DPAD_DOWN,
00157     JOYSTICK_BUTTON_DPAD_LEFT,
00158     JOYSTICK_BUTTON_DPAD_RIGHT,
00159 /* START of ResidualVM-specific code */
00160     // Left and right trigger button events are generated in place of the axis events for now
00161     JOYSTICK_BUTTON_LEFT_TRIGGER,
00162     JOYSTICK_BUTTON_RIGHT_TRIGGER
00163 /* END of ResidualVM-specific code */
00164 };
00165 
00169 enum JoystickAxis {
00170     JOYSTICK_AXIS_LEFT_STICK_X,
00171     JOYSTICK_AXIS_LEFT_STICK_Y,
00172     JOYSTICK_AXIS_RIGHT_STICK_X,
00173     JOYSTICK_AXIS_RIGHT_STICK_Y,
00174     JOYSTICK_AXIS_LEFT_TRIGGER,
00175     JOYSTICK_AXIS_RIGHT_TRIGGER
00176 };
00177 
00181 enum MouseButton {
00182     MOUSE_BUTTON_LEFT   = 0,
00183     MOUSE_BUTTON_RIGHT  = 1,
00184     MOUSE_BUTTON_MIDDLE = 2,
00185     MOUSE_WHEEL_UP      = 3,
00186     MOUSE_WHEEL_DOWN    = 4,
00187     MOUSE_BUTTON_X1     = 5,
00188     MOUSE_BUTTON_X2     = 6
00189 };
00190 
00191 typedef uint32 CustomEventType;
00192 
00197 struct Event {
00198 
00200     EventType type;
00201 
00207     bool kbdRepeat;
00208 
00213     KeyState kbd;
00214 
00221     Point mouse;
00222 
00223     CustomEventType customType;
00224 
00225     /* The path of the file or directory dragged to the ScummVM window */
00226     Common::String path;
00227 
00233     Common::Point relMouse;
00234 
00239     JoystickState joystick;
00240 
00241     Event() : type(EVENT_INVALID), kbdRepeat(false), customType(0) {
00242     }
00243 };
00244 
00250 bool isMouseEvent(const Event &event);
00251 
00258 class EventSource {
00259 public:
00260     virtual ~EventSource();
00261 
00268     virtual bool pollEvent(Event &event) = 0;
00269 
00278     virtual bool allowMapping() const { return true; }
00279 };
00280 
00287 class ArtificialEventSource : public EventSource {
00288 protected:
00289     Queue<Event> _artificialEventQueue;
00290 public:
00291     void addEvent(const Event &ev) {
00292         _artificialEventQueue.push(ev);
00293     }
00294 
00295     bool pollEvent(Event &ev) {
00296     if (!_artificialEventQueue.empty()) {
00297             ev = _artificialEventQueue.pop();
00298             return true;
00299         } else {
00300             return false;
00301         }
00302     }
00303 
00308     virtual bool allowMapping() const { return false; }
00309 };
00310 
00316 class EventObserver {
00317 public:
00318     virtual ~EventObserver();
00319 
00333     virtual bool notifyEvent(const Event &event) = 0;
00334 
00338     virtual void notifyPoll() { }
00339 };
00340 
00346 class EventMapper {
00347 public:
00348     virtual ~EventMapper();
00349 
00353     virtual List<Event> mapEvent(const Event &ev) = 0;
00354 };
00355 
00369 class EventDispatcher {
00370 public:
00371     EventDispatcher();
00372     ~EventDispatcher();
00373 
00380     void dispatch();
00381 
00386     void clearEvents();
00387 
00391     void registerMapper(EventMapper *mapper);
00392 
00396     void registerSource(EventSource *source, bool autoFree);
00397 
00403     void unregisterSource(EventSource *source);
00404 
00411     void registerObserver(EventObserver *obs, uint priority, bool autoFree, bool listenPolls = false);
00412 
00418     void unregisterObserver(EventObserver *obs);
00419 private:
00420     EventMapper *_mapper;
00421 
00422     struct Entry {
00423         bool autoFree;
00424     };
00425 
00426     struct SourceEntry : public Entry {
00427         EventSource *source;
00428     };
00429 
00430     List<SourceEntry> _sources;
00431 
00432     struct ObserverEntry : public Entry {
00433         uint priority;
00434         EventObserver *observer;
00435         bool poll;
00436     };
00437 
00438     List<ObserverEntry> _observers;
00439 
00440     void dispatchEvent(const Event &event);
00441     void dispatchPoll();
00442 };
00443 
00444 class Keymap;
00445 class Keymapper;
00446 
00452 class EventManager : NonCopyable {
00453 public:
00454     virtual ~EventManager();
00455 
00456     enum {
00457         LBUTTON = 1 << MOUSE_BUTTON_LEFT,
00458         RBUTTON = 1 << MOUSE_BUTTON_RIGHT
00459     };
00460 
00461 
00466     virtual void init() {}
00467 
00473     virtual bool pollEvent(Event &event) = 0;
00474 
00478     virtual void pushEvent(const Event &event) = 0;
00479 
00483     virtual void purgeMouseEvents() = 0;
00484 
00486     virtual Point getMousePos() const = 0;
00487 
00493     virtual int getButtonState() const = 0;
00494 
00496     virtual int getModifierState() const = 0;
00497 
00502     virtual int shouldQuit() const = 0;
00503 
00507     virtual int shouldReturnToLauncher() const = 0;
00508 
00513     virtual void resetReturnToLauncher() = 0;
00514 #ifdef FORCE_RETURN_TO_LAUNCHER
00515     virtual void resetQuit() = 0;
00516 #endif
00517     // Optional: check whether a given key is currently pressed ????
00518     //virtual bool isKeyPressed(int keycode) = 0;
00519 
00520     // TODO: Keyboard repeat support?
00521 
00522     // TODO: Consider removing OSystem::getScreenChangeID and
00523     // replacing it by a generic getScreenChangeID method here
00524 
00525     virtual Keymapper *getKeymapper() = 0;
00526     virtual Keymap *getGlobalKeymap() = 0;
00527 
00528     enum {
00533         kEventManPriority = 0,
00538         kEventRecorderPriority = 1,
00543         kEventRemapperPriority = 999
00544     };
00545 
00549     EventDispatcher *getEventDispatcher() { return &_dispatcher; }
00550 
00551 protected:
00552     EventDispatcher _dispatcher;
00553 };
00554 
00561 EventSource *makeKeyboardRepeatingEventSource(EventSource *eventSource);
00562 
00563 } // End of namespace Common
00564 
00565 #endif


Generated on Sat Sep 19 2020 05:01:02 for ResidualVM by doxygen 1.7.1
curved edge   curved edge