2019-11-04 22:24:37 +01: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.
|
|
|
|
*
|
2021-12-26 15:54:17 -08:00
|
|
|
* 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2019-11-04 22:24:37 +01: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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 15:54:17 -08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-11-04 22:24:37 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-03-06 14:40:22 +02:00
|
|
|
#include "graphics/cursorman.h"
|
2021-10-13 21:08:54 -07:00
|
|
|
#include "chewy/cursor.h"
|
|
|
|
#include "chewy/events.h"
|
2022-02-13 18:43:31 -08:00
|
|
|
#include "chewy/globals.h"
|
2019-11-04 22:24:37 +01:00
|
|
|
|
2021-09-12 15:41:09 -07:00
|
|
|
namespace Chewy {
|
|
|
|
|
2022-06-29 01:21:04 +03:00
|
|
|
Cursor::Cursor() {
|
|
|
|
const auto res = new SpriteResource(CURSOR_TAF);
|
|
|
|
const auto invRes = new SpriteResource(INVENTORY_TAF);
|
|
|
|
_cursorCount = res->getChunkCount();
|
|
|
|
_invCursorCount = invRes->getChunkCount();
|
|
|
|
_curSprites = new CursorSprite[_cursorCount + _invCursorCount];
|
2022-02-10 20:27:40 -08:00
|
|
|
|
2022-06-29 01:21:04 +03:00
|
|
|
for (uint32 i = 0; i < _cursorCount + _invCursorCount; i++) {
|
|
|
|
const TAFChunk *sprite = (i < _cursorCount) ? res->getSprite(i) : invRes->getSprite(i - _cursorCount);
|
|
|
|
_curSprites[i].width = sprite->width;
|
|
|
|
_curSprites[i].height = sprite->height;
|
|
|
|
_curSprites[i].data = new byte[sprite->width * sprite->height];
|
|
|
|
memcpy(_curSprites[i].data, sprite->data, sprite->width * sprite->height);
|
|
|
|
delete sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete invRes;
|
|
|
|
delete res;
|
|
|
|
|
|
|
|
_currentCursor.data = _customCursor.data = nullptr;
|
|
|
|
_currentCursor.width = _customCursor.width = 0;
|
|
|
|
_currentCursor.height = _customCursor.height = 0;
|
|
|
|
|
|
|
|
clearCustomCursor();
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
Cursor::~Cursor() {
|
2022-06-29 01:21:04 +03:00
|
|
|
for (uint32 i = 0; i < _cursorCount + _invCursorCount; i++) {
|
|
|
|
delete[] _curSprites[i].data;
|
|
|
|
_curSprites[i].data = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] _curSprites;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-06-29 01:21:04 +03:00
|
|
|
void Cursor::updateCursor() {
|
2022-03-06 14:40:22 +02:00
|
|
|
if (CursorMan.isVisible()) {
|
2022-02-25 00:46:48 +01:00
|
|
|
--_curAniCountdown;
|
2022-04-13 02:16:10 +03:00
|
|
|
if (_curAniCountdown <= 0) {
|
|
|
|
_curAniCountdown = _animDelay;
|
2022-02-25 00:46:48 +01:00
|
|
|
++_aniCount;
|
2022-04-13 02:16:10 +03:00
|
|
|
if (_aniCount > _animEnd)
|
|
|
|
_aniCount = _animStart;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-06-29 01:21:04 +03:00
|
|
|
if (_customCursor.data != nullptr) {
|
|
|
|
CursorMan.replaceCursor(_customCursor.data, _customCursor.width, _customCursor.height, 0, 0, 0);
|
|
|
|
_currentCursor.data = _customCursor.data;
|
|
|
|
_currentCursor.width = _customCursor.width;
|
|
|
|
_currentCursor.height = _customCursor.height;
|
|
|
|
} else {
|
|
|
|
const CursorSprite s = _curSprites[_aniCount + _cursorOffset];
|
|
|
|
CursorMan.replaceCursor(s.data, s.width, s.height, 0, 0, 0);
|
|
|
|
_currentCursor.data = s.data;
|
|
|
|
_currentCursor.width = s.width;
|
|
|
|
_currentCursor.height = s.height;
|
|
|
|
}
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-29 01:21:04 +03:00
|
|
|
void Cursor::showCursor() {
|
2022-03-06 14:40:22 +02:00
|
|
|
CursorMan.showMouse(true);
|
2022-06-29 01:21:04 +03:00
|
|
|
updateCursor();
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-06-29 01:21:04 +03:00
|
|
|
void Cursor::hideCursor() {
|
2022-03-06 14:40:22 +02:00
|
|
|
CursorMan.showMouse(false);
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-04-13 02:16:10 +03:00
|
|
|
void Cursor::setAnimation(uint8 start, uint8 end, int16 delay) {
|
|
|
|
_aniCount = _animStart = start;
|
|
|
|
_animEnd = end;
|
|
|
|
if (delay >= 0)
|
|
|
|
_animDelay = delay;
|
2022-02-25 00:46:48 +01:00
|
|
|
_curAniCountdown = 0;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-06-29 01:21:04 +03:00
|
|
|
void Cursor::setCustomRoomCursor(byte *roomSprite) {
|
|
|
|
const uint16 width = READ_LE_INT16(roomSprite);
|
|
|
|
const uint16 height = READ_LE_INT16(roomSprite + 2);
|
|
|
|
setCustomCursor(roomSprite + 4, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cursor::setCustomCursor(byte *data, uint16 width, uint16 height) {
|
|
|
|
_currentCursor.data = _customCursor.data = data;
|
|
|
|
_currentCursor.width = _customCursor.width = width;
|
|
|
|
_currentCursor.height = _customCursor.height = height;
|
|
|
|
|
|
|
|
CursorMan.replaceCursor(_customCursor.data, _customCursor.width, _customCursor.height, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cursor::clearCustomCursor() {
|
|
|
|
if (_customCursor.data) {
|
|
|
|
const CursorSprite s = _curSprites[_aniCount + _cursorOffset];
|
|
|
|
CursorMan.replaceCursor(s.data, s.width, s.height, 0, 0, 0);
|
|
|
|
_currentCursor.data = s.data;
|
|
|
|
_currentCursor.width = s.width;
|
|
|
|
_currentCursor.height = s.height;
|
|
|
|
|
|
|
|
_customCursor.data = nullptr;
|
|
|
|
_customCursor.width = 0;
|
|
|
|
_customCursor.height = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
void Cursor::move(int16 x, int16 y) {
|
2022-03-06 14:40:22 +02:00
|
|
|
g_events->warpMouse(Common::Point(x, y));
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2021-09-12 15:41:09 -07:00
|
|
|
} // namespace Chewy
|