2014-02-19 01:08:58 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2014-02-22 22:25:30 +00:00
|
|
|
#include "graphics/cursorman.h"
|
2014-02-19 01:08:58 +00:00
|
|
|
#include "common/events.h"
|
2014-02-20 04:17:57 +00:00
|
|
|
#include "engines/util.h"
|
2014-02-19 01:08:58 +00:00
|
|
|
#include "mads/mads.h"
|
|
|
|
#include "mads/events.h"
|
|
|
|
|
2014-02-22 22:25:30 +00:00
|
|
|
#define GAME_FRAME_RATE 50
|
|
|
|
#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)
|
|
|
|
|
2014-02-19 01:08:58 +00:00
|
|
|
namespace MADS {
|
|
|
|
|
|
|
|
EventsManager::EventsManager(MADSEngine *vm) {
|
|
|
|
_vm = vm;
|
2014-02-22 16:13:35 +00:00
|
|
|
_cursorSprites = nullptr;
|
2014-03-21 01:59:43 +00:00
|
|
|
_frameCounter = 10;
|
2014-02-22 22:25:30 +00:00
|
|
|
_priorFrameTime = 0;
|
2014-02-22 23:21:18 +00:00
|
|
|
_keyPressed = false;
|
|
|
|
_mouseClicked = false;
|
2014-03-03 04:09:17 +00:00
|
|
|
_mouseReleased = false;
|
|
|
|
_mouseButtons = 0;
|
2014-03-22 16:02:17 +00:00
|
|
|
_vCC = 0;
|
2014-03-03 04:09:17 +00:00
|
|
|
_vD2 = 0;
|
|
|
|
_vD4 = 0;
|
2014-03-22 16:02:17 +00:00
|
|
|
_mouseMoved = false;
|
2014-03-03 04:09:17 +00:00
|
|
|
_vD8 = 0;
|
2014-04-05 18:27:33 +00:00
|
|
|
_rightMousePressed = false;
|
2014-02-22 16:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EventsManager::~EventsManager() {
|
2014-02-24 00:33:26 +00:00
|
|
|
freeCursors();
|
2014-02-22 16:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventsManager::loadCursors(const Common::String &spritesName) {
|
2014-02-25 14:21:19 +00:00
|
|
|
delete _cursorSprites;
|
2014-02-22 22:25:30 +00:00
|
|
|
_cursorSprites = new SpriteAsset(_vm, spritesName, 0x4000);
|
2014-02-22 16:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventsManager::setCursor(CursorType cursorId) {
|
2014-02-22 17:17:37 +00:00
|
|
|
_cursorId = cursorId;
|
|
|
|
changeCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventsManager::setCursor2(CursorType cursorId) {
|
2014-02-22 16:13:35 +00:00
|
|
|
_cursorId = cursorId;
|
|
|
|
_newCursorId = cursorId;
|
|
|
|
changeCursor();
|
|
|
|
}
|
|
|
|
|
2014-02-22 22:25:30 +00:00
|
|
|
void EventsManager::showCursor() {
|
|
|
|
CursorMan.showMouse(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventsManager::hideCursor() {
|
|
|
|
CursorMan.showMouse(false);
|
|
|
|
}
|
|
|
|
|
2014-03-28 01:04:27 +00:00
|
|
|
void EventsManager::waitCursor() {
|
2014-02-24 00:33:26 +00:00
|
|
|
CursorType cursorId = (CursorType)MIN(_cursorSprites->getCount(), (int)CURSOR_WAIT);
|
|
|
|
_newCursorId = cursorId;
|
|
|
|
if (_cursorId != _newCursorId) {
|
|
|
|
changeCursor();
|
|
|
|
_cursorId = _newCursorId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 16:13:35 +00:00
|
|
|
void EventsManager::changeCursor() {
|
2014-03-20 00:12:32 +00:00
|
|
|
if (_cursorSprites) {
|
|
|
|
MSprite *cursor = _cursorSprites->getFrame(_cursorId - 1);
|
|
|
|
CursorMan.replaceCursor(cursor->getData(), cursor->w, cursor->h, 0, 0,
|
|
|
|
cursor->getTransparencyIndex());
|
|
|
|
showCursor();
|
|
|
|
}
|
2014-02-24 00:33:26 +00:00
|
|
|
}
|
2014-02-22 16:13:35 +00:00
|
|
|
|
2014-02-24 00:33:26 +00:00
|
|
|
void EventsManager::freeCursors() {
|
|
|
|
delete _cursorSprites;
|
|
|
|
_cursorSprites = nullptr;
|
2014-02-19 01:08:58 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 22:25:30 +00:00
|
|
|
void EventsManager::pollEvents() {
|
|
|
|
checkForNextFrameCounter();
|
2014-03-22 16:02:17 +00:00
|
|
|
_mouseMoved = false;
|
2014-02-22 22:25:30 +00:00
|
|
|
|
|
|
|
Common::Event event;
|
|
|
|
while (g_system->getEventManager()->pollEvent(event)) {
|
|
|
|
// Handle keypress
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
case Common::EVENT_RTL:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
// Check for debugger
|
|
|
|
if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) {
|
|
|
|
// Attach to the debugger
|
|
|
|
_vm->_debugger->attach();
|
|
|
|
_vm->_debugger->onFrame();
|
|
|
|
} else {
|
|
|
|
_keyPressed = true;
|
|
|
|
}
|
|
|
|
return;
|
2014-02-22 23:21:18 +00:00
|
|
|
case Common::EVENT_KEYUP:
|
|
|
|
_keyPressed = false;
|
|
|
|
return;
|
2014-02-22 22:25:30 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
_mouseClicked = true;
|
2014-03-03 04:09:17 +00:00
|
|
|
_mouseButtons = 1;
|
2014-04-05 18:27:33 +00:00
|
|
|
_rightMousePressed = event.type == Common::EVENT_RBUTTONDOWN;
|
2014-03-27 02:22:50 +00:00
|
|
|
_mouseMoved = true;
|
2014-02-22 22:25:30 +00:00
|
|
|
return;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
2014-02-22 23:21:18 +00:00
|
|
|
_mouseClicked = false;
|
2014-03-24 01:52:18 +00:00
|
|
|
_mouseReleased = true;
|
2014-03-22 16:02:17 +00:00
|
|
|
_mouseMoved = true;
|
2014-04-05 18:27:33 +00:00
|
|
|
_rightMousePressed = false;
|
2014-02-22 22:25:30 +00:00
|
|
|
return;
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
_mousePos = event.mouse;
|
2014-03-22 16:02:17 +00:00
|
|
|
_currentPos = event.mouse;
|
|
|
|
_mouseMoved = true;
|
2014-02-22 22:25:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventsManager::checkForNextFrameCounter() {
|
|
|
|
// Check for next game frame
|
|
|
|
uint32 milli = g_system->getMillis();
|
|
|
|
if ((milli - _priorFrameTime) >= GAME_FRAME_TIME) {
|
2014-03-05 01:06:48 +00:00
|
|
|
++_frameCounter;
|
2014-02-22 22:25:30 +00:00
|
|
|
_priorFrameTime = milli;
|
|
|
|
|
|
|
|
// Give time to the debugger
|
|
|
|
_vm->_debugger->onFrame();
|
|
|
|
|
|
|
|
// Display the frame
|
2014-03-05 03:33:27 +00:00
|
|
|
_vm->_screen.updateScreen();
|
2014-02-22 22:25:30 +00:00
|
|
|
|
|
|
|
// Signal the ScummVM debugger
|
|
|
|
_vm->_debugger->onFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventsManager::delay(int cycles) {
|
|
|
|
uint32 totalMilli = cycles * 1000 / GAME_FRAME_RATE;
|
|
|
|
uint32 delayEnd = g_system->getMillis() + totalMilli;
|
|
|
|
|
|
|
|
while (!_vm->shouldQuit() && g_system->getMillis() < delayEnd) {
|
2014-02-20 04:17:57 +00:00
|
|
|
g_system->delayMillis(10);
|
2014-02-22 22:25:30 +00:00
|
|
|
|
|
|
|
pollEvents();
|
2014-02-20 04:17:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 01:06:48 +00:00
|
|
|
void EventsManager::waitForNextFrame() {
|
2014-03-27 02:58:24 +00:00
|
|
|
_mouseClicked = false;
|
|
|
|
_mouseReleased = false;
|
|
|
|
_mouseButtons = 0;
|
|
|
|
|
|
|
|
bool mouseClicked = false;
|
|
|
|
bool mouseReleased = false;
|
|
|
|
int mouseButtons = 0;
|
|
|
|
|
2014-03-12 03:42:20 +00:00
|
|
|
uint32 frameCtr = getFrameCounter();
|
2014-03-27 02:58:24 +00:00
|
|
|
while (!_vm->shouldQuit() && frameCtr == _frameCounter) {
|
2014-03-05 01:06:48 +00:00
|
|
|
delay(1);
|
2014-03-27 02:58:24 +00:00
|
|
|
|
|
|
|
mouseClicked |= _mouseClicked;
|
|
|
|
mouseReleased |= _mouseReleased;
|
|
|
|
mouseButtons |= _mouseButtons;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mouseClicked = mouseClicked;
|
|
|
|
_mouseReleased = mouseReleased;
|
|
|
|
_mouseButtons = mouseButtons;
|
2014-03-31 03:03:11 +00:00
|
|
|
_mouseMoved |= _mouseClicked || _mouseReleased;
|
2014-03-05 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 00:29:54 +00:00
|
|
|
void EventsManager::initVars() {
|
|
|
|
_mousePos = Common::Point(-1, -1);
|
|
|
|
_vD4 = _vCC;
|
|
|
|
_vD2 = _vD8 = 0;
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:08:58 +00:00
|
|
|
} // End of namespace MADS
|