riscos: Ensure the window size is consistent at different DPIs SDL-1.2
authorJeffrey Lee <me@phlamethrower.co.uk>
Sun, 26 May 2019 12:02:02 +0100
branchSDL-1.2
changeset 12782600cbd188a36
parent 12781 46ee0c51a81b
child 12783 de7c0427180c
riscos: Ensure the window size is consistent at different DPIs
src/video/riscos/SDL_riscosevents.c
src/video/riscos/SDL_riscosmouse.c
src/video/riscos/SDL_riscossprite.c
src/video/riscos/SDL_riscosvideo.h
src/video/riscos/SDL_wimppoll.c
src/video/riscos/SDL_wimpvideo.c
     1.1 --- a/src/video/riscos/SDL_riscosevents.c	Fri Apr 26 21:01:27 2019 +0100
     1.2 +++ b/src/video/riscos/SDL_riscosevents.c	Sun May 26 12:02:02 2019 +0100
     1.3 @@ -295,13 +295,13 @@
     1.4               topLeftY = window_state[4];
     1.5            }
     1.6  
     1.7 -		  /* Convert co-ordinates to workspace */
     1.8 -		  x = new_x - topLeftX;
     1.9 +          /* Convert co-ordinates to workspace */
    1.10 +          x = new_x - topLeftX;
    1.11            y = topLeftY - new_y; /* Y goes from top of window/screen */
    1.12  
    1.13 -	 	  /* Convert OS units to pixels */
    1.14 -	      x >>= this->hidden->xeig;
    1.15 -		  y >>= this->hidden->yeig;
    1.16 +          /* Convert OS units to pixels */
    1.17 +          x >>= 1;
    1.18 +          y >>= 1;
    1.19  
    1.20            if (last_x != new_x || last_y != new_y)
    1.21            {
     2.1 --- a/src/video/riscos/SDL_riscosmouse.c	Fri Apr 26 21:01:27 2019 +0100
     2.2 +++ b/src/video/riscos/SDL_riscosmouse.c	Sun May 26 12:02:02 2019 +0100
     2.3 @@ -233,8 +233,8 @@
     2.4  	regs.r[1] = (unsigned int)window_state;
     2.5  	_kernel_swi(Wimp_GetWindowState, &regs, &regs);
     2.6  
     2.7 -	 osX = (x << this->hidden->xeig) + window_state[1];
     2.8 -	 osY = window_state[4] - (y << this->hidden->yeig);
     2.9 +	 osX = (x << 1) + window_state[1];
    2.10 +	 osY = window_state[4] - (y << 1);
    2.11  
    2.12  	block[0] = 3;
    2.13  	block[1] = osX & 0xFF;
     3.1 --- a/src/video/riscos/SDL_riscossprite.c	Fri Apr 26 21:01:27 2019 +0100
     3.2 +++ b/src/video/riscos/SDL_riscossprite.c	Sun May 26 12:02:02 2019 +0100
     3.3 @@ -36,9 +36,6 @@
     3.4  
     3.5  extern void WIMP_ReadModeInfo(_THIS);
     3.6  
     3.7 -void WIMP_PaletteChanged(_THIS);
     3.8 -
     3.9 -
    3.10  /* Create sprite buffer for screen */
    3.11  
    3.12  unsigned char *WIMP_CreateBuffer(int width, int height, int bpp)
    3.13 @@ -168,6 +165,20 @@
    3.14        /* Actually read the buffer */
    3.15        _kernel_swi(ColourTrans_GenerateTable, &regs, &regs);
    3.16     }
    3.17 +
    3.18 +   if (this->hidden->scale) SDL_free(this->hidden->scale);
    3.19 +   this->hidden->scale = 0; /* No scale factors i.e. 1:1 */
    3.20 +
    3.21 +   if (this->hidden->xeig != 1 || this->hidden->yeig != 1) {
    3.22 +      int eig_mul[4] = { 2, 1, 1, 1 };
    3.23 +      int eig_div[4] = { 1, 1, 2, 4 };
    3.24 +
    3.25 +      this->hidden->scale = SDL_malloc(16);
    3.26 +      this->hidden->scale[0] = eig_mul[this->hidden->xeig];
    3.27 +      this->hidden->scale[1] = eig_mul[this->hidden->yeig];
    3.28 +      this->hidden->scale[2] = eig_div[this->hidden->xeig];
    3.29 +      this->hidden->scale[3] = eig_div[this->hidden->yeig];
    3.30 +   }
    3.31  }
    3.32  
    3.33  /* Plot the sprite in the given context */
    3.34 @@ -182,7 +193,7 @@
    3.35     regs.r[3] = x;
    3.36     regs.r[4] = y;
    3.37     regs.r[5] = 0|32; /* Overwrite screen and pixtrans contains wide colour entries */
    3.38 -   regs.r[6] = 0; /* No scale factors i.e. 1:1 */
    3.39 +   regs.r[6] = (int)this->hidden->scale;
    3.40     regs.r[7] = (int)this->hidden->pixtrans;
    3.41  
    3.42     if ((err = _kernel_swi(OS_SpriteOp, &regs, &regs)) != 0)
    3.43 @@ -194,72 +205,3 @@
    3.44     }
    3.45  }
    3.46  
    3.47 -
    3.48 -/* Wimp mode has changes so update colour mapping and pixel sizes 
    3.49 -   of windows and the sprites they plot */
    3.50 -
    3.51 -void WIMP_ModeChanged(_THIS)
    3.52 -{
    3.53 -	int oldXeig = this->hidden->xeig;
    3.54 -	int oldYeig = this->hidden->yeig;
    3.55 -
    3.56 -	WIMP_ReadModeInfo(this);
    3.57 -
    3.58 -	if (oldXeig == this->hidden->xeig && oldYeig == this->hidden->yeig)
    3.59 -	{
    3.60 -		/* Only need to update the palette */
    3.61 -		WIMP_PaletteChanged(this);
    3.62 -	} else
    3.63 -	{
    3.64 -		_kernel_swi_regs regs;
    3.65 -		int window_state[9];
    3.66 -		int extent[4];
    3.67 -		int currWidth, currHeight;
    3.68 -		int newWidth, newHeight;
    3.69 -		
    3.70 -		/* Need to resize windows and update the palette */
    3.71 -		WIMP_SetupPlotInfo(this);
    3.72 -
    3.73 -
    3.74 -		window_state[0] = this->hidden->window_handle;
    3.75 -		regs.r[1] = (unsigned int)window_state;
    3.76 -		_kernel_swi(Wimp_GetWindowState, &regs, &regs);
    3.77 -						
    3.78 -		currWidth = window_state[3] - window_state[1];
    3.79 -		currHeight = window_state[4] - window_state[2];
    3.80 -		
    3.81 -		newWidth = (currWidth >> oldXeig) << this->hidden->xeig;
    3.82 -		newHeight = (currHeight >> oldYeig) << this->hidden->yeig;
    3.83 -		/* Need to avoid extent getting too small for visible part
    3.84 -		of window */
    3.85 -		extent[0] = 0;
    3.86 -		if (currHeight <= newHeight)
    3.87 -		{
    3.88 -			extent[1] = -newHeight;
    3.89 -		} else
    3.90 -		{
    3.91 -			extent[1] = -currHeight;
    3.92 -		}
    3.93 -		if (currWidth <= newWidth)
    3.94 -		{
    3.95 -			extent[2] = newWidth;
    3.96 -		} else
    3.97 -		{
    3.98 -			extent[2] = currWidth;
    3.99 -		}
   3.100 -		extent[3] = 0;
   3.101 -		
   3.102 -		regs.r[0] = this->hidden->window_handle;
   3.103 -		regs.r[1] = (int)extent;
   3.104 -		_kernel_swi(Wimp_SetExtent, &regs, &regs);
   3.105 -
   3.106 -		/*TODO: May need to set flag to resize window on next open */
   3.107 -	}
   3.108 -}
   3.109 -
   3.110 -/* Palette has changed so update palettes used for windows sprites */
   3.111 -
   3.112 -void WIMP_PaletteChanged(_THIS)
   3.113 -{
   3.114 -	WIMP_SetupPlotInfo(this);
   3.115 -}
     4.1 --- a/src/video/riscos/SDL_riscosvideo.h	Fri Apr 26 21:01:27 2019 +0100
     4.2 +++ b/src/video/riscos/SDL_riscosvideo.h	Sun May 26 12:02:02 2019 +0100
     4.3 @@ -45,6 +45,7 @@
     4.4  	int screen_width;
     4.5  	int screen_height;
     4.6  	char *pixtrans;
     4.7 +	int *scale;
     4.8  
     4.9  	/* Wimp variables */
    4.10  	unsigned int window_handle;
     5.1 --- a/src/video/riscos/SDL_wimppoll.c	Fri Apr 26 21:01:27 2019 +0100
     5.2 +++ b/src/video/riscos/SDL_wimppoll.c	Sun May 26 12:02:02 2019 +0100
     5.3 @@ -55,8 +55,6 @@
     5.4  
     5.5  /* SDL_riscossprite functions */
     5.6  void WIMP_PlotSprite(_THIS, int x, int y);
     5.7 -void WIMP_ModeChanged(_THIS);
     5.8 -void WIMP_PaletteChanged(_THIS);
     5.9  
    5.10  
    5.11  extern void WIMP_PollMouse(_THIS);
    5.12 @@ -165,8 +163,8 @@
    5.13  		   {
    5.14  		      /* Ensure window is correct size */
    5.15  		      resizeOnOpen = 0;
    5.16 -		      message[3] = message[1] + (this->screen->w << this->hidden->xeig);
    5.17 -		      message[4] = message[2] + (this->screen->h << this->hidden->yeig);       
    5.18 +		      message[3] = message[1] + (this->screen->w << 1);
    5.19 +		      message[4] = message[2] + (this->screen->h << 1);       
    5.20  		   }
    5.21          	_kernel_swi(Wimp_OpenWindow, &regs, &regs);
    5.22         	    break;
    5.23 @@ -254,7 +252,7 @@
    5.24  			case 0: /* Quit Event */
    5.25  				/* No choice - have to quit */
    5.26  			   SDL_Quit();
    5.27 -        	   exit(0);
    5.28 +			   exit(0);
    5.29  			   break;
    5.30  
    5.31  			case 8: /* Pre Quit */
    5.32 @@ -262,12 +260,13 @@
    5.33  				break;
    5.34  
    5.35  			case 0x400c1: /* Mode change */
    5.36 -				WIMP_ModeChanged(this);
    5.37 +				WIMP_ReadModeInfo(this);
    5.38 +				WIMP_SetupPlotInfo(this);
    5.39  				resizeOnOpen = 1;
    5.40  				break;
    5.41  
    5.42  			case 9:      /* Palette changed */
    5.43 -				WIMP_PaletteChanged(this);
    5.44 +				WIMP_SetupPlotInfo(this);
    5.45  				break;
    5.46  			}
    5.47  			break;
     6.1 --- a/src/video/riscos/SDL_wimpvideo.c	Fri Apr 26 21:01:27 2019 +0100
     6.2 +++ b/src/video/riscos/SDL_wimpvideo.c	Sun May 26 12:02:02 2019 +0100
     6.3 @@ -249,19 +249,17 @@
     6.4  	_kernel_swi_regs regs;
     6.5  	int window_data[23];
     6.6      int	*window_block = window_data+1;
     6.7 -	int x = (this->hidden->screen_width - surface->w) / 2;
     6.8 -	int y = (this->hidden->screen_height - surface->h) / 2;
     6.9 -	int xeig = this->hidden->xeig;
    6.10 -	int yeig = this->hidden->yeig;
    6.11 -    
    6.12 +	int x = ((this->hidden->screen_width << this->hidden->xeig) - (surface->w << 1)) / 2;
    6.13 +	int y = ((this->hidden->screen_height << this->hidden->yeig) - (surface->h << 1)) / 2;    
    6.14 +
    6.15  	/* Always delete the window and recreate on a change */
    6.16  	if (this->hidden->window_handle) WIMP_DeleteWindow(this);
    6.17  
    6.18  	/* Setup window co-ordinates */
    6.19 -   window_block[0] = x << xeig;
    6.20 -   window_block[1] = y << yeig;
    6.21 -   window_block[2] = window_block[0] + (surface->w << xeig);
    6.22 -   window_block[3] = window_block[1] + (surface->h << yeig);
    6.23 +   window_block[0] = x;
    6.24 +   window_block[1] = y;
    6.25 +   window_block[2] = window_block[0] + (surface->w << 1);
    6.26 +   window_block[3] = window_block[1] + (surface->h << 1);
    6.27  
    6.28     
    6.29     window_block[4] = 0;				  /* Scroll offsets */
    6.30 @@ -276,8 +274,8 @@
    6.31     window_block[8] = 0xff070207;      /* Window colours */
    6.32     window_block[9] = 0x000c0103;
    6.33     window_block[10] = 0;                    /* Work area minimum */
    6.34 -   window_block[11] = -surface->h << yeig;
    6.35 -   window_block[12] = surface->w << xeig;   /* Work area maximum */
    6.36 +   window_block[11] = -surface->h << 1;
    6.37 +   window_block[12] = surface->w << 1;   /* Work area maximum */
    6.38     window_block[13] = 0;
    6.39     window_block[14] = 0x2700013d;    /* Title icon flags */
    6.40     window_block[15] = 0x00003000;	 /* Work area flags - Mouse click down reported */
    6.41 @@ -324,17 +322,15 @@
    6.42  {
    6.43  	_kernel_swi_regs regs;
    6.44  	int update_block[12];
    6.45 -	int xeig = this->hidden->xeig;
    6.46 -	int yeig = this->hidden->yeig;
    6.47  	int j;
    6.48  	update_block[0] = this->hidden->window_handle;
    6.49  
    6.50  	for (j = 0; j < numrects; j++)
    6.51  	{
    6.52 -		update_block[1] = rects[j].x << xeig; /* Min X */
    6.53 -		update_block[4] = -(rects[j].y << yeig);
    6.54 -		update_block[3] = update_block[1] + (rects[j].w << xeig);
    6.55 -		update_block[2] = update_block[4] - (rects[j].h << yeig);
    6.56 +		update_block[1] = rects[j].x << 1; /* Min X */
    6.57 +		update_block[4] = -(rects[j].y << 1);
    6.58 +		update_block[3] = update_block[1] + (rects[j].w << 1);
    6.59 +		update_block[2] = update_block[4] - (rects[j].h << 1);
    6.60  
    6.61  		regs.r[1] = (int)update_block;
    6.62  		/* Update window can fail if called before first poll */
    6.63 @@ -419,19 +415,6 @@
    6.64  	}
    6.65  }
    6.66  
    6.67 -void WIMP_RefreshDesktop(_THIS)
    6.68 -{
    6.69 -   int width = this->hidden->screen_width << this->hidden->xeig;
    6.70 -   int height = this->hidden->screen_height << this->hidden->yeig;
    6.71 -   _kernel_swi_regs regs;
    6.72 -   regs.r[0] = -1; /* Whole screen */
    6.73 -   regs.r[1] = 0;
    6.74 -   regs.r[2] = 0;
    6.75 -   regs.r[3] = width;
    6.76 -   regs.r[4] = height;
    6.77 -   _kernel_swi(Wimp_ForceRedraw, &regs, &regs);
    6.78 -}
    6.79 -
    6.80  /* Toggle to window from full screen */
    6.81  int WIMP_ToggleFromFullScreen(_THIS)
    6.82  {