2012-09-08 08:45:22 +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.
|
2014-02-18 01:34:21 +00:00
|
|
|
*
|
2012-09-08 08:45:22 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:21 +00:00
|
|
|
*
|
2012-09-08 08:45:22 +00:00
|
|
|
* 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 "hopkins/events.h"
|
2013-02-15 21:20:24 +00:00
|
|
|
|
2012-09-19 11:34:23 +00:00
|
|
|
#include "hopkins/files.h"
|
|
|
|
#include "hopkins/globals.h"
|
|
|
|
#include "hopkins/hopkins.h"
|
|
|
|
#include "hopkins/sound.h"
|
2012-09-08 08:45:22 +00:00
|
|
|
|
2013-02-15 21:20:24 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/textconsole.h"
|
|
|
|
#include "graphics/cursorman.h"
|
|
|
|
|
2012-09-08 08:45:22 +00:00
|
|
|
namespace Hopkins {
|
|
|
|
|
2013-03-19 19:40:55 +00:00
|
|
|
EventsManager::EventsManager(HopkinsEngine *vm) {
|
|
|
|
_vm = vm;
|
2012-12-11 00:53:50 +00:00
|
|
|
_mouseFl = false;
|
|
|
|
_mouseLinuxFl = false;
|
|
|
|
_mouseSizeX = _mouseSizeY = 0;
|
|
|
|
_mouseOffset.x = _mouseOffset.y = 0;
|
|
|
|
_startPos.x = _startPos.y = 0;
|
|
|
|
_breakoutFl = false;
|
2012-12-11 07:31:07 +00:00
|
|
|
_mouseSpriteId = 0;
|
|
|
|
_curMouseButton = 0;
|
|
|
|
_mouseButton = 0;
|
2013-04-04 05:54:45 +00:00
|
|
|
_mouseCursor = NULL;
|
2012-10-27 09:19:21 +00:00
|
|
|
_gameCounter = 0;
|
2012-12-11 07:31:07 +00:00
|
|
|
_rateCounter = 0;
|
2012-12-11 00:53:50 +00:00
|
|
|
_escKeyFl = false;
|
|
|
|
_gameKey = KEY_NONE;
|
2012-12-11 07:31:07 +00:00
|
|
|
_mouseCursorId = 0;
|
2012-12-11 00:53:50 +00:00
|
|
|
_oldIconId = 0;
|
2013-04-04 05:54:45 +00:00
|
|
|
_objectBuf = NULL;
|
2012-10-13 07:27:14 +00:00
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
Common::fill(&_keyState[0], &_keyState[256], false);
|
2013-04-09 06:25:49 +00:00
|
|
|
_priorCounterTime = _priorFrameTime = g_system->getMillis();
|
2012-09-19 11:34:23 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 11:35:33 +00:00
|
|
|
EventsManager::~EventsManager() {
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->freeMemory(_objectBuf);
|
|
|
|
_vm->_globals->freeMemory(_mouseCursor);
|
2012-11-01 11:35:33 +00:00
|
|
|
}
|
|
|
|
|
2013-03-24 14:31:59 +00:00
|
|
|
void EventsManager::clearAll() {
|
2013-03-24 14:36:32 +00:00
|
|
|
_vm->_globals->freeMemory(_objectBuf);
|
2013-03-24 14:31:59 +00:00
|
|
|
_objectBuf = _vm->_globals->allocMemory(2500);
|
|
|
|
}
|
|
|
|
|
2013-02-15 07:33:42 +00:00
|
|
|
void EventsManager::initMouseData() {
|
|
|
|
if (_vm->getPlatform() == Common::kPlatformLinux)
|
|
|
|
_mouseLinuxFl = true;
|
|
|
|
else
|
|
|
|
_mouseLinuxFl = false;
|
|
|
|
|
|
|
|
if (_mouseLinuxFl) {
|
|
|
|
_mouseSizeX = 52;
|
|
|
|
_mouseSizeY = 32;
|
|
|
|
} else {
|
|
|
|
_mouseSizeX = 34;
|
|
|
|
_mouseSizeY = 20;
|
|
|
|
}
|
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
switch (_vm->_globals->_language) {
|
2013-02-15 07:33:42 +00:00
|
|
|
case LANG_EN:
|
|
|
|
if (!_mouseLinuxFl)
|
2013-04-10 08:27:06 +00:00
|
|
|
_mouseCursor = _vm->_fileIO->loadFile("SOUAN.SPR");
|
2013-02-15 07:33:42 +00:00
|
|
|
else
|
2013-04-10 08:27:06 +00:00
|
|
|
_mouseCursor = _vm->_fileIO->loadFile("LSOUAN.SPR");
|
2013-02-15 07:33:42 +00:00
|
|
|
break;
|
|
|
|
case LANG_FR:
|
|
|
|
if (!_mouseLinuxFl)
|
2013-04-10 08:27:06 +00:00
|
|
|
_mouseCursor = _vm->_fileIO->loadFile("SOUFR.SPR");
|
2013-02-15 07:33:42 +00:00
|
|
|
else
|
2013-04-10 08:27:06 +00:00
|
|
|
_mouseCursor = _vm->_fileIO->loadFile("LSOUFR.SPR");
|
2013-02-15 07:33:42 +00:00
|
|
|
break;
|
|
|
|
case LANG_SP:
|
2013-04-10 08:27:06 +00:00
|
|
|
_mouseCursor = _vm->_fileIO->loadFile("SOUES.SPR");
|
2013-02-15 07:33:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-20 16:59:06 +00:00
|
|
|
// Mouse On
|
2012-12-11 00:53:50 +00:00
|
|
|
void EventsManager::setMouseOn() {
|
|
|
|
_mouseFl = true;
|
2012-09-08 08:45:22 +00:00
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
if (_mouseLinuxFl) {
|
|
|
|
_mouseSizeX = 52;
|
|
|
|
_mouseSizeY = 32;
|
2012-09-08 08:45:22 +00:00
|
|
|
} else {
|
2012-12-11 00:53:50 +00:00
|
|
|
_mouseSizeX = 34;
|
|
|
|
_mouseSizeY = 20;
|
2012-09-08 08:45:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
_mouseOffset.x = 0;
|
|
|
|
_mouseOffset.y = 0;
|
2012-09-08 08:45:22 +00:00
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
if (!_breakoutFl)
|
|
|
|
setMouseXY(300, 200);
|
2012-09-08 08:45:22 +00:00
|
|
|
else
|
2012-12-11 00:53:50 +00:00
|
|
|
setMouseXY(150, 100);
|
2012-09-08 08:45:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 06:56:26 +00:00
|
|
|
/**
|
|
|
|
* Set Mouse position
|
|
|
|
*/
|
|
|
|
void EventsManager::setMouseXY(Common::Point pos) {
|
|
|
|
g_system->warpMouse(pos.x, pos.y);
|
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
/**
|
|
|
|
* Set Mouse position
|
|
|
|
*/
|
|
|
|
void EventsManager::setMouseXY(int xp, int yp) {
|
2012-09-08 08:45:22 +00:00
|
|
|
g_system->warpMouse(xp, yp);
|
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
/**
|
|
|
|
* Get Mouse X
|
|
|
|
*/
|
|
|
|
int EventsManager::getMouseX() {
|
|
|
|
_mousePos.x = _startPos.x + g_system->getEventManager()->getMousePos().x;
|
|
|
|
_mousePos.y = g_system->getEventManager()->getMousePos().y;
|
2012-09-15 03:23:46 +00:00
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
return _mousePos.x + _mouseOffset.x;
|
2012-09-15 03:23:46 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
/**
|
|
|
|
* Get Mouse Y
|
|
|
|
*/
|
|
|
|
int EventsManager::getMouseY() {
|
|
|
|
_mousePos.x = _startPos.x + g_system->getEventManager()->getMousePos().x;
|
|
|
|
_mousePos.y = g_system->getEventManager()->getMousePos().y;
|
2012-09-15 03:23:46 +00:00
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
return _mousePos.y + _mouseOffset.y;
|
2012-09-15 03:23:46 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
/**
|
|
|
|
* Get Mouse Button
|
|
|
|
*/
|
|
|
|
int EventsManager::getMouseButton() {
|
2012-12-11 07:31:07 +00:00
|
|
|
refreshEvents();
|
|
|
|
return _curMouseButton;
|
2012-09-15 00:27:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
/**
|
|
|
|
* Mouse Off
|
|
|
|
*/
|
|
|
|
void EventsManager::mouseOff() {
|
|
|
|
_mouseFl = false;
|
2012-11-09 11:11:38 +00:00
|
|
|
CursorMan.showMouse(false);
|
2012-09-17 06:53:21 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
/**
|
|
|
|
* Mouse On
|
|
|
|
*/
|
|
|
|
void EventsManager::mouseOn() {
|
|
|
|
setMouseOn();
|
|
|
|
_mouseFl = true;
|
2012-11-09 11:11:38 +00:00
|
|
|
CursorMan.showMouse(true);
|
2012-09-17 06:53:21 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
/**
|
|
|
|
* Change Mouse Cursor
|
|
|
|
*/
|
2013-04-11 10:17:06 +00:00
|
|
|
void EventsManager::changeMouseCursor(int id) {
|
2012-09-19 11:34:23 +00:00
|
|
|
int cursorId = id;
|
|
|
|
|
2012-12-30 18:33:53 +00:00
|
|
|
if (_mouseCursorId == 23)
|
|
|
|
return;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
if (id == 4 && _mouseCursorId == 4 && _vm->_globals->_freezeCharacterFl)
|
2012-12-30 18:33:53 +00:00
|
|
|
cursorId = 0;
|
|
|
|
if (cursorId == 25)
|
|
|
|
cursorId = 5;
|
2012-09-21 23:55:40 +00:00
|
|
|
|
2012-12-30 18:33:53 +00:00
|
|
|
if (_oldIconId != cursorId || !cursorId) {
|
|
|
|
_oldIconId = cursorId;
|
|
|
|
_mouseSpriteId = cursorId;
|
|
|
|
|
|
|
|
updateCursor();
|
2012-09-19 11:34:23 +00:00
|
|
|
}
|
2012-09-15 00:27:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 07:31:07 +00:00
|
|
|
/**
|
|
|
|
* Check Events
|
|
|
|
*/
|
|
|
|
void EventsManager::refreshEvents() {
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_soundMan->checkSounds();
|
2012-11-11 07:58:45 +00:00
|
|
|
|
2012-09-15 00:27:15 +00:00
|
|
|
pollEvents();
|
2012-09-08 13:43:35 +00:00
|
|
|
}
|
|
|
|
|
2012-09-15 01:45:36 +00:00
|
|
|
void EventsManager::checkForNextFrameCounter() {
|
2013-04-09 13:17:11 +00:00
|
|
|
int32 delayAmount = 10 - (g_system->getMillis() - _priorCounterTime);
|
|
|
|
if (delayAmount > 0)
|
|
|
|
_vm->_system->delayMillis(delayAmount);
|
2013-04-09 06:31:02 +00:00
|
|
|
|
2012-10-13 07:27:14 +00:00
|
|
|
// Check for whether to increment the game counter
|
2012-09-15 00:27:15 +00:00
|
|
|
uint32 milli = g_system->getMillis();
|
2012-10-13 07:27:14 +00:00
|
|
|
while ((milli - _priorCounterTime) >= 10) {
|
|
|
|
_priorCounterTime += 10;
|
2012-12-11 07:31:07 +00:00
|
|
|
_rateCounter += 3;
|
2012-10-13 07:27:14 +00:00
|
|
|
}
|
2012-09-15 01:45:36 +00:00
|
|
|
|
2012-10-13 07:27:14 +00:00
|
|
|
// Check for next game frame
|
|
|
|
if ((milli - _priorFrameTime) >= GAME_FRAME_TIME) {
|
2012-10-28 03:51:17 +00:00
|
|
|
++_gameCounter;
|
2012-10-13 07:27:14 +00:00
|
|
|
_priorFrameTime = milli;
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->updateScreen();
|
2012-10-14 02:43:29 +00:00
|
|
|
|
|
|
|
// Signal the ScummVM debugger
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_debug->onFrame();
|
2012-09-15 00:27:15 +00:00
|
|
|
}
|
2012-09-15 01:45:36 +00:00
|
|
|
}
|
|
|
|
|
2012-09-30 11:33:00 +00:00
|
|
|
void EventsManager::delay(int totalMilli) {
|
|
|
|
uint32 delayEnd = g_system->getMillis() + totalMilli;
|
2012-09-15 00:27:15 +00:00
|
|
|
|
2013-04-26 00:50:08 +00:00
|
|
|
while (!_vm->shouldQuit() && g_system->getMillis() < delayEnd) {
|
2012-09-15 01:45:36 +00:00
|
|
|
g_system->delayMillis(10);
|
2012-12-14 00:49:22 +00:00
|
|
|
}
|
2012-09-15 01:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventsManager::pollEvents() {
|
2012-09-15 11:42:20 +00:00
|
|
|
checkForNextFrameCounter();
|
|
|
|
|
2012-09-15 00:27:15 +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:
|
2012-12-11 00:53:50 +00:00
|
|
|
_keyState[(byte)toupper(event.kbd.ascii)] = true;
|
2012-10-24 08:55:43 +00:00
|
|
|
handleKey(event);
|
2012-09-15 00:27:15 +00:00
|
|
|
return;
|
2012-11-18 08:31:43 +00:00
|
|
|
case Common::EVENT_KEYUP:
|
2012-12-11 00:53:50 +00:00
|
|
|
_keyState[(byte)toupper(event.kbd.ascii)] = false;
|
2012-11-18 08:31:43 +00:00
|
|
|
return;
|
2012-09-15 00:27:15 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2012-12-11 07:31:07 +00:00
|
|
|
_mouseButton = 1;
|
2012-11-21 22:55:16 +00:00
|
|
|
return;
|
2012-09-15 00:27:15 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2012-12-11 07:31:07 +00:00
|
|
|
_mouseButton = 2;
|
2012-11-21 22:55:16 +00:00
|
|
|
return;
|
2012-09-22 10:45:08 +00:00
|
|
|
case Common::EVENT_LBUTTONUP:
|
2012-09-15 00:27:15 +00:00
|
|
|
case Common::EVENT_RBUTTONUP:
|
2012-12-11 07:31:07 +00:00
|
|
|
_mouseButton = 0;
|
2012-09-15 00:27:15 +00:00
|
|
|
return;
|
|
|
|
default:
|
2013-11-23 09:26:45 +00:00
|
|
|
break;
|
2012-09-15 00:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-21 22:55:16 +00:00
|
|
|
|
|
|
|
for (char chr = 'A'; chr <= 'Z'; chr++)
|
2012-12-11 00:53:50 +00:00
|
|
|
_keyState[(byte)chr] = false;
|
2012-11-21 22:55:16 +00:00
|
|
|
|
|
|
|
for (char chr = '0'; chr <= '9'; chr++)
|
2012-12-11 00:53:50 +00:00
|
|
|
_keyState[(byte)chr] = false;
|
2012-09-08 13:43:35 +00:00
|
|
|
}
|
|
|
|
|
2013-04-11 10:17:06 +00:00
|
|
|
void EventsManager::handleKey(const Common::Event &event) {
|
2012-12-11 00:53:50 +00:00
|
|
|
_escKeyFl = (event.kbd.keycode == Common::KEYCODE_ESCAPE);
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-10-28 03:26:07 +00:00
|
|
|
if (event.kbd.keycode == Common::KEYCODE_i || event.kbd.keycode == Common::KEYCODE_TAB)
|
2012-12-11 00:53:50 +00:00
|
|
|
_gameKey = KEY_INVENTORY;
|
2012-10-28 03:26:07 +00:00
|
|
|
else if (event.kbd.keycode == Common::KEYCODE_F5)
|
2012-12-11 00:53:50 +00:00
|
|
|
_gameKey = KEY_SAVE;
|
2012-10-28 03:26:07 +00:00
|
|
|
else if (event.kbd.keycode == Common::KEYCODE_F7)
|
2012-12-11 00:53:50 +00:00
|
|
|
_gameKey = KEY_LOAD;
|
2012-10-28 03:26:07 +00:00
|
|
|
else if (event.kbd.keycode == Common::KEYCODE_F1 || event.kbd.keycode == Common::KEYCODE_o)
|
2012-12-11 00:53:50 +00:00
|
|
|
_gameKey = KEY_OPTIONS;
|
2012-10-24 08:55:43 +00:00
|
|
|
|
|
|
|
// Check for debugger
|
|
|
|
if ((event.kbd.keycode == Common::KEYCODE_d) && (event.kbd.flags & Common::KBD_CTRL)) {
|
|
|
|
// Attach to the debugger
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_debug->attach();
|
|
|
|
_vm->_debug->onFrame();
|
2012-10-24 08:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-11 07:31:07 +00:00
|
|
|
/**
|
|
|
|
* Waits for a keypress, ignoring mouse events
|
|
|
|
* @return Keypress, or -1 if game quit was requested
|
|
|
|
*/
|
|
|
|
int EventsManager::waitKeyPress() {
|
2012-11-18 08:31:43 +00:00
|
|
|
char foundChar = '\0';
|
|
|
|
|
|
|
|
while (!foundChar) {
|
|
|
|
if (_vm->shouldQuit())
|
|
|
|
return -1;
|
2012-11-17 09:49:07 +00:00
|
|
|
|
2012-11-18 08:31:43 +00:00
|
|
|
for (char ch = 'A'; ch <= 'Z'; ++ch) {
|
2012-12-11 00:53:50 +00:00
|
|
|
if (_keyState[(byte)ch]) {
|
2012-11-18 08:31:43 +00:00
|
|
|
foundChar = ch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-17 09:49:07 +00:00
|
|
|
|
2012-11-18 08:31:43 +00:00
|
|
|
for (char ch = '0'; ch <= '9'; ++ch) {
|
2012-12-11 00:53:50 +00:00
|
|
|
if (_keyState[(byte)ch]) {
|
2012-11-18 08:31:43 +00:00
|
|
|
foundChar = ch;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-17 09:49:07 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 00:53:50 +00:00
|
|
|
if (_keyState[(byte)'.'])
|
2012-11-18 08:31:43 +00:00
|
|
|
foundChar = '.';
|
2012-12-11 00:53:50 +00:00
|
|
|
else if (_keyState[8])
|
2012-11-21 22:55:16 +00:00
|
|
|
// BACKSPACE
|
2012-11-18 08:31:43 +00:00
|
|
|
foundChar = 8;
|
2012-12-11 00:53:50 +00:00
|
|
|
else if (_keyState[13])
|
2012-11-21 22:55:16 +00:00
|
|
|
// ENTER
|
2012-11-18 08:31:43 +00:00
|
|
|
foundChar = 13;
|
2012-12-11 00:53:50 +00:00
|
|
|
else if (_keyState[(byte)' '])
|
2012-11-18 08:31:43 +00:00
|
|
|
foundChar = ' ';
|
|
|
|
|
2013-03-04 06:46:15 +00:00
|
|
|
refreshScreenAndEvents();
|
2012-11-18 08:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for keypress release
|
2012-12-11 00:53:50 +00:00
|
|
|
while (_keyState[(byte)foundChar] && !_vm->shouldQuit()) {
|
2013-03-04 06:46:15 +00:00
|
|
|
refreshScreenAndEvents();
|
2012-11-17 09:49:07 +00:00
|
|
|
g_system->delayMillis(10);
|
|
|
|
}
|
|
|
|
|
2012-11-18 08:31:43 +00:00
|
|
|
// Return character
|
|
|
|
return foundChar;
|
2012-11-17 09:49:07 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 06:46:15 +00:00
|
|
|
void EventsManager::refreshScreenAndEvents() {
|
2013-02-07 07:44:22 +00:00
|
|
|
int bottom = 0;
|
|
|
|
int right = 0;
|
2013-02-01 06:36:13 +00:00
|
|
|
int height = 0;
|
2013-02-01 06:55:49 +00:00
|
|
|
int width = 0;
|
2013-02-01 06:36:13 +00:00
|
|
|
int xp = 0;
|
2012-10-13 07:27:14 +00:00
|
|
|
int yp = 0;
|
|
|
|
|
2012-12-26 21:02:48 +00:00
|
|
|
if (_mouseFl) {
|
2013-02-01 06:36:13 +00:00
|
|
|
int mouseWidth = 20;
|
2012-12-11 00:53:50 +00:00
|
|
|
if (!_mouseLinuxFl)
|
2013-02-01 06:36:13 +00:00
|
|
|
mouseWidth = 10;
|
|
|
|
int mouseHeight = 20;
|
2012-12-11 00:53:50 +00:00
|
|
|
if (!_mouseLinuxFl)
|
2013-02-01 06:36:13 +00:00
|
|
|
mouseHeight = 15;
|
|
|
|
xp = _mousePos.x - mouseWidth;
|
2012-12-11 00:53:50 +00:00
|
|
|
yp = _mousePos.y;
|
2013-02-01 06:36:13 +00:00
|
|
|
width = _mouseSizeX;
|
|
|
|
height = _mouseSizeY;
|
2012-12-11 07:31:07 +00:00
|
|
|
if (_mouseCursorId == 23) {
|
2013-04-10 08:27:06 +00:00
|
|
|
width = _vm->_objectsMan->getObjectWidth();
|
|
|
|
height = _vm->_objectsMan->getObjectHeight();
|
2012-09-23 00:59:52 +00:00
|
|
|
} else {
|
2013-02-01 06:55:49 +00:00
|
|
|
if (_breakoutFl) {
|
2013-04-10 08:27:06 +00:00
|
|
|
if (xp < _vm->_graphicsMan->_minX)
|
|
|
|
xp = _vm->_graphicsMan->_minX;
|
|
|
|
if (_mousePos.y < _vm->_graphicsMan->_minY)
|
|
|
|
yp = _vm->_graphicsMan->_minY;
|
|
|
|
if (_mouseSizeX + xp >= _vm->_graphicsMan->_maxX)
|
|
|
|
width = _mouseSizeX - (_mouseSizeX + xp - _vm->_graphicsMan->_maxX);
|
|
|
|
if (yp + _mouseSizeY >= _vm->_graphicsMan->_maxY)
|
|
|
|
height = _vm->_graphicsMan->_maxY - yp;
|
2013-02-01 06:55:49 +00:00
|
|
|
} else {
|
2013-04-10 08:27:06 +00:00
|
|
|
if (xp < _vm->_graphicsMan->_minX)
|
|
|
|
xp = _vm->_graphicsMan->_minX - mouseWidth;
|
2013-02-01 06:55:49 +00:00
|
|
|
mouseHeight = (int16)mouseHeight;
|
2013-04-10 08:27:06 +00:00
|
|
|
if (_mousePos.y < _vm->_graphicsMan->_minY - mouseHeight)
|
|
|
|
yp = _vm->_graphicsMan->_minY - mouseHeight;
|
|
|
|
if (_mouseSizeX + xp >= _vm->_graphicsMan->_maxX)
|
|
|
|
width = _mouseSizeX - (_mouseSizeX + xp - _vm->_graphicsMan->_maxX - mouseWidth);
|
|
|
|
if (yp + _mouseSizeY >= mouseHeight + _vm->_graphicsMan->_maxY)
|
|
|
|
height = _vm->_graphicsMan->_maxY - mouseHeight - yp;
|
2013-02-01 06:55:49 +00:00
|
|
|
}
|
2013-02-07 07:44:22 +00:00
|
|
|
right = xp + width;
|
|
|
|
bottom = yp + height;
|
2012-09-23 00:59:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-01 06:55:49 +00:00
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
if (!_vm->_globals->_linuxEndDemoFl)
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_objectsMan->displaySprite();
|
2012-12-26 21:02:48 +00:00
|
|
|
if (!_mouseFl) {
|
2012-11-23 10:55:17 +00:00
|
|
|
updateCursor();
|
2013-02-01 06:36:13 +00:00
|
|
|
} else if (_mouseCursorId == 23) {
|
2013-04-10 08:27:06 +00:00
|
|
|
if (yp < _vm->_graphicsMan->_maxY && xp < _vm->_graphicsMan->_maxX) {
|
|
|
|
if (width + xp > _vm->_graphicsMan->_maxX)
|
|
|
|
width = _vm->_graphicsMan->_maxX - xp;
|
|
|
|
if (yp + height > _vm->_graphicsMan->_maxY)
|
|
|
|
height = _vm->_graphicsMan->_maxY - yp;
|
2013-02-01 06:36:13 +00:00
|
|
|
if (width > 1 && height > 1) {
|
2013-03-19 19:40:55 +00:00
|
|
|
updateCursor();
|
2012-09-23 00:59:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-10 08:27:06 +00:00
|
|
|
} else if (yp < _vm->_graphicsMan->_maxY && xp < _vm->_graphicsMan->_maxX && width > 1 && height > 1) {
|
2013-03-19 19:40:55 +00:00
|
|
|
updateCursor();
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->addDirtyRect(xp, yp, right, bottom);
|
2013-02-01 06:36:13 +00:00
|
|
|
}
|
2012-10-13 07:41:55 +00:00
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->_speed = 2;
|
2013-02-06 18:59:23 +00:00
|
|
|
bool externalLoopFl = false;
|
2012-09-23 00:59:52 +00:00
|
|
|
do {
|
2012-10-13 07:27:14 +00:00
|
|
|
while (!_vm->shouldQuit()) {
|
2013-04-06 06:23:14 +00:00
|
|
|
checkForNextFrameCounter();
|
2013-02-06 18:59:23 +00:00
|
|
|
bool innerLoopFl = false;
|
2012-09-23 00:59:52 +00:00
|
|
|
|
2013-03-31 14:47:46 +00:00
|
|
|
while (!_vm->shouldQuit() && (_breakoutFl || _vm->_globals->_eventMode != EVENTMODE_IGNORE)) {
|
2013-04-06 06:23:14 +00:00
|
|
|
checkForNextFrameCounter();
|
2012-11-18 09:58:53 +00:00
|
|
|
|
2013-02-06 18:59:23 +00:00
|
|
|
if (!_breakoutFl) {
|
|
|
|
innerLoopFl = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (_rateCounter > 1) {
|
|
|
|
externalLoopFl = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-09-23 00:59:52 +00:00
|
|
|
}
|
2013-03-20 06:27:42 +00:00
|
|
|
if (innerLoopFl || _vm->_globals->_speed != 2)
|
2012-09-23 00:59:52 +00:00
|
|
|
break;
|
2013-02-06 18:59:23 +00:00
|
|
|
if (externalLoopFl ||_rateCounter > 9) {
|
|
|
|
externalLoopFl = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-09-23 00:59:52 +00:00
|
|
|
}
|
2013-02-06 18:59:23 +00:00
|
|
|
if (externalLoopFl)
|
|
|
|
break;
|
2013-04-10 11:26:26 +00:00
|
|
|
} while (!_vm->shouldQuit() && _vm->_globals->_eventMode == EVENTMODE_CREDITS && _rateCounter <= 15);
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->_speed = 2;
|
2012-12-11 07:31:07 +00:00
|
|
|
_rateCounter = 0;
|
2013-04-10 08:27:06 +00:00
|
|
|
if (!_vm->_graphicsMan->_largeScreenFl || _vm->_graphicsMan->_scrollStatus == 1) {
|
|
|
|
_vm->_graphicsMan->displayDirtyRects();
|
2012-09-23 00:59:52 +00:00
|
|
|
} else {
|
2013-04-10 08:27:06 +00:00
|
|
|
if (_vm->_graphicsMan->_scrollStatus != 2) {
|
|
|
|
if (getMouseX() > _vm->_graphicsMan->_scrollPosX + 620)
|
|
|
|
_vm->_graphicsMan->_scrollPosX += _vm->_graphicsMan->_scrollSpeed;
|
|
|
|
if (getMouseX() < _vm->_graphicsMan->_scrollPosX + 10)
|
|
|
|
_vm->_graphicsMan->_scrollPosX -= _vm->_graphicsMan->_scrollSpeed;
|
2012-09-23 00:59:52 +00:00
|
|
|
}
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->_scrollPosX = CLIP(_vm->_graphicsMan->_scrollPosX, 0, SCREEN_WIDTH);
|
|
|
|
if (_vm->_graphicsMan->_oldScrollPosX == _vm->_graphicsMan->_scrollPosX) {
|
|
|
|
_vm->_graphicsMan->displayDirtyRects();
|
2012-09-23 00:59:52 +00:00
|
|
|
} else {
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_fontMan->hideText(9);
|
2013-04-13 21:24:13 +00:00
|
|
|
_vm->_graphicsMan->display8BitRect(_vm->_graphicsMan->_frontBuffer, _vm->_graphicsMan->_scrollPosX, 20, SCREEN_WIDTH, 440, 0, 20);
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->resetRefreshRects();
|
|
|
|
_vm->_graphicsMan->addRefreshRect(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT - 20);
|
2012-11-23 21:21:35 +00:00
|
|
|
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->resetDirtyRects();
|
2012-12-22 00:28:31 +00:00
|
|
|
|
2013-04-10 08:27:06 +00:00
|
|
|
_startPos.x = _vm->_graphicsMan->_scrollPosX;
|
|
|
|
_vm->_graphicsMan->_scrollOffset = _vm->_graphicsMan->_scrollPosX;
|
2012-09-23 00:59:52 +00:00
|
|
|
}
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->_oldScrollPosX = _vm->_graphicsMan->_scrollPosX;
|
|
|
|
_startPos.x = _vm->_graphicsMan->_scrollPosX;
|
|
|
|
_vm->_graphicsMan->_scrollOffset = _vm->_graphicsMan->_scrollPosX;
|
2012-09-23 00:59:52 +00:00
|
|
|
}
|
2012-12-11 07:31:07 +00:00
|
|
|
_curMouseButton = _mouseButton;
|
|
|
|
_mouseButton = 0;
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_soundMan->checkSoundEnd();
|
2012-12-11 07:31:07 +00:00
|
|
|
refreshEvents();
|
2012-12-14 00:49:22 +00:00
|
|
|
}
|
2012-09-23 00:59:52 +00:00
|
|
|
|
2012-11-01 11:35:33 +00:00
|
|
|
void EventsManager::updateCursor() {
|
|
|
|
// Backup the current sprite clipping bounds and reset them
|
2013-04-10 08:27:06 +00:00
|
|
|
Common::Rect clipBounds(_vm->_graphicsMan->_minX, _vm->_graphicsMan->_minY,
|
|
|
|
_vm->_graphicsMan->_maxX, _vm->_graphicsMan->_maxY);
|
|
|
|
_vm->_graphicsMan->_minX = _vm->_graphicsMan->_minY = 0;
|
|
|
|
_vm->_graphicsMan->_maxX = _vm->_objectsMan->getObjectWidth();
|
|
|
|
_vm->_graphicsMan->_maxY = _vm->_objectsMan->getObjectHeight();
|
|
|
|
int pitch = _vm->_graphicsMan->_lineNbr2;
|
|
|
|
_vm->_graphicsMan->_lineNbr2 = _vm->_objectsMan->getObjectWidth();
|
2012-11-01 11:35:33 +00:00
|
|
|
|
|
|
|
// Create the temporary cursor surface
|
2013-04-10 08:27:06 +00:00
|
|
|
byte *cursorSurface = new byte[_vm->_objectsMan->getObjectHeight() * _vm->_objectsMan->getObjectWidth()];
|
|
|
|
Common::fill(cursorSurface, cursorSurface + _vm->_objectsMan->getObjectHeight() * _vm->_objectsMan->getObjectWidth(), 0);
|
2012-11-01 11:35:33 +00:00
|
|
|
|
2012-12-11 07:31:07 +00:00
|
|
|
if (_mouseCursorId != 23) {
|
2012-11-01 11:35:33 +00:00
|
|
|
// Draw standard cursor
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->drawVesaSprite(cursorSurface, _mouseCursor, 300, 300, _mouseSpriteId);
|
2012-11-01 11:35:33 +00:00
|
|
|
} else {
|
|
|
|
// Draw the active inventory object
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->drawCompressedSprite(cursorSurface, _objectBuf, 300, 300, 0, 0, 0, false);
|
2012-11-01 11:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the clipping bounds
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_graphicsMan->_minX = clipBounds.left;
|
|
|
|
_vm->_graphicsMan->_minY = clipBounds.top;
|
|
|
|
_vm->_graphicsMan->_maxX = clipBounds.right;
|
|
|
|
_vm->_graphicsMan->_maxY = clipBounds.bottom;
|
|
|
|
_vm->_graphicsMan->_lineNbr2 = pitch;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-02-10 11:19:41 +00:00
|
|
|
// Create a cursor palette
|
|
|
|
Graphics::PixelFormat pixelFormat = g_system->getScreenFormat();
|
2012-11-01 11:35:33 +00:00
|
|
|
|
2013-02-10 11:19:41 +00:00
|
|
|
byte *cursorPalette = new byte[3 * PALETTE_SIZE];
|
2013-04-10 08:27:06 +00:00
|
|
|
uint16 *paletteColors = (uint16 *)_vm->_graphicsMan->_palettePixels;
|
2012-11-01 11:35:33 +00:00
|
|
|
|
2013-02-10 11:19:41 +00:00
|
|
|
for (int i = 0; i < PALETTE_SIZE; i++) {
|
|
|
|
uint8 r, g, b;
|
2013-02-10 14:56:18 +00:00
|
|
|
pixelFormat.colorToRGB(READ_LE_UINT16(&paletteColors[i]), r, g, b);
|
2013-02-10 11:19:41 +00:00
|
|
|
cursorPalette[3 * i] = r;
|
|
|
|
cursorPalette[3 * i + 1] = g;
|
|
|
|
cursorPalette[3 * i + 2] = b;
|
2012-11-01 11:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the X offset within the pointer image to the actual cursor data
|
2012-12-11 00:53:50 +00:00
|
|
|
int xOffset = !_mouseLinuxFl ? 10 : 20;
|
2012-11-01 11:35:33 +00:00
|
|
|
|
|
|
|
// Set the ScummVM cursor from the surface
|
2013-02-10 11:19:41 +00:00
|
|
|
CursorMan.replaceCursorPalette(cursorPalette, 0, PALETTE_SIZE - 1);
|
2013-04-10 08:27:06 +00:00
|
|
|
CursorMan.replaceCursor(cursorSurface, _vm->_objectsMan->getObjectWidth(), _vm->_objectsMan->getObjectHeight(),
|
2013-02-10 11:19:41 +00:00
|
|
|
xOffset, 0, 0, true);
|
2012-11-01 11:35:33 +00:00
|
|
|
|
2013-02-10 11:19:41 +00:00
|
|
|
// Delete the cursor surface and palette
|
|
|
|
delete[] cursorPalette;
|
2012-11-01 11:35:33 +00:00
|
|
|
delete[] cursorSurface;
|
|
|
|
}
|
|
|
|
|
2012-09-08 08:45:22 +00:00
|
|
|
} // End of namespace Hopkins
|