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