Exemple #1
0
void EventsManager::changeCursor() {
	if (_cursorSprites) {
		MSprite *cursor = _cursorSprites->getFrame(_cursorId - 1);
		assert(cursor->w == cursor->h);
		byte transIndex = cursor->getTransparencyIndex();

		// Check for hotspot indication pixels along the right-hand and bottom
		// row. Put together, these give the cursor's hotspot x,y
		int hotspotX = 0, hotspotY = 0;
		const byte *cursorData = (const byte *)cursor->getPixels();
		for (int idx = 0; idx < cursor->w; ++idx) {
			if (cursorData[(cursor->h - 1) * cursor->w + idx] != transIndex)
				hotspotX = idx;

			if (cursorData[(idx + 1) * cursor->w - 1] != transIndex)
				hotspotY = idx;
		}

		// Reduce the cursor data to remove the last column from each row, since
		// the cursor routines don't have a pitch option
		byte *destCursor = new byte[(cursor->w - 1) * (cursor->h - 1)];
		const byte *srcP = cursorData;
		byte *destP = destCursor;

		for (int idx = 0; idx < (cursor->h - 1); ++idx) {
			Common::copy(srcP, srcP + cursor->w - 1, destP);
			srcP += cursor->w;
			destP += cursor->w - 1;
		}

		// Set the raw cursor data to use
		CursorMan.replaceCursor(destCursor, cursor->w - 1, cursor->h - 1,
			hotspotX, hotspotY, transIndex);
		showCursor();
		delete[] destCursor;
	}
}