Perform resizing of SDL screen during redraw.

This commit is contained in:
Andrew Alderwick 2022-01-20 01:24:22 +00:00
parent cd0ca2eb17
commit d186b7a038
3 changed files with 9 additions and 12 deletions

View File

@ -132,12 +132,13 @@ void
screen_deo(Device *d, Uint8 port) screen_deo(Device *d, Uint8 port)
{ {
switch(port) { switch(port) {
case 0x3:
case 0x5: case 0x5:
if(!FIXED_SIZE) { if(!FIXED_SIZE) {
Uint16 w, h; Uint16 w, h;
DEVPEEK16(w, 0x2); DEVPEEK16(w, 0x2);
DEVPEEK16(h, 0x4); DEVPEEK16(h, 0x4);
set_size(w, h, 1); screen_resize(&uxn_screen, clamp(w, 1, 1024), clamp(h, 1, 1024));
} }
break; break;
case 0xe: { case 0xe: {

View File

@ -24,9 +24,6 @@ typedef struct UxnScreen {
extern UxnScreen uxn_screen; extern UxnScreen uxn_screen;
/* this should probably be done differently */
int set_size(Uint16 width, Uint16 height, int is_resize);
void screen_palette(UxnScreen *p, Uint8 *addr); void screen_palette(UxnScreen *p, Uint8 *addr);
void screen_resize(UxnScreen *p, Uint16 width, Uint16 height); void screen_resize(UxnScreen *p, Uint16 width, Uint16 height);
void screen_clear(UxnScreen *p, Layer *layer); void screen_clear(UxnScreen *p, Layer *layer);

View File

@ -100,14 +100,14 @@ set_window_size(SDL_Window *window, int w, int h)
SDL_Point win, win_old; SDL_Point win, win_old;
SDL_GetWindowPosition(window, &win.x, &win.y); SDL_GetWindowPosition(window, &win.x, &win.y);
SDL_GetWindowSize(window, &win_old.x, &win_old.y); SDL_GetWindowSize(window, &win_old.x, &win_old.y);
if(w == win_old.x && h == win_old.y) return;
SDL_SetWindowPosition(window, (win.x + win_old.x / 2) - w / 2, (win.y + win_old.y / 2) - h / 2); SDL_SetWindowPosition(window, (win.x + win_old.x / 2) - w / 2, (win.y + win_old.y / 2) - h / 2);
SDL_SetWindowSize(window, w, h); SDL_SetWindowSize(window, w, h);
} }
int int
set_size(Uint16 width, Uint16 height, int is_resize) set_size(void)
{ {
screen_resize(&uxn_screen, clamp(width, 1, 1024), clamp(height, 1, 1024));
gRect.x = PAD; gRect.x = PAD;
gRect.y = PAD; gRect.y = PAD;
gRect.w = uxn_screen.width; gRect.w = uxn_screen.width;
@ -119,14 +119,14 @@ set_size(Uint16 width, Uint16 height, int is_resize)
return error("gTexture", SDL_GetError()); return error("gTexture", SDL_GetError());
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0) if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0)
return error("SDL_UpdateTexture", SDL_GetError()); return error("SDL_UpdateTexture", SDL_GetError());
if(is_resize) set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom);
set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom);
return 1; return 1;
} }
static void static void
redraw(void) redraw(void)
{ {
if(gRect.w != uxn_screen.width || gRect.h != uxn_screen.height) set_size();
screen_redraw(&uxn_screen, uxn_screen.pixels); screen_redraw(&uxn_screen, uxn_screen.pixels);
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0) if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
error("SDL_UpdateTexture", SDL_GetError()); error("SDL_UpdateTexture", SDL_GetError());
@ -306,7 +306,7 @@ capture_screen(void)
static void static void
restart(Uxn *u) restart(Uxn *u)
{ {
set_size(WIDTH, HEIGHT, 1); screen_resize(&uxn_screen, WIDTH, HEIGHT);
start(u, "launcher.rom"); start(u, "launcher.rom");
} }
@ -391,7 +391,7 @@ run(Uxn *u)
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED) else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED)
redraw(); redraw();
else if(event.type == SDL_DROPFILE) { else if(event.type == SDL_DROPFILE) {
set_size(WIDTH, HEIGHT, 0); screen_resize(&uxn_screen, WIDTH, HEIGHT);
start(u, event.drop.file); start(u, event.drop.file);
SDL_free(event.drop.file); SDL_free(event.drop.file);
} }
@ -461,8 +461,7 @@ main(int argc, char **argv)
if(!init()) if(!init())
return error("Init", "Failed to initialize emulator."); return error("Init", "Failed to initialize emulator.");
if(!set_size(WIDTH, HEIGHT, 0)) screen_resize(&uxn_screen, WIDTH, HEIGHT);
return error("Window", "Failed to set window size.");
/* set default zoom */ /* set default zoom */
if(SDL_GetCurrentDisplayMode(0, &DM) == 0) if(SDL_GetCurrentDisplayMode(0, &DM) == 0)