scummvm/engines/lab/eventman.cpp

209 lines
5.4 KiB
C++
Raw Normal View History

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.
*
*/
#include "common/events.h"
2015-11-24 23:59:30 +01:00
#include "lab/lab.h"
#include "lab/dispman.h"
#include "lab/eventman.h"
#include "lab/image.h"
2014-10-06 14:50:05 +02:00
namespace Lab {
2015-12-13 05:00:28 +02:00
static const byte mouseData[] = {
2015-12-08 09:19:00 +01:00
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
#define MOUSE_WIDTH 10
#define MOUSE_HEIGHT 15
2014-10-06 14:50:05 +02:00
EventManager::EventManager(LabEngine *vm) : _vm(vm) {
_leftClick = false;
_rightClick = false;
_lastButtonHit = nullptr;
_screenButtonList = nullptr;
_hitButton = nullptr;
_mousePos = Common::Point(0, 0);
_keyPressed = Common::KEYCODE_INVALID;
}
2015-12-13 19:36:56 +02:00
Button *EventManager::checkButtonHit(ButtonList *buttonList, Common::Point pos) {
for (ButtonList::iterator buttonItr = buttonList->begin(); buttonItr != buttonList->end(); ++buttonItr) {
Button *button = *buttonItr;
2015-12-13 20:15:24 +01:00
Common::Rect buttonRect(button->_x, button->_y, button->_x + button->_image->_width - 1, button->_y + button->_image->_height - 1);
2015-12-07 10:31:46 +02:00
2015-12-13 20:15:24 +01:00
if (buttonRect.contains(pos) && button->_isEnabled) {
2015-11-30 00:12:01 +01:00
if (_vm->_isHiRes) {
2015-12-13 19:36:56 +02:00
_hitButton = button;
2014-10-06 14:50:05 +02:00
} else {
2015-12-13 20:15:24 +01:00
button->_altImage->drawImage(button->_x, button->_y);
2014-10-06 14:50:05 +02:00
for (int i = 0; i < 3; i++)
2015-11-29 23:34:35 +01:00
_vm->waitTOF();
2014-10-06 14:50:05 +02:00
2015-12-13 20:15:24 +01:00
button->_image->drawImage(button->_x, button->_y);
2014-10-06 14:50:05 +02:00
}
2015-12-13 19:36:56 +02:00
return button;
2014-10-06 14:50:05 +02:00
}
}
return nullptr;
2014-10-06 14:50:05 +02:00
}
2015-12-13 19:36:56 +02:00
void EventManager::attachButtonList(ButtonList *buttonList) {
if (_screenButtonList != buttonList)
_lastButtonHit = nullptr;
2014-10-06 14:50:05 +02:00
2015-12-13 19:36:56 +02:00
_screenButtonList = buttonList;
2014-10-06 14:50:05 +02:00
}
2015-12-13 19:36:56 +02:00
Button *EventManager::getButton(uint16 id) {
for (ButtonList::iterator buttonItr = _screenButtonList->begin(); buttonItr != _screenButtonList->end(); ++buttonItr) {
Button *button = *buttonItr;
2015-12-16 23:27:32 +02:00
if (button->_buttonId == id)
2015-12-13 19:36:56 +02:00
return button;
}
return nullptr;
}
void EventManager::updateMouse() {
if (!_hitButton)
return;
2014-10-06 14:50:05 +02:00
_hitButton->_altImage->drawImage(_hitButton->_x, _hitButton->_y);
for (int i = 0; i < 3; i++)
_vm->waitTOF();
_hitButton->_image->drawImage(_hitButton->_x, _hitButton->_y);
_hitButton = nullptr;
_vm->_graphics->screenUpdate();
2014-10-06 14:50:05 +02:00
}
void EventManager::initMouse() {
2015-12-23 18:56:35 +01:00
_vm->_system->setMouseCursor(mouseData, MOUSE_WIDTH, MOUSE_HEIGHT, 0, 0, 0);
_vm->_system->showMouse(false);
2014-10-06 14:50:05 +02:00
setMousePos(Common::Point(_vm->_graphics->_screenWidth / 2, _vm->_graphics->_screenHeight / 2));
2014-10-06 14:50:05 +02:00
}
void EventManager::mouseShow() {
2015-12-23 18:56:35 +01:00
_vm->_system->showMouse(true);
2014-10-06 14:50:05 +02:00
}
void EventManager::mouseHide() {
_vm->_system->showMouse(false);
2014-10-06 14:50:05 +02:00
}
void EventManager::setMousePos(Common::Point pos) {
2015-11-30 00:12:01 +01:00
if (_vm->_isHiRes)
2015-12-23 18:56:35 +01:00
_vm->_system->warpMouse(pos.x, pos.y);
else
2015-12-23 18:56:35 +01:00
_vm->_system->warpMouse(pos.x * 2, pos.y);
2014-10-06 14:50:05 +02:00
}
void EventManager::processInput() {
Common::Event event;
Button *curButton = nullptr;
2015-12-23 18:56:35 +01:00
while (_vm->_system->getEventManager()->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_LBUTTONDOWN:
if (_screenButtonList)
curButton = checkButtonHit(_screenButtonList, _vm->_isHiRes ? _mousePos : Common::Point(_mousePos.x / 2, _mousePos.y));
if (curButton)
_lastButtonHit = curButton;
else
_leftClick = true;
break;
case Common::EVENT_RBUTTONDOWN:
_rightClick = true;
break;
case Common::EVENT_MOUSEMOVE:
_mousePos = event.mouse;
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_d:
if (event.kbd.hasFlags(Common::KBD_CTRL)) {
// Open debugger console
_vm->_console->attach();
continue;
}
// Intentional fall through
default:
_keyPressed = event.kbd;
break;
}
break;
case Common::EVENT_QUIT:
case Common::EVENT_RTL:
default:
break;
}
}
2015-12-23 18:56:35 +01:00
_vm->_system->copyRectToScreen(_vm->_graphics->_displayBuffer, _vm->_graphics->_screenWidth, 0, 0, _vm->_graphics->_screenWidth, _vm->_graphics->_screenHeight);
_vm->_console->onFrame();
2015-12-23 18:56:35 +01:00
_vm->_system->updateScreen();
}
Common::Point EventManager::updateAndGetMousePos() {
processInput();
return _mousePos;
}
2015-12-19 12:48:12 +02:00
2014-10-06 14:50:05 +02:00
} // End of namespace Lab