symbian-qemu-0.9.1-12/libsdl-trunk/src/video/ps2gs/SDL_gsmouse.c
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 /*
       
     2     SDL - Simple DirectMedia Layer
       
     3     Copyright (C) 1997-2006 Sam Lantinga
       
     4 
       
     5     This library is free software; you can redistribute it and/or
       
     6     modify it under the terms of the GNU Lesser General Public
       
     7     License as published by the Free Software Foundation; either
       
     8     version 2.1 of the License, or (at your option) any later version.
       
     9 
       
    10     This library is distributed in the hope that it will be useful,
       
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13     Lesser General Public License for more details.
       
    14 
       
    15     You should have received a copy of the GNU Lesser General Public
       
    16     License along with this library; if not, write to the Free Software
       
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    18 
       
    19     Sam Lantinga
       
    20     slouken@libsdl.org
       
    21 */
       
    22 #include "SDL_config.h"
       
    23 
       
    24 #include <sys/ioctl.h>
       
    25 
       
    26 #include "SDL_mouse.h"
       
    27 #include "../../events/SDL_events_c.h"
       
    28 #include "../SDL_cursor_c.h"
       
    29 #include "SDL_gsvideo.h"
       
    30 #include "SDL_gsmouse_c.h"
       
    31 
       
    32 
       
    33 /* The implementation dependent data for the window manager cursor */
       
    34 struct WMcursor {
       
    35 	int unused;
       
    36 };
       
    37 
       
    38 /* There isn't any implementation dependent data */
       
    39 void GS_FreeWMCursor(_THIS, WMcursor *cursor)
       
    40 {
       
    41 	return;
       
    42 }
       
    43 
       
    44 /* There isn't any implementation dependent data */
       
    45 WMcursor *GS_CreateWMCursor(_THIS,
       
    46 		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
       
    47 {
       
    48 	return((WMcursor *)0x01);
       
    49 }
       
    50 
       
    51 static void GS_MoveCursor(_THIS, SDL_Cursor *cursor, int x, int y)
       
    52 {
       
    53 	SDL_Surface *screen;
       
    54 	struct ps2_image image;
       
    55 	SDL_Rect area;
       
    56 	int mouse_y1, mouse_y2;
       
    57 	void *saved_pixels;
       
    58 	int screen_updated;
       
    59 
       
    60 	/* Lock so we don't interrupt an update with mouse motion */
       
    61 	SDL_LockCursor();
       
    62 
       
    63 	/* Make sure any pending DMA has completed */
       
    64 	if ( dma_pending ) {
       
    65 		ioctl(console_fd, PS2IOC_SENDQCT, 1);
       
    66 		dma_pending = 0;
       
    67 	}
       
    68 
       
    69 	/* Remove the cursor image from the DMA area */
       
    70 	screen = this->screen;
       
    71 	saved_pixels = screen->pixels;
       
    72 	screen->pixels = mapped_mem + screen->offset;
       
    73 	screen_updated = 0;
       
    74 	if ( cursor_drawn ) {
       
    75 		SDL_EraseCursorNoLock(screen);
       
    76 		cursor_drawn = 0;
       
    77 		screen_updated = 1;
       
    78 	}
       
    79 
       
    80 	/* Save the current mouse area */
       
    81 	SDL_MouseRect(&area);
       
    82 	mouse_y1 = area.y;
       
    83 	mouse_y2 = area.y+area.h;
       
    84 
       
    85 	/* Only draw the new cursor if there was one passed in */
       
    86 	if ( cursor ) {
       
    87 		/* Set the new location */
       
    88 		cursor->area.x = (x - cursor->hot_x);
       
    89 		cursor->area.y = (y - cursor->hot_y);
       
    90 
       
    91 		/* Draw the cursor at the new location */
       
    92 		if ( (SDL_cursorstate & CURSOR_VISIBLE) && screen->pixels ) {
       
    93 			SDL_DrawCursorNoLock(screen);
       
    94 			cursor_drawn = 1;
       
    95 			screen_updated = 1;
       
    96 		}
       
    97 	}
       
    98 	screen->pixels = saved_pixels;
       
    99 
       
   100 	/* Update the affected area of the screen */
       
   101 	if ( screen_updated ) {
       
   102 		SDL_MouseRect(&area);
       
   103 		if ( area.y < mouse_y1 ) {
       
   104 			mouse_y1 = area.y;
       
   105 		}
       
   106 		if ( (area.y+area.h) > mouse_y2 ) {
       
   107 			mouse_y2 = area.y+area.h;
       
   108 		}
       
   109 		image = screen_image;
       
   110 		image.y += screen->offset / screen->pitch + mouse_y1;
       
   111 		image.h = mouse_y2 - mouse_y1;
       
   112 		image.ptr = mapped_mem +
       
   113 		            (image.y - screen_image.y) * screen->pitch;
       
   114 		ioctl(console_fd, PS2IOC_LOADIMAGE, &image);
       
   115 
       
   116 		/* Need to scale offscreen image to TV output */
       
   117 		if ( image.y > 0 ) {
       
   118 			scaleimage_nonblock(console_fd,
       
   119 			                    tex_tags_mem, scale_tags_mem);
       
   120 		}
       
   121 	}
       
   122 
       
   123 	/* We're finished */
       
   124 	SDL_UnlockCursor();
       
   125 }
       
   126 
       
   127 void GS_MoveWMCursor(_THIS, int x, int y)
       
   128 {
       
   129 	GS_MoveCursor(this, SDL_cursor, x, y);
       
   130 }
       
   131 
       
   132 int GS_ShowWMCursor(_THIS, WMcursor *wmcursor)
       
   133 {
       
   134 	SDL_Cursor *cursor;
       
   135 	int x, y;
       
   136 
       
   137 	/* Draw the cursor at the appropriate location */
       
   138 	SDL_GetMouseState(&x, &y);
       
   139 	if ( wmcursor ) {
       
   140 		cursor = SDL_cursor;
       
   141 	} else {
       
   142 		cursor = NULL;
       
   143 	}
       
   144 	GS_MoveCursor(this, cursor, x, y);
       
   145 	return(1);
       
   146 }