ScummVM API documentation
events.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef COMMON_EVENTS_H
23#define COMMON_EVENTS_H
24
25#include "common/keyboard.h"
26#include "common/path.h"
27#include "common/queue.h"
28#include "common/rect.h"
29#include "common/noncopyable.h"
30
31#include "common/list.h"
32#include "common/singleton.h"
33
34namespace Common {
35
50 EVENT_INVALID = 0,
57 EVENT_LBUTTONDOWN = 4,
58 EVENT_LBUTTONUP = 5,
59 EVENT_RBUTTONDOWN = 6,
60 EVENT_RBUTTONUP = 7,
61 EVENT_WHEELUP = 8,
62 EVENT_WHEELDOWN = 9,
63 EVENT_MBUTTONDOWN = 13,
64 EVENT_MBUTTONUP = 14,
65
66 EVENT_MAINMENU = 15,
67 EVENT_RETURN_TO_LAUNCHER = 16,
68 EVENT_MUTE = 17,
69
70 EVENT_QUIT = 10,
71 EVENT_SCREEN_CHANGED = 11,
72
75
85
86 EVENT_CUSTOM_BACKEND_ACTION_START = 18,
87 EVENT_CUSTOM_BACKEND_ACTION_END = 19,
88 EVENT_CUSTOM_BACKEND_ACTION_AXIS = 34,
89 EVENT_CUSTOM_ENGINE_ACTION_START = 20,
90 EVENT_CUSTOM_ENGINE_ACTION_END = 21,
91
92 EVENT_VIRTUAL_KEYBOARD = 22,
93
94 EVENT_DROP_FILE = 23,
95
96 EVENT_JOYAXIS_MOTION = 24,
97 EVENT_JOYBUTTON_DOWN = 25,
98 EVENT_JOYBUTTON_UP = 26,
99
100 EVENT_CLIPBOARD_UPDATE = 27,
101
102 EVENT_CUSTOM_BACKEND_HARDWARE = 28,
103 EVENT_DEBUGGER = 29,
104
112 EVENT_X1BUTTONUP = 31,
113 EVENT_X2BUTTONDOWN = 32,
114 EVENT_X2BUTTONUP = 33,
115
118 EVENT_FOCUS_LOST = 37,
119
126 EVENT_HOTSPOTS_HIDE = 39,
127
137 EVENT_USER_LAST_AVAILABLE = 9999
138};
139
140const int16 JOYAXIS_MIN = -32768;
141const int16 JOYAXIS_MAX = 32767;
142
148 byte axis;
150 int16 position;
157 uint8 button;
158
159 JoystickState() : axis(0), position(0), button(0) {}
160};
161
166 JOYSTICK_BUTTON_INVALID,
167 JOYSTICK_BUTTON_A,
168 JOYSTICK_BUTTON_B,
169 JOYSTICK_BUTTON_X,
170 JOYSTICK_BUTTON_Y,
171 JOYSTICK_BUTTON_BACK,
172 JOYSTICK_BUTTON_GUIDE,
173 JOYSTICK_BUTTON_START,
174 JOYSTICK_BUTTON_LEFT_STICK,
175 JOYSTICK_BUTTON_RIGHT_STICK,
176 JOYSTICK_BUTTON_LEFT_SHOULDER,
177 JOYSTICK_BUTTON_RIGHT_SHOULDER,
178 JOYSTICK_BUTTON_DPAD_UP,
179 JOYSTICK_BUTTON_DPAD_DOWN,
180 JOYSTICK_BUTTON_DPAD_LEFT,
181 JOYSTICK_BUTTON_DPAD_RIGHT,
182 JOYSTICK_BUTTON_DPAD_CENTER
183};
184
189 JOYSTICK_AXIS_LEFT_STICK_X,
190 JOYSTICK_AXIS_LEFT_STICK_Y,
191 JOYSTICK_AXIS_RIGHT_STICK_X,
192 JOYSTICK_AXIS_RIGHT_STICK_Y,
193 JOYSTICK_AXIS_LEFT_TRIGGER,
194 JOYSTICK_AXIS_RIGHT_TRIGGER,
195 JOYSTICK_AXIS_HAT_X,
196 JOYSTICK_AXIS_HAT_Y
197};
198
203 MOUSE_BUTTON_LEFT = 0,
204 MOUSE_BUTTON_RIGHT = 1,
205 MOUSE_BUTTON_MIDDLE = 2,
206 MOUSE_WHEEL_UP = 3,
207 MOUSE_WHEEL_DOWN = 4,
208 MOUSE_BUTTON_X1 = 5,
209 MOUSE_BUTTON_X2 = 6
210};
212typedef uint32 CustomEventType;
213
218struct Event {
219
222
229
235
243
246
249
254
260
261 Event() : type(EVENT_INVALID), kbdRepeat(false), customType(0) {
262 }
263};
264
270bool isMouseEvent(const Event &event);
271
279public:
280 virtual ~EventSource();
281
288 virtual bool pollEvent(Event &event) = 0;
289
298 virtual bool allowMapping() const { return true; }
299};
300
308protected:
309 Queue<Event> _artificialEventQueue;
310public:
312 void addEvent(const Event &ev) {
313 _artificialEventQueue.push(ev);
314 }
315
316 bool pollEvent(Event &ev) override {
317 if (!_artificialEventQueue.empty()) {
318 ev = _artificialEventQueue.pop();
319 return true;
320 } else {
321 return false;
322 }
323 }
324
329 bool allowMapping() const override { return false; }
330};
331
338public:
339 virtual ~EventObserver();
340
354 virtual bool notifyEvent(const Event &event) = 0;
355
359 virtual void notifyPoll() { }
360};
361
368public:
369 virtual ~EventMapper();
370
374 virtual bool mapEvent(const Event &ev, List<Event> &mappedEvents) = 0;
375};
376
391public:
394
401 void dispatch();
402
408
412 void registerMapper(EventMapper *mapper, bool autoFree);
413
420
424 void registerSource(EventSource *source, bool autoFree);
425
432
437 void ignoreSources(bool ignore);
438
445 void registerObserver(EventObserver *obs, uint priority, bool autoFree, bool listenPolls = false);
446
453private:
454 struct Entry {
455 bool autoFree;
456 bool ignore;
457 };
458
459 struct MapperEntry : public Entry {
460 EventMapper *mapper;
461 };
462
463 List<MapperEntry> _mappers;
464
465 struct SourceEntry : public Entry {
466 EventSource *source;
467 };
468
469 List<SourceEntry> _sources;
470
471 struct ObserverEntry : public Entry {
472 uint priority;
473 EventObserver *observer;
474 bool poll;
475 };
476
477 List<ObserverEntry> _observers;
478
479 void dispatchEvent(const Event &event);
480 void dispatchPoll();
481};
482
483class Keymap;
484class Keymapper;
485
492public:
493 virtual ~EventManager();
494
495 enum {
496 LBUTTON = 1 << MOUSE_BUTTON_LEFT,
497 RBUTTON = 1 << MOUSE_BUTTON_RIGHT
498 };
499
500
505 virtual void init() {}
506
512 virtual bool pollEvent(Event &event) = 0;
513
517 virtual void pushEvent(const Event &event) = 0;
518
522 virtual void purgeMouseEvents() = 0;
523
527 virtual void purgeKeyboardEvents() = 0;
528
530 virtual Point getMousePos() const = 0;
531
537 virtual int getButtonState() const = 0;
538
540 virtual int getModifierState() const = 0;
541
545 virtual int shouldQuit() const = 0;
546
550 virtual int shouldReturnToLauncher() const = 0;
551
556 virtual void resetReturnToLauncher() = 0;
557 virtual void resetQuit() = 0;
558 // Optional: check whether a given key is currently pressed ????
559 //virtual bool isKeyPressed(int keycode) = 0;
560
561 // TODO: Keyboard repeat support?
562
563 // TODO: Consider removing OSystem::getScreenChangeID and
564 // replacing it by a generic getScreenChangeID method here
566 virtual Keymapper *getKeymapper() = 0;
568 virtual Keymap *getGlobalKeymap() = 0;
569
570 enum {
586 };
587
591 EventDispatcher *getEventDispatcher() { return &_dispatcher; }
592
593protected:
594 EventDispatcher _dispatcher;
595};
596
604
607} // End of namespace Common
608
609#endif
Definition: events.h:307
bool allowMapping() const override
Definition: events.h:329
void addEvent(const Event &ev)
Definition: events.h:312
bool pollEvent(Event &ev) override
Definition: events.h:316
Definition: events.h:390
void registerObserver(EventObserver *obs, uint priority, bool autoFree, bool listenPolls=false)
void registerMapper(EventMapper *mapper, bool autoFree)
void registerSource(EventSource *source, bool autoFree)
void ignoreSources(bool ignore)
void unregisterSource(EventSource *source)
void unregisterMapper(EventMapper *mapper)
void unregisterObserver(EventObserver *obs)
Definition: events.h:491
virtual bool pollEvent(Event &event)=0
EventDispatcher * getEventDispatcher()
Definition: events.h:591
virtual Keymap * getGlobalKeymap()=0
virtual int shouldQuit() const =0
virtual void init()
Definition: events.h:505
virtual void pushEvent(const Event &event)=0
virtual void purgeKeyboardEvents()=0
virtual int getButtonState() const =0
virtual Keymapper * getKeymapper()=0
@ kEventRemapperPriority
Definition: events.h:585
@ kEventRecorderPriority
Definition: events.h:580
@ kEventManPriority
Definition: events.h:575
virtual int shouldReturnToLauncher() const =0
virtual void resetReturnToLauncher()=0
virtual void purgeMouseEvents()=0
virtual int getModifierState() const =0
virtual Point getMousePos() const =0
Definition: events.h:367
virtual bool mapEvent(const Event &ev, List< Event > &mappedEvents)=0
Definition: events.h:337
virtual void notifyPoll()
Definition: events.h:359
virtual bool notifyEvent(const Event &event)=0
Definition: events.h:278
virtual bool pollEvent(Event &event)=0
virtual bool allowMapping() const
Definition: events.h:298
Definition: keymap.h:66
Definition: keymapper.h:44
Definition: list.h:44
Definition: noncopyable.h:39
Definition: path.h:52
Definition: queue.h:42
JoystickButton
Definition: events.h:165
EventType
Definition: events.h:49
MouseButton
Definition: events.h:202
uint32 CustomEventType
Definition: events.h:212
bool isMouseEvent(const Event &event)
EventSource * makeKeyboardRepeatingEventSource(EventSource *eventSource)
JoystickAxis
Definition: events.h:188
@ EVENT_FOCUS_GAINED
Definition: events.h:117
@ EVENT_PREDICTIVE_DIALOG
Definition: events.h:84
@ EVENT_KEYDOWN
Definition: events.h:52
@ EVENT_USER_FIRST_AVAILABLE
Definition: events.h:136
@ EVENT_INPUT_CHANGED
Definition: events.h:74
@ EVENT_MOUSEMOVE
Definition: events.h:56
@ EVENT_HOTSPOTS_SHOW
Definition: events.h:125
@ EVENT_KEYUP
Definition: events.h:54
@ EVENT_X1BUTTONDOWN
Definition: events.h:111
Definition: algorithm.h:29
Definition: events.h:218
Point mouse
Definition: events.h:242
bool kbdRepeat
Definition: events.h:228
CustomEventType customType
Definition: events.h:245
EventType type
Definition: events.h:221
JoystickState joystick
Definition: events.h:259
Common::Path path
Definition: events.h:248
Common::Point relMouse
Definition: events.h:253
KeyState kbd
Definition: events.h:234
Definition: events.h:146
int16 position
Definition: events.h:150
byte axis
Definition: events.h:148
uint8 button
Definition: events.h:157
Definition: keyboard.h:294
Definition: rect.h:144