GRAPHICS: Unify loading Windows cursor groups

This commit is contained in:
Cameron Cawley 2020-01-02 22:32:03 +00:00 committed by Filippos Karapetis
parent e49282577f
commit 5cd6812b9d
2 changed files with 3 additions and 65 deletions

View File

@ -23,8 +23,6 @@
#include "common/ptr.h"
#include "common/stream.h"
#include "common/textconsole.h"
#include "common/winexe_ne.h"
#include "common/winexe_pe.h"
#include "graphics/wincursor.h"
@ -242,63 +240,7 @@ WinCursorGroup::~WinCursorGroup() {
delete cursors[i].cursor;
}
WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources *exe, const Common::WinResourceID &id) {
Common::ScopedPtr<Common::SeekableReadStream> stream(exe->getResource(Common::kWinGroupCursor, id));
if (!stream || stream->size() <= 6)
return 0;
stream->skip(4);
uint32 cursorCount = stream->readUint16LE();
if ((uint32)stream->size() < (6 + cursorCount * 14))
return 0;
WinCursorGroup *group = new WinCursorGroup();
group->cursors.reserve(cursorCount);
for (uint32 i = 0; i < cursorCount; i++) {
stream->readUint16LE(); // width
stream->readUint16LE(); // height
// Plane count
if (stream->readUint16LE() != 1) {
delete group;
return 0;
}
// Bits per pixel
// NE cursors can only be 1bpp
if (stream->readUint16LE() != 1) {
delete group;
return 0;
}
stream->readUint32LE(); // data size
uint32 cursorId = stream->readUint16LE();
Common::ScopedPtr<Common::SeekableReadStream> cursorStream(exe->getResource(Common::kWinCursor, cursorId));
if (!cursorStream) {
delete group;
return 0;
}
WinCursor *cursor = new WinCursor();
if (!cursor->readFromStream(*cursorStream)) {
delete cursor;
delete group;
return 0;
}
CursorItem item;
item.id = cursorId;
item.cursor = cursor;
group->cursors.push_back(item);
}
return group;
}
WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources *exe, const Common::WinResourceID &id) {
WinCursorGroup *WinCursorGroup::createCursorGroup(Common::WinResources *exe, const Common::WinResourceID &id) {
Common::ScopedPtr<Common::SeekableReadStream> stream(exe->getResource(Common::kWinGroupCursor, id));
if (!stream || stream->size() <= 6)

View File

@ -29,8 +29,6 @@
#include "graphics/cursor.h"
namespace Common {
class NEResources;
class PEResources;
class SeekableReadStream;
}
@ -56,10 +54,8 @@ struct WinCursorGroup {
Common::Array<CursorItem> cursors;
/** Create a cursor group from an NE EXE, returns 0 on failure */
static WinCursorGroup *createCursorGroup(Common::NEResources *exe, const Common::WinResourceID &id);
/** Create a cursor group from an PE EXE, returns 0 on failure */
static WinCursorGroup *createCursorGroup(Common::PEResources *exe, const Common::WinResourceID &id);
/** Create a cursor group from an EXE, returns 0 on failure */
static WinCursorGroup *createCursorGroup(Common::WinResources *exe, const Common::WinResourceID &id);
};
/**