2010-11-25 04:49:11 +00: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 18:47:58 +01: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.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2010-11-25 04:49:11 +00: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.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2010-11-25 04:49:11 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-25 04:49:11 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mohawk/cursors.h"
|
2011-03-28 15:20:30 -04:00
|
|
|
#include "mohawk/mohawk.h"
|
2010-11-25 04:49:11 +00:00
|
|
|
#include "mohawk/resource.h"
|
|
|
|
|
2010-11-28 22:55:15 +00:00
|
|
|
#include "common/macresman.h"
|
2010-11-25 04:49:11 +00:00
|
|
|
#include "common/system.h"
|
2011-05-05 19:35:31 -04:00
|
|
|
#include "common/textconsole.h"
|
2022-12-01 14:17:17 +00:00
|
|
|
#include "common/formats/winexe_ne.h"
|
|
|
|
#include "common/formats/winexe_pe.h"
|
2010-11-25 04:49:11 +00:00
|
|
|
#include "graphics/cursorman.h"
|
2011-05-05 19:35:31 -04:00
|
|
|
#include "graphics/maccursor.h"
|
2011-03-04 23:17:57 -05:00
|
|
|
#include "graphics/wincursor.h"
|
2010-11-25 04:49:11 +00:00
|
|
|
|
2011-03-28 15:20:30 -04:00
|
|
|
#ifdef ENABLE_MYST
|
|
|
|
#include "mohawk/myst.h"
|
2016-06-26 07:20:21 +02:00
|
|
|
#include "mohawk/myst_graphics.h"
|
2011-03-28 15:20:30 -04:00
|
|
|
#endif
|
|
|
|
|
2010-11-25 04:49:11 +00:00
|
|
|
namespace Mohawk {
|
|
|
|
|
|
|
|
void CursorManager::showCursor() {
|
|
|
|
CursorMan.showMouse(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CursorManager::hideCursor() {
|
|
|
|
CursorMan.showMouse(false);
|
|
|
|
}
|
|
|
|
|
2010-11-28 22:55:15 +00:00
|
|
|
void CursorManager::setDefaultCursor() {
|
2011-08-16 00:30:42 -04:00
|
|
|
Graphics::Cursor *cursor = Graphics::makeDefaultWinCursor();
|
|
|
|
|
2019-08-09 20:45:27 +01:00
|
|
|
CursorMan.replaceCursor(cursor);
|
2011-08-16 00:30:42 -04:00
|
|
|
|
|
|
|
delete cursor;
|
2010-11-28 22:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CursorManager::setCursor(uint16 id) {
|
|
|
|
// For the base class, just use the default cursor always
|
|
|
|
setDefaultCursor();
|
|
|
|
}
|
|
|
|
|
2011-05-05 19:35:31 -04:00
|
|
|
void CursorManager::setMacCursor(Common::SeekableReadStream *stream) {
|
2010-11-28 22:55:15 +00:00
|
|
|
assert(stream);
|
2011-03-07 01:07:53 -05:00
|
|
|
|
2011-05-05 19:35:31 -04:00
|
|
|
Graphics::MacCursor *macCursor = new Graphics::MacCursor();
|
2010-11-28 22:55:15 +00:00
|
|
|
|
2011-05-05 19:35:31 -04:00
|
|
|
if (!macCursor->readFromStream(*stream))
|
|
|
|
error("Could not parse Mac cursor");
|
2010-11-28 22:55:15 +00:00
|
|
|
|
2019-08-09 20:45:27 +01:00
|
|
|
CursorMan.replaceCursor(macCursor);
|
2010-11-28 22:55:15 +00:00
|
|
|
|
2011-05-05 19:35:31 -04:00
|
|
|
delete macCursor;
|
|
|
|
delete stream;
|
2010-11-28 22:55:15 +00:00
|
|
|
}
|
|
|
|
|
2011-01-26 19:13:53 +00:00
|
|
|
void DefaultCursorManager::setCursor(uint16 id) {
|
2011-05-05 19:35:31 -04:00
|
|
|
setMacCursor(_vm->getResource(_tag, id));
|
2011-01-26 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-28 15:20:30 -04:00
|
|
|
#ifdef ENABLE_MYST
|
|
|
|
|
2010-11-25 04:49:11 +00:00
|
|
|
MystCursorManager::MystCursorManager(MohawkEngine_Myst *vm) : _vm(vm) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MystCursorManager::~MystCursorManager() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MystCursorManager::showCursor() {
|
|
|
|
CursorMan.showMouse(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MystCursorManager::hideCursor() {
|
|
|
|
CursorMan.showMouse(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MystCursorManager::setCursor(uint16 id) {
|
2011-05-15 17:22:09 +02:00
|
|
|
// Zero means empty cursor
|
|
|
|
if (id == 0) {
|
2012-12-17 19:01:03 +02:00
|
|
|
static const byte emptyCursor[4] = { 0, 0, 0, 0 };
|
2012-12-17 18:45:17 +02:00
|
|
|
CursorMan.replaceCursor(&emptyCursor, 2, 2, 0, 0, 0);
|
2011-05-15 17:22:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-25 04:49:11 +00:00
|
|
|
Common::SeekableReadStream *clrcStream = _vm->getResource(ID_CLRC, id);
|
|
|
|
uint16 hotspotX = clrcStream->readUint16LE();
|
|
|
|
uint16 hotspotY = clrcStream->readUint16LE();
|
|
|
|
delete clrcStream;
|
|
|
|
|
2016-06-26 07:20:21 +02:00
|
|
|
// Both Myst and Myst ME use the "MystBitmap" format for cursor images.
|
|
|
|
MohawkSurface *mhkSurface = _vm->_gfx->findImage(id);
|
|
|
|
Graphics::Surface *surface = mhkSurface->getSurface();
|
|
|
|
|
2010-11-25 04:49:11 +00:00
|
|
|
// Myst ME stores some cursors as 24bpp images instead of 8bpp
|
2011-04-17 17:28:16 +02:00
|
|
|
if (surface->format.bytesPerPixel == 1) {
|
2016-09-25 10:00:54 +02:00
|
|
|
// The transparent color is almost always 255, except for the main cursor (100)
|
|
|
|
// in the D'ni archive, where it is 0.
|
2016-12-11 09:50:48 +01:00
|
|
|
// Using the color of the first pixel as the transparent color for the main cursor always works.
|
|
|
|
byte transparentColor;
|
|
|
|
if (id == kDefaultMystCursor) {
|
|
|
|
transparentColor = ((byte *)surface->getPixels())[0];
|
|
|
|
} else {
|
|
|
|
transparentColor = 255;
|
|
|
|
}
|
2016-09-25 10:00:54 +02:00
|
|
|
CursorMan.replaceCursor(surface->getPixels(), surface->w, surface->h, hotspotX, hotspotY, transparentColor);
|
2013-08-22 20:37:16 -04:00
|
|
|
|
|
|
|
// We're using the screen palette for the original game, but we need
|
|
|
|
// to use this for any 8bpp cursor in ME.
|
2020-03-27 20:14:46 +01:00
|
|
|
if (_vm->isGameVariant(GF_ME))
|
2013-08-22 20:37:16 -04:00
|
|
|
CursorMan.replaceCursorPalette(mhkSurface->getPalette(), 0, 256);
|
2010-11-25 04:49:11 +00:00
|
|
|
} else {
|
|
|
|
Graphics::PixelFormat pixelFormat = g_system->getScreenFormat();
|
2013-08-03 02:40:23 +02:00
|
|
|
CursorMan.replaceCursor(surface->getPixels(), surface->w, surface->h, hotspotX, hotspotY, pixelFormat.RGBToColor(255, 255, 255), false, &pixelFormat);
|
2010-11-25 04:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-28 22:55:15 +00:00
|
|
|
void MystCursorManager::setDefaultCursor() {
|
|
|
|
setCursor(kDefaultMystCursor);
|
|
|
|
}
|
|
|
|
|
2011-03-28 15:20:30 -04:00
|
|
|
#endif
|
|
|
|
|
2010-11-28 22:55:15 +00:00
|
|
|
MacCursorManager::MacCursorManager(const Common::String &appName) {
|
2010-11-29 06:35:50 +00:00
|
|
|
if (!appName.empty()) {
|
|
|
|
_resFork = new Common::MacResManager();
|
2010-11-28 22:55:15 +00:00
|
|
|
|
2010-11-29 06:35:50 +00:00
|
|
|
if (!_resFork->open(appName)) {
|
|
|
|
// Not all have cursors anyway, so this is not a problem
|
|
|
|
delete _resFork;
|
2018-03-31 12:52:08 +02:00
|
|
|
_resFork = nullptr;
|
2010-11-29 06:35:50 +00:00
|
|
|
}
|
2011-03-07 10:56:55 -05:00
|
|
|
} else {
|
2018-03-31 12:52:08 +02:00
|
|
|
_resFork = nullptr;
|
2010-11-28 22:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MacCursorManager::~MacCursorManager() {
|
|
|
|
delete _resFork;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacCursorManager::setCursor(uint16 id) {
|
|
|
|
if (!_resFork) {
|
|
|
|
setDefaultCursor();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-07 01:07:53 -05:00
|
|
|
// Try a color cursor first
|
2011-04-12 16:53:15 +02:00
|
|
|
Common::SeekableReadStream *stream = _resFork->getResource(MKTAG('c','r','s','r'), id);
|
2010-11-28 22:55:15 +00:00
|
|
|
|
2011-05-05 19:35:31 -04:00
|
|
|
// Fall back to monochrome cursors
|
|
|
|
if (!stream)
|
|
|
|
stream = _resFork->getResource(MKTAG('C','U','R','S'), id);
|
2010-11-28 22:55:15 +00:00
|
|
|
|
2011-08-29 10:34:48 -04:00
|
|
|
if (stream)
|
2011-05-05 19:35:31 -04:00
|
|
|
setMacCursor(stream);
|
2011-08-29 10:34:48 -04:00
|
|
|
else
|
2011-03-07 01:07:53 -05:00
|
|
|
setDefaultCursor();
|
2010-11-28 22:55:15 +00:00
|
|
|
}
|
|
|
|
|
2011-01-26 19:13:53 +00:00
|
|
|
LivingBooksCursorManager_v2::LivingBooksCursorManager_v2() {
|
|
|
|
// Try to open the system archive if we have it
|
|
|
|
_sysArchive = new MohawkArchive();
|
|
|
|
|
2011-06-28 11:58:52 -04:00
|
|
|
if (!_sysArchive->openFile("system.mhk")) {
|
2011-01-26 19:13:53 +00:00
|
|
|
delete _sysArchive;
|
2018-03-31 12:52:08 +02:00
|
|
|
_sysArchive = nullptr;
|
2011-01-26 19:13:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LivingBooksCursorManager_v2::~LivingBooksCursorManager_v2() {
|
|
|
|
delete _sysArchive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LivingBooksCursorManager_v2::setCursor(uint16 id) {
|
|
|
|
if (_sysArchive && _sysArchive->hasResource(ID_TCUR, id)) {
|
2011-05-05 19:35:31 -04:00
|
|
|
setMacCursor(_sysArchive->getResource(ID_TCUR, id));
|
2011-01-26 19:13:53 +00:00
|
|
|
} else {
|
|
|
|
// TODO: Handle generated cursors
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-05 13:09:27 -04:00
|
|
|
void LivingBooksCursorManager_v2::setCursor(const Common::String &name) {
|
|
|
|
if (!_sysArchive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint16 id = _sysArchive->findResourceID(ID_TCUR, name);
|
|
|
|
if (id == 0xffff)
|
|
|
|
error("Could not find cursor '%s'", name.c_str());
|
|
|
|
else
|
|
|
|
setCursor(id);
|
|
|
|
}
|
|
|
|
|
2020-01-03 13:51:15 +00:00
|
|
|
NECursorManager::NECursorManager(const Common::String &appName) {
|
|
|
|
Common::NEResources *exe = new Common::NEResources();
|
|
|
|
if (exe->loadFromEXE(appName)) {
|
|
|
|
// Not all have cursors anyway, so it's not a problem if this fails
|
|
|
|
loadCursors(exe);
|
|
|
|
}
|
|
|
|
delete exe;
|
|
|
|
}
|
|
|
|
|
2011-03-07 01:07:53 -05:00
|
|
|
PECursorManager::PECursorManager(const Common::String &appName) {
|
2019-10-12 14:47:20 -05:00
|
|
|
Common::PEResources *exe = new Common::PEResources();
|
2020-01-03 13:51:15 +00:00
|
|
|
if (exe->loadFromEXE(appName)) {
|
|
|
|
// Not all have cursors anyway, so it's not a problem if this fails
|
|
|
|
loadCursors(exe);
|
|
|
|
}
|
|
|
|
delete exe;
|
|
|
|
}
|
|
|
|
|
|
|
|
WinCursorManager::~WinCursorManager() {
|
|
|
|
for (uint i = 0; i < _cursors.size(); i++) {
|
|
|
|
delete _cursors[i].cursorGroup;
|
2017-07-01 14:56:03 +02:00
|
|
|
}
|
2020-01-03 13:51:15 +00:00
|
|
|
}
|
2017-07-01 14:56:03 +02:00
|
|
|
|
2020-01-03 13:51:15 +00:00
|
|
|
void WinCursorManager::loadCursors(Common::WinResources *exe) {
|
2019-12-31 19:02:48 +00:00
|
|
|
const Common::Array<Common::WinResourceID> cursorGroups = exe->getIDList(Common::kWinGroupCursor);
|
2017-07-01 14:56:03 +02:00
|
|
|
|
|
|
|
_cursors.resize(cursorGroups.size());
|
|
|
|
for (uint i = 0; i < cursorGroups.size(); i++) {
|
|
|
|
_cursors[i].id = cursorGroups[i].getID();
|
2019-12-31 19:19:42 +00:00
|
|
|
_cursors[i].cursorGroup = Graphics::WinCursorGroup::createCursorGroup(exe, cursorGroups[i]);
|
2011-03-07 01:07:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-03 13:51:15 +00:00
|
|
|
void WinCursorManager::setCursor(uint16 id) {
|
2017-07-01 14:56:03 +02:00
|
|
|
for (uint i = 0; i < _cursors.size(); i++) {
|
|
|
|
if (_cursors[i].id == id) {
|
|
|
|
Graphics::Cursor *cursor = _cursors[i].cursorGroup->cursors[0].cursor;
|
2019-08-09 20:45:27 +01:00
|
|
|
CursorMan.replaceCursor(cursor);
|
2011-03-07 01:07:53 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last resort (not all have cursors)
|
|
|
|
setDefaultCursor();
|
|
|
|
}
|
|
|
|
|
2010-11-25 04:49:11 +00:00
|
|
|
} // End of namespace Mohawk
|