Skip to content

Commit

Permalink
riscos: Ensure the window size is consistent at different DPIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Phlamethrower committed May 26, 2019
1 parent dfd5168 commit e8f788c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 117 deletions.
10 changes: 5 additions & 5 deletions src/video/riscos/SDL_riscosevents.c
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/video/riscos/SDL_riscosmouse.c
Expand Up @@ -233,8 +233,8 @@ void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
regs.r[1] = (unsigned int)window_state;
_kernel_swi(Wimp_GetWindowState, &regs, &regs);

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;
Expand Down
88 changes: 15 additions & 73 deletions src/video/riscos/SDL_riscossprite.c
Expand Up @@ -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)
Expand Down Expand Up @@ -168,6 +165,20 @@ void WIMP_SetupPlotInfo(_THIS)
/* Actually read the buffer */
_kernel_swi(ColourTrans_GenerateTable, &regs, &regs);
}

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 */
Expand All @@ -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, &regs, &regs)) != 0)
Expand All @@ -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, &regs, &regs);

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, &regs, &regs);

/*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);
}
1 change: 1 addition & 0 deletions src/video/riscos/SDL_riscosvideo.h
Expand Up @@ -45,6 +45,7 @@ struct SDL_PrivateVideoData {
int screen_width;
int screen_height;
char *pixtrans;
int *scale;

/* Wimp variables */
unsigned int window_handle;
Expand Down
13 changes: 6 additions & 7 deletions src/video/riscos/SDL_wimppoll.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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, &regs, &regs);
break;
Expand Down Expand Up @@ -254,20 +252,21 @@ 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 */
SDL_PrivateQuit();
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;
Expand Down
43 changes: 13 additions & 30 deletions src/video/riscos/SDL_wimpvideo.c
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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, &regs, &regs);
}

/* Toggle to window from full screen */
int WIMP_ToggleFromFullScreen(_THIS)
{
Expand Down

0 comments on commit e8f788c

Please sign in to comment.