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 "graphics/screen.h"
27 
28 namespace Chewy {
29 
30 struct KbdInfo {
31  char _keyCode = '\0';
32  int _scanCode = Common::KEYCODE_INVALID;
33 };
34 
35 typedef void (*TimerProc)();
36 
38  struct TimerRecord {
39  TimerProc _proc;
40  uint32 _interval;
41  uint32 _nextFrameTime;
42  TimerRecord(TimerProc proc, uint32 interval) : _proc(proc), _interval(interval), _nextFrameTime(0) {
43  }
44  };
46 
47 private:
48  void init_timer_handler();
49  static void timer_handler();
50 
51  void handleMouseEvent(const Common::Event &event);
52  void handleKbdEvent(const Common::Event &event);
53 
54  TimerList _timers;
55  int16 _hotkey = Common::KEYCODE_INVALID;
56  bool _ignoreKeyUp = false;
57 
61  void checkTimers();
62 
66  static void updateScreen();
67 
73  void addTimer(TimerProc proc, uint interval) {
74  _timers.push_back(TimerRecord(proc, interval));
75  }
76 
80  void processEvents();
81 
85  void handleEvent(const Common::Event &event);
86 
87 public:
88  KbdInfo _kbInfo;
89  Common::Point _mousePos;
90  bool _flag1 = false;
91  bool _flag2 = false;
92 
93  EventsManager(Graphics::Screen *screen, uint refreshRate = 1000 / 50);
94  virtual ~EventsManager();
95 
96  void delay(size_t time);
97 
98  Graphics::Screen *_screen;
99 
104  void update();
105 
109  void warpMouse(const Common::Point &newPos);
110 
114  void clearEvents();
115 
116  void setHotKey(Common::KeyCode key) { _hotkey = key; }
117  int16 getSwitchCode();
118 
123  void ignoreNextKeyUp() { _ignoreKeyUp = true; }
124 };
125 
126 extern EventsManager *g_events;
127 
128 extern void delay(size_t time);
129 
130 extern bool kbhit();
131 extern char getch();
132 
133 #define EVENTS_UPDATE g_events->update()
134 #define EVENTS_CLEAR g_events->clearEvents()
135 #define ALT 0x1000
136 
137 } // namespace Chewy
138 
139 #endif
Definition: events.h:30
Definition: screen.h:47
void ignoreNextKeyUp()
Definition: events.h:123
Definition: events.h:218
Definition: rect.h:144
Definition: ani_dat.h:25
void push_back(const t_T &element)
Definition: list.h:174
Definition: events.h:37