diff src/video/photon/SDL_ph_mouse.c @ 283:3d8b6b9f1e18

Date: Mon, 18 Feb 2002 16:46:59 +1200 From: Julian Kinraid <jkinraid@clear.net.nz> Subject: Patches for photon port of SDL Hi, A couple more patches for photon and the nto audio. Adds mouse grabbing support, fixed cursor images, unicode keyboard events (though no unicode data on kye release, is that a problem?), hopefully fixing some audio lag problems, and a few other fixes. Thanks, Julian Kinraid
author Sam Lantinga <slouken@libsdl.org>
date Wed, 20 Feb 2002 01:05:51 +0000
parents c6abdda2f666
children f6ffac90895c
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_mouse.c	Wed Feb 20 01:02:33 2002 +0000
+++ b/src/video/photon/SDL_ph_mouse.c	Wed Feb 20 01:05:51 2002 +0000
@@ -62,6 +62,7 @@
 {
 	WMcursor* cursor;
 	int clen, i;
+	unsigned char bit, databit, maskbit;
 
 	/* Allocate and initialize the cursor memory */
 	if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL)
@@ -70,13 +71,13 @@
         return(NULL);
 	}
 	memset(cursor,0,sizeof(WMcursor));
-	
+
 	cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2);
 	if(cursor->ph_cursor == NULL)
 	   printf("cursor malloc failed\n");
 
 	memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
-	   
+
 	cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR;   
 	cursor->ph_cursor->size1.x = (short)w;
 	cursor->ph_cursor->size1.y = (short)h;
@@ -90,18 +91,27 @@
         cursor->ph_cursor->offset2.y = (short)hot_y;
         cursor->ph_cursor->bytesperline2 = (char)w/8;
         cursor->ph_cursor->color2 = Pg_BLACK;
-      
+
 	clen = (w/8)*h;
 
 	/* Copy the mask and the data to different 
 	   bitmap planes */
 	for ( i=0; i<clen; ++i )
-        {
-           cursor->ph_cursor->images[i] = data[i];
-           cursor->ph_cursor->images[i+clen] = mask[i];
-        }
-    
-        //#bytes following the hdr struct
+	{
+		for ( bit = 0; bit < 8; bit++ )
+		{
+			databit = data[i] & (1 << bit);
+			maskbit = mask[i] & (1 << bit);
+
+			cursor->ph_cursor->images[i] |= 
+				(databit == 0) ? maskbit : 0;
+			/* If the databit != 0, treat it as a black pixel and
+			 * ignore the maskbit (can't do an inverted color) */
+			cursor->ph_cursor->images[i+clen] |= databit;
+		}
+	}
+
+        /* #bytes following the hdr struct */
 	cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); 
 
 	return (cursor);
@@ -113,7 +123,6 @@
 	return(*cursor->ph_cursor);
 }
 
-
 int ph_ShowWMCursor(_THIS, WMcursor *cursor)
 {
 	PtArg_t args[3];
@@ -130,13 +139,13 @@
 		
 		if ( cursor != NULL ) {
 			PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0 );
-			// Could set next to any PgColor_t value
+			/* Could set next to any PgColor_t value */
 			PtSetArg( &args[1], Pt_ARG_CURSOR_COLOR,Ph_CURSOR_DEFAULT_COLOR , 0 );
 			PtSetArg( &args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)) );
 			nargs = 3;
 			cursor_is_defined = 1;
 		}
-		else // Ph_CURSOR_NONE
+		else /* Ph_CURSOR_NONE */
 		{
 			PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE,Ph_CURSOR_NONE, 0);
 			nargs = 1;
@@ -161,13 +170,22 @@
 
 void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
 {
-   SDL_Lock_EventThread();
-   PhMoveCursorRel( PhInputGroup(NULL), x, y );	
-   SDL_Unlock_EventThread();
+	short abs_x, abs_y;
+
+	SDL_Lock_EventThread();
+	PtGetAbsPosition( window, &abs_x, &abs_y );
+	PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y );
+	SDL_Unlock_EventThread();
 }
 
 
 void ph_CheckMouseMode(_THIS)
 {
-   mouse_relative = 1;
+        /* If the mouse is hidden and input is grabbed, we use relative mode */
+        if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
+             (this->input_grab != SDL_GRAB_OFF) ) {
+                mouse_relative = 1;
+        } else {
+                mouse_relative = 0;
+        }
 }