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
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 /*
24 * This code is based on Labyrinth of Time code with assistance of
25 *
26 * Copyright (c) 1993 Terra Nova Development
27 * Copyright (c) 2004 The Wyrmkeep Entertainment Co.
28 *
29 */
30
31 #include "common/events.h"
32
33 #include "graphics/cursorman.h"
34
35 #include "lab/lab.h"
36
37 #include "lab/dispman.h"
38 #include "lab/eventman.h"
39 #include "lab/image.h"
40 #include "lab/interface.h"
41
42 namespace Lab {
43
44 static const byte mouseData[] = {
45 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
46 1, 7, 1, 0, 0, 0, 0, 0, 0, 0,
47 1, 7, 7, 1, 0, 0, 0, 0, 0, 0,
48 1, 7, 7, 7, 1, 0, 0, 0, 0, 0,
49 1, 7, 7, 7, 7, 1, 0, 0, 0, 0,
50 1, 7, 7, 7, 7, 7, 1, 0, 0, 0,
51 1, 7, 7, 7, 7, 7, 7, 1, 0, 0,
52 1, 7, 7, 7, 7, 7, 7, 7, 1, 0,
53 1, 7, 7, 7, 7, 7, 1, 1, 1, 1,
54 1, 7, 7, 1, 7, 7, 1, 0, 0, 0,
55 1, 7, 1, 0, 1, 7, 7, 1, 0, 0,
56 1, 1, 0, 0, 1, 7, 7, 1, 0, 0,
57 0, 0, 0, 0, 0, 1, 7, 7, 1, 0,
58 0, 0, 0, 0, 0, 1, 7, 7, 1, 0,
59 0, 0, 0, 0, 0, 0, 1, 1, 0, 0
60 };
61
62 #define MOUSE_WIDTH 10
63 #define MOUSE_HEIGHT 15
64
EventManager(LabEngine * vm)65 EventManager::EventManager(LabEngine *vm) : _vm(vm) {
66 _leftClick = false;
67 _rightClick = false;
68 _buttonHit = false;
69 _mousePos = Common::Point(0, 0);
70 _keyPressed = Common::KEYCODE_INVALID;
71 }
72
initMouse()73 void EventManager::initMouse() {
74 CursorMan.pushCursor(mouseData, MOUSE_WIDTH, MOUSE_HEIGHT, 0, 0, 0);
75 CursorMan.showMouse(false);
76
77 setMousePos(Common::Point(_vm->_graphics->_screenWidth / 2, _vm->_graphics->_screenHeight / 2));
78 }
79
mouseShow()80 void EventManager::mouseShow() {
81 CursorMan.showMouse(true);
82 }
83
mouseHide()84 void EventManager::mouseHide() {
85 CursorMan.showMouse(false);
86 }
87
setMousePos(Common::Point pos)88 void EventManager::setMousePos(Common::Point pos) {
89 if (_vm->_isHiRes)
90 _vm->_system->warpMouse(pos.x, pos.y);
91 else
92 _vm->_system->warpMouse(pos.x * 2, pos.y);
93 }
94
processInput()95 void EventManager::processInput() {
96 Common::Event event;
97
98 while (_vm->_system->getEventManager()->pollEvent(event)) {
99 switch (event.type) {
100 case Common::EVENT_LBUTTONDOWN:
101 if (_vm->_interface->checkButtonHit(_mousePos))
102 _buttonHit = true;
103 else
104 _leftClick = true;
105 break;
106 case Common::EVENT_RBUTTONDOWN:
107 _rightClick = true;
108 break;
109 case Common::EVENT_MOUSEMOVE:
110 _mousePos = event.mouse;
111 break;
112 case Common::EVENT_KEYDOWN:
113 switch (event.kbd.keycode) {
114 case Common::KEYCODE_LEFTBRACKET:
115 _vm->changeVolume(-1);
116 break;
117 case Common::KEYCODE_RIGHTBRACKET:
118 _vm->changeVolume(1);
119 break;
120 case Common::KEYCODE_d:
121 if (event.kbd.hasFlags(Common::KBD_CTRL)) {
122 // Open debugger console
123 _vm->_console->attach();
124 continue;
125 }
126 // Intentional fall through
127 default:
128 _keyPressed = event.kbd;
129 break;
130 }
131 break;
132 case Common::EVENT_QUIT:
133 case Common::EVENT_RTL:
134 default:
135 break;
136 }
137 }
138 }
139
getMsg()140 IntuiMessage *EventManager::getMsg() {
141 static IntuiMessage message;
142
143 _vm->_interface->handlePressedButton();
144 processInput();
145
146 if (_buttonHit) {
147 Button *lastButtonHit = _vm->_interface->checkButtonHit(_mousePos);
148 _buttonHit = false;
149 if (lastButtonHit) {
150 _vm->_interface->handlePressedButton();
151 message._msgClass = kMessageButtonUp;
152 message._code = lastButtonHit->_buttonId;
153 message._qualifier = _keyPressed.flags;
154
155 return &message;
156 } else
157 return nullptr;
158 } else if (_leftClick || _rightClick) {
159 message._msgClass = (_leftClick) ? kMessageLeftClick : kMessageRightClick;
160 message._qualifier = 0;
161 message._mouse = _mousePos;
162 _leftClick = _rightClick = false;
163 return &message;
164 } else if (_keyPressed.keycode != Common::KEYCODE_INVALID) {
165 Button *curButton = _vm->_interface->checkNumButtonHit(_keyPressed.keycode);
166
167 if (curButton) {
168 message._msgClass = kMessageButtonUp;
169 message._code = curButton->_buttonId;
170 } else {
171 message._msgClass = kMessageRawKey;
172 message._code = _keyPressed.keycode;
173 }
174
175 message._qualifier = _keyPressed.flags;
176 message._mouse = _mousePos;
177
178 _keyPressed.keycode = Common::KEYCODE_INVALID;
179
180 return &message;
181 } else
182 return nullptr;
183 }
184
updateAndGetMousePos()185 Common::Point EventManager::updateAndGetMousePos() {
186 processInput();
187
188 return _mousePos;
189 }
190
simulateEvent()191 void EventManager::simulateEvent() {
192 // Simulate an event by setting an unused key
193 _keyPressed = Common::KeyState(Common::KEYCODE_SEMICOLON);
194 }
195
196 } // End of namespace Lab
197