Skip to content

Commit

Permalink
HOPKINS: Fix cursor tranparency
Browse files Browse the repository at this point in the history
Before, cursor images were converted to 16 bpp, and anything that
was the same as the first color in PAL_PIXELS[] was made transparent.
Now, cursors images are drawn as 8 bpp with a cursor palette created
from PAL_PIXELS[]. This preserves all the black parts of the cursor
that weren't actually color index 0.

It would be nice if we only regenerated the cursor/palette when they
have actually changed, but that's for later.
  • Loading branch information
Torbjörn Andersson committed Feb 10, 2013
1 parent 2044a71 commit f645600
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions engines/hopkins/events.cpp
Expand Up @@ -477,33 +477,30 @@ void EventsManager::updateCursor() {
_vm->_graphicsManager._maxY = clipBounds.bottom;
_vm->_graphicsManager._lineNbr2 = pitch;

// Convert the cursor to the pixel format. At the moment, it's hardcoded
// to expect the game to be in 16-bit mode
uint16 *cursorPixels = new uint16[_vm->_globals._objectHeight * _vm->_globals._objectWidth];
const byte *srcP = cursorSurface;
uint16 *destP = cursorPixels;

for (int yp = 0; yp < _vm->_globals._objectHeight; ++yp) {
const byte *lineSrcP = srcP;
uint16 *lineDestP = destP;
// Create a cursor palette
Graphics::PixelFormat pixelFormat = g_system->getScreenFormat();

for (int xp = 0; xp < _vm->_globals._objectWidth; ++xp)
*lineDestP++ = *(uint16 *)&_vm->_graphicsManager.PAL_PIXELS[*lineSrcP++ * 2];
byte *cursorPalette = new byte[3 * PALETTE_SIZE];
uint16 *paletteColors = (uint16 *)_vm->_graphicsManager.PAL_PIXELS;

srcP += _vm->_globals._objectWidth;
destP += _vm->_globals._objectWidth;
for (int i = 0; i < PALETTE_SIZE; i++) {
uint8 r, g, b;
pixelFormat.colorToRGB(paletteColors[i], r, g, b);
cursorPalette[3 * i] = r;
cursorPalette[3 * i + 1] = g;
cursorPalette[3 * i + 2] = b;
}

// Calculate the X offset within the pointer image to the actual cursor data
int xOffset = !_mouseLinuxFl ? 10 : 20;

// Set the ScummVM cursor from the surface
Graphics::PixelFormat pixelFormat = g_system->getScreenFormat();
CursorMan.replaceCursor(cursorPixels, _vm->_globals._objectWidth, _vm->_globals._objectHeight,
xOffset, 0, *((uint16 *)cursorPixels), true, &pixelFormat);
CursorMan.replaceCursorPalette(cursorPalette, 0, PALETTE_SIZE - 1);
CursorMan.replaceCursor(cursorSurface, _vm->_globals._objectWidth, _vm->_globals._objectHeight,
xOffset, 0, 0, true);

// Delete the cursor surface
delete[] cursorPixels;
// Delete the cursor surface and palette
delete[] cursorPalette;
delete[] cursorSurface;
}

Expand Down

0 comments on commit f645600

Please sign in to comment.