Corrected backend to be able to accept a 16-bit mouseKeyColor without overflow

svn-id: r41194
This commit is contained in:
Jody Northup 2009-06-05 08:09:37 +00:00
parent 662a305752
commit 9789ba7f28
7 changed files with 105 additions and 15 deletions

View file

@ -1403,6 +1403,49 @@ void OSystem_SDL::warpMouse(int x, int y) {
}
}
#ifdef ENABLE_16BIT
void OSystem_SDL::setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale) {
if (w == 0 || h == 0)
return;
_mouseCurState.hotX = hotspot_x;
_mouseCurState.hotY = hotspot_y;
_mouseKeyColor = keycolor;
_cursorTargetScale = cursorTargetScale;
if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h) {
_mouseCurState.w = w;
_mouseCurState.h = h;
if (_mouseOrigSurface)
SDL_FreeSurface(_mouseOrigSurface);
// Allocate bigger surface because AdvMame2x adds black pixel at [0,0]
_mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
_mouseCurState.w + 2,
_mouseCurState.h + 2,
16,
_hwscreen->format->Rmask,
_hwscreen->format->Gmask,
_hwscreen->format->Bmask,
_hwscreen->format->Amask);
if (_mouseOrigSurface == NULL)
error("allocating _mouseOrigSurface failed");
SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey);
}
free(_mouseData);
_mouseData = (byte *)malloc(w * h * 2);
memcpy(_mouseData, buf, w * h * 2);
blitCursor();
}
#endif
void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) {
if (w == 0 || h == 0)
return;
@ -1438,13 +1481,9 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x,
free(_mouseData);
#ifdef ENABLE_16BIT
_mouseData = (byte *)malloc(w * h * 2);
memcpy(_mouseData, buf, w * h * 2);
#else
_mouseData = (byte *)malloc(w * h);
memcpy(_mouseData, buf, w * h);
#endif
blitCursor();
}

View file

@ -112,6 +112,10 @@ public:
virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME)
// Set the bitmap that's used when drawing the cursor.
#ifdef ENABLE_16BIT
//HACK Made a second method as a quick and dirty workaround to avoid linker errors with engine libs
virtual void setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME)
#endif
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME)
// Set colors of cursor palette

View file

@ -687,8 +687,13 @@ public:
* @param keycolor transparency color index
* @param cursorTargetScale scale factor which cursor is designed for
*/
#ifdef ENABLE_16BIT
//HACK made a second method as a quick and dirty workaround to avoid linker errors with engine libs
virtual void setMouseCursor16(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor = 65535, int cursorTargetScale = 1) = 0;
#endif
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int cursorTargetScale = 1) = 0;
/**
* Replace the specified range of cursor the palette with new colors.
* The palette entries from 'start' till (start+num-1) will be replaced - so

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="scumm"
ProjectGUID="{B6AFD548-63D2-40CD-A652-E87095AFCBAF}"
RootNamespace="scumm"
@ -43,7 +43,7 @@
Optimization="0"
InlineFunctionExpansion="0"
AdditionalIncludeDirectories="../../;../../engines"
PreprocessorDefinitions="WIN32;_DEBUG;ENABLE_SCUMM_7_8;ENABLE_HE;USE_ZLIB;USE_MAD;USE_VORBIS"
PreprocessorDefinitions="WIN32;_DEBUG;ENABLE_SCUMM_7_8;ENABLE_HE;USE_ZLIB;USE_MAD;USE_VORBIS; ENABLE_16BIT"
MinimalRebuild="true"
ExceptionHandling="1"
BasicRuntimeChecks="3"

View file

@ -112,10 +112,20 @@ void ScummEngine_v6::setCursorTransparency(int a) {
void ScummEngine::updateCursor() {
int transColor = (_game.heversion >= 80) ? 5 : 255;
if (_game.features & GF_16BIT_COLOR && _hePalettes) {
//HACK Had to make a second method to avoid many, many linker errors from other engines
//this requires ENABLE_16BIT to be defined in the Scumm project, again, because I #ifdef'ed
//the method's definition and declaration in cursorman.h
CursorMan.replaceCursor16(_grabbedCursor, _cursor.width, _cursor.height,
_cursor.hotspotX, _cursor.hotspotY,
(_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor),
(_game.heversion == 70 ? 2 : 1));
} else {
CursorMan.replaceCursor(_grabbedCursor, _cursor.width, _cursor.height,
_cursor.hotspotX, _cursor.hotspotY,
(_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor),
(_game.heversion == 70 ? 2 : 1));
}
}
void ScummEngine_v6::grabCursor(int x, int y, int w, int h) {

View file

@ -100,6 +100,37 @@ void CursorManager::popAllCursors() {
g_system->showMouse(isVisible());
}
#ifdef ENABLE_16BIT
//HACK Made a separate method to avoid massive linker errors on every engine
void CursorManager::replaceCursor16(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor, int targetScale) {
if (_cursorStack.empty()) {
pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale);
return;
}
Cursor *cur = _cursorStack.top();
uint size = w * h * 2;
if (cur->_size < size) {
delete[] cur->_data;
cur->_data = new byte[size];
cur->_size = size;
}
if (buf && cur->_data)
memcpy(cur->_data, buf, size);
cur->_width = w;
cur->_height = h;
cur->_hotspotX = hotspotX;
cur->_hotspotY = hotspotY;
cur->_keycolor = keycolor;
cur->_targetScale = targetScale;
g_system->setMouseCursor16(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale);
}
#endif
void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) {
if (_cursorStack.empty()) {
@ -108,11 +139,8 @@ void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX,
}
Cursor *cur = _cursorStack.top();
#ifdef ENABLE_16BIT
uint size = w * h * 2;
#else
uint size = w * h;
#endif
if (cur->_size < size) {
delete[] cur->_data;

View file

@ -77,6 +77,10 @@ public:
* @param keycolor the index for the transparent color
* @param targetScale the scale for which the cursor is designed
*/
#ifdef ENABLE_16BIT
//HACK made a separate method to avoid massive linker errors on every engine.
void replaceCursor16(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint16 keycolor = 65535, int targetScale = 1);
#endif
void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1);
/**