scummvm/engines/lab/interface.cpp

169 lines
4.6 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"
#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) {
2015-12-13 20:15:24 +01:00
button->_x = _vm->_utils->vgaScaleX(x);
button->_y = y;
2015-12-16 23:27:32 +02:00
button->_buttonId = id;
2015-12-13 19:36:56 +02:00
button->_keyEquiv = key;
button->_image = image;
button->_altImage = altImage;
2015-12-13 20:15:24 +01:00
button->_isEnabled = true;
2015-12-13 19:36:56 +02:00
return button;
2014-10-06 14:50:05 +02:00
} else
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-13 19:36:56 +02:00
buttonList->clear();
2014-10-06 14:50:05 +02:00
}
/**
2015-12-13 19:36:56 +02:00
* Draws a button list to the screen.
*/
2015-12-13 19:36:56 +02:00
void EventManager::drawButtonList(ButtonList *buttonList) {
for (ButtonList::iterator button = buttonList->begin(); button != buttonList->end(); ++button) {
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 20:15:24 +01:00
if (!(*button)->_isEnabled)
2015-12-13 19:36:56 +02:00
disableButton((*button), 1);
2014-10-06 14:50:05 +02:00
}
}
/**
2015-12-13 19:36:56 +02:00
* Dims a button, and makes it unavailable for using.
*/
2015-12-13 19:36:56 +02:00
void EventManager::disableButton(Button *button, uint16 penColor) {
2015-12-13 20:15:24 +01:00
_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-13 19:36:56 +02:00
* Undims a button, and makes it available again.
*/
2015-12-13 19:36:56 +02:00
void EventManager::enableButton(Button *button) {
2015-12-13 20:15:24 +01:00
button->_image->drawImage(button->_x, button->_y);
button->_isEnabled = true;
2014-10-06 14:50:05 +02:00
}
/**
2015-12-13 19:36:56 +02:00
* Make a key press have the right case for a button KeyEquiv value.
*/
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-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-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)
return nullptr;
2015-12-13 19:36:56 +02:00
for (ButtonList::iterator buttonItr = buttonList->begin(); buttonItr != buttonList->end(); ++buttonItr) {
Button *button = *buttonItr;
2015-12-16 23:27:32 +02:00
if (((gkey - 1 == button->_buttonId) || ((gkey == 0) && (button->_buttonId == 9))
|| ((button->_keyEquiv != 0) && (makeButtonKeyEquiv(key) == button->_keyEquiv)))
2015-12-13 20:15:24 +01:00
&& button->_isEnabled) {
button->_altImage->drawImage(button->_x, button->_y);
2014-10-06 14:50:05 +02:00
g_system->delayMillis(80);
2015-12-13 20:15:24 +01:00
button->_image->drawImage(button->_x, button->_y);
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 15:37:39 +02:00
IntuiMessage *EventManager::getMsg() {
static IntuiMessage message;
2015-12-13 15:37:39 +02:00
updateMouse();
2014-12-26 00:32:42 +01:00
if (_lastButtonHit) {
2015-12-13 15:37:39 +02:00
updateMouse();
2015-12-18 00:41:24 +02:00
message._msgClass = kMessageButtonUp;
message._code = _lastButtonHit->_buttonId;
message._qualifier = _keyPressed.flags;
_lastButtonHit = nullptr;
return &message;
2015-12-17 00:35:36 +02:00
} else if (_leftClick || _rightClick) {
2015-12-18 00:41:24 +02:00
message._msgClass = (_leftClick) ? kMessageLeftClick : kMessageRightClick;
message._qualifier = 0;
2015-12-18 00:58:36 +02:00
message._mouse = _mousePos;
if (!_vm->_isHiRes)
message._mouse.x /= 2;
2015-12-17 00:35:36 +02:00
_leftClick = _rightClick = false;
return &message;
2015-12-13 15:37:39 +02:00
} else if (keyPress(&message._code)) {
Button *curButton = checkNumButtonHit(_screenButtonList, message._code);
2014-10-06 14:50:05 +02:00
2015-12-16 23:27:32 +02:00
if (curButton) {
2015-12-18 00:41:24 +02:00
message._msgClass = kMessageButtonUp;
message._code = curButton->_buttonId;
2014-10-06 14:50:05 +02:00
} else
2015-12-18 00:41:24 +02:00
message._msgClass = kMessageRawKey;
2014-10-06 14:50:05 +02:00
message._qualifier = _keyPressed.flags;
return &message;
2014-10-06 14:50:05 +02:00
} else
return nullptr;
2014-10-06 14:50:05 +02:00
}
} // End of namespace Lab