[Scummvm-cvs-logs] CVS: scummvm/bs2/driver _mouse.cpp,1.4,1.5
Torbj?rn Andersson
eriktorbjorn at users.sourceforge.net
Wed Aug 20 04:18:02 CEST 2003
Update of /cvsroot/scummvm/scummvm/bs2/driver
In directory sc8-pr-cvs1:/tmp/cvs-serv2683
Modified Files:
_mouse.cpp
Log Message:
This should fix mouse cursor animations. (Actually, I hardly even looked at
what the old mouse cursor patch did. I simply replaced it with my own.
Sorry about that. :-)
Index: _mouse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/_mouse.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- _mouse.cpp 19 Aug 2003 21:42:21 -0000 1.4
+++ _mouse.cpp 20 Aug 2003 06:35:15 -0000 1.5
@@ -140,13 +140,12 @@
#include "../sword2.h"
-
#define MAX_MOUSE_EVENTS 16
#define MOUSEFLASHFRAME 6
+// FIXME: Does this struct have to be packed?
-typedef struct
-{
+typedef struct {
uint8 runTimeComp; // type of runtime compression used for the frame data
uint8 noAnimFrames; // number of frames in the anim
int8 xHotSpot;
@@ -155,34 +154,28 @@
uint8 mouseh;
} _mouseAnim;
-
int16 mousex;
int16 mousey;
static uint8 mouseBacklog = 0;
static uint8 mouseLogPos = 0;
static uint8 mouseFrame;
-//static uint8 luggageFrame = 0;
static uint8 *mouseSprite = NULL;
static _mouseAnim *mouseAnim = NULL;
-//static _mouseAnim *luggageAnim = NULL;
+static _mouseAnim *luggageAnim = NULL;
static _mouseEvent mouseLog[MAX_MOUSE_EVENTS];
static int32 *mouseOffsets;
-//static int32 *luggageOffset;
-//static LPDIRECTDRAWSURFACE *mouseSurfaces;
-//static LPDIRECTDRAWSURFACE luggageSurface = NULL;
-
+static int32 *luggageOffset;
+// FIXME: I have no idea how large the mouse cursor can be. Is this enough?
+byte _mouseData[128 * 128];
-void ResetRenderEngine(void)
-{
-
- memset(myScreenBuffer, 0, RENDERWIDE * RENDERDEEP);
+void ResetRenderEngine(void) {
parallaxScrollx = 0;
parallaxScrolly = 0;
scrollx = 0;
@@ -218,269 +211,35 @@
+// FIXME: The original code used 0 for transparency, while our backend uses
+// 0xFF. That means that parts of the mouse cursor that weren't meant to be
+// transparent may be now.
-
-
-int32 DecompressMouse(uint8 *decomp, uint8 *comp, int32 size)
-
-{
-
+int32 DecompressMouse(uint8 *decomp, uint8 *comp, int32 size) {
int32 i = 0;
- while (i < size)
- {
- if (*comp > 183)
- {
+ while (i < size) {
+ if (*comp > 183) {
*decomp++ = *comp++;
- i += 1;
- }
- else
- {
- memset(decomp, 0, *comp);
+ i++;
+ } else {
+ memset(decomp, 0xFF, *comp);
decomp += *comp;
i += *comp++;
}
}
- return(RD_OK);
+ return RD_OK;
}
-// --------------------------------------------------------------------------
-// Draws the mouse sprite to the back buffer.
-// --------------------------------------------------------------------------
-int32 DrawMouse(void)
-
-{
- warning("stub DrawMouse");
-/*
- uint8 *src, *dst;
- int16 i;
- int16 xoff=0, yoff=0;
- uint8 *decompSprite;
- DDSURFACEDESC ddsd;
- HRESULT hr;
- RECT rs, rd;
-
-
-
- if (luggageAnim)
- {
-
- if (luggageSurface == NULL)
- {
- // Create the luggage surface.
- memset(&ddsd, 0, sizeof(DDSURFACEDESC));
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
- if (dxHalCaps & RDCAPS_SRCBLTCKEY)
- ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
- else
- ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
-
- ddsd.dwWidth = luggageAnim->mousew;
- ddsd.dwHeight = luggageAnim->mouseh;
- hr = IDirectDraw2_CreateSurface(lpDD2, &ddsd, &luggageSurface, NULL);
- if (hr != DD_OK)
- {
- if (hr == DDERR_OUTOFVIDEOMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
- hr = IDirectDraw2_CreateSurface(lpDD2, &ddsd, &luggageSurface, NULL);
- }
- if (hr != DD_OK)
- {
- DirectDrawError("Cannot create mouse surface", hr);
- return(hr);
- }
- }
- // Set the surface blt source colour key
- hr = IDirectDrawSurface2_SetColorKey(luggageSurface, DDCKEY_SRCBLT, &blackColorKey);
-
- // Copy the data into the surfaces.
- decompSprite = (uint8 *) malloc(luggageAnim->mousew * luggageAnim->mouseh);
- if (decompSprite == NULL)
- return(RDERR_OUTOFMEMORY);
-// DecompressMouse(decompSprite, (uint8 *) luggageAnim + *mouseOffsets, luggageAnim->mousew * luggageAnim->mouseh);
- DecompressMouse(decompSprite, (uint8 *) luggageAnim + *luggageOffset, luggageAnim->mousew * luggageAnim->mouseh);
- memset(&ddsd, 0, sizeof(DDSURFACEDESC));
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- hr = IDirectDrawSurface2_Lock(luggageSurface, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
- if (hr != DD_OK)
- {
- IDirectDrawSurface2_Restore(luggageSurface);
- hr = IDirectDrawSurface2_Lock(luggageSurface, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
- if (hr != DD_OK)
- {
- DirectDrawError("Unable to lock luggage surface", hr);
- return(hr);
- }
- }
- dst = ddsd.lpSurface;
- src = decompSprite;
- for (i=0; i<luggageAnim->mouseh; i++)
- {
- memcpy(dst, src, luggageAnim->mousew);
- dst += ddsd.lPitch;
- src += luggageAnim->mousew;
- }
- IDirectDrawSurface2_Unlock(luggageSurface, ddsd.lpSurface);
- free(decompSprite);
- }
-
-
- rd.top = mousey + MENUDEEP - luggageAnim->yHotSpot;
- rd.bottom = rd.top + luggageAnim->mouseh;
- rd.left = mousex - luggageAnim->xHotSpot;
- rd.right = rd.left + luggageAnim->mousew;
-
- rs.left = 0;
- rs.right = luggageAnim->mousew;
- rs.top = 0;
- rs.bottom = luggageAnim->mouseh;
-
- if (rd.left < 0)
- {
- rs.left = 0 - rd.left;
- rd.left = 0;
- }
- if (rd.top < 0)
- {
- rs.top = 0 - rd.top;
- rd.top = 0;
- }
- if (rd.right > RENDERWIDE)
- {
- rs.right -= (rd.right - RENDERWIDE);
- rd.right = RENDERWIDE;
- }
- if (rd.bottom > ALIGNRENDERDEEP)
- {
- rs.bottom -= (rd.bottom - ALIGNRENDERDEEP);
- rd.bottom = ALIGNRENDERDEEP;
- }
-
- hr = IDirectDrawSurface2_Blt(lpBackBuffer, &rd, luggageSurface, &rs, DDBLT_WAIT | DDBLT_KEYSRC, NULL);
- if (hr = DDERR_SURFACELOST)
- {
- IDirectDrawSurface2_Release(luggageSurface);
- luggageSurface = NULL;
- }
-
- }
-
- if (mouseAnim == NULL)
- {
- return(RD_OK);
- }
-
-
- // Decompress the mouse sprite onto the directDraw surface, if it is not
- // there already.
- if (*(mouseSurfaces + mouseFrame) == NULL)
- {
-
- // Create the mouse surface.
- memset(&ddsd, 0, sizeof(DDSURFACEDESC));
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
- if (dxHalCaps & RDCAPS_SRCBLTCKEY)
- ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
- else
- ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
-
- ddsd.dwWidth = mouseAnim->mousew;
- ddsd.dwHeight = mouseAnim->mouseh;
- hr = IDirectDraw2_CreateSurface(lpDD2, &ddsd, mouseSurfaces + mouseFrame, NULL);
- if (hr != DD_OK)
- {
- if (hr == DDERR_OUTOFVIDEOMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
- hr = IDirectDraw2_CreateSurface(lpDD2, &ddsd, mouseSurfaces + mouseFrame, NULL);
- }
- if (hr != DD_OK)
- {
- DirectDrawError("Cannot create mouse surface", hr);
- return(hr);
- }
- }
- // Set the surface blt source colour key
- hr = IDirectDrawSurface2_SetColorKey(*(mouseSurfaces + mouseFrame), DDCKEY_SRCBLT, &blackColorKey);
-
- // Copy the data into the surfaces.
- decompSprite = (uint8 *) malloc(mouseAnim->mousew * mouseAnim->mouseh);
- if (decompSprite == NULL)
- return(RDERR_OUTOFMEMORY);
- DecompressMouse(decompSprite, mouseSprite, mouseAnim->mousew * mouseAnim->mouseh);
- memset(&ddsd, 0, sizeof(DDSURFACEDESC));
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- hr = IDirectDrawSurface2_Lock(*(mouseSurfaces + mouseFrame), NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
- if (hr != DD_OK)
- {
- IDirectDrawSurface2_Restore(*(mouseSurfaces + mouseFrame));
- hr = IDirectDrawSurface2_Lock(*(mouseSurfaces + mouseFrame), NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
- if (hr != DD_OK)
- {
- DirectDrawError("Cannot lock mouse surface", hr);
- return(hr);
- }
- }
- dst = ddsd.lpSurface;
- src = decompSprite;
- for (i=0; i<mouseAnim->mouseh; i++)
- {
- memcpy(dst, src, mouseAnim->mousew);
- dst += ddsd.lPitch;
- src += mouseAnim->mousew;
- }
- IDirectDrawSurface2_Unlock(*(mouseSurfaces + mouseFrame), ddsd.lpSurface);
- free(decompSprite);
- }
-
-
- rd.top = mousey + MENUDEEP - mouseAnim->yHotSpot;
- rd.bottom = rd.top + mouseAnim->mouseh;
- rd.left = mousex - mouseAnim->xHotSpot;
- rd.right = rd.left + mouseAnim->mousew;
-
- rs.left = 0;
- rs.right = mouseAnim->mousew;
- rs.top = 0;
- rs.bottom = mouseAnim->mouseh;
-
- if (rd.left < 0)
- {
- rs.left = 0 - rd.left;
- rd.left = 0;
- }
- if (rd.top < 0)
- {
- rs.top = 0 - rd.top;
- rd.top = 0;
- }
- if (rd.right > RENDERWIDE)
- {
- rs.right -= (rd.right - RENDERWIDE);
- rd.right = RENDERWIDE;
- }
- if (rd.bottom > ALIGNRENDERDEEP)
- {
- rs.bottom -= (rd.bottom - ALIGNRENDERDEEP);
- rd.bottom = ALIGNRENDERDEEP;
- }
-
- hr = IDirectDrawSurface2_Blt(lpBackBuffer, &rd, *(mouseSurfaces + mouseFrame), &rs, DDBLT_WAIT | DDBLT_KEYSRC, NULL);
- if (hr == DDERR_SURFACELOST)
- {
- IDirectDrawSurface2_Release(*(mouseSurfaces + mouseFrame));
- *(mouseSurfaces + mouseFrame) = NULL;
+int32 DrawMouse(void) {
+ if (mouseAnim) {
+ memset(_mouseData, 0, sizeof(_mouseData));
+ DecompressMouse(_mouseData, mouseSprite, mouseAnim->mousew * mouseAnim->mouseh);
+ g_sword2->_system->set_mouse_cursor(_mouseData, mouseAnim->mousew, mouseAnim->mouseh, mouseAnim->xHotSpot, mouseAnim->yHotSpot);
}
-*/
- return(RD_OK);
-
+ return RD_OK;
}
@@ -512,137 +271,76 @@
}
-int32 AnimateMouse(void)
+int32 AnimateMouse(void) {
+ uint8 prevMouseFrame = mouseFrame;
-{
- if (mouseAnim)
- {
- if (++mouseFrame == mouseAnim->noAnimFrames)
- {
- mouseFrame = MOUSEFLASHFRAME;
- }
- mouseSprite = (uint8 *) mouseAnim + *(mouseOffsets+mouseFrame);
- }
- else
- {
- return(RDERR_UNKNOWN);
- }
-
- return(RD_OK);
+ if (!mouseAnim)
+ return RDERR_UNKNOWN;
-}
+ if (++mouseFrame == mouseAnim->noAnimFrames)
+ mouseFrame = MOUSEFLASHFRAME;
+ mouseSprite = (uint8 *) mouseAnim + *(mouseOffsets + mouseFrame);
+ if (mouseFrame != prevMouseFrame)
+ DrawMouse();
+
+ return RD_OK;
+}
-int32 SetMouseAnim(uint8 *ma, int32 size, int32 mouseFlash)
-{
- if (ma) {
- if (mouseAnim)
- free(mouseAnim);
+int32 SetMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) {
+ if (mouseAnim) {
+ free(mouseAnim);
+ mouseAnim = NULL;
+ }
+ if (ma) {
if (mouseFlash == RDMOUSE_FLASH)
mouseFrame = 0;
else
mouseFrame = MOUSEFLASHFRAME;
+ mouseAnim = (_mouseAnim *) malloc(size);
+ if (!mouseAnim)
+ return RDERR_OUTOFMEMORY;
- mouseAnim = (_mouseAnim *)malloc(size);
- memcpy((uint8 *)mouseAnim, ma, size);
-
- mouseOffsets = (int32 *)((uint8 *)mouseAnim + sizeof(_mouseAnim));
+ memcpy((uint8 *) mouseAnim, ma, size);
+ mouseOffsets = (int32 *) ((uint8 *) mouseAnim + sizeof(_mouseAnim));
AnimateMouse();
+ DrawMouse();
- uint8 *decompSprite = (uint8 *)malloc(mouseAnim->mousew * mouseAnim->mouseh);
- DecompressMouse(decompSprite, mouseSprite, mouseAnim->mousew * mouseAnim->mouseh);
-
- int i;
- for (i = 0; i < mouseAnim->mousew * mouseAnim->mouseh; i++)
- if (decompSprite[i] == 0)
- decompSprite[i] = 0xff;
-
- g_sword2->_system->set_mouse_cursor(decompSprite,
- mouseAnim->mousew, mouseAnim->mouseh,
- mouseAnim->xHotSpot, mouseAnim->yHotSpot - MENUDEEP);
g_sword2->_system->show_mouse(true);
} else
g_sword2->_system->show_mouse(false);
+ return RD_OK;
+}
-/*
- int32 i;
- if (mouseAnim)
- {
- for (i=0; i<mouseAnim->noAnimFrames; i++)
- {
- if (*(mouseSurfaces + i))
- {
- IDirectDrawSurface2_Release(*(mouseSurfaces + i));
- *(mouseSurfaces + i) = NULL;
- }
- }
-
- free(mouseAnim);
- mouseAnim = NULL;
- free(mouseSurfaces);
- mouseSurfaces = NULL;
+int32 SetLuggageAnim(uint8 *ma, int32 size) {
+ if (luggageAnim) {
+ free(luggageAnim);
+ luggageAnim = NULL;
}
-
- if (ma)
- {
- if (mouseFlash == RDMOUSE_FLASH)
- mouseFrame = 0;
- else
- mouseFrame = MOUSEFLASHFRAME;
- mouseAnim = malloc(size);
- if (mouseAnim == NULL)
- {
+ if (ma) {
+ luggageAnim = (_mouseAnim *) malloc(size);
+ if (!luggageAnim)
return(RDERR_OUTOFMEMORY);
- }
- else
- {
- memcpy((uint8 *) mouseAnim, ma, size);
- mouseOffsets = (int32 *) ((uint8 *) mouseAnim + sizeof(_mouseAnim));
- AnimateMouse();
- mouseSurfaces = (LPDIRECTDRAWSURFACE *) malloc(mouseAnim->noAnimFrames * sizeof(LPDIRECTDRAWSURFACE));
- if (mouseSurfaces == NULL)
- return(RDERR_OUTOFMEMORY);
- memset(mouseSurfaces, 0, sizeof(LPDIRECTDRAWSURFACE) * mouseAnim->noAnimFrames);
- }
- }
-*/
- return(RD_OK);
-}
+ memcpy((uint8 *) luggageAnim, ma, size);
+ luggageOffset = (int32 *) ((uint8 *) luggageAnim + sizeof(_mouseAnim));
+ // The luggage animation is only one frame.
-int32 SetLuggageAnim(uint8 *ma, int32 size)
+ memset(_mouseData, 0, sizeof(_mouseData));
-{
- warning("stub SetLugggeAnim");
-/*
-
- if (luggageAnim)
- {
- free(luggageAnim);
- luggageAnim = NULL;
- }
+ DecompressMouse(_mouseData, (uint8 *) luggageAnim + *mouseOffsets, luggageAnim->mousew * luggageAnim->mouseh);
+ DecompressMouse(_mouseData, (uint8 *) luggageAnim + *luggageOffset, luggageAnim->mousew * luggageAnim->mouseh);
- if (ma)
- {
- luggageAnim = malloc(size);
- if (luggageAnim == NULL)
- {
- return(RDERR_OUTOFMEMORY);
- }
- else
- {
- memcpy((uint8 *) luggageAnim, ma, size);
- luggageOffset = (int32 *) ((uint8 *) luggageAnim + sizeof(_mouseAnim));
- AnimateMouse();
- }
- }
-*/
- return(RD_OK);
+ g_sword2->_system->set_mouse_cursor(_mouseData, luggageAnim->mousew, luggageAnim->mouseh, luggageAnim->xHotSpot, luggageAnim->yHotSpot);
+ g_sword2->_system->show_mouse(true);
+ } else
+ g_sword2->_system->show_mouse(false);
+ return RD_OK;
}
More information about the Scummvm-git-logs
mailing list