ScummVM API documentation
event_handler.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 ULTIMA4_EVENTS_EVENT_HANDLER_H
23 #define ULTIMA4_EVENTS_EVENT_HANDLER_H
24 
25 #include "ultima/ultima4/events/timed_event_mgr.h"
26 #include "ultima/ultima4/controllers/key_handler_controller.h"
27 #include "ultima/ultima4/core/types.h"
28 #include "ultima/ultima4/gfx/screen.h"
29 #include "common/events.h"
30 #include "common/list.h"
31 #include "common/rect.h"
32 #include "common/str.h"
33 
34 namespace Ultima {
35 namespace Ultima4 {
36 
37 #define eventHandler (EventHandler::getInstance())
38 
39 #if defined(IOS_ULTIMA4)
40 #ifndef __OBJC__
41 typedef void *TimedManagerHelper;
42 typedef void *UIEvent;
43 #else
44 @class TimedManagerHelper;
45 @class UIEvent;
46 #endif
47 #endif
48 
49 typedef void(*updateScreenCallback)();
50 
55 class WalkTrigger {
56 private:
57  int _ticksCtr, _ticksPerWalk;
58  KeybindingAction _action;
59 public:
63  WalkTrigger() : _ticksCtr(0), _ticksPerWalk(0), _action(KEYBIND_NONE) {
64  }
65 
69  void reset();
70 
74  void setDelta(Direction dir, int distance);
75 
79  KeybindingAction getAction();
80 };
81 
82 
86 class EventHandler {
88 private:
89  static EventHandler *_instance;
90  WalkTrigger _walk;
91  bool _isRightButtonDown;
92 private:
93  void handleMouseMotionEvent(const Common::Event &event);
94  void handleMouseButtonDownEvent(const Common::Event &event, Controller *controller, updateScreenCallback updateScreen);
95  void handleMouseButtonUpEvent(const Common::Event &event, Controller *controller, updateScreenCallback updateScreen);
96  void handleKeyDownEvent(const Common::Event &event, Controller *controller, updateScreenCallback updateScreen);
97 protected:
98  static bool _controllerDone;
99  static bool _ended;
100  TimedEventMgr _timer;
101  Common::Array<Controller *> _controllers;
102  MouseAreaList _mouseAreaSets;
103  updateScreenCallback _updateScreen;
104 public:
108  EventHandler();
109 
110  /* Static functions */
111  static EventHandler *getInstance();
112 
118  static void sleep(uint usec);
119 
123  static void wait_msecs(uint msecs);
124 
128  static void wait_cycles(uint cycles);
129 
130  static void setControllerDone(bool exit = true);
131 
135  static bool getControllerDone();
136  static void end();
137 
138  /* Member functions */
139  TimedEventMgr *getTimer();
140 
141  /* Event functions */
142  void run();
143  void setScreenUpdate(void (*updateScreen)(void));
144 #if defined(IOS_ULTIMA4)
145  void handleEvent(UIEvent *);
146  static void controllerStopped_helper();
147  updateScreenCallback screenCallback() {
148  return updateScreen;
149  }
150 #endif
151 
152  /* Controller functions */
153  Controller *pushController(Controller *c);
154  Controller *popController();
155  Controller *getController() const;
156  void setController(Controller *c);
157 
158  /* Key handler functions */
162  void pushKeyHandler(KeyHandler kh);
163 
169  void popKeyHandler();
170 
175  KeyHandler *getKeyHandler() const;
176 
184  void setKeyHandler(KeyHandler kh);
185 
186  /* Mouse area functions */
187  void pushMouseAreaSet(const MouseArea *mouseAreas);
188  void popMouseAreaSet();
189 
193  const MouseArea *getMouseAreaSet() const;
194 
195  const MouseArea *mouseAreaForPoint(int x, int y);
196 
200  KeybindingAction getAction() {
201  return _isRightButtonDown ? _walk.getAction() : KEYBIND_NONE;
202  }
203 };
204 
205 } // End of namespace Ultima4
206 } // End of namespace Ultima
207 
208 #endif
KeybindingAction getAction()
Definition: event_handler.h:200
Definition: array.h:52
Definition: event_handler.h:55
Definition: controller.h:35
Definition: timed_event_mgr.h:63
Definition: detection.h:27
WalkTrigger()
Definition: event_handler.h:63
Definition: events.h:218
Definition: key_handler_controller.h:33
void setDelta(Direction dir, int distance)
Definition: screen.h:87
KeybindingAction getAction()
Definition: event_handler.h:86