changeset 943:715c32d8f26c

Date: Sun, 18 Jul 2004 00:22:07 -0400 From: "Philippe Anctil" Subject: [SDL] odd mouse event generated on init The mouse relative and absolute coordinates appear to be always equal for the first mouse event.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 21 Aug 2004 12:38:50 +0000
parents 41a59de7f2ed
children cdea7cbc3e23
files src/events/SDL_mouse.c
diffstat 1 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/events/SDL_mouse.c	Sat Aug 21 12:27:02 2004 +0000
+++ b/src/events/SDL_mouse.c	Sat Aug 21 12:38:50 2004 +0000
@@ -38,8 +38,8 @@
 
 
 /* These are static for our mouse handling code */
-static Sint16 SDL_MouseX = 0;
-static Sint16 SDL_MouseY = 0;
+static Sint16 SDL_MouseX = -1;
+static Sint16 SDL_MouseY = -1;
 static Sint16 SDL_DeltaX = 0;
 static Sint16 SDL_DeltaY = 0;
 static Uint8  SDL_ButtonState = 0;
@@ -49,8 +49,8 @@
 int SDL_MouseInit(void)
 {
 	/* The mouse is at (0,0) */
-	SDL_MouseX = 0;
-	SDL_MouseY = 0;
+	SDL_MouseX = -1;
+	SDL_MouseY = -1;
 	SDL_DeltaX = 0;
 	SDL_DeltaY = 0;
 	SDL_ButtonState = 0;
@@ -72,10 +72,20 @@
 
 Uint8 SDL_GetMouseState (int *x, int *y)
 {
-	if ( x )
-		*x = SDL_MouseX;
-	if ( y )
-		*y = SDL_MouseY;
+	if ( x ) {
+		if ( SDL_MouseX < 0 ) {
+			*x = 0;
+		} else {
+			*x = SDL_MouseX;
+		}
+	}
+	if ( y ) {
+		if ( SDL_MouseY < 0 ) {
+			*y = 0;
+		} else {
+			*y = SDL_MouseY;
+		}
+	}
 	return(SDL_ButtonState);
 }
 
@@ -152,7 +162,7 @@
 	   This prevents lots of extraneous large delta relative motion when
 	   the screen is windowed mode and the mouse is outside the window.
 	*/
-	if ( ! relative ) {
+	if ( ! relative && SDL_MouseX >= 0 && SDL_MouseY >= 0 ) {
 		Xrel = X-SDL_MouseX;
 		Yrel = Y-SDL_MouseY;
 	}