Re: SetCursorProperties

Jarmo <[email protected]>
Newsgroups gmane.comp.emulators.winex.devel
Message-ID <[email protected]>
Thanks,

It seems that I was wrong about XFree86 color cursor support I had some out of 
date documentation. So here is the patch for D3D8_SetCursorProperties. This 
patch requires libXcursor.so I don't know does this require modifications in 
configure scripts. A game called Wazzal is used for testing and everyting 
seems to work fine. Infact the cursor moves much smoother that in a Windows 
:) 

Regards,
Jarmo Nikkanen
d3d8_patch.diff (text/x-diff, 4.8 KB)
diff -ur wine/dlls/d3d8/Makefile.in wine_patch/dlls/d3d8/Makefile.in
--- wine/dlls/d3d8/Makefile.in	2003-02-04 23:03:09.000000000 +0200
+++ wine_patch/dlls/d3d8/Makefile.in	2003-08-07 00:24:09.000000000 +0300
@@ -7,6 +7,8 @@
 EXTRALIBS = $(LIBUUID)
 EXTRADEFS = @DDRAW_HACKS@
 
+IMPORTS   = user32
+
 LDDLLFLAGS = @LDDLLFLAGS@
 SYMBOLFILE = $(MODULE).tmp.o
 
diff -ur wine/dlls/d3d8/cursor.c wine_patch/dlls/d3d8/cursor.c
--- wine/dlls/d3d8/cursor.c	2003-07-30 00:12:37.000000000 +0300
+++ wine_patch/dlls/d3d8/cursor.c	2003-08-07 13:10:03.000000000 +0300
@@ -11,6 +11,9 @@
 
 #include "d3d8_private.h"
 
