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
30namespace Titanic {
31
32#define GAME_FRAME_RATE 30
33#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)
34#define DOUBLE_CLICK_TIME 100
35
36enum SpecialButtons {
37 MK_LBUTTON = 1, MK_RBUTTON = 2, MK_SHIFT = 4, MK_CONTROL = 8,
38 MK_MBUTTON = 0x10
39};
40
41class TitanicEngine;
42
47public:
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
74class CPressTarget : public CEventTarget {
75public:
76 bool _pressed;
77public:
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
88class Events {
89private:
90 TitanicEngine *_vm;
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);
114public:
116 ~Events() {}
117
123 void addTarget(CEventTarget *target) {
124 _eventTargets.push(target);
125 }
126
131 _eventTargets.pop();
132 }
133
138
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 */
Definition: stack.h:102
Definition: events.h:46
virtual void onIdle()
Definition: events.h:53
virtual void mouseMove(const Point &mousePos)
Definition: events.h:58
Definition: events.h:74
Definition: events.h:88
uint32 getFrameCounter() const
Definition: events.h:148
void addTarget(CEventTarget *target)
Definition: events.h:123
void setTotalPlayTicks(uint frames)
void pollEventsAndWait()
void removeTarget()
Definition: events.h:130
bool waitForPress(uint expiry)
uint32 getTicksCount() const
void sleep(uint time)
Common::Point getMousePos() const
Definition: events.h:178
void setMousePos(const Common::Point &pt)
uint32 getTotalPlayTicks() const
uint getSpecialButtons() const
Definition: events.h:195
Definition: titanic.h:121
uint32 CustomEventType
Definition: events.h:212
Definition: keyboard.h:294
uint16 ascii
Definition: keyboard.h:310
Definition: rect.h:144
Definition: display_client.h:58