comparison src/video/riscos/SDL_riscosmouse.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
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 58 void
59 RISCOS_FreeWMCursor (_THIS, WMcursor * cursor) 59 RISCOS_FreeWMCursor(_THIS, WMcursor * cursor)
60 { 60 {
61 SDL_free (cursor->data); 61 SDL_free(cursor->data);
62 SDL_free (cursor); 62 SDL_free(cursor);
63 } 63 }
64 64
65 WMcursor * 65 WMcursor *
66 RISCOS_CreateWMCursor (_THIS, 66 RISCOS_CreateWMCursor(_THIS,
67 Uint8 * data, Uint8 * mask, int w, int h, int hot_x, 67 Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
68 int hot_y) 68 int hot_y)
69 { 69 {
70 WMcursor *cursor; 70 WMcursor *cursor;
71 Uint8 *cursor_data; 71 Uint8 *cursor_data;
72 Uint8 *ptr; 72 Uint8 *ptr;
73 int i, j, k; 73 int i, j, k;
74 int data_byte, mask_byte; 74 int data_byte, mask_byte;
75 75
76 /* Check to make sure the cursor size is okay */ 76 /* Check to make sure the cursor size is okay */
77 if ((w > 32) || (h > 32)) { 77 if ((w > 32) || (h > 32)) {
78 SDL_SetError ("Only with width and height <= 32 pixels are allowed"); 78 SDL_SetError("Only with width and height <= 32 pixels are allowed");
79 return (NULL); 79 return (NULL);
80 } 80 }
81 81
82 /* Allocate the cursor */ 82 /* Allocate the cursor */
83 cursor = (WMcursor *) SDL_malloc (sizeof (*cursor)); 83 cursor = (WMcursor *) SDL_malloc(sizeof(*cursor));
84 if (cursor == NULL) { 84 if (cursor == NULL) {
85 SDL_SetError ("Out of memory"); 85 SDL_SetError("Out of memory");
86 return (NULL); 86 return (NULL);
87 } 87 }
88 88
89 /* Note: SDL says width must be a multiple of 8 */ 89 /* Note: SDL says width must be a multiple of 8 */
90 cursor_data = SDL_malloc (w / 4 * h); 90 cursor_data = SDL_malloc(w / 4 * h);
91 if (cursor_data == NULL) { 91 if (cursor_data == NULL) {
92 SDL_free (cursor); 92 SDL_free(cursor);
93 SDL_SetError ("Out of memory"); 93 SDL_SetError("Out of memory");
94 return (NULL); 94 return (NULL);
95 } 95 }
96 96
97 cursor->w = w; 97 cursor->w = w;
98 cursor->h = h; 98 cursor->h = h;
135 135
136 return (cursor); 136 return (cursor);
137 } 137 }
138 138
139 int 139 int
140 RISCOS_ShowWMCursor (_THIS, WMcursor * cursor) 140 RISCOS_ShowWMCursor(_THIS, WMcursor * cursor)
141 { 141 {
142 current_cursor = cursor; 142 current_cursor = cursor;
143 143
144 if (cursor == NULL) { 144 if (cursor == NULL) {
145 _kernel_osbyte (106, 0, 0); 145 _kernel_osbyte(106, 0, 0);
146 defined_cursor = NULL; 146 defined_cursor = NULL;
147 } else { 147 } else {
148 WMcursor *old_cursor = defined_cursor; 148 WMcursor *old_cursor = defined_cursor;
149 149
150 if (cursor != defined_cursor) { 150 if (cursor != defined_cursor) {
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 SDL_SetError("RISCOS couldn't create the cursor to show");
166 return (0); 166 return (0);
167 } 167 }
168 defined_cursor = cursor; 168 defined_cursor = cursor;
169 } 169 }
170 170
171 if (old_cursor == NULL) { 171 if (old_cursor == NULL) {
172 /* First time or reshow in window, so save/setup palette */ 172 /* First time or reshow in window, so save/setup palette */
173 if (!cursor_palette_saved) { 173 if (!cursor_palette_saved) {
174 WIMP_SaveCursorPalette (); 174 WIMP_SaveCursorPalette();
175 } 175 }
176 WIMP_SetSDLCursorPalette (); 176 WIMP_SetSDLCursorPalette();
177 } 177 }
178 178
179 _kernel_osbyte (106, 2, 0); 179 _kernel_osbyte(106, 2, 0);
180 } 180 }
181 181
182 return (1); 182 return (1);
183 } 183 }
184 184
185 void 185 void
186 FULLSCREEN_WarpWMCursor (_THIS, Uint16 x, Uint16 y) 186 FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
187 { 187 {
188 Uint8 move_block[5]; 188 Uint8 move_block[5];
189 int eig_block[3]; 189 int eig_block[3];
190 _kernel_swi_regs regs; 190 _kernel_swi_regs regs;
191 int os_x, os_y; 191 int os_x, os_y;
194 eig_block[1] = 5; /* Y eig factor */ 194 eig_block[1] = 5; /* Y eig factor */
195 eig_block[2] = -1; /* End of list of variables to request */ 195 eig_block[2] = -1; /* End of list of variables to request */
196 196
197 regs.r[0] = (int) eig_block; 197 regs.r[0] = (int) eig_block;
198 regs.r[1] = (int) eig_block; 198 regs.r[1] = (int) eig_block;
199 _kernel_swi (OS_ReadVduVariables, &regs, &regs); 199 _kernel_swi(OS_ReadVduVariables, &regs, &regs);
200 200
201 os_x = x << eig_block[0]; 201 os_x = x << eig_block[0];
202 os_y = y << eig_block[1]; 202 os_y = y << eig_block[1];
203 203
204 move_block[0] = 3; /* Move cursor */ 204 move_block[0] = 3; /* Move cursor */
205 move_block[1] = os_x & 0xFF; 205 move_block[1] = os_x & 0xFF;
206 move_block[2] = (os_x >> 8) & 0xFF; 206 move_block[2] = (os_x >> 8) & 0xFF;
207 move_block[3] = os_y & 0xFF; 207 move_block[3] = os_y & 0xFF;
208 move_block[4] = (os_y >> 8) & 0xFF; 208 move_block[4] = (os_y >> 8) & 0xFF;
209 209
210 _kernel_osword (21, (int *) move_block); 210 _kernel_osword(21, (int *) move_block);
211 SDL_PrivateMouseMotion (0, 0, x, y); 211 SDL_PrivateMouseMotion(0, 0, x, y);
212 } 212 }
213 213
214 214
215 /* Reshow cursor when mouse re-enters the window */ 215 /* Reshow cursor when mouse re-enters the window */
216 void 216 void
217 WIMP_ReshowCursor (_THIS) 217 WIMP_ReshowCursor(_THIS)
218 { 218 {
219 defined_cursor = NULL; 219 defined_cursor = NULL;
220 cursor_palette_saved = 0; 220 cursor_palette_saved = 0;
221 RISCOS_ShowWMCursor (this, current_cursor); 221 RISCOS_ShowWMCursor(this, current_cursor);
222 } 222 }
223 223
224 void 224 void
225 WIMP_WarpWMCursor (_THIS, Uint16 x, Uint16 y) 225 WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
226 { 226 {
227 _kernel_swi_regs regs; 227 _kernel_swi_regs regs;
228 int window_state[9]; 228 int window_state[9];
229 char block[5]; 229 char block[5];
230 int osX, osY; 230 int osX, osY;
231 231
232 window_state[0] = this->hidden->window_handle; 232 window_state[0] = this->hidden->window_handle;
233 regs.r[1] = (unsigned int) window_state; 233 regs.r[1] = (unsigned int) window_state;
234 _kernel_swi (Wimp_GetWindowState, &regs, &regs); 234 _kernel_swi(Wimp_GetWindowState, &regs, &regs);
235 235
236 osX = (x << this->hidden->xeig) + window_state[1]; 236 osX = (x << this->hidden->xeig) + window_state[1];
237 osY = window_state[4] - (y << this->hidden->yeig); 237 osY = window_state[4] - (y << this->hidden->yeig);
238 238
239 block[0] = 3; 239 block[0] = 3;
242 block[3] = osY & 0xFF; 242 block[3] = osY & 0xFF;
243 block[4] = (osY >> 8) & 0xFF; 243 block[4] = (osY >> 8) & 0xFF;
244 244
245 regs.r[0] = 21; 245 regs.r[0] = 21;
246 regs.r[1] = (int) block; 246 regs.r[1] = (int) block;
247 _kernel_swi (OS_Word, &regs, &regs); 247 _kernel_swi(OS_Word, &regs, &regs);
248 SDL_PrivateMouseMotion (0, 0, x, y); 248 SDL_PrivateMouseMotion(0, 0, x, y);
249 } 249 }
250 250
251 int 251 int
252 WIMP_ShowWMCursor (_THIS, WMcursor * cursor) 252 WIMP_ShowWMCursor(_THIS, WMcursor * cursor)
253 { 253 {
254 if (mouseInWindow) 254 if (mouseInWindow)
255 return RISCOS_ShowWMCursor (this, cursor); 255 return RISCOS_ShowWMCursor(this, cursor);
256 else 256 else
257 current_cursor = cursor; 257 current_cursor = cursor;
258 258
259 return 1; 259 return 1;
260 } 260 }
261 261
262 SDL_GrabMode 262 SDL_GrabMode
263 RISCOS_GrabInput (_THIS, SDL_GrabMode mode) 263 RISCOS_GrabInput(_THIS, SDL_GrabMode mode)
264 { 264 {
265 /* In fullscreen mode we don't need to do anything */ 265 /* In fullscreen mode we don't need to do anything */
266 if (mode < SDL_GRAB_FULLSCREEN) { 266 if (mode < SDL_GRAB_FULLSCREEN) {
267 _kernel_swi_regs regs; 267 _kernel_swi_regs regs;
268 unsigned char block[9]; 268 unsigned char block[9];
286 /* Clip to window */ 286 /* Clip to window */
287 unsigned char window_state[36]; 287 unsigned char window_state[36];
288 288
289 *((int *) window_state) = this->hidden->window_handle; 289 *((int *) window_state) = this->hidden->window_handle;
290 regs.r[1] = (unsigned int) window_state; 290 regs.r[1] = (unsigned int) window_state;
291 _kernel_swi (Wimp_GetWindowState, &regs, &regs); 291 _kernel_swi(Wimp_GetWindowState, &regs, &regs);
292 292
293 block[1] = window_state[4]; 293 block[1] = window_state[4];
294 block[2] = window_state[5]; 294 block[2] = window_state[5];
295 block[3] = window_state[8]; 295 block[3] = window_state[8];
296 block[4] = window_state[9]; 296 block[4] = window_state[9];
301 301
302 } 302 }
303 303
304 regs.r[0] = 21; /* OS word code */ 304 regs.r[0] = 21; /* OS word code */
305 regs.r[1] = (int) block; 305 regs.r[1] = (int) block;
306 _kernel_swi (OS_Word, &regs, &regs); 306 _kernel_swi(OS_Word, &regs, &regs);
307 } 307 }
308 308
309 return mode; 309 return mode;
310 } 310 }
311 311
312 /* 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
313 defining a cursor */ 313 defining a cursor */
314 314
315 void 315 void
316 WIMP_SaveCursorPalette () 316 WIMP_SaveCursorPalette()
317 { 317 {
318 _kernel_swi_regs regs; 318 _kernel_swi_regs regs;
319 int colour; 319 int colour;
320 320
321 for (colour = 0; colour < 2; colour++) { 321 for (colour = 0; colour < 2; colour++) {
322 regs.r[0] = (int) wimp_cursor_palette[colour][0]; 322 regs.r[0] = (int) wimp_cursor_palette[colour][0];
323 regs.r[1] = 25; 323 regs.r[1] = 25;
324 /* Read settings with OS_ReadPalette */ 324 /* Read settings with OS_ReadPalette */
325 if (_kernel_swi (0x2f, &regs, &regs) == NULL) { 325 if (_kernel_swi(0x2f, &regs, &regs) == NULL) {
326 wimp_cursor_palette[colour][2] = 326 wimp_cursor_palette[colour][2] =
327 (unsigned char) ((regs.r[2] >> 8) & 0xFF); 327 (unsigned char) ((regs.r[2] >> 8) & 0xFF);
328 wimp_cursor_palette[colour][3] = 328 wimp_cursor_palette[colour][3] =
329 (unsigned char) ((regs.r[2] >> 16) & 0xFF); 329 (unsigned char) ((regs.r[2] >> 16) & 0xFF);
330 wimp_cursor_palette[colour][4] = 330 wimp_cursor_palette[colour][4] =
335 cursor_palette_saved = 1; 335 cursor_palette_saved = 1;
336 } 336 }
337 337
338 /* Restore the WIMP's cursor when we leave the SDL window */ 338 /* Restore the WIMP's cursor when we leave the SDL window */
339 void 339 void
340 WIMP_RestoreWimpCursor () 340 WIMP_RestoreWimpCursor()
341 { 341 {
342 int colour; 342 int colour;
343 343
344 /* Reset to pointer shape 1 */ 344 /* Reset to pointer shape 1 */
345 _kernel_osbyte (106, 1, 0); 345 _kernel_osbyte(106, 1, 0);
346 346
347 /* Reset pointer colours */ 347 /* Reset pointer colours */
348 if (cursor_palette_saved) { 348 if (cursor_palette_saved) {
349 for (colour = 0; colour < 2; colour++) { 349 for (colour = 0; colour < 2; colour++) {
350 _kernel_osword (12, (int *) wimp_cursor_palette[colour]); 350 _kernel_osword(12, (int *) wimp_cursor_palette[colour]);
351 } 351 }
352 } 352 }
353 cursor_palette_saved = 0; 353 cursor_palette_saved = 0;
354 } 354 }
355 355
356 /* Set palette used for SDL mouse cursors */ 356 /* Set palette used for SDL mouse cursors */
357 void 357 void
358 WIMP_SetSDLCursorPalette () 358 WIMP_SetSDLCursorPalette()
359 { 359 {
360 /* First time set up the mouse colours */ 360 /* First time set up the mouse colours */
361 Uint8 block[5]; 361 Uint8 block[5];
362 362
363 /* Set up colour 1 as white */ 363 /* Set up colour 1 as white */
364 block[0] = 1; /* Colour to change 1 - 3 */ 364 block[0] = 1; /* Colour to change 1 - 3 */
365 block[1] = 25; /* Set pointer colour */ 365 block[1] = 25; /* Set pointer colour */
366 block[2] = 255; /* red component */ 366 block[2] = 255; /* red component */
367 block[3] = 255; /* green component */ 367 block[3] = 255; /* green component */
368 block[4] = 255; /* blue component */ 368 block[4] = 255; /* blue component */
369 _kernel_osword (12, (int *) block); 369 _kernel_osword(12, (int *) block);
370 370
371 /* Set colour 3 to back */ 371 /* Set colour 3 to back */
372 block[0] = 3; /* Colour to change 1 - 3 */ 372 block[0] = 3; /* Colour to change 1 - 3 */
373 block[1] = 25; /* Set pointer colour */ 373 block[1] = 25; /* Set pointer colour */
374 block[2] = 0; /* red component */ 374 block[2] = 0; /* red component */
375 block[3] = 0; /* green component */ 375 block[3] = 0; /* green component */
376 block[4] = 0; /* blue component */ 376 block[4] = 0; /* blue component */
377 _kernel_osword (12, (int *) block); 377 _kernel_osword(12, (int *) block);
378 } 378 }
379 379
380 /* vi: set ts=4 sw=4 expandtab: */ 380 /* vi: set ts=4 sw=4 expandtab: */