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 CHEWY_EVENTS_H
23 #define CHEWY_EVENTS_H
24 
25 #include "common/events.h"
26 #include "common/queue.h"
27 #include "graphics/screen.h"
28 
29 namespace Chewy {
30 
31 struct KbdInfo {
32  char _keyCode = '\0';
33  int _scanCode = Common::KEYCODE_INVALID;
34 };
35 
36 typedef void (*TimerProc)();
37 
39  struct TimerRecord {
40  TimerProc _proc;
41  uint32 _interval;
42  uint32 _nextFrameTime;
43  TimerRecord(TimerProc proc, uint32 interval) : _proc(proc), _interval(interval), _nextFrameTime(0) {
44  }
45  };
47 
48 private:
49  void init_timer_handler();
50  static void timer_handler();
51 
52  void handleMouseEvent(const Common::Event &event);
53  void handleKbdEvent(const Common::Event &event);
54 
55  TimerList _timers;
56  Common::Queue<Common::Event> _pendingEvents;
57  Common::Queue<Common::Event> _pendingKeyEvents;
58  int16 _hotkey = Common::KEYCODE_INVALID;
59 
63  void checkTimers();
64 
68  static void updateScreen();
69 
75  void addTimer(TimerProc proc, uint interval) {
76  _timers.push_back(TimerRecord(proc, interval));
77  }
78 
82  void processEvents();
83 
87  void handleEvent(const Common::Event &event);
88 
89 public:
90  KbdInfo _kbInfo;
91  Common::Point _mousePos;
92  bool _flag1 = false;
93  bool _flag2 = false;
94 
95  EventsManager(Graphics::Screen *screen, uint refreshRate = 1000 / 50);
96  virtual ~EventsManager();
97 
98  void delay(size_t time);
99 
100  Graphics::Screen *_screen;
101 
106  void update();
107 
112  processEvents();
113  return !_pendingKeyEvents.empty();
114  }
115 
120  bool eventPending() {
121  processEvents();
122  return !_pendingEvents.empty();
123  }
124 
129  processEvents();
130  return _pendingKeyEvents.empty() ? Common::Event() : _pendingKeyEvents.pop();
131  }
132 
137  processEvents();
138  return _pendingEvents.empty() ? Common::Event() : _pendingEvents.pop();
139  }
140 
144  void warpMouse(const Common::Point &newPos);
145 
149  void clearEvents();
150 
151  void setHotKey(Common::KeyCode key) { _hotkey = key; }
152  int16 getSwitchCode();
153 };
154 
155 extern EventsManager *g_events;
156 
157 extern void delay(size_t time);
158 
159 extern bool kbhit();
160 extern char getch();
161 
162 #define EVENTS_UPDATE g_events->update()
163 #define EVENTS_CLEAR g_events->clearEvents()
164 #define ALT 0x1000
165 
166 } // namespace Chewy
167 
168 #endif
Definition: events.h:31
Common::Event getPendingKeyEvent()
Definition: events.h:128
Definition: screen.h:50
bool eventPending()
Definition: events.h:120
Definition: events.h:198
Definition: rect.h:45
bool keyEventPending()
Definition: events.h:111
Definition: ani_dat.h:25
Common::Event getPendingEvent()
Definition: events.h:136
void push_back(const t_T &element)
Definition: list.h:139
Definition: events.h:38