MOHAWK: Use new MacCursor code instead of convertCrsrCursor()

This commit is contained in:
Matthew Hoops 2011-05-05 19:35:31 -04:00
parent 0f0ae4576e
commit 1f39e0b6c6
2 changed files with 25 additions and 48 deletions

View File

@ -29,9 +29,11 @@
#include "common/macresman.h"
#include "common/system.h"
#include "common/textconsole.h"
#include "common/winexe_ne.h"
#include "common/winexe_pe.h"
#include "graphics/cursorman.h"
#include "graphics/maccursor.h"
#include "graphics/wincursor.h"
#ifdef ENABLE_MYST
@ -41,11 +43,6 @@
namespace Mohawk {
static const byte s_bwPalette[] = {
0x00, 0x00, 0x00, // Black
0xFF, 0xFF, 0xFF // White
};
void CursorManager::showCursor() {
CursorMan.showMouse(true);
}
@ -78,8 +75,13 @@ void CursorManager::setDefaultCursor() {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0
};
static const byte bwPalette[] = {
0x00, 0x00, 0x00, // Black
0xFF, 0xFF, 0xFF // White
};
CursorMan.replaceCursor(defaultCursor, 12, 20, 0, 0, 0);
CursorMan.replaceCursorPalette(s_bwPalette, 1, 2);
CursorMan.replaceCursorPalette(bwPalette, 1, 2);
}
void CursorManager::setCursor(uint16 id) {
@ -87,35 +89,24 @@ void CursorManager::setCursor(uint16 id) {
setDefaultCursor();
}
void CursorManager::setMacXorCursor(Common::SeekableReadStream *stream) {
void CursorManager::setMacCursor(Common::SeekableReadStream *stream) {
assert(stream);
byte cursorBitmap[16 * 16];
Graphics::MacCursor *macCursor = new Graphics::MacCursor();
// Get black and white data
for (int i = 0; i < 32; i++) {
byte imageByte = stream->readByte();
for (int b = 0; b < 8; b++)
cursorBitmap[i * 8 + b] = (imageByte & (0x80 >> b)) ? 1 : 2;
}
if (!macCursor->readFromStream(*stream))
error("Could not parse Mac cursor");
// Apply mask data
for (int i = 0; i < 32; i++) {
byte imageByte = stream->readByte();
for (int b = 0; b < 8; b++)
if ((imageByte & (0x80 >> b)) == 0)
cursorBitmap[i * 8 + b] = 0;
}
CursorMan.replaceCursor(macCursor->getSurface(), macCursor->getWidth(), macCursor->getHeight(),
macCursor->getHotspotX(), macCursor->getHotspotY(), macCursor->getKeyColor());
CursorMan.replaceCursorPalette(macCursor->getPalette(), 0, 256);
uint16 hotspotY = stream->readUint16BE();
uint16 hotspotX = stream->readUint16BE();
CursorMan.replaceCursor(cursorBitmap, 16, 16, hotspotX, hotspotY, 0);
CursorMan.replaceCursorPalette(s_bwPalette, 1, 2);
delete macCursor;
delete stream;
}
void DefaultCursorManager::setCursor(uint16 id) {
setMacXorCursor(_vm->getResource(_tag, id));
setMacCursor(_vm->getResource(_tag, id));
}
#ifdef ENABLE_MYST
@ -223,26 +214,12 @@ void MacCursorManager::setCursor(uint16 id) {
// Try a color cursor first
Common::SeekableReadStream *stream = _resFork->getResource(MKTAG('c','r','s','r'), id);
if (stream) {
byte *cursor, *palette;
int width, height, hotspotX, hotspotY, keyColor, palSize;
_resFork->convertCrsrCursor(stream, &cursor, width, height, hotspotX, hotspotY, keyColor, true, &palette, palSize);
CursorMan.replaceCursor(cursor, width, height, hotspotX, hotspotY, keyColor);
CursorMan.replaceCursorPalette(palette, 0, palSize);
delete[] cursor;
delete[] palette;
delete stream;
return;
}
// Fall back to b&w cursors
stream = _resFork->getResource(MKTAG('C','U','R','S'), id);
// Fall back to monochrome cursors
if (!stream)
stream = _resFork->getResource(MKTAG('C','U','R','S'), id);
if (stream) {
setMacXorCursor(stream);
setMacCursor(stream);
delete stream;
} else {
setDefaultCursor();
@ -265,7 +242,7 @@ LivingBooksCursorManager_v2::~LivingBooksCursorManager_v2() {
void LivingBooksCursorManager_v2::setCursor(uint16 id) {
if (_sysArchive && _sysArchive->hasResource(ID_TCUR, id)) {
setMacXorCursor(_sysArchive->getResource(ID_TCUR, id));
setMacCursor(_sysArchive->getResource(ID_TCUR, id));
} else {
// TODO: Handle generated cursors
}

View File

@ -63,8 +63,8 @@ public:
virtual bool hasSource() const { return false; }
protected:
// Set a Mac XOR/AND map cursor to the screen
void setMacXorCursor(Common::SeekableReadStream *stream);
// Set a Mac CURS/crsr cursor to the screen
void setMacCursor(Common::SeekableReadStream *stream);
};
// The default Mohawk cursor manager