Example #1
0
/* SDL_SetCursor(NULL) can be used to force the cursor redraw,
   if this is desired for any reason.  This is used when setting
   the video mode and when the SDL window gains the mouse focus.
 */
void SDL_SetCursor (SDL_Cursor *cursor)
{
	SDL_VideoDevice *video = current_video;
	SDL_VideoDevice *this  = current_video;

	/* Make sure that the video subsystem has been initialized */
	if ( ! video ) {
		return;
	}

	/* Prevent the event thread from moving the mouse */
	SDL_LockCursor();

	/* Set the new cursor */
	if ( cursor && (cursor != SDL_cursor) ) {
		/* Erase the current mouse position */
		if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
			SDL_EraseCursor(SDL_VideoSurface);
		} else if ( video->MoveWMCursor ) {
			/* If the video driver is moving the cursor directly,
			   it needs to hide the old cursor before (possibly)
			   showing the new one.  (But don't erase NULL cursor)
			 */
			if ( SDL_cursor ) {
				video->ShowWMCursor(this, NULL);
			}
		}
		SDL_cursor = cursor;
	}

	/* Draw the new mouse cursor */
	if ( SDL_cursor && (SDL_cursorstate&CURSOR_VISIBLE) ) {
		/* Use window manager cursor if possible */
		if ( SDL_cursor->wm_cursor && 
	             video->ShowWMCursor(this, SDL_cursor->wm_cursor) )
			SDL_cursorstate &= ~CURSOR_USINGSW;
		else {
			SDL_cursorstate |= CURSOR_USINGSW;
			if ( video->ShowWMCursor ) {
				video->ShowWMCursor(this, NULL);
			}
			{ int x, y;
				SDL_GetMouseState(&x, &y);
				SDL_cursor->area.x = (x - SDL_cursor->hot_x);
				SDL_cursor->area.y = (y - SDL_cursor->hot_y);
			}
			SDL_DrawCursor(SDL_VideoSurface);
		}
	} else {
		/* Erase window manager mouse (cursor not visible) */
		if ( SDL_cursor && (SDL_cursorstate & CURSOR_USINGSW) ) {
			SDL_EraseCursor(SDL_VideoSurface);
		} else {
			if ( video ) {
				video->ShowWMCursor(this, NULL);
			}
		}
	}
	SDL_UnlockCursor();
}
Example #2
0
void SDL_MoveCursor(int x, int y)
{
 SDL_VideoDevice *video = current_video;

 /* Erase and update the current mouse position */
 if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
   /* Erase and redraw mouse cursor in new position */
   SDL_LockCursor();
   SDL_EraseCursor(SDL_VideoSurface);
   SDL_cursor->area.x = (x - SDL_cursor->hot_x);
   SDL_cursor->area.y = (y - SDL_cursor->hot_y);
   SDL_DrawCursor(SDL_VideoSurface);
   SDL_UnlockCursor();
 } else if ( video->MoveWMCursor ) {
   video->MoveWMCursor(video, x, y);
 }
}