From e8f788c09d56c5d26204c8e3207dd31c7c0dc657 Mon Sep 17 00:00:00 2001 From: Jeffrey Lee Date: Sun, 26 May 2019 12:02:02 +0100 Subject: [PATCH] riscos: Ensure the window size is consistent at different DPIs --- src/video/riscos/SDL_riscosevents.c | 10 ++-- src/video/riscos/SDL_riscosmouse.c | 4 +- src/video/riscos/SDL_riscossprite.c | 88 +++++------------------------ src/video/riscos/SDL_riscosvideo.h | 1 + src/video/riscos/SDL_wimppoll.c | 13 ++--- src/video/riscos/SDL_wimpvideo.c | 43 +++++--------- 6 files changed, 42 insertions(+), 117 deletions(-) diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c index 9538a2b5f..ca5e637d4 100644 --- a/src/video/riscos/SDL_riscosevents.c +++ b/src/video/riscos/SDL_riscosevents.c @@ -295,13 +295,13 @@ void RISCOS_PollMouseHelper(_THIS, int fullscreen) topLeftY = window_state[4]; } - /* Convert co-ordinates to workspace */ - x = new_x - topLeftX; + /* Convert co-ordinates to workspace */ + x = new_x - topLeftX; y = topLeftY - new_y; /* Y goes from top of window/screen */ - /* Convert OS units to pixels */ - x >>= this->hidden->xeig; - y >>= this->hidden->yeig; + /* Convert OS units to pixels */ + x >>= 1; + y >>= 1; if (last_x != new_x || last_y != new_y) { diff --git a/src/video/riscos/SDL_riscosmouse.c b/src/video/riscos/SDL_riscosmouse.c index 90da7324c..5dba7b184 100644 --- a/src/video/riscos/SDL_riscosmouse.c +++ b/src/video/riscos/SDL_riscosmouse.c @@ -233,8 +233,8 @@ void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y) regs.r[1] = (unsigned int)window_state; _kernel_swi(Wimp_GetWindowState, ®s, ®s); - osX = (x << this->hidden->xeig) + window_state[1]; - osY = window_state[4] - (y << this->hidden->yeig); + osX = (x << 1) + window_state[1]; + osY = window_state[4] - (y << 1); block[0] = 3; block[1] = osX & 0xFF; diff --git a/src/video/riscos/SDL_riscossprite.c b/src/video/riscos/SDL_riscossprite.c index 70b2f919d..1a71520be 100644 --- a/src/video/riscos/SDL_riscossprite.c +++ b/src/video/riscos/SDL_riscossprite.c @@ -36,9 +36,6 @@ extern void WIMP_ReadModeInfo(_THIS); -void WIMP_PaletteChanged(_THIS); - - /* Create sprite buffer for screen */ unsigned char *WIMP_CreateBuffer(int width, int height, int bpp) @@ -168,6 +165,20 @@ void WIMP_SetupPlotInfo(_THIS) /* Actually read the buffer */ _kernel_swi(ColourTrans_GenerateTable, ®s, ®s); } + + if (this->hidden->scale) SDL_free(this->hidden->scale); + this->hidden->scale = 0; /* No scale factors i.e. 1:1 */ + + if (this->hidden->xeig != 1 || this->hidden->yeig != 1) { + int eig_mul[4] = { 2, 1, 1, 1 }; + int eig_div[4] = { 1, 1, 2, 4 }; + + this->hidden->scale = SDL_malloc(16); + this->hidden->scale[0] = eig_mul[this->hidden->xeig]; + this->hidden->scale[1] = eig_mul[this->hidden->yeig]; + this->hidden->scale[2] = eig_div[this->hidden->xeig]; + this->hidden->scale[3] = eig_div[this->hidden->yeig]; + } } /* Plot the sprite in the given context */ @@ -182,7 +193,7 @@ void WIMP_PlotSprite(_THIS, int x, int y) regs.r[3] = x; regs.r[4] = y; regs.r[5] = 0|32; /* Overwrite screen and pixtrans contains wide colour entries */ - regs.r[6] = 0; /* No scale factors i.e. 1:1 */ + regs.r[6] = (int)this->hidden->scale; regs.r[7] = (int)this->hidden->pixtrans; if ((err = _kernel_swi(OS_SpriteOp, ®s, ®s)) != 0) @@ -194,72 +205,3 @@ void WIMP_PlotSprite(_THIS, int x, int y) } } - -/* Wimp mode has changes so update colour mapping and pixel sizes - of windows and the sprites they plot */ - -void WIMP_ModeChanged(_THIS) -{ - int oldXeig = this->hidden->xeig; - int oldYeig = this->hidden->yeig; - - WIMP_ReadModeInfo(this); - - if (oldXeig == this->hidden->xeig && oldYeig == this->hidden->yeig) - { - /* Only need to update the palette */ - WIMP_PaletteChanged(this); - } else - { - _kernel_swi_regs regs; - int window_state[9]; - int extent[4]; - int currWidth, currHeight; - int newWidth, newHeight; - - /* Need to resize windows and update the palette */ - WIMP_SetupPlotInfo(this); - - - window_state[0] = this->hidden->window_handle; - regs.r[1] = (unsigned int)window_state; - _kernel_swi(Wimp_GetWindowState, ®s, ®s); - - currWidth = window_state[3] - window_state[1]; - currHeight = window_state[4] - window_state[2]; - - newWidth = (currWidth >> oldXeig) << this->hidden->xeig; - newHeight = (currHeight >> oldYeig) << this->hidden->yeig; - /* Need to avoid extent getting too small for visible part - of window */ - extent[0] = 0; - if (currHeight <= newHeight) - { - extent[1] = -newHeight; - } else - { - extent[1] = -currHeight; - } - if (currWidth <= newWidth) - { - extent[2] = newWidth; - } else - { - extent[2] = currWidth; - } - extent[3] = 0; - - regs.r[0] = this->hidden->window_handle; - regs.r[1] = (int)extent; - _kernel_swi(Wimp_SetExtent, ®s, ®s); - - /*TODO: May need to set flag to resize window on next open */ - } -} - -/* Palette has changed so update palettes used for windows sprites */ - -void WIMP_PaletteChanged(_THIS) -{ - WIMP_SetupPlotInfo(this); -} diff --git a/src/video/riscos/SDL_riscosvideo.h b/src/video/riscos/SDL_riscosvideo.h index 7c717ad66..a1afc40fc 100644 --- a/src/video/riscos/SDL_riscosvideo.h +++ b/src/video/riscos/SDL_riscosvideo.h @@ -45,6 +45,7 @@ struct SDL_PrivateVideoData { int screen_width; int screen_height; char *pixtrans; + int *scale; /* Wimp variables */ unsigned int window_handle; diff --git a/src/video/riscos/SDL_wimppoll.c b/src/video/riscos/SDL_wimppoll.c index 499966453..309806a0e 100644 --- a/src/video/riscos/SDL_wimppoll.c +++ b/src/video/riscos/SDL_wimppoll.c @@ -55,8 +55,6 @@ void WIMP_SetFocus(int win); /* SDL_riscossprite functions */ void WIMP_PlotSprite(_THIS, int x, int y); -void WIMP_ModeChanged(_THIS); -void WIMP_PaletteChanged(_THIS); extern void WIMP_PollMouse(_THIS); @@ -165,8 +163,8 @@ void WIMP_Poll(_THIS, int waitTime) { /* Ensure window is correct size */ resizeOnOpen = 0; - message[3] = message[1] + (this->screen->w << this->hidden->xeig); - message[4] = message[2] + (this->screen->h << this->hidden->yeig); + message[3] = message[1] + (this->screen->w << 1); + message[4] = message[2] + (this->screen->h << 1); } _kernel_swi(Wimp_OpenWindow, ®s, ®s); break; @@ -254,7 +252,7 @@ void WIMP_Poll(_THIS, int waitTime) case 0: /* Quit Event */ /* No choice - have to quit */ SDL_Quit(); - exit(0); + exit(0); break; case 8: /* Pre Quit */ @@ -262,12 +260,13 @@ void WIMP_Poll(_THIS, int waitTime) break; case 0x400c1: /* Mode change */ - WIMP_ModeChanged(this); + WIMP_ReadModeInfo(this); + WIMP_SetupPlotInfo(this); resizeOnOpen = 1; break; case 9: /* Palette changed */ - WIMP_PaletteChanged(this); + WIMP_SetupPlotInfo(this); break; } break; diff --git a/src/video/riscos/SDL_wimpvideo.c b/src/video/riscos/SDL_wimpvideo.c index d4191be1c..d28ff385e 100644 --- a/src/video/riscos/SDL_wimpvideo.c +++ b/src/video/riscos/SDL_wimpvideo.c @@ -249,19 +249,17 @@ unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface) _kernel_swi_regs regs; int window_data[23]; int *window_block = window_data+1; - int x = (this->hidden->screen_width - surface->w) / 2; - int y = (this->hidden->screen_height - surface->h) / 2; - int xeig = this->hidden->xeig; - int yeig = this->hidden->yeig; - + int x = ((this->hidden->screen_width << this->hidden->xeig) - (surface->w << 1)) / 2; + int y = ((this->hidden->screen_height << this->hidden->yeig) - (surface->h << 1)) / 2; + /* Always delete the window and recreate on a change */ if (this->hidden->window_handle) WIMP_DeleteWindow(this); /* Setup window co-ordinates */ - window_block[0] = x << xeig; - window_block[1] = y << yeig; - window_block[2] = window_block[0] + (surface->w << xeig); - window_block[3] = window_block[1] + (surface->h << yeig); + window_block[0] = x; + window_block[1] = y; + window_block[2] = window_block[0] + (surface->w << 1); + window_block[3] = window_block[1] + (surface->h << 1); window_block[4] = 0; /* Scroll offsets */ @@ -276,8 +274,8 @@ unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface) window_block[8] = 0xff070207; /* Window colours */ window_block[9] = 0x000c0103; window_block[10] = 0; /* Work area minimum */ - window_block[11] = -surface->h << yeig; - window_block[12] = surface->w << xeig; /* Work area maximum */ + window_block[11] = -surface->h << 1; + window_block[12] = surface->w << 1; /* Work area maximum */ window_block[13] = 0; window_block[14] = 0x2700013d; /* Title icon flags */ window_block[15] = 0x00003000; /* Work area flags - Mouse click down reported */ @@ -324,17 +322,15 @@ void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects) { _kernel_swi_regs regs; int update_block[12]; - int xeig = this->hidden->xeig; - int yeig = this->hidden->yeig; int j; update_block[0] = this->hidden->window_handle; for (j = 0; j < numrects; j++) { - update_block[1] = rects[j].x << xeig; /* Min X */ - update_block[4] = -(rects[j].y << yeig); - update_block[3] = update_block[1] + (rects[j].w << xeig); - update_block[2] = update_block[4] - (rects[j].h << yeig); + update_block[1] = rects[j].x << 1; /* Min X */ + update_block[4] = -(rects[j].y << 1); + update_block[3] = update_block[1] + (rects[j].w << 1); + update_block[2] = update_block[4] - (rects[j].h << 1); regs.r[1] = (int)update_block; /* Update window can fail if called before first poll */ @@ -419,19 +415,6 @@ void WIMP_SetWMCaption(_THIS, const char *title, const char *icon) } } -void WIMP_RefreshDesktop(_THIS) -{ - int width = this->hidden->screen_width << this->hidden->xeig; - int height = this->hidden->screen_height << this->hidden->yeig; - _kernel_swi_regs regs; - regs.r[0] = -1; /* Whole screen */ - regs.r[1] = 0; - regs.r[2] = 0; - regs.r[3] = width; - regs.r[4] = height; - _kernel_swi(Wimp_ForceRedraw, ®s, ®s); -} - /* Toggle to window from full screen */ int WIMP_ToggleFromFullScreen(_THIS) {