comparison src/video/riscos/SDL_riscosmouse.c @ 1208:d90b362628ea

From: "alan buckley" <alan_baa@hotmail.com> Subject: Patch for RISC OS cursor palette handling in SDL Date: Mon, 07 Nov 2005 09:14:15 -0800 The mouse cursor palette was not correctly restored on RISC OS if the system was using anything but the default mouse colours. Additionally I've modifed the order the wait for vsync is called as it should be after the screen bank switching.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 23 Dec 2005 09:40:15 +0000
parents 974ba6ae0fa3
children c9b51268668f
comparison
equal deleted inserted replaced
1207:c9ec00d3e8bc 1208:d90b362628ea
38 38
39 #include "kernel.h" 39 #include "kernel.h"
40 #include "swis.h" 40 #include "swis.h"
41 41
42 static WMcursor *current_cursor = NULL; 42 static WMcursor *current_cursor = NULL;
43 static WMcursor *defined_cursor = NULL;
43 44
44 extern int mouseInWindow; 45 extern int mouseInWindow;
46
47 /* Area to save cursor palette colours changed by SDL.
48 Actual values will be read before we change to the SDL cursor */
49 static Uint8 wimp_cursor_palette[2][5] = {
50 {1, 25, 255, 255, 255},
51 {3, 25, 255, 255, 255}
52 };
53
54 static int cursor_palette_saved = 0;
55
56 void WIMP_SaveCursorPalette();
57 void WIMP_RestoreWimpCursor();
58 void WIMP_SetSDLCursorPalette();
59
45 60
46 void RISCOS_FreeWMCursor(_THIS, WMcursor *cursor) 61 void RISCOS_FreeWMCursor(_THIS, WMcursor *cursor)
47 { 62 {
48 free(cursor->data); 63 free(cursor->data);
49 free(cursor); 64 free(cursor);
122 return(cursor); 137 return(cursor);
123 } 138 }
124 139
125 int RISCOS_ShowWMCursor(_THIS, WMcursor *cursor) 140 int RISCOS_ShowWMCursor(_THIS, WMcursor *cursor)
126 { 141 {
142 current_cursor = cursor;
143
127 if (cursor == NULL) 144 if (cursor == NULL)
128 { 145 {
129 _kernel_osbyte(106,0,0); 146 _kernel_osbyte(106,0,0);
130 current_cursor = NULL; 147 defined_cursor = NULL;
131 } else 148 } else
132 { 149 {
133 if (current_cursor == NULL) 150 WMcursor *old_cursor = defined_cursor;
134 { 151
135 /* First time set up the mouse colours */ 152 if (cursor != defined_cursor)
136 Uint8 block[5];
137
138 /* Set up colour 1 as white */
139 block[0] = 1; /* Colour to change 1 - 3 */
140 block[1] = 25; /* Set pointer colour */
141 block[2] = 255; /* red component*/
142 block[3] = 255; /* green component */
143 block[4] = 255; /* blue component*/
144 _kernel_osword(12, (int *)block);
145
146 /* Set colour 3 to back */
147 block[0] = 3; /* Colour to change 1 - 3 */
148 block[1] = 25; /* Set pointer colour*/
149 block[2] = 0; /* red component*/
150 block[3] = 0; /* green component */
151 block[4] = 0; /* blue component*/
152 _kernel_osword(12, (int *)block);
153 }
154
155 if (cursor != current_cursor)
156 { 153 {
157 Uint8 cursor_def[10]; 154 Uint8 cursor_def[10];
158 155
159 cursor_def[0] = 0; 156 cursor_def[0] = 0;
160 cursor_def[1] = 2; /* Use shape number 2 */ 157 cursor_def[1] = 2; /* Use shape number 2 */
165 cursor_def[6] = ((int)(cursor->data) & 0xFF); /* Least significant byte of pointer to data */ 162 cursor_def[6] = ((int)(cursor->data) & 0xFF); /* Least significant byte of pointer to data */
166 cursor_def[7] = ((int)(cursor->data) >> 8) & 0xFF; /* ... */ 163 cursor_def[7] = ((int)(cursor->data) >> 8) & 0xFF; /* ... */
167 cursor_def[8] = ((int)(cursor->data) >> 16) & 0xFF; /* ... */ 164 cursor_def[8] = ((int)(cursor->data) >> 16) & 0xFF; /* ... */
168 cursor_def[9] = ((int)(cursor->data) >> 24) & 0xFF; /* Most significant byte of pointer to data */ 165 cursor_def[9] = ((int)(cursor->data) >> 24) & 0xFF; /* Most significant byte of pointer to data */
169 166
170 if (_kernel_osword(21, (int *)cursor_def) == 0) 167 if (_kernel_osword(21, (int *)cursor_def) != 0)
171 { 168 {
172 SDL_SetError("RISCOS couldn't create the cursor to show"); 169 SDL_SetError("RISCOS couldn't create the cursor to show");
173 return(0); 170 return(0);
174 } 171 }
175 current_cursor = cursor; 172 defined_cursor = cursor;
176 } 173 }
177 174
178 if ((this->screen->flags & SDL_FULLSCREEN) || mouseInWindow) _kernel_osbyte(106, 2, 0); 175 if (old_cursor == NULL)
176 {
177 /* First time or reshow in window, so save/setup palette */
178 if (!cursor_palette_saved)
179 {
180 WIMP_SaveCursorPalette();
181 }
182 WIMP_SetSDLCursorPalette();
183 }
184
185 _kernel_osbyte(106, 2, 0);
179 } 186 }
180 187
181 return(1); 188 return(1);
182 } 189 }
183 190
211 218
212 219
213 /* Reshow cursor when mouse re-enters the window */ 220 /* Reshow cursor when mouse re-enters the window */
214 void WIMP_ReshowCursor(_THIS) 221 void WIMP_ReshowCursor(_THIS)
215 { 222 {
216 WMcursor *cursor = current_cursor; 223 defined_cursor = NULL;
217 current_cursor = NULL; 224 cursor_palette_saved = 0;
218 RISCOS_ShowWMCursor(this, cursor); 225 RISCOS_ShowWMCursor(this, current_cursor);
219 } 226 }
220
221 extern int mouseInWindow;
222 227
223 void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y) 228 void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
224 { 229 {
225 _kernel_swi_regs regs; 230 _kernel_swi_regs regs;
226 int window_state[9]; 231 int window_state[9];
247 } 252 }
248 253
249 int WIMP_ShowWMCursor(_THIS, WMcursor *cursor) 254 int WIMP_ShowWMCursor(_THIS, WMcursor *cursor)
250 { 255 {
251 if (mouseInWindow) return RISCOS_ShowWMCursor(this, cursor); 256 if (mouseInWindow) return RISCOS_ShowWMCursor(this, cursor);
257 else current_cursor = cursor;
258
252 return 1; 259 return 1;
253 } 260 }
254 261
255 SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode) 262 SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode)
256 { 263 {
297 _kernel_swi(OS_Word, &regs, &regs); 304 _kernel_swi(OS_Word, &regs, &regs);
298 } 305 }
299 306
300 return mode; 307 return mode;
301 } 308 }
309
310 /* Save mouse cursor palette to be restore when we are no longer
311 defining a cursor */
312
313 void WIMP_SaveCursorPalette()
314 {
315 _kernel_swi_regs regs;
316 int colour;
317
318 for (colour = 0; colour < 2; colour++)
319 {
320 regs.r[0] = (int)wimp_cursor_palette[colour][0];
321 regs.r[1] = 25;
322 /* Read settings with OS_ReadPalette */
323 if (_kernel_swi(0x2f, &regs, &regs) == NULL)
324 {
325 wimp_cursor_palette[colour][2] = (unsigned char)((regs.r[2] >> 8) & 0xFF);
326 wimp_cursor_palette[colour][3] = (unsigned char)((regs.r[2] >> 16) & 0xFF);
327 wimp_cursor_palette[colour][4] = (unsigned char)((regs.r[2] >> 24) & 0xFF);
328 }
329 }
330
331 cursor_palette_saved = 1;
332 }
333
334 /* Restore the WIMP's cursor when we leave the SDL window */
335 void WIMP_RestoreWimpCursor()
336 {
337 int colour;
338
339 /* Reset to pointer shape 1 */
340 _kernel_osbyte(106, 1, 0);
341
342 /* Reset pointer colours */
343 if (cursor_palette_saved)
344 {
345 for (colour = 0; colour < 2; colour++)
346 {
347 _kernel_osword(12, (int *)wimp_cursor_palette[colour]);
348 }
349 }
350 cursor_palette_saved = 0;
351 }
352
353 /* Set palette used for SDL mouse cursors */
354 void WIMP_SetSDLCursorPalette()
355 {
356 /* First time set up the mouse colours */
357 Uint8 block[5];
358
359 /* Set up colour 1 as white */
360 block[0] = 1; /* Colour to change 1 - 3 */
361 block[1] = 25; /* Set pointer colour */
362 block[2] = 255; /* red component*/
363 block[3] = 255; /* green component */
364 block[4] = 255; /* blue component*/
365 _kernel_osword(12, (int *)block);
366
367 /* Set colour 3 to back */
368 block[0] = 3; /* Colour to change 1 - 3 */
369 block[1] = 25; /* Set pointer colour*/
370 block[2] = 0; /* red component*/
371 block[3] = 0; /* green component */
372 block[4] = 0; /* blue component*/
373 _kernel_osword(12, (int *)block);
374 }