comparison src/video/ps2gs/SDL_gsmouse.c @ 70:f590dd383b5d

Added Linux PlayStation 2 Graphics Synthesizer support
author Sam Lantinga <slouken@lokigames.com>
date Sat, 16 Jun 2001 03:17:45 +0000
parents
children 717f739d6ec1
comparison
equal deleted inserted replaced
69:280ff3af2ecc 70:f590dd383b5d
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <sys/ioctl.h>
31
32 #include "SDL_error.h"
33 #include "SDL_mouse.h"
34 #include "SDL_events_c.h"
35 #include "SDL_cursor_c.h"
36 #include "SDL_gsvideo.h"
37 #include "SDL_gsmouse_c.h"
38
39
40 /* The implementation dependent data for the window manager cursor */
41 struct WMcursor {
42 int unused;
43 };
44
45 /* There isn't any implementation dependent data */
46 void GS_FreeWMCursor(_THIS, WMcursor *cursor)
47 {
48 return;
49 }
50
51 /* There isn't any implementation dependent data */
52 WMcursor *GS_CreateWMCursor(_THIS,
53 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
54 {
55 return((WMcursor *)0x01);
56 }
57
58 static void GS_MoveCursor(_THIS, SDL_Cursor *cursor, int x, int y)
59 {
60 SDL_Surface *screen;
61 struct ps2_image image;
62 SDL_Rect area;
63 int mouse_y1, mouse_y2;
64 void *saved_pixels;
65 int screen_updated;
66
67 /* Lock so we don't interrupt an update with mouse motion */
68 SDL_LockCursor();
69
70 /* Make sure any pending DMA has completed */
71 if ( dma_pending ) {
72 ioctl(console_fd, PS2IOC_SENDQCT, 1);
73 dma_pending = 0;
74 }
75
76 /* Remove the cursor image from the DMA area */
77 screen = this->screen;
78 saved_pixels = screen->pixels;
79 screen->pixels = mapped_mem + screen->offset;
80 screen_updated = 0;
81 if ( cursor_drawn ) {
82 SDL_EraseCursorNoLock(this->screen);
83 cursor_drawn = 0;
84 screen_updated = 1;
85 }
86
87 /* Save the current mouse area */
88 SDL_MouseRect(&area);
89 mouse_y1 = area.y;
90 mouse_y2 = area.y+area.h;
91
92 /* Only draw the new cursor if there was one passed in */
93 if ( cursor ) {
94 /* Set the new location */
95 cursor->area.x = (x - cursor->hot_x);
96 cursor->area.y = (y - cursor->hot_y);
97
98 /* Draw the cursor at the new location */
99 if ( (SDL_cursorstate & CURSOR_VISIBLE) && screen->pixels ) {
100 SDL_DrawCursorNoLock(screen);
101 cursor_drawn = 1;
102 screen_updated = 1;
103 }
104 }
105 screen->pixels = saved_pixels;
106
107 /* Update the affected area of the screen */
108 if ( screen_updated ) {
109 SDL_MouseRect(&area);
110 if ( area.y < mouse_y1 ) {
111 mouse_y1 = area.y;
112 }
113 if ( (area.y+area.h) > mouse_y2 ) {
114 mouse_y2 = area.y+area.h;
115 }
116 image = screen_image;
117 image.y = screen->offset / screen->pitch + mouse_y1;
118 image.h = mouse_y2 - mouse_y1;
119 image.ptr = mapped_mem + image.y * screen->pitch;
120 ioctl(console_fd, PS2IOC_LOADIMAGE, &image);
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 }