2021-02-19 02:17:41 +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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-03-26 01:17:07 +02:00
|
|
|
#include "graphics/cursorman.h"
|
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
#include "engines/nancy/nancy.h"
|
2021-04-01 21:04:38 +03:00
|
|
|
#include "engines/nancy/cursor.h"
|
2021-02-19 02:17:41 +02:00
|
|
|
#include "engines/nancy/graphics.h"
|
|
|
|
#include "engines/nancy/resource.h"
|
|
|
|
#include "engines/nancy/util.h"
|
|
|
|
|
|
|
|
namespace Nancy {
|
|
|
|
|
|
|
|
void CursorManager::init() {
|
2021-03-19 18:37:20 +02:00
|
|
|
Common::SeekableReadStream *chunk = g_nancy->getBootChunkStream("INV");
|
|
|
|
chunk->seek(0x1D2); // TODO
|
|
|
|
Common::String inventoryCursorsImageName = chunk->readString();
|
|
|
|
|
|
|
|
chunk = g_nancy->getBootChunkStream("CURS");
|
2021-03-20 18:18:29 +02:00
|
|
|
_cursors.reserve(56);
|
2021-03-19 18:37:20 +02:00
|
|
|
for (uint i = 0; i < 56; ++i) {
|
|
|
|
_cursors.push_back(Cursor());
|
|
|
|
chunk->seek(i * 16, SEEK_SET);
|
|
|
|
readRect(*chunk, _cursors[i].bounds);
|
|
|
|
chunk->seek(0x380 + i * 8, SEEK_SET);
|
|
|
|
_cursors[i].hotspot.x = chunk->readUint32LE();
|
|
|
|
_cursors[i].hotspot.y = chunk->readUint32LE();
|
|
|
|
}
|
|
|
|
|
|
|
|
readRect(*chunk, _primaryVideoInactiveZone);
|
|
|
|
_primaryVideoInitialPos.x = chunk->readUint16LE();
|
|
|
|
_primaryVideoInitialPos.y = chunk->readUint16LE();
|
|
|
|
|
|
|
|
g_nancy->_resource->loadImage(inventoryCursorsImageName, _invCursorsSurface);
|
|
|
|
|
|
|
|
setCursor(kNormalArrow, -1);
|
|
|
|
showCursor(false);
|
|
|
|
|
|
|
|
_isInitialized = true;
|
2021-02-19 02:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CursorManager::setCursor(CursorType type, int16 itemID) {
|
2021-03-19 18:37:20 +02:00
|
|
|
if (!_isInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == _curCursorType && itemID == _curItemID) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
_curCursorType = type;
|
|
|
|
_curItemID = itemID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasItem = false;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case kNormalArrow:
|
2021-04-17 15:20:59 +03:00
|
|
|
_curCursorID = 4;
|
2021-03-19 18:37:20 +02:00
|
|
|
break;
|
|
|
|
case kHotspotArrow:
|
2021-04-17 15:20:59 +03:00
|
|
|
_curCursorID = 6;
|
2021-03-19 18:37:20 +02:00
|
|
|
break;
|
2021-04-17 15:20:59 +03:00
|
|
|
default:
|
2021-03-19 18:37:20 +02:00
|
|
|
if (itemID == -1) {
|
|
|
|
// No item held, set to eyeglass
|
|
|
|
itemID = 0;
|
|
|
|
} else {
|
|
|
|
// Item held
|
|
|
|
itemID += 3;
|
|
|
|
hasItem = true;
|
|
|
|
}
|
|
|
|
|
2021-04-17 15:20:59 +03:00
|
|
|
_curCursorID = itemID * 4 + type;
|
2021-03-19 18:37:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Graphics::ManagedSurface *surf;
|
2021-04-17 15:20:59 +03:00
|
|
|
Common::Rect bounds = _cursors[_curCursorID].bounds;
|
|
|
|
Common::Point hotspot = _cursors[_curCursorID].hotspot;
|
2021-03-19 18:37:20 +02:00
|
|
|
|
|
|
|
if (hasItem) {
|
|
|
|
surf = &_invCursorsSurface;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
surf = &g_nancy->_graphicsManager->_object0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO this is ridiculous, figure out why just calling
|
|
|
|
// GetBasePtr() results in garbage
|
|
|
|
Graphics::Surface s;
|
|
|
|
s.create(bounds.width(), bounds.height(), surf->format);
|
|
|
|
s.copyRectToSurface(*surf, 0, 0, bounds);
|
|
|
|
|
|
|
|
// TODO hotspots are terrible for arrow cursors, fix that??
|
2021-03-22 18:56:52 +02:00
|
|
|
CursorMan.replaceCursor(s.getPixels(), s.w, s.h, hotspot.x, hotspot.y, g_nancy->_graphicsManager->getTransColor(), false, &g_nancy->_graphicsManager->getInputPixelFormat());
|
2021-03-19 18:37:20 +02:00
|
|
|
|
|
|
|
s.free();
|
2021-02-19 02:17:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CursorManager::setCursorType(CursorType type) {
|
2021-03-19 18:37:20 +02:00
|
|
|
setCursor(type, _curItemID);
|
2021-02-19 02:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CursorManager::setCursorItemID(int16 itemID) {
|
2021-03-19 18:37:20 +02:00
|
|
|
setCursor(_curCursorType, itemID);
|
2021-02-19 02:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CursorManager::showCursor(bool shouldShow) {
|
2021-03-19 18:37:20 +02:00
|
|
|
CursorMan.showMouse(shouldShow);
|
2021-02-19 02:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Nancy
|