+#include "wine/winuser16.h"
+#include "user.h"
+
 DEFAULT_DEBUG_CHANNEL(ddraw);
 
 HRESULT WINAPI Direct3DDevice8_SetCursorProperties(LPDIRECT3DDEVICE8 iface,
@@ -18,9 +21,47 @@
 						   UINT YHotSpot,
 						   IDirect3DSurface8* pCursorBitmap)
 {
-  /* ICOM_THIS(IDirect3DDevice8Impl, iface); */
-  FIXME("(%p)->(%d,%d,%p): stub\n", iface, XHotSpot, YHotSpot, pCursorBitmap);
-  return D3D_OK;
+    TRACE("(%p)->(%d,%d,%p): stub\n", iface, XHotSpot, YHotSpot, pCursorBitmap);
+    ICOM_THIS(IDirect3DDevice8Impl, iface);
+    D3DSURFACE_DESC	desc;
+    DDPIXELFORMAT pf;
+
+    IDirect3DSurface8_GetDesc(pCursorBitmap, &desc);
+    D3D8_GetPixelFormat(&pf,desc.Format);
+
+    if (pf.u1.dwRGBBitCount!=32) {
+	FIXME("Unsupported bitcount %ld\n",pf.u1.dwRGBBitCount);
+    	return D3DERR_INVALIDCALL;
+    }
+
+    char *lp =  (char *)((IDirect3DSurface8Impl *)pCursorBitmap)->t.gbl.fpVidMem;
+    int size_color = desc.Width * desc.Height * 4;
+    int size_mask = desc.Width * desc.Height / 8;
+
+    if (This->hCursor) DeleteObject(This->hCursor);
+    This->hCursor = GlobalAlloc16( GMEM_MOVEABLE, sizeof(CURSORICONINFO) + size_color + size_mask);
+
+    if (This->hCursor)
+    {
+	CURSORICONINFO *info;
+	info = (CURSORICONINFO *)GlobalLock16( This->hCursor );
+	info->ptHotSpot.x   = XHotSpot;
+	info->ptHotSpot.y   = YHotSpot;
+	info->nWidth        = desc.Width;
+	info->nHeight       = desc.Height;
+	info->nWidthBytes   = desc.Width * 4;
+	info->bPlanes       = 1;
+	info->bBitsPerPixel = 32;
+        /* There is no need to use BitMask becouse Alpha values are stored in ARGB pixels */
+	char *ptr = (char *)(info + 1);
+	memcpy(ptr, lp, size_color);
+
+	TRACE("%p, HCURSOR=%x\n",info,This->hCursor);
+	/* USER_Driver.pSetCursor( info ); This will cause "CriticalSection" error */
+	GlobalUnlock16( This->hCursor );
+	return D3D_OK;
+    }
+  return D3DERR_INVALIDCALL;
 }
 
 VOID WINAPI Direct3DDevice8_SetCursorPosition(LPDIRECT3DDEVICE8 iface,
@@ -30,12 +71,29 @@
 {
   /* ICOM_THIS(IDirect3DDevice8Impl, iface); */
   TRACE("(%p)->(%d,%d,%ld)\n", iface, XScreenSpace, YScreenSpace, Flags);
+  SetCursorPos(XScreenSpace,YScreenSpace);
 }
 
 BOOL WINAPI Direct3DDevice8_ShowCursor(LPDIRECT3DDEVICE8 iface,
 				       BOOL bShow)
 {
-  /* ICOM_THIS(IDirect3DDevice8Impl, iface); */
-  FIXME("(%p)->(%d): stub\n", iface, bShow);
-  return FALSE;
+  static BOOL visible=FALSE;
+  BOOL vis=visible;
+  ICOM_THIS(IDirect3DDevice8Impl, iface);
+  TRACE("(%p)->(%d,%d, HCURSOR=%x):\n", iface, bShow, visible, This->hCursor);
+
+  if (This->hCursor) {
+	if (bShow)
+	{
+		visible=TRUE;
+		USER_Driver.pSetCursor( (CURSORICONINFO*)GlobalLock16( This->hCursor ) );
+		GlobalUnlock16( This->hCursor );
+	}
+	else
+	{
+		visible=FALSE;
+		USER_Driver.pSetCursor( NULL );
+	}
+  }
+  return vis;
 }
Only in wine_patch/dlls/d3d8/: d3d8.spec.c
diff -ur wine/dlls/d3d8/d3d8_main.c wine_patch/dlls/d3d8/d3d8_main.c
--- wine/dlls/d3d8/d3d8_main.c	2003-08-01 22:39:02.000000000 +0300
+++ wine_patch/dlls/d3d8/d3d8_main.c	2003-08-07 12:10:59.000000000 +0300
@@ -183,6 +183,7 @@
   TRACE("(%p)->(%p)\n", iface, pPresPar);
 
   This->current = &This->state;
+  This->hCursor = 0;
 
   if (d3d_hal_data->hwCaps.dwFlags & D3DDD_WINE_OPENGL_DEVICE) {
     D3DConstructFunc func;
@@ -624,6 +625,9 @@
 
   if (dd_gbl->lpExclusiveOwner == &This->local)
     dd_gbl->lpExclusiveOwner = NULL;
+
+  /* delete cursor */
+  if (This->hCursor) DeleteObject(This->hCursor);
 }
 
 HRESULT WINAPI Direct3DDevice8_QueryInterface(LPDIRECT3DDEVICE8 iface,
@@ -1282,6 +1286,7 @@
   pD3DD->ref = 1;
   pD3DD->parent = This;
   pD3DD->caps = d3d8caps;
+  pD3DD->hCursor = 0;
 
   pD3DD->local.lpGbl = dd_gbl;
   pD3DD->local.dwLocalFlags = DDRAWILCL_DIRECTDRAW7 | DDRAWILCL_SETCOOPCALLED;
diff -ur wine/dlls/d3d8/d3d8_private.h wine_patch/dlls/d3d8/d3d8_private.h
--- wine/dlls/d3d8/d3d8_private.h	2003-07-08 06:01:26.000000000 +0300
+++ wine_patch/dlls/d3d8/d3d8_private.h	2003-08-07 12:04:17.000000000 +0300
@@ -102,13 +102,14 @@
 
   HDC mem_dc;
   HBITMAP old_bmp;
+  HCURSOR hCursor;
 
   D3DGAMMARAMP orig_gamma;
 
   IDirect3DBaseTexture8Impl *textures;
   LPDIRECT3DVERTEXBUFFER8 streamsource[16];
   VertexShader *vshaders;
-  
+
 #if defined( DDRAW_SAVE_AND_RESTORE_FPU_HACK )
   fpu_control_t fpucw; /* FPU control word - saved while in a scene */
 #endif
x11_mouse_patch.diff (text/x-diff, 1.9 KB)
diff -ur wine/dlls/x11drv/Makefile.in wine_patch/dlls/x11drv/Makefile.in
--- wine/dlls/x11drv/Makefile.in	2003-08-01 22:58:48.000000000 +0300
+++ wine_patch/dlls/x11drv/Makefile.in	2003-08-06 23:32:41.000000000 +0300
@@ -3,7 +3,7 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = x11drv
-EXTRALIBS = $(LIBTSX11) $(X_LIBS) $(XLIB) $(LIBUUID)
+EXTRALIBS = $(LIBTSX11) $(X_LIBS) $(XLIB) $(LIBUUID) -lXcursor
 IMPORTS   = user32 gdi32 kernel32
 
 OPENGLFILES = \
diff -ur wine/dlls/x11drv/mouse.c wine_patch/dlls/x11drv/mouse.c
--- wine/dlls/x11drv/mouse.c	2003-08-01 22:58:54.000000000 +0300
+++ wine_patch/dlls/x11drv/mouse.c	2003-08-07 13:08:31.000000000 +0300
@@ -17,6 +17,8 @@
 #include "x11drv.h"
 #include "wine/debug.h"
 
+#include <X11/Xcursor/Xcursor.h>
+
 DEFAULT_DEBUG_CHANNEL(cursor);
 
 extern Window X11DRV_DD_PrimaryFrame;
@@ -171,6 +173,29 @@
     }
     else  /* Create the X cursor from the bits */
     {
+
+    if (ptr->bBitsPerPixel == 32) {
+    if (!XcursorSupportsARGB( display )) ERR("32-bit ARGB cursors not supported by server\n");
+    else
+    {
+        XcursorImage cur;
+    	TRACE("32-bit ARGB cursor used %p Width=%d Height=%d HotX=%d HotY=%d\n",ptr,ptr->nWidth,ptr->nHeight,ptr->ptHotSpot.x,ptr->ptHotSpot.y);
+	/* BitMask is not used. ARGB pixels follows the header */
+        char *p = (char *)(ptr + 1);
+        cur.version = 1;
+	cur.width = ptr->nWidth;
+	cur.height = ptr->nHeight;
+	cur.xhot = ptr->ptHotSpot.x;
+	cur.yhot = ptr->ptHotSpot.y;
+	cur.delay = 0;
+	cur.size = ptr->nWidth; /* ??? */
+	cur.pixels = (unsigned int *) p;
+	return XcursorImageLoadCursor( thread_display(), &cur );
+    }
+    }
+
+    else
+    {
         XImage *image;
         GC gc;
 
@@ -393,6 +418,7 @@
         if (pixmapMaskInv) XFreePixmap( display, pixmapMaskInv );
         XFreeGC( display, gc );
     }
+    }
     return cursor;
 }
 
Only in wine_patch/dlls/x11drv/: x11drv.spec.c
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.