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 TITANIC_EVENTS_H
23 #define TITANIC_EVENTS_H
24 
25 #include "common/scummsys.h"
26 #include "common/events.h"
27 #include "common/stack.h"
28 #include "support/rect.h"
29 
30 namespace Titanic {
31 
32 #define GAME_FRAME_RATE 30
33 #define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)
34 #define DOUBLE_CLICK_TIME 100
35 
36 enum SpecialButtons {
37  MK_LBUTTON = 1, MK_RBUTTON = 2, MK_SHIFT = 4, MK_CONTROL = 8,
38  MK_MBUTTON = 0x10
39 };
40 
41 class TitanicEngine;
42 
46 class CEventTarget {
47 public:
48  virtual ~CEventTarget() {}
49 
53  virtual void onIdle() {}
54 
58  virtual void mouseMove(const Point &mousePos) {}
59  virtual void leftButtonDown(const Point &mousePos) {}
60  virtual void leftButtonUp(const Point &mousePos) {}
61  virtual void leftButtonDoubleClick(const Point &mousePos) {}
62  virtual void middleButtonDown(const Point &mousePos) {}
63  virtual void middleButtonUp(const Point &mousePos) {}
64  virtual void middleButtonDoubleClick(const Point &mousePos) {}
65  virtual void mouseWheel(const Point &mousePos, bool wheelUp) {}
66  virtual void keyDown(Common::KeyState keyState) {}
67  virtual void keyUp(Common::KeyState keyState) {}
68  virtual void actionStart(Common::CustomEventType action) {}
69 };
70 
74 class CPressTarget : public CEventTarget {
75 public:
76  bool _pressed;
77 public:
78  CPressTarget() : _pressed(false) {}
79  ~CPressTarget() override {}
80  void leftButtonDown(const Point &mousePos) override { _pressed = true; }
81  void middleButtonDown(const Point &mousePos) override { _pressed = true; }
82  void keyDown(Common::KeyState keyState) override {
83  if (keyState.ascii)
84  _pressed = true;
85  }
86 };
87 
88 class Events {
89 private:
90  TitanicEngine *_vm;
91  Common::Stack<CEventTarget *> _eventTargets;
92  uint32 _frameCounter;
93  uint32 _priorFrameTime;
94  uint _totalFrames;
95  Common::Point _mousePos;
96  uint _specialButtons;
97 
101  bool checkForNextFrameCounter();
102 
106  CEventTarget *eventTarget() const {
107  return _eventTargets.top();
108  }
109 
113  void handleKbdSpecial(Common::CustomEventType action);
114 public:
115  Events(TitanicEngine *vm);
116  ~Events() {}
117 
123  void addTarget(CEventTarget *target) {
124  _eventTargets.push(target);
125  }
126 
130  void removeTarget() {
131  _eventTargets.pop();
132  }
133 
137  void pollEvents();
138 
143  void pollEventsAndWait();
144 
148  uint32 getFrameCounter() const { return _frameCounter; }
149 
153  uint32 getTicksCount() const;
154 
158  uint32 getTotalPlayTicks() const;
159 
163  void setTotalPlayTicks(uint frames);
164 
168  void sleep(uint time);
169 
173  bool waitForPress(uint expiry);
174 
178  Common::Point getMousePos() const { return _mousePos; }
179 
183  void setMousePos(const Common::Point &pt);
184 
185  /*
186  * Return whether a given special key is currently pressed
187  */
188  bool isSpecialPressed(SpecialButtons btn) const {
189  return (_specialButtons & btn) != 0;
190  }
191 
195  uint getSpecialButtons() const { return _specialButtons; }
196 };
197 
198 } // End of namespace Titanic
199 
200 #endif /* TITANIC_EVENTS_H */
Common::Point getMousePos() const
Definition: events.h:178
Definition: events.h:88
uint getSpecialButtons() const
Definition: events.h:195
uint32 getFrameCounter() const
Definition: events.h:148
virtual void mouseMove(const Point &mousePos)
Definition: events.h:58
Definition: events.h:74
uint32 CustomEventType
Definition: events.h:204
void removeTarget()
Definition: events.h:130
Definition: titanic.h:121
virtual void onIdle()
Definition: events.h:53
Definition: rect.h:144
Definition: arm.h:30
void addTarget(CEventTarget *target)
Definition: events.h:123
Definition: keyboard.h:294
uint16 ascii
Definition: keyboard.h:310
Definition: stack.h:102
Definition: events.h:46