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-12-08 21:39:30 +01:00
|
|
|
#include "common/events.h"
|
|
|
|
|
2015-11-24 23:59:30 +01:00
|
|
|
#include "lab/lab.h"
|
2015-12-08 21:19:41 +01:00
|
|
|
|
|
|
|
#include "lab/dispman.h"
|
|
|
|
#include "lab/eventman.h"
|
2015-12-08 20:46:13 +01:00
|
|
|
#include "lab/image.h"
|
2015-12-08 21:00:50 +01:00
|
|
|
#include "lab/utils.h"
|
2014-10-06 14:50:05 +02:00
|
|
|
|
|
|
|
namespace Lab {
|
|
|
|
|
2015-12-13 19:36:56 +02:00
|
|
|
Button *EventManager::createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *image, Image *altImage) {
|
|
|
|
Button *button = new Button();
|
|
|
|
|
|
|
|
if (button) {
|
|
|
|
button->x = _vm->_utils->vgaScaleX(x);
|
|
|
|
button->y = y;
|
|
|
|
button->_buttonID = id;
|
|
|
|
button->_keyEquiv = key;
|
|
|
|
button->_image = image;
|
|
|
|
button->_altImage = altImage;
|
|
|
|
button->isEnabled = true;
|
|
|
|
|
|
|
|
return button;
|
2014-10-06 14:50:05 +02:00
|
|
|
} else
|
2015-12-08 08:53:35 +01:00
|
|
|
return nullptr;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-13 19:36:56 +02:00
|
|
|
void EventManager::freeButtonList(ButtonList *buttonList) {
|
|
|
|
for (ButtonList::iterator buttonIter = buttonList->begin(); buttonIter != buttonList->end(); ++buttonIter) {
|
|
|
|
Button *button = *buttonIter;
|
|
|
|
delete button->_image;
|
|
|
|
delete button->_altImage;
|
|
|
|
delete button;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
2015-12-06 22:50:41 +02:00
|
|
|
|
2015-12-13 19:36:56 +02:00
|
|
|
buttonList->clear();
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
2015-12-13 19:36:56 +02:00
|
|
|
* Draws a button list to the screen.
|
2015-12-08 09:46:54 +01:00
|
|
|
*/
|
2015-12-13 19:36:56 +02:00
|
|
|
void EventManager::drawButtonList(ButtonList *buttonList) {
|
|
|
|
for (ButtonList::iterator button = buttonList->begin(); button != buttonList->end(); ++button) {
|
|
|
|
(*button)->_image->drawImage((*button)->x, (*button)->y);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-13 19:36:56 +02:00
|
|
|
if (!(*button)->isEnabled)
|
|
|
|
disableButton((*button), 1);
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
2015-12-13 19:36:56 +02:00
|
|
|
* Dims a button, and makes it unavailable for using.
|
2015-12-08 09:46:54 +01:00
|
|
|
*/
|
2015-12-13 19:36:56 +02:00
|
|
|
void EventManager::disableButton(Button *button, uint16 penColor) {
|
|
|
|
_vm->_graphics->overlayRect(penColor, button->x, button->y, button->x + button->_image->_width - 1, button->y + button->_image->_height - 1);
|
|
|
|
button->isEnabled = false;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
2015-12-13 19:36:56 +02:00
|
|
|
* Undims a button, and makes it available again.
|
2015-12-08 09:46:54 +01:00
|
|
|
*/
|
2015-12-13 19:36:56 +02:00
|
|
|
void EventManager::enableButton(Button *button) {
|
|
|
|
button->_image->drawImage(button->x, button->y);
|
|
|
|
button->isEnabled = true;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
2015-12-13 19:36:56 +02:00
|
|
|
* Make a key press have the right case for a button KeyEquiv value.
|
2015-12-08 09:46:54 +01:00
|
|
|
*/
|
2015-12-13 19:36:56 +02:00
|
|
|
uint16 EventManager::makeButtonKeyEquiv(uint16 key) {
|
2014-10-06 14:50:05 +02:00
|
|
|
if (Common::isAlnum(key))
|
|
|
|
key = tolower(key);
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
2015-12-13 19:36:56 +02:00
|
|
|
* Checks whether or not the coords fall within one of the buttons in a list
|
|
|
|
* of buttons.
|
2015-12-08 09:46:54 +01:00
|
|
|
*/
|
2015-12-13 19:36:56 +02:00
|
|
|
Button *EventManager::checkNumButtonHit(ButtonList *buttonList, uint16 key) {
|
2014-10-06 14:50:05 +02:00
|
|
|
uint16 gkey = key - '0';
|
|
|
|
|
2015-12-13 19:36:56 +02:00
|
|
|
if (!buttonList)
|
2015-12-08 08:53:35 +01:00
|
|
|
return nullptr;
|
2015-12-06 22:50:41 +02:00
|
|
|
|
2015-12-13 19:36:56 +02:00
|
|
|
for (ButtonList::iterator buttonItr = buttonList->begin(); buttonItr != buttonList->end(); ++buttonItr) {
|
|
|
|
Button *button = *buttonItr;
|
|
|
|
if ((gkey - 1 == button->_buttonID || (gkey == 0 && button->_buttonID == 9) ||
|
|
|
|
(button->_keyEquiv != 0 && makeButtonKeyEquiv(key) == button->_keyEquiv))
|
|
|
|
&& button->isEnabled) {
|
2015-12-13 14:04:00 +01:00
|
|
|
mouseHide();
|
2015-12-13 19:36:56 +02:00
|
|
|
button->_altImage->drawImage(button->x, button->y);
|
2015-12-13 14:04:00 +01:00
|
|
|
mouseShow();
|
2014-10-06 14:50:05 +02:00
|
|
|
g_system->delayMillis(80);
|
2015-12-13 14:04:00 +01:00
|
|
|
mouseHide();
|
2015-12-13 19:36:56 +02:00
|
|
|
button->_image->drawImage(button->x, button->y);
|
2015-12-13 14:04:00 +01:00
|
|
|
mouseShow();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 14:04:00 +01:00
|
|
|
return nullptr;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-13 15:37:39 +02:00
|
|
|
IntuiMessage *EventManager::getMsg() {
|
2015-12-13 14:04:00 +01:00
|
|
|
static IntuiMessage message;
|
|
|
|
|
2015-12-13 15:37:39 +02:00
|
|
|
updateMouse();
|
2014-12-26 00:32:42 +01:00
|
|
|
|
2015-12-13 15:37:39 +02:00
|
|
|
int qualifiers = _keyPressed.flags;
|
2015-12-13 19:36:56 +02:00
|
|
|
Button *curgad = mouseButton();
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-08 08:53:35 +01:00
|
|
|
if (curgad) {
|
2015-12-13 15:37:39 +02:00
|
|
|
updateMouse();
|
2015-12-13 19:36:56 +02:00
|
|
|
message._msgClass = BUTTONUP;
|
|
|
|
message._code = curgad->_buttonID;
|
|
|
|
message._buttonID = curgad->_buttonID;
|
2015-12-13 14:04:00 +01:00
|
|
|
message._qualifier = qualifiers;
|
|
|
|
return &message;
|
2015-12-13 15:37:39 +02:00
|
|
|
} else if (mouseButton(&message._mouseX, &message._mouseY, true)) {
|
2015-12-08 11:27:34 +01:00
|
|
|
// Left Button
|
2015-12-13 14:04:00 +01:00
|
|
|
message._qualifier = IEQUALIFIER_LEFTBUTTON | qualifiers;
|
|
|
|
message._msgClass = MOUSEBUTTONS;
|
|
|
|
return &message;
|
2015-12-13 15:37:39 +02:00
|
|
|
} else if (mouseButton(&message._mouseX, &message._mouseY, false)) {
|
2015-12-08 11:27:34 +01:00
|
|
|
// Right Button
|
2015-12-13 14:12:18 +01:00
|
|
|
message._qualifier = IEQUALIFIER_RIGHTBUTTON | qualifiers;
|
2015-12-13 14:04:00 +01:00
|
|
|
message._msgClass = MOUSEBUTTONS;
|
|
|
|
return &message;
|
2015-12-13 15:37:39 +02:00
|
|
|
} else if (keyPress(&message._code)) {
|
2015-12-08 11:27:34 +01:00
|
|
|
// Keyboard key
|
2015-12-13 19:36:56 +02:00
|
|
|
curgad = checkNumButtonHit(_screenButtonList, message._code);
|
2014-10-06 14:50:05 +02:00
|
|
|
|
|
|
|
if (curgad) {
|
2015-12-13 19:36:56 +02:00
|
|
|
message._msgClass = BUTTONUP;
|
|
|
|
message._code = curgad->_buttonID;
|
|
|
|
message._buttonID = curgad->_buttonID;
|
2014-10-06 14:50:05 +02:00
|
|
|
} else
|
2015-12-13 14:04:00 +01:00
|
|
|
message._msgClass = RAWKEY;
|
2014-10-06 14:50:05 +02:00
|
|
|
|
2015-12-13 14:04:00 +01:00
|
|
|
message._qualifier = qualifiers;
|
|
|
|
return &message;
|
2014-10-06 14:50:05 +02:00
|
|
|
} else
|
2015-12-08 08:53:35 +01:00
|
|
|
return nullptr;
|
2014-10-06 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Lab
|