comparison src/video/riscos/SDL_riscosmouse.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents d910939febfa
children 99210400e8b9
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
42 extern int mouseInWindow; 42 extern int mouseInWindow;
43 43
44 /* Area to save cursor palette colours changed by SDL. 44 /* Area to save cursor palette colours changed by SDL.
45 Actual values will be read before we change to the SDL cursor */ 45 Actual values will be read before we change to the SDL cursor */
46 static Uint8 wimp_cursor_palette[2][5] = { 46 static Uint8 wimp_cursor_palette[2][5] = {
47 {1, 25, 255, 255, 255}, 47 {1, 25, 255, 255, 255},
48 {3, 25, 255, 255, 255} 48 {3, 25, 255, 255, 255}
49 }; 49 };
50 50
51 static int cursor_palette_saved = 0; 51 static int cursor_palette_saved = 0;
52 52
53 void WIMP_SaveCursorPalette(); 53 void WIMP_SaveCursorPalette();
54 void WIMP_RestoreWimpCursor(); 54 void WIMP_RestoreWimpCursor();
55 void WIMP_SetSDLCursorPalette(); 55 void WIMP_SetSDLCursorPalette();
56 56
57 57
58 void RISCOS_FreeWMCursor(_THIS, WMcursor *cursor) 58 void
59 RISCOS_FreeWMCursor(_THIS, WMcursor * cursor)
59 { 60 {
60 SDL_free(cursor->data); 61 SDL_free(cursor->data);
61 SDL_free(cursor); 62 SDL_free(cursor);
62 } 63 }
63 64
64 WMcursor *RISCOS_CreateWMCursor(_THIS, 65 WMcursor *
65 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) 66 RISCOS_CreateWMCursor(_THIS,
66 { 67 Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
67 WMcursor *cursor; 68 int hot_y)
68 Uint8 *cursor_data; 69 {
69 Uint8 *ptr; 70 WMcursor *cursor;
70 int i,j,k; 71 Uint8 *cursor_data;
71 int data_byte, mask_byte; 72 Uint8 *ptr;
72 73 int i, j, k;
73 /* Check to make sure the cursor size is okay */ 74 int data_byte, mask_byte;
74 if ( (w > 32) || (h > 32) ) { 75
75 SDL_SetError("Only with width and height <= 32 pixels are allowed"); 76 /* Check to make sure the cursor size is okay */
76 return(NULL); 77 if ((w > 32) || (h > 32)) {
77 } 78 SDL_SetError("Only with width and height <= 32 pixels are allowed");
78 79 return (NULL);
79 /* Allocate the cursor */ 80 }
80 cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); 81
81 if ( cursor == NULL ) { 82 /* Allocate the cursor */
82 SDL_SetError("Out of memory"); 83 cursor = (WMcursor *) SDL_malloc(sizeof(*cursor));
83 return(NULL); 84 if (cursor == NULL) {
84 } 85 SDL_SetError("Out of memory");
85 86 return (NULL);
86 /* Note: SDL says width must be a multiple of 8 */ 87 }
87 cursor_data = SDL_malloc(w/4 * h); 88
88 if (cursor_data == NULL) 89 /* Note: SDL says width must be a multiple of 8 */
89 { 90 cursor_data = SDL_malloc(w / 4 * h);
90 SDL_free(cursor); 91 if (cursor_data == NULL) {
91 SDL_SetError("Out of memory"); 92 SDL_free(cursor);
92 return(NULL); 93 SDL_SetError("Out of memory");
93 } 94 return (NULL);
94 95 }
95 cursor->w = w; 96
96 cursor->h = h; 97 cursor->w = w;
97 cursor->hot_x = hot_x; 98 cursor->h = h;
98 cursor->hot_y = hot_y; 99 cursor->hot_x = hot_x;
99 cursor->data = cursor_data; 100 cursor->hot_y = hot_y;
101 cursor->data = cursor_data;
100 102
101 103
102 /* Data / Mask Resulting pixel on screen 104 /* Data / Mask Resulting pixel on screen
103 0 / 1 White 105 0 / 1 White
104 1 / 1 Black 106 1 / 1 Black
105 0 / 0 Transparent 107 0 / 0 Transparent
106 1 / 0 Inverted color if possible, black if not. 108 1 / 0 Inverted color if possible, black if not.
107 */ 109 */
108 ptr = cursor_data; 110 ptr = cursor_data;
109 111
110 for ( i=0; i<h; ++i ) 112 for (i = 0; i < h; ++i) {
111 { 113 for (j = 0; j < w / 8; ++j) {
112 for (j = 0; j < w/8; ++j) 114 data_byte = *data;
113 { 115 mask_byte = *mask;
114 data_byte = *data; 116 *ptr++ = 0; /* Sets whole byte transparent */
115 mask_byte = *mask; 117 *ptr = 0;
116 *ptr++ = 0; /* Sets whole byte transparent */ 118 for (k = 0; k < 8; k++) {
117 *ptr = 0; 119 (*ptr) <<= 2;
118 for (k = 0; k < 8; k++) 120 if (data_byte & 1)
119 { 121 *ptr |= 3; /* Black or inverted */
120 (*ptr) <<= 2; 122 else if (mask_byte & 1)
121 if (data_byte & 1) *ptr |= 3; /* Black or inverted */ 123 *ptr |= 1; /* White */
122 else if(mask_byte & 1) *ptr |= 1; /* White */ 124 if ((k & 3) == 3)
123 if ((k&3) == 3) ptr--; 125 ptr--;
124 data_byte >>= 1; 126 data_byte >>= 1;
125 mask_byte >>= 1; 127 mask_byte >>= 1;
126 } 128 }
127 129
128 ptr+=3; 130 ptr += 3;
129 data++; 131 data++;
130 mask++; 132 mask++;
131 } 133 }
132 } 134 }
133 135
134 return(cursor); 136 return (cursor);
135 } 137 }
136 138
137 int RISCOS_ShowWMCursor(_THIS, WMcursor *cursor) 139 int
138 { 140 RISCOS_ShowWMCursor(_THIS, WMcursor * cursor)
139 current_cursor = cursor; 141 {
140 142 current_cursor = cursor;
141 if (cursor == NULL) 143
142 { 144 if (cursor == NULL) {
143 _kernel_osbyte(106,0,0); 145 _kernel_osbyte(106, 0, 0);
144 defined_cursor = NULL; 146 defined_cursor = NULL;
145 } else 147 } else {
146 {
147 WMcursor *old_cursor = defined_cursor; 148 WMcursor *old_cursor = defined_cursor;
148 149
149 if (cursor != defined_cursor) 150 if (cursor != defined_cursor) {
150 { 151 Uint8 cursor_def[10];
151 Uint8 cursor_def[10]; 152
152 153 cursor_def[0] = 0;
153 cursor_def[0] = 0; 154 cursor_def[1] = 2; /* Use shape number 2 */
154 cursor_def[1] = 2; /* Use shape number 2 */ 155 cursor_def[2] = cursor->w / 4; /* Width in bytes */
155 cursor_def[2] = cursor->w/4; /* Width in bytes */ 156 cursor_def[3] = cursor->h; /* Height (h) in pixels */
156 cursor_def[3] = cursor->h; /* Height (h) in pixels */ 157 cursor_def[4] = cursor->hot_x; /* ActiveX in pixels from left */
157 cursor_def[4] = cursor->hot_x; /* ActiveX in pixels from left */ 158 cursor_def[5] = cursor->hot_y; /* ActiveY in pixels from top */
158 cursor_def[5] = cursor->hot_y; /* ActiveY in pixels from top */ 159 cursor_def[6] = ((int) (cursor->data) & 0xFF); /* Least significant byte of pointer to data */
159 cursor_def[6] = ((int)(cursor->data) & 0xFF); /* Least significant byte of pointer to data */ 160 cursor_def[7] = ((int) (cursor->data) >> 8) & 0xFF; /* ... */
160 cursor_def[7] = ((int)(cursor->data) >> 8) & 0xFF; /* ... */ 161 cursor_def[8] = ((int) (cursor->data) >> 16) & 0xFF; /* ... */
161 cursor_def[8] = ((int)(cursor->data) >> 16) & 0xFF; /* ... */ 162 cursor_def[9] = ((int) (cursor->data) >> 24) & 0xFF; /* Most significant byte of pointer to data */
162 cursor_def[9] = ((int)(cursor->data) >> 24) & 0xFF; /* Most significant byte of pointer to data */ 163
163 164 if (_kernel_osword(21, (int *) cursor_def) != 0) {
164 if (_kernel_osword(21, (int *)cursor_def) != 0) 165 SDL_SetError("RISCOS couldn't create the cursor to show");
165 { 166 return (0);
166 SDL_SetError("RISCOS couldn't create the cursor to show"); 167 }
167 return(0); 168 defined_cursor = cursor;
168 } 169 }
169 defined_cursor = cursor; 170
170 } 171 if (old_cursor == NULL) {
171
172 if (old_cursor == NULL)
173 {
174 /* First time or reshow in window, so save/setup palette */ 172 /* First time or reshow in window, so save/setup palette */
175 if (!cursor_palette_saved) 173 if (!cursor_palette_saved) {
176 {
177 WIMP_SaveCursorPalette(); 174 WIMP_SaveCursorPalette();
178 } 175 }
179 WIMP_SetSDLCursorPalette(); 176 WIMP_SetSDLCursorPalette();
180 } 177 }
181 178
182 _kernel_osbyte(106, 2, 0); 179 _kernel_osbyte(106, 2, 0);
183 } 180 }
184 181
185 return(1); 182 return (1);
186 } 183 }
187 184
188 void FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y) 185 void
189 { 186 FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
190 Uint8 move_block[5]; 187 {
191 int eig_block[3]; 188 Uint8 move_block[5];
192 _kernel_swi_regs regs; 189 int eig_block[3];
193 int os_x, os_y; 190 _kernel_swi_regs regs;
194 191 int os_x, os_y;
195 eig_block[0] = 4; /* X eig factor */ 192
196 eig_block[1] = 5; /* Y eig factor */ 193 eig_block[0] = 4; /* X eig factor */
197 eig_block[2] = -1; /* End of list of variables to request */ 194 eig_block[1] = 5; /* Y eig factor */
198 195 eig_block[2] = -1; /* End of list of variables to request */
199 regs.r[0] = (int)eig_block; 196
200 regs.r[1] = (int)eig_block; 197 regs.r[0] = (int) eig_block;
198 regs.r[1] = (int) eig_block;
201 _kernel_swi(OS_ReadVduVariables, &regs, &regs); 199 _kernel_swi(OS_ReadVduVariables, &regs, &regs);
202 200
203 os_x = x << eig_block[0]; 201 os_x = x << eig_block[0];
204 os_y = y << eig_block[1]; 202 os_y = y << eig_block[1];
205 203
206 move_block[0] = 3; /* Move cursor */ 204 move_block[0] = 3; /* Move cursor */
207 move_block[1] = os_x & 0xFF; 205 move_block[1] = os_x & 0xFF;
208 move_block[2] = (os_x >> 8) & 0xFF; 206 move_block[2] = (os_x >> 8) & 0xFF;
209 move_block[3] = os_y & 0xFF; 207 move_block[3] = os_y & 0xFF;
210 move_block[4] = (os_y >> 8) & 0xFF; 208 move_block[4] = (os_y >> 8) & 0xFF;
211 209
212 _kernel_osword(21, (int *)move_block); 210 _kernel_osword(21, (int *) move_block);
213 SDL_PrivateMouseMotion(0, 0, x, y); 211 SDL_PrivateMouseMotion(0, 0, x, y);
214 } 212 }
215 213
216 214
217 /* Reshow cursor when mouse re-enters the window */ 215 /* Reshow cursor when mouse re-enters the window */
218 void WIMP_ReshowCursor(_THIS) 216 void
219 { 217 WIMP_ReshowCursor(_THIS)
220 defined_cursor = NULL; 218 {
219 defined_cursor = NULL;
221 cursor_palette_saved = 0; 220 cursor_palette_saved = 0;
222 RISCOS_ShowWMCursor(this, current_cursor); 221 RISCOS_ShowWMCursor(this, current_cursor);
223 } 222 }
224 223
225 void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y) 224 void
226 { 225 WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
227 _kernel_swi_regs regs; 226 {
228 int window_state[9]; 227 _kernel_swi_regs regs;
229 char block[5]; 228 int window_state[9];
230 int osX, osY; 229 char block[5];
231 230 int osX, osY;
232 window_state[0] = this->hidden->window_handle; 231
233 regs.r[1] = (unsigned int)window_state; 232 window_state[0] = this->hidden->window_handle;
234 _kernel_swi(Wimp_GetWindowState, &regs, &regs); 233 regs.r[1] = (unsigned int) window_state;
235 234 _kernel_swi(Wimp_GetWindowState, &regs, &regs);
236 osX = (x << this->hidden->xeig) + window_state[1]; 235
237 osY = window_state[4] - (y << this->hidden->yeig); 236 osX = (x << this->hidden->xeig) + window_state[1];
238 237 osY = window_state[4] - (y << this->hidden->yeig);
239 block[0] = 3; 238
240 block[1] = osX & 0xFF; 239 block[0] = 3;
241 block[2] = (osX >> 8) & 0xFF; 240 block[1] = osX & 0xFF;
242 block[3] = osY & 0xFF; 241 block[2] = (osX >> 8) & 0xFF;
243 block[4] = (osY >> 8) & 0xFF; 242 block[3] = osY & 0xFF;
244 243 block[4] = (osY >> 8) & 0xFF;
245 regs.r[0] = 21; 244
246 regs.r[1] = (int)block; 245 regs.r[0] = 21;
247 _kernel_swi(OS_Word, &regs, &regs); 246 regs.r[1] = (int) block;
248 SDL_PrivateMouseMotion(0, 0, x, y); 247 _kernel_swi(OS_Word, &regs, &regs);
249 } 248 SDL_PrivateMouseMotion(0, 0, x, y);
250 249 }
251 int WIMP_ShowWMCursor(_THIS, WMcursor *cursor) 250
252 { 251 int
253 if (mouseInWindow) return RISCOS_ShowWMCursor(this, cursor); 252 WIMP_ShowWMCursor(_THIS, WMcursor * cursor)
254 else current_cursor = cursor; 253 {
255 254 if (mouseInWindow)
256 return 1; 255 return RISCOS_ShowWMCursor(this, cursor);
257 } 256 else
258 257 current_cursor = cursor;
259 SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode) 258
260 { 259 return 1;
261 /* In fullscreen mode we don't need to do anything */ 260 }
262 if (mode < SDL_GRAB_FULLSCREEN) 261
263 { 262 SDL_GrabMode
264 _kernel_swi_regs regs; 263 RISCOS_GrabInput(_THIS, SDL_GrabMode mode)
265 unsigned char block[9]; 264 {
266 block[0] = 1; /* Define mouse cursor bounding block */ 265 /* In fullscreen mode we don't need to do anything */
267 266 if (mode < SDL_GRAB_FULLSCREEN) {
268 if ( mode == SDL_GRAB_OFF ) 267 _kernel_swi_regs regs;
269 { 268 unsigned char block[9];
270 /* Clip to whole screen */ 269 block[0] = 1; /* Define mouse cursor bounding block */
271 270
272 int r = (this->hidden->screen_width << this->hidden->xeig) - 1; 271 if (mode == SDL_GRAB_OFF) {
273 int t = (this->hidden->screen_height << this->hidden->yeig) - 1; 272 /* Clip to whole screen */
274 273
275 block[1] = 0; block[2] = 0; /* Left*/ 274 int r = (this->hidden->screen_width << this->hidden->xeig) - 1;
276 block[3] = 0; block[4] = 0; /* Bottom */ 275 int t = (this->hidden->screen_height << this->hidden->yeig) - 1;
277 block[5] = r & 0xFF; block[6] = (r >> 8) & 0xFF; /* Right */ 276
278 block[7] = t & 0xFF; block[8] = (t >> 8) & 0xFF; /* Top */ 277 block[1] = 0;
279 } else 278 block[2] = 0; /* Left */
280 { 279 block[3] = 0;
281 /* Clip to window */ 280 block[4] = 0; /* Bottom */
282 unsigned char window_state[36]; 281 block[5] = r & 0xFF;
283 282 block[6] = (r >> 8) & 0xFF; /* Right */
284 *((int *)window_state) = this->hidden->window_handle; 283 block[7] = t & 0xFF;
285 regs.r[1] = (unsigned int)window_state; 284 block[8] = (t >> 8) & 0xFF; /* Top */
286 _kernel_swi(Wimp_GetWindowState, &regs, &regs); 285 } else {
287 286 /* Clip to window */
288 block[1] = window_state[4]; 287 unsigned char window_state[36];
289 block[2] = window_state[5]; 288
290 block[3] = window_state[8]; 289 *((int *) window_state) = this->hidden->window_handle;
291 block[4] = window_state[9]; 290 regs.r[1] = (unsigned int) window_state;
292 block[5] = window_state[12]; 291 _kernel_swi(Wimp_GetWindowState, &regs, &regs);
293 block[6] = window_state[13]; 292
294 block[7] = window_state[16]; 293 block[1] = window_state[4];
295 block[8] = window_state[17]; 294 block[2] = window_state[5];
296 295 block[3] = window_state[8];
297 } 296 block[4] = window_state[9];
298 297 block[5] = window_state[12];
299 regs.r[0] = 21; /* OS word code */ 298 block[6] = window_state[13];
300 regs.r[1] = (int)block; 299 block[7] = window_state[16];
301 _kernel_swi(OS_Word, &regs, &regs); 300 block[8] = window_state[17];
302 } 301
303 302 }
304 return mode; 303
304 regs.r[0] = 21; /* OS word code */
305 regs.r[1] = (int) block;
306 _kernel_swi(OS_Word, &regs, &regs);
307 }
308
309 return mode;
305 } 310 }
306 311
307 /* Save mouse cursor palette to be restore when we are no longer 312 /* Save mouse cursor palette to be restore when we are no longer
308 defining a cursor */ 313 defining a cursor */
309 314
310 void WIMP_SaveCursorPalette() 315 void
316 WIMP_SaveCursorPalette()
311 { 317 {
312 _kernel_swi_regs regs; 318 _kernel_swi_regs regs;
313 int colour; 319 int colour;
314 320
315 for (colour = 0; colour < 2; colour++) 321 for (colour = 0; colour < 2; colour++) {
316 { 322 regs.r[0] = (int) wimp_cursor_palette[colour][0];
317 regs.r[0] = (int)wimp_cursor_palette[colour][0]; 323 regs.r[1] = 25;
318 regs.r[1] = 25; 324 /* Read settings with OS_ReadPalette */
319 /* Read settings with OS_ReadPalette */ 325 if (_kernel_swi(0x2f, &regs, &regs) == NULL) {
320 if (_kernel_swi(0x2f, &regs, &regs) == NULL) 326 wimp_cursor_palette[colour][2] =
321 { 327 (unsigned char) ((regs.r[2] >> 8) & 0xFF);
322 wimp_cursor_palette[colour][2] = (unsigned char)((regs.r[2] >> 8) & 0xFF); 328 wimp_cursor_palette[colour][3] =
323 wimp_cursor_palette[colour][3] = (unsigned char)((regs.r[2] >> 16) & 0xFF); 329 (unsigned char) ((regs.r[2] >> 16) & 0xFF);
324 wimp_cursor_palette[colour][4] = (unsigned char)((regs.r[2] >> 24) & 0xFF); 330 wimp_cursor_palette[colour][4] =
325 } 331 (unsigned char) ((regs.r[2] >> 24) & 0xFF);
332 }
326 } 333 }
327 334
328 cursor_palette_saved = 1; 335 cursor_palette_saved = 1;
329 } 336 }
330 337
331 /* Restore the WIMP's cursor when we leave the SDL window */ 338 /* Restore the WIMP's cursor when we leave the SDL window */
332 void WIMP_RestoreWimpCursor() 339 void
340 WIMP_RestoreWimpCursor()
333 { 341 {
334 int colour; 342 int colour;
335 343
336 /* Reset to pointer shape 1 */ 344 /* Reset to pointer shape 1 */
337 _kernel_osbyte(106, 1, 0); 345 _kernel_osbyte(106, 1, 0);
338 346
339 /* Reset pointer colours */ 347 /* Reset pointer colours */
340 if (cursor_palette_saved) 348 if (cursor_palette_saved) {
341 { 349 for (colour = 0; colour < 2; colour++) {
342 for (colour = 0; colour < 2; colour++) 350 _kernel_osword(12, (int *) wimp_cursor_palette[colour]);
343 { 351 }
344 _kernel_osword(12, (int *)wimp_cursor_palette[colour]);
345 }
346 } 352 }
347 cursor_palette_saved = 0; 353 cursor_palette_saved = 0;
348 } 354 }
349 355
350 /* Set palette used for SDL mouse cursors */ 356 /* Set palette used for SDL mouse cursors */
351 void WIMP_SetSDLCursorPalette() 357 void
352 { 358 WIMP_SetSDLCursorPalette()
353 /* First time set up the mouse colours */ 359 {
354 Uint8 block[5]; 360 /* First time set up the mouse colours */
355 361 Uint8 block[5];
356 /* Set up colour 1 as white */ 362
357 block[0] = 1; /* Colour to change 1 - 3 */ 363 /* Set up colour 1 as white */
358 block[1] = 25; /* Set pointer colour */ 364 block[0] = 1; /* Colour to change 1 - 3 */
359 block[2] = 255; /* red component*/ 365 block[1] = 25; /* Set pointer colour */
360 block[3] = 255; /* green component */ 366 block[2] = 255; /* red component */
361 block[4] = 255; /* blue component*/ 367 block[3] = 255; /* green component */
362 _kernel_osword(12, (int *)block); 368 block[4] = 255; /* blue component */
363 369 _kernel_osword(12, (int *) block);
364 /* Set colour 3 to back */ 370
365 block[0] = 3; /* Colour to change 1 - 3 */ 371 /* Set colour 3 to back */
366 block[1] = 25; /* Set pointer colour*/ 372 block[0] = 3; /* Colour to change 1 - 3 */
367 block[2] = 0; /* red component*/ 373 block[1] = 25; /* Set pointer colour */
368 block[3] = 0; /* green component */ 374 block[2] = 0; /* red component */
369 block[4] = 0; /* blue component*/ 375 block[3] = 0; /* green component */
370 _kernel_osword(12, (int *)block); 376 block[4] = 0; /* blue component */
371 } 377 _kernel_osword(12, (int *) block);
378 }
379
380 /* vi: set ts=4 sw=4 expandtab: */