From: "alan buckley" <alan_baa@hotmail.com>
authorSam Lantinga <slouken@libsdl.org>
Fri, 23 Dec 2005 09:40:15 +0000
changeset 1208d90b362628ea
parent 1207 c9ec00d3e8bc
child 1209 a55ac374271c
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.
src/video/riscos/SDL_riscosFullScreenVideo.c
src/video/riscos/SDL_riscosmouse.c
src/video/riscos/SDL_riscosvideo.c
src/video/riscos/SDL_wimppoll.c
     1.1 --- a/src/video/riscos/SDL_riscosFullScreenVideo.c	Wed Dec 21 18:02:36 2005 +0000
     1.2 +++ b/src/video/riscos/SDL_riscosFullScreenVideo.c	Fri Dec 23 09:40:15 2005 +0000
     1.3 @@ -280,8 +280,6 @@
     1.4        } else
     1.5  	   this->UpdateRects = FULLSCREEN_UpdateRects; /* Default do nothing implementation */
     1.6  
     1.7 -	if (this->SetColors == FULLSCREEN_SetColors) return; /* Already set up */
     1.8 -
     1.9  	this->SetColors   = FULLSCREEN_SetColors;
    1.10  
    1.11  	this->FlipHWSurface = FULLSCREEN_FlipHWSurface;
    1.12 @@ -368,14 +366,15 @@
    1.13  {
    1.14     _kernel_swi_regs regs;
    1.15     regs.r[0] = 19;
    1.16 -   /* Wait for Vsync */
    1.17 -   _kernel_swi(OS_Byte, &regs, &regs);
    1.18  
    1.19     FULLSCREEN_SetDisplayBank(this->hidden->current_bank);
    1.20     this->hidden->current_bank ^= 1;
    1.21     FULLSCREEN_SetWriteBank(this->hidden->current_bank);
    1.22     surface->pixels = this->hidden->bank[this->hidden->current_bank];
    1.23  
    1.24 +   /* Wait for Vsync */
    1.25 +   _kernel_swi(OS_Byte, &regs, &regs);
    1.26 +
    1.27  	return(0);
    1.28  }
    1.29  
     2.1 --- a/src/video/riscos/SDL_riscosmouse.c	Wed Dec 21 18:02:36 2005 +0000
     2.2 +++ b/src/video/riscos/SDL_riscosmouse.c	Fri Dec 23 09:40:15 2005 +0000
     2.3 @@ -40,9 +40,24 @@
     2.4  #include "swis.h"
     2.5  
     2.6  static WMcursor *current_cursor = NULL;
     2.7 +static WMcursor *defined_cursor = NULL;
     2.8  
     2.9  extern int mouseInWindow;
    2.10  
    2.11 +/* Area to save cursor palette colours changed by SDL.
    2.12 +   Actual values will be read before we change to the SDL cursor */
    2.13 +static Uint8 wimp_cursor_palette[2][5] = {
    2.14 +  {1, 25, 255, 255, 255},
    2.15 +  {3, 25, 255, 255, 255}
    2.16 +};
    2.17 +
    2.18 +static int cursor_palette_saved = 0;
    2.19 +
    2.20 +void WIMP_SaveCursorPalette();
    2.21 +void WIMP_RestoreWimpCursor();
    2.22 +void WIMP_SetSDLCursorPalette();
    2.23 +
    2.24 +
    2.25  void RISCOS_FreeWMCursor(_THIS, WMcursor *cursor)
    2.26  {
    2.27      free(cursor->data);
    2.28 @@ -124,35 +139,17 @@
    2.29  
    2.30  int RISCOS_ShowWMCursor(_THIS, WMcursor *cursor)
    2.31  {
    2.32 +	current_cursor = cursor;
    2.33 +
    2.34  	if (cursor == NULL)
    2.35  	{
    2.36  		_kernel_osbyte(106,0,0);
    2.37 -		current_cursor = NULL;
    2.38 +		defined_cursor = NULL;
    2.39  	} else
    2.40  	{
    2.41 -		if (current_cursor == NULL)
    2.42 -		{
    2.43 -			/* First time set up the mouse colours */
    2.44 -			Uint8 block[5];
    2.45 +        WMcursor *old_cursor = defined_cursor;
    2.46  
    2.47 -			/* Set up colour 1 as white */
    2.48 -			block[0] = 1;   /* Colour to change 1 - 3 */
    2.49 -			block[1] = 25;  /* Set pointer colour */
    2.50 -			block[2] = 255; /* red component*/
    2.51 -			block[3] = 255; /* green component */
    2.52 -			block[4] = 255; /* blue component*/
    2.53 -			_kernel_osword(12, (int *)block);
    2.54 -		
    2.55 -			/* Set colour 3 to back */
    2.56 -			block[0] = 3;   /* Colour to change 1 - 3 */
    2.57 -			block[1] = 25;  /* Set pointer colour*/
    2.58 -			block[2] = 0; /* red component*/
    2.59 -			block[3] = 0; /* green component */
    2.60 -			block[4] = 0; /* blue component*/
    2.61 -			_kernel_osword(12, (int *)block);
    2.62 -		}
    2.63 -
    2.64 -		if (cursor != current_cursor)
    2.65 +		if (cursor != defined_cursor)
    2.66  		{
    2.67  			Uint8 cursor_def[10];
    2.68  
    2.69 @@ -167,15 +164,25 @@
    2.70  			cursor_def[8] = ((int)(cursor->data) >> 16) & 0xFF; /* ... */
    2.71  			cursor_def[9] = ((int)(cursor->data) >> 24) & 0xFF; /* Most significant byte of pointer to data */
    2.72  
    2.73 -			if (_kernel_osword(21, (int *)cursor_def) == 0)
    2.74 +			if (_kernel_osword(21, (int *)cursor_def) != 0)
    2.75  			{
    2.76  				SDL_SetError("RISCOS couldn't create the cursor to show");
    2.77  				return(0);
    2.78  			}
    2.79 -			current_cursor = cursor;
    2.80 +			defined_cursor = cursor;
    2.81  		}
    2.82  
    2.83 -		if ((this->screen->flags & SDL_FULLSCREEN) || mouseInWindow) _kernel_osbyte(106, 2, 0);
    2.84 +        if (old_cursor == NULL)
    2.85 +        {
    2.86 +            /* First time or reshow in window, so save/setup palette */
    2.87 +            if (!cursor_palette_saved)
    2.88 +            {
    2.89 +                WIMP_SaveCursorPalette();
    2.90 +            }
    2.91 +            WIMP_SetSDLCursorPalette();
    2.92 +        }
    2.93 +
    2.94 +        _kernel_osbyte(106, 2, 0);        
    2.95  	}
    2.96  	
    2.97  	return(1);
    2.98 @@ -213,13 +220,11 @@
    2.99  /* Reshow cursor when mouse re-enters the window */
   2.100  void WIMP_ReshowCursor(_THIS)
   2.101  {
   2.102 -	WMcursor *cursor = current_cursor;
   2.103 -	current_cursor = NULL;
   2.104 -	RISCOS_ShowWMCursor(this, cursor);
   2.105 +	defined_cursor = NULL;
   2.106 +    cursor_palette_saved = 0;
   2.107 +	RISCOS_ShowWMCursor(this, current_cursor);
   2.108  }
   2.109  
   2.110 -extern int mouseInWindow;
   2.111 -
   2.112  void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
   2.113  {
   2.114  	_kernel_swi_regs regs;
   2.115 @@ -249,6 +254,8 @@
   2.116  int WIMP_ShowWMCursor(_THIS, WMcursor *cursor)
   2.117  {
   2.118  	if (mouseInWindow) return RISCOS_ShowWMCursor(this, cursor);
   2.119 +	else current_cursor = cursor;
   2.120 +
   2.121  	return 1;
   2.122  }
   2.123  
   2.124 @@ -299,3 +306,69 @@
   2.125  
   2.126     return mode;
   2.127  }
   2.128 +
   2.129 +/* Save mouse cursor palette to be restore when we are no longer
   2.130 +   defining a cursor */
   2.131 +
   2.132 +void WIMP_SaveCursorPalette()
   2.133 +{
   2.134 +    _kernel_swi_regs regs;
   2.135 +    int colour;
   2.136 +
   2.137 +    for (colour = 0; colour < 2; colour++)
   2.138 +    {
   2.139 +      regs.r[0] = (int)wimp_cursor_palette[colour][0];
   2.140 +      regs.r[1] = 25;
   2.141 +      /* Read settings with OS_ReadPalette */
   2.142 +      if (_kernel_swi(0x2f, &regs, &regs) == NULL)
   2.143 +      {
   2.144 +        wimp_cursor_palette[colour][2] = (unsigned char)((regs.r[2] >> 8) & 0xFF);
   2.145 +        wimp_cursor_palette[colour][3] = (unsigned char)((regs.r[2] >> 16) & 0xFF);
   2.146 +        wimp_cursor_palette[colour][4] = (unsigned char)((regs.r[2] >> 24) & 0xFF);
   2.147 +      }
   2.148 +    }
   2.149 +
   2.150 +    cursor_palette_saved = 1;
   2.151 +}
   2.152 +
   2.153 +/* Restore the WIMP's cursor when we leave the SDL window */
   2.154 +void WIMP_RestoreWimpCursor()
   2.155 +{
   2.156 +    int colour;
   2.157 +
   2.158 +    /* Reset to pointer shape 1 */
   2.159 +    _kernel_osbyte(106, 1, 0);
   2.160 +
   2.161 +    /* Reset pointer colours */
   2.162 +    if (cursor_palette_saved)
   2.163 +    {
   2.164 +      for (colour = 0; colour < 2; colour++)
   2.165 +      {
   2.166 +        _kernel_osword(12, (int *)wimp_cursor_palette[colour]);
   2.167 +      }
   2.168 +    }
   2.169 +    cursor_palette_saved = 0;
   2.170 +}
   2.171 +
   2.172 +/* Set palette used for SDL mouse cursors */
   2.173 +void WIMP_SetSDLCursorPalette()
   2.174 +{
   2.175 +  /* First time set up the mouse colours */
   2.176 +  Uint8 block[5];
   2.177 +
   2.178 +  /* Set up colour 1 as white */
   2.179 +  block[0] = 1;   /* Colour to change 1 - 3 */
   2.180 +  block[1] = 25;  /* Set pointer colour */
   2.181 +  block[2] = 255; /* red component*/
   2.182 +  block[3] = 255; /* green component */
   2.183 +  block[4] = 255; /* blue component*/
   2.184 + _kernel_osword(12, (int *)block);
   2.185 +		
   2.186 + /* Set colour 3 to back */
   2.187 + block[0] = 3;   /* Colour to change 1 - 3 */
   2.188 + block[1] = 25;  /* Set pointer colour*/
   2.189 + block[2] = 0; /* red component*/
   2.190 + block[3] = 0; /* green component */
   2.191 + block[4] = 0; /* blue component*/
   2.192 + _kernel_osword(12, (int *)block);
   2.193 +}
     3.1 --- a/src/video/riscos/SDL_riscosvideo.c	Wed Dec 21 18:02:36 2005 +0000
     3.2 +++ b/src/video/riscos/SDL_riscosvideo.c	Fri Dec 23 09:40:15 2005 +0000
     3.3 @@ -150,6 +150,11 @@
     3.4  	/* Set other entries for fullscreen mode */
     3.5  	FULLSCREEN_SetDeviceMode(device);
     3.6  
     3.7 +	/* Mouse pointer needs to use the WIMP ShowCursor version so
     3.8 +	   that it doesn't modify the pointer until the SDL Window is
     3.9 +	   entered or the application goes full screen */
    3.10 +	device->ShowWMCursor = WIMP_ShowWMCursor;
    3.11 +
    3.12  	return device;
    3.13  }
    3.14  
     4.1 --- a/src/video/riscos/SDL_wimppoll.c	Wed Dec 21 18:02:36 2005 +0000
     4.2 +++ b/src/video/riscos/SDL_wimppoll.c	Fri Dec 23 09:40:15 2005 +0000
     4.3 @@ -71,6 +71,7 @@
     4.4  
     4.5  /* Mouse cursor handling */
     4.6  extern void WIMP_ReshowCursor(_THIS);
     4.7 +extern void WIMP_RestoreWimpCursor();
     4.8  
     4.9  int hasFocus = 0;
    4.10  int mouseInWindow = 0;
    4.11 @@ -191,10 +192,7 @@
    4.12  				mouseInWindow = 0;
    4.13  				//TODO: Lose buttons / dragging
    4.14  				 /* Reset to default pointer */
    4.15 -   				 regs.r[0] = 106;
    4.16 -				 regs.r[1] = 1;
    4.17 -				 regs.r[2] = 0;
    4.18 -				 _kernel_swi(OS_Byte, &regs, &regs);
    4.19 +				 WIMP_RestoreWimpCursor();
    4.20  				 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
    4.21  			} else
    4.22  				sysEvent = 1;