src/events/SDL_mouse.c
branchSDL-1.2
changeset 4249 429c8dd3175d
parent 4159 a1b03ba2fcd0
child 6137 4720145f848b
equal deleted inserted replaced
4248:a9c6e65c1416 4249:429c8dd3175d
    32 /* These are static for our mouse handling code */
    32 /* These are static for our mouse handling code */
    33 static Sint16 SDL_MouseX = 0;
    33 static Sint16 SDL_MouseX = 0;
    34 static Sint16 SDL_MouseY = 0;
    34 static Sint16 SDL_MouseY = 0;
    35 static Sint16 SDL_DeltaX = 0;
    35 static Sint16 SDL_DeltaX = 0;
    36 static Sint16 SDL_DeltaY = 0;
    36 static Sint16 SDL_DeltaY = 0;
       
    37 static Sint16 SDL_MouseMaxX = 0;
       
    38 static Sint16 SDL_MouseMaxY = 0;
    37 static Uint8  SDL_ButtonState = 0;
    39 static Uint8  SDL_ButtonState = 0;
    38 
    40 
    39 
    41 
    40 /* Public functions */
    42 /* Public functions */
    41 int SDL_MouseInit(void)
    43 int SDL_MouseInit(void)
    43 	/* The mouse is at (0,0) */
    45 	/* The mouse is at (0,0) */
    44 	SDL_MouseX = 0;
    46 	SDL_MouseX = 0;
    45 	SDL_MouseY = 0;
    47 	SDL_MouseY = 0;
    46 	SDL_DeltaX = 0;
    48 	SDL_DeltaX = 0;
    47 	SDL_DeltaY = 0;
    49 	SDL_DeltaY = 0;
       
    50 	SDL_MouseMaxX = 0;
       
    51 	SDL_MouseMaxY = 0;
    48 	SDL_ButtonState = 0;
    52 	SDL_ButtonState = 0;
    49 
    53 
    50 	/* That's it! */
    54 	/* That's it! */
    51 	return(0);
    55 	return(0);
    52 }
    56 }
    90 static void ClipOffset(Sint16 *x, Sint16 *y)
    94 static void ClipOffset(Sint16 *x, Sint16 *y)
    91 {
    95 {
    92 	/* This clips absolute mouse coordinates when the apparent
    96 	/* This clips absolute mouse coordinates when the apparent
    93 	   display surface is smaller than the real display surface.
    97 	   display surface is smaller than the real display surface.
    94 	 */
    98 	 */
    95 	if ( SDL_VideoSurface->offset ) {
    99 	if ( SDL_VideoSurface && SDL_VideoSurface->offset ) {
    96 		*y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch;
   100 		*y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch;
    97 		*x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
   101 		*x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
    98 				SDL_VideoSurface->format->BytesPerPixel;
   102 				SDL_VideoSurface->format->BytesPerPixel;
    99 	}
   103 	}
       
   104 }
       
   105 
       
   106 void SDL_SetMouseRange(int maxX, int maxY)
       
   107 {
       
   108 	SDL_MouseMaxX = (Sint16)maxX;
       
   109 	SDL_MouseMaxY = (Sint16)maxY;
   100 }
   110 }
   101 
   111 
   102 /* These are global for SDL_eventloop.c */
   112 /* These are global for SDL_eventloop.c */
   103 int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
   113 int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
   104 {
   114 {
   105 	int posted;
   115 	int posted;
   106 	Uint16 X, Y;
   116 	Uint16 X, Y;
   107 	Sint16 Xrel;
   117 	Sint16 Xrel;
   108 	Sint16 Yrel;
   118 	Sint16 Yrel;
   109 
       
   110 	/* Don't handle mouse motion if there's no cursor surface */
       
   111 	if ( SDL_VideoSurface == NULL ) {
       
   112 		return(0);
       
   113 	}
       
   114 
   119 
   115 	/* Default buttonstate is the current one */
   120 	/* Default buttonstate is the current one */
   116 	if ( ! buttonstate ) {
   121 	if ( ! buttonstate ) {
   117 		buttonstate = SDL_ButtonState;
   122 		buttonstate = SDL_ButtonState;
   118 	}
   123 	}
   130 
   135 
   131 	/* Mouse coordinates range from 0 - width-1 and 0 - height-1 */
   136 	/* Mouse coordinates range from 0 - width-1 and 0 - height-1 */
   132 	if ( x < 0 )
   137 	if ( x < 0 )
   133 		X = 0;
   138 		X = 0;
   134 	else
   139 	else
   135 	if ( x >= SDL_VideoSurface->w )
   140 	if ( x >= SDL_MouseMaxX )
   136 		X = SDL_VideoSurface->w-1;
   141 		X = SDL_MouseMaxX-1;
   137 	else
   142 	else
   138 		X = (Uint16)x;
   143 		X = (Uint16)x;
   139 
   144 
   140 	if ( y < 0 )
   145 	if ( y < 0 )
   141 		Y = 0;
   146 		Y = 0;
   142 	else
   147 	else
   143 	if ( y >= SDL_VideoSurface->h )
   148 	if ( y >= SDL_MouseMaxY )
   144 		Y = SDL_VideoSurface->h-1;
   149 		Y = SDL_MouseMaxY-1;
   145 	else
   150 	else
   146 		Y = (Uint16)y;
   151 		Y = (Uint16)y;
   147 
   152 
   148 	/* If not relative mode, generate relative motion from clamped X/Y.
   153 	/* If not relative mode, generate relative motion from clamped X/Y.
   149 	   This prevents lots of extraneous large delta relative motion when
   154 	   This prevents lots of extraneous large delta relative motion when
   204 		move_mouse = 1;
   209 		move_mouse = 1;
   205 		/* Mouse coordinates range from 0 - width-1 and 0 - height-1 */
   210 		/* Mouse coordinates range from 0 - width-1 and 0 - height-1 */
   206 		if ( x < 0 )
   211 		if ( x < 0 )
   207 			x = 0;
   212 			x = 0;
   208 		else
   213 		else
   209 		if ( x >= SDL_VideoSurface->w )
   214 		if ( x >= SDL_MouseMaxX )
   210 			x = SDL_VideoSurface->w-1;
   215 			x = SDL_MouseMaxX-1;
   211 
   216 
   212 		if ( y < 0 )
   217 		if ( y < 0 )
   213 			y = 0;
   218 			y = 0;
   214 		else
   219 		else
   215 		if ( y >= SDL_VideoSurface->h )
   220 		if ( y >= SDL_MouseMaxY )
   216 			y = SDL_VideoSurface->h-1;
   221 			y = SDL_MouseMaxY-1;
   217 	} else {
   222 	} else {
   218 		move_mouse = 0;
   223 		move_mouse = 0;
   219 	}
   224 	}
   220 	if ( ! x )
   225 	if ( ! x )
   221 		x = SDL_MouseX;
   226 		x = SDL_MouseX;