2014-10-06 14:50:05 +02: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on Labyrinth of Time code with assistance of
|
|
|
|
*
|
|
|
|
* Copyright (c) 1993 Terra Nova Development
|
|
|
|
* Copyright (c) 2004 The Wyrmkeep Entertainment Co.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-11-24 23:59:30 +01:00
|
|
|
#include "lab/lab.h"
|
2015-12-01 21:42:44 +01:00
|
|
|
#include "lab/image.h"
|
2014-10-06 14:50:05 +02:00
|
|
|
#include "lab/interface.h"
|
|
|
|
|
|
|
|
namespace Lab {
|
|
|
|
|
2015-12-08 09:19:00 +01:00
|
|
|
static byte MouseData[] = {
|
|
|
|
1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1, 7, 1, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1, 7, 7, 1, 0, 0, 0, 0, 0, 0,
|
|
|
|
1, 7, 7, 7, 1, 0, 0, 0, 0, 0,
|
|
|
|
1, 7, 7, 7, 7, 1, 0, 0, 0, 0,
|
|
|
|
1, 7, 7, 7, 7, 7, 1, 0, 0, 0,
|
|
|
|
1, 7, 7, 7, 7, 7, 7, 1, 0, 0,
|
|
|
|
1, 7, 7, 7, 7, 7, 7, 7, 1, 0,
|
|
|
|
1, 7, 7, 7, 7, 7, 1, 1, 1, 1,
|
|
|
|
1, 7, 7, 1, 7, 7, 1, 0, 0, 0,
|
|
|
|
1, 7, 1, 0, 1, 7, 7, 1, 0, 0,
|
|
|
|
1, 1, 0, 0, 1, 7, 7, 1, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 1, 7, 7, 1, 0,
|
|
|
|
0, 0, 0, 0, 0, 1, 7, 7, 1, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 1, 1, 0, 0
|
|
|
|
};
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-17 11:48:53 +02:00
|
|
|
#define MOUSE_WIDTH 10
|
|
|
|
#define MOUSE_HEIGHT 15
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Checks whether or not the cords fall within one of the gadgets in a list
|
|
|
|
* of gadgets.
|
|
|
|
*/
|
2015-12-06 22:50:41 +02:00
|
|
|
Gadget *EventManager::checkGadgetHit(GadgetList *gadgetList, Common::Point pos) {
|
|
|
|
for (GadgetList::iterator gadgetItr = gadgetList->begin(); gadgetItr != gadgetList->end(); ++gadgetItr) {
|
|
|
|
Gadget *gadget = *gadgetItr;
|
2015-12-07 10:31:46 +02:00
|
|
|
Common::Rect gadgetRect(gadget->x, gadget->y, gadget->x + gadget->_image->_width - 1, gadget->y + gadget->_image->_height - 1);
|
|
|
|
bool gadgetIsEnabled = !(gadget->_flags & GADGETOFF);
|
|
|
|
|
|
|
|
if (gadgetRect.contains(pos) && gadgetIsEnabled) {
|
2015-11-30 00:12:01 +01:00
|
|
|
if (_vm->_isHiRes) {
|
2015-12-06 22:50:41 +02:00
|
|
|
_hitGadget = gadget;
|
2014-10-06 14:50:05 +02:00
|
|
|
} else {
|
2015-02-24 12:16:33 +02:00
|
|
|
mouseHide();
|
2015-12-06 22:50:41 +02:00
|
|
|
gadget->_altImage->drawImage(gadget->x, gadget->y);
|
2015-02-24 12:16:33 +02:00
|
|
|
mouseShow();
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-11-27 23:18:15 +01:00
|
|
|
for (uint16 i = 0; i < 3; i++)
|
2015-11-29 23:34:35 +01:00
|
|
|
_vm->waitTOF();
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-02-24 12:16:33 +02:00
|
|
|
mouseHide();
|
2015-12-06 22:50:41 +02:00
|
|
|
gadget->_image->drawImage(gadget->x, gadget->y);
|
2015-02-24 12:16:33 +02:00
|
|
|
mouseShow();
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-06 22:50:41 +02:00
|
|
|
return gadget;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-06 22:50:41 +02:00
|
|
|
void EventManager::attachGadgetList(GadgetList *gadgetList) {
|
2015-12-02 00:55:29 +01:00
|
|
|
if (_screenGadgetList != gadgetList)
|
|
|
|
_lastGadgetHit = nullptr;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-02 00:55:29 +01:00
|
|
|
_screenGadgetList = gadgetList;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-11-29 18:10:06 +01:00
|
|
|
EventManager::EventManager(LabEngine *vm) : _vm(vm) {
|
2015-12-02 00:55:29 +01:00
|
|
|
_leftClick = false;
|
|
|
|
_rightClick = false;
|
|
|
|
|
|
|
|
_mouseHidden = true;
|
|
|
|
_lastGadgetHit = nullptr;
|
|
|
|
_screenGadgetList = nullptr;
|
2015-12-02 01:39:58 +01:00
|
|
|
_hitGadget = nullptr;
|
|
|
|
_nextKeyIn = 0;
|
|
|
|
_nextKeyOut = 0;
|
|
|
|
_mousePos = Common::Point(0, 0);
|
|
|
|
_mouseAtEdge = false;
|
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
_keyBuf[i] = 0;
|
|
|
|
|
2015-11-29 18:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventManager::mouseHandler(int flag, Common::Point pos) {
|
2015-07-17 10:24:34 +03:00
|
|
|
if (flag & 0x02) { /* Left mouse button click */
|
|
|
|
Gadget *tmp = NULL;
|
2015-12-02 00:55:29 +01:00
|
|
|
if (_screenGadgetList)
|
|
|
|
tmp = checkGadgetHit(_screenGadgetList, _vm->_isHiRes ? pos : Common::Point(pos.x / 2, pos.y));
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-07-17 10:24:34 +03:00
|
|
|
if (tmp)
|
2015-12-02 00:55:29 +01:00
|
|
|
_lastGadgetHit = tmp;
|
2015-07-17 10:24:34 +03:00
|
|
|
else
|
2015-12-02 00:55:29 +01:00
|
|
|
_leftClick = true;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-07-17 10:24:34 +03:00
|
|
|
if (flag & 0x08) /* Right mouse button click */
|
2015-12-02 00:55:29 +01:00
|
|
|
_rightClick = true;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-11-29 18:10:06 +01:00
|
|
|
void EventManager::updateMouse() {
|
2014-10-06 14:50:05 +02:00
|
|
|
bool doUpdateDisplay = false;
|
|
|
|
|
2015-12-02 00:55:29 +01:00
|
|
|
if (!_mouseHidden)
|
2014-10-06 14:50:05 +02:00
|
|
|
doUpdateDisplay = true;
|
|
|
|
|
2015-12-02 01:39:58 +01:00
|
|
|
if (_hitGadget) {
|
2014-10-06 14:50:05 +02:00
|
|
|
mouseHide();
|
2015-12-03 01:06:04 +01:00
|
|
|
_hitGadget->_altImage->drawImage(_hitGadget->x, _hitGadget->y);
|
2014-10-06 14:50:05 +02:00
|
|
|
mouseShow();
|
|
|
|
|
2015-11-27 23:18:15 +01:00
|
|
|
for (uint16 i = 0; i < 3; i++)
|
2015-11-29 23:34:35 +01:00
|
|
|
_vm->waitTOF();
|
2014-10-06 14:50:05 +02:00
|
|
|
|
|
|
|
mouseHide();
|
2015-12-03 01:06:04 +01:00
|
|
|
_hitGadget->_image->drawImage(_hitGadget->x, _hitGadget->y);
|
2014-10-06 14:50:05 +02:00
|
|
|
mouseShow();
|
|
|
|
doUpdateDisplay = true;
|
2015-12-02 01:39:58 +01:00
|
|
|
_hitGadget = nullptr;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doUpdateDisplay)
|
2015-12-04 13:32:08 +01:00
|
|
|
_vm->_graphics->screenUpdate();
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Initializes the mouse.
|
|
|
|
*/
|
2015-11-29 18:10:06 +01:00
|
|
|
void EventManager::initMouse() {
|
2015-02-17 11:48:53 +02:00
|
|
|
g_system->setMouseCursor(MouseData, MOUSE_WIDTH, MOUSE_HEIGHT, 0, 0, 0);
|
2014-12-29 00:03:58 +01:00
|
|
|
g_system->showMouse(false);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-11-28 02:17:05 +01:00
|
|
|
setMousePos(Common::Point(0, 0));
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Shows the mouse.
|
|
|
|
*/
|
2015-11-29 18:10:06 +01:00
|
|
|
void EventManager::mouseShow() {
|
2015-12-07 10:40:40 +02:00
|
|
|
if (_mouseHidden) {
|
2015-12-02 01:39:58 +01:00
|
|
|
processInput();
|
2015-12-02 00:55:29 +01:00
|
|
|
_mouseHidden = false;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 12:16:33 +02:00
|
|
|
g_system->showMouse(true);
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Hides the mouse.
|
|
|
|
*/
|
2015-11-29 18:10:06 +01:00
|
|
|
void EventManager::mouseHide() {
|
2015-12-07 10:40:40 +02:00
|
|
|
if (!_mouseHidden) {
|
2015-12-02 00:55:29 +01:00
|
|
|
_mouseHidden = true;
|
2014-12-29 00:03:58 +01:00
|
|
|
|
|
|
|
g_system->showMouse(false);
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Gets the current mouse co-ordinates. NOTE: On IBM version, will scale
|
|
|
|
* from virtual to screen co-ordinates automatically.
|
|
|
|
*/
|
2015-11-29 18:10:06 +01:00
|
|
|
Common::Point EventManager::getMousePos() {
|
2015-11-30 00:12:01 +01:00
|
|
|
if (_vm->_isHiRes)
|
2015-12-02 01:39:58 +01:00
|
|
|
return _mousePos;
|
2015-11-28 02:17:05 +01:00
|
|
|
else
|
2015-12-02 01:39:58 +01:00
|
|
|
return Common::Point(_mousePos.x / 2, _mousePos.y);
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Moves the mouse to new co-ordinates.
|
|
|
|
*/
|
2015-11-29 18:10:06 +01:00
|
|
|
void EventManager::setMousePos(Common::Point pos) {
|
2015-11-30 00:12:01 +01:00
|
|
|
if (_vm->_isHiRes)
|
2015-11-28 02:17:05 +01:00
|
|
|
g_system->warpMouse(pos.x, pos.y);
|
|
|
|
else
|
|
|
|
g_system->warpMouse(pos.x * 2, pos.y);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-02 00:55:29 +01:00
|
|
|
if (!_mouseHidden)
|
2015-12-02 01:39:58 +01:00
|
|
|
processInput();
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Checks whether or not the mouse buttons have been pressed, and the last
|
|
|
|
* co-ordinates of the button press. leftbutton tells whether to check the
|
|
|
|
* left or right button.
|
|
|
|
*/
|
2015-11-29 18:10:06 +01:00
|
|
|
bool EventManager::mouseButton(uint16 *x, uint16 *y, bool leftbutton) {
|
2014-10-06 14:50:05 +02:00
|
|
|
if (leftbutton) {
|
2015-12-02 00:55:29 +01:00
|
|
|
if (_leftClick) {
|
2015-12-02 01:39:58 +01:00
|
|
|
*x = (!_vm->_isHiRes) ? (uint16)_mousePos.x / 2 : (uint16)_mousePos.x;
|
|
|
|
*y = (uint16)_mousePos.y;
|
2015-12-02 00:55:29 +01:00
|
|
|
_leftClick = false;
|
2014-10-06 14:50:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
2015-12-02 00:55:29 +01:00
|
|
|
if (_rightClick) {
|
2015-12-02 01:39:58 +01:00
|
|
|
*x = (!_vm->_isHiRes) ? (uint16)_mousePos.x / 2 : (uint16)_mousePos.x;
|
|
|
|
*y = (uint16)_mousePos.y;
|
2015-12-02 00:55:29 +01:00
|
|
|
_rightClick = false;
|
2014-10-06 14:50:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-29 18:10:06 +01:00
|
|
|
Gadget *EventManager::mouseGadget() {
|
2015-12-02 00:55:29 +01:00
|
|
|
Gadget *temp = _lastGadgetHit;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-02 00:55:29 +01:00
|
|
|
_lastGadgetHit = nullptr;
|
|
|
|
return temp;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
|
|
|
* Checks whether or not a key has been pressed.
|
|
|
|
*/
|
2015-12-02 01:39:58 +01:00
|
|
|
bool EventManager::keyPress(uint16 *keyCode) {
|
|
|
|
if (haveNextChar()) {
|
|
|
|
*keyCode = getNextChar();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EventManager::haveNextChar() {
|
|
|
|
processInput();
|
|
|
|
return _nextKeyIn != _nextKeyOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventManager::processInput(bool can_delay) {
|
|
|
|
Common::Event event;
|
|
|
|
|
|
|
|
if (1 /*!g_IgnoreProcessInput*/) {
|
|
|
|
int flags = 0;
|
|
|
|
while (g_system->getEventManager()->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
flags |= 8;
|
|
|
|
mouseHandler(flags, _mousePos);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
flags |= 2;
|
|
|
|
mouseHandler(flags, _mousePos);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_MOUSEMOVE: {
|
|
|
|
int lastMouseAtEdge = _mouseAtEdge;
|
|
|
|
_mouseAtEdge = false;
|
|
|
|
_mousePos.x = event.mouse.x;
|
|
|
|
if (event.mouse.x <= 0) {
|
|
|
|
_mousePos.x = 0;
|
|
|
|
_mouseAtEdge = true;
|
|
|
|
}
|
2015-12-06 14:36:49 +01:00
|
|
|
|
|
|
|
if (_mousePos.x >= _vm->_graphics->_screenWidth) {
|
|
|
|
_mousePos.x = _vm->_graphics->_screenWidth;
|
2015-12-02 01:39:58 +01:00
|
|
|
_mouseAtEdge = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mousePos.y = event.mouse.y;
|
|
|
|
if (event.mouse.y <= 0) {
|
|
|
|
_mousePos.y = 0;
|
|
|
|
_mouseAtEdge = true;
|
|
|
|
}
|
2015-12-06 14:36:49 +01:00
|
|
|
|
|
|
|
if (_mousePos.y >= _vm->_graphics->_screenHeight) {
|
|
|
|
_mousePos.y = _vm->_graphics->_screenHeight;
|
2015-12-02 01:39:58 +01:00
|
|
|
_mouseAtEdge = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lastMouseAtEdge || !_mouseAtEdge)
|
|
|
|
mouseHandler(1, _mousePos);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
switch (event.kbd.keycode) {
|
|
|
|
case Common::KEYCODE_LEFTBRACKET:
|
|
|
|
_vm->changeVolume(-1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::KEYCODE_RIGHTBRACKET:
|
|
|
|
_vm->changeVolume(1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::KEYCODE_z:
|
|
|
|
//saveSettings();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
int n = ((((unsigned int)((_nextKeyIn + 1) >> 31) >> 26) + (byte)_nextKeyIn + 1) & 0x3F)
|
|
|
|
- ((unsigned int)((_nextKeyIn + 1) >> 31) >> 26);
|
|
|
|
if (n != _nextKeyOut) {
|
|
|
|
_keyBuf[_nextKeyIn] = event.kbd.keycode;
|
|
|
|
_nextKeyIn = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
case Common::EVENT_RTL:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-06 14:36:49 +01:00
|
|
|
g_system->copyRectToScreen(_vm->_graphics->_displayBuffer, _vm->_graphics->_screenWidth, 0, 0, _vm->_graphics->_screenWidth, _vm->_graphics->_screenHeight);
|
2015-12-02 01:39:58 +01:00
|
|
|
g_system->updateScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (can_delay)
|
|
|
|
g_system->delayMillis(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 EventManager::getNextChar() {
|
|
|
|
uint16 c = 0;
|
|
|
|
|
|
|
|
processInput();
|
|
|
|
if (_nextKeyIn != _nextKeyOut) {
|
|
|
|
c = _keyBuf[_nextKeyOut];
|
|
|
|
_nextKeyOut = ((((unsigned int)((_nextKeyOut + 1) >> 31) >> 26) + (byte)_nextKeyOut + 1) & 0x3F)
|
|
|
|
- ((unsigned int)((_nextKeyOut + 1) >> 31) >> 26);
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Point EventManager::updateAndGetMousePos() {
|
|
|
|
processInput();
|
|
|
|
|
|
|
|
return _mousePos;
|
|
|
|
}
|
2014-10-06 14:50:05 +02:00
|
|
|
} // End of namespace Lab
|