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 };
69 
73 class CPressTarget : public CEventTarget {
74 public:
75  bool _pressed;
76 public:
77  CPressTarget() : _pressed(false) {}
78  ~CPressTarget() override {}
79  void leftButtonDown(const Point &mousePos) override { _pressed = true; }
80  void middleButtonDown(const Point &mousePos) override { _pressed = true; }
81  void keyDown(Common::KeyState keyState) override {
82  if (keyState.ascii)
83  _pressed = true;
84  }
85 };
86 
87 class Events {
88 private:
89  TitanicEngine *_vm;
90  Common::Stack<CEventTarget *> _eventTargets;
91  uint32 _frameCounter;
92  uint32 _priorFrameTime;
93  uint _totalFrames;
94  Common::Point _mousePos;
95  uint _specialButtons;
96 
100  bool checkForNextFrameCounter();
101 
105  CEventTarget *eventTarget() const {
106  return _eventTargets.top();
107  }
108 
112  void handleKbdSpecial(Common::KeyState keyState);
113 public:
114  Events(TitanicEngine *vm);
115  ~Events() {}
116 
122  void addTarget(CEventTarget *target) {
123  _eventTargets.push(target);
124  }
125 
129  void removeTarget() {
130  _eventTargets.pop();
131  }
132 
136  void pollEvents();
137 
142  void pollEventsAndWait();
143 
147  uint32 getFrameCounter() const { return _frameCounter; }
148 
152  uint32 getTicksCount() const;
153 
157  uint32 getTotalPlayTicks() const;
158 
162  void setTotalPlayTicks(uint frames);
163 
167  void sleep(uint time);
168 
172  bool waitForPress(uint expiry);
173 
177  Common::Point getMousePos() const { return _mousePos; }
178 
182  void setMousePos(const Common::Point &pt);
183 
184  /*
185  * Return whether a given special key is currently pressed
186  */
187  bool isSpecialPressed(SpecialButtons btn) const {
188  return (_specialButtons & btn) != 0;
189  }
190 
194  uint getSpecialButtons() const { return _specialButtons; }
195 };
196 
197 } // End of namespace Titanic
198 
199 #endif /* TITANIC_EVENTS_H */
Common::Point getMousePos() const
Definition: events.h:177
Definition: events.h:87
uint getSpecialButtons() const
Definition: events.h:194
uint32 getFrameCounter() const
Definition: events.h:147
virtual void mouseMove(const Point &mousePos)
Definition: events.h:58
Definition: events.h:73
void removeTarget()
Definition: events.h:129
Definition: titanic.h:81
virtual void onIdle()
Definition: events.h:53
Definition: rect.h:45
Definition: arm.h:30
void addTarget(CEventTarget *target)
Definition: events.h:122
Definition: keyboard.h:294
uint16 ascii
Definition: keyboard.h:310
Definition: stack.h:102
Definition: events.h:46