From 6ca7a938ad99261dd44cf6696af79ae35c588817 Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Wed, 8 Jul 2020 08:28:38 +0200 Subject: [PATCH] VIDEO: Stretch frame buffer to accomodate output window. --- sim_video.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/sim_video.c b/sim_video.c index e8237b90..796f4f4e 100644 --- a/sim_video.c +++ b/sim_video.c @@ -1418,21 +1418,38 @@ else return SCPE_OK; } +static void vid_stretch(SDL_Rect *r) +{ +/* Return in r a rectangle with the same aspect ratio as the video + buffer but scaled to fit precisely in the output window. Normally, + the buffer and the window have the same sizes, but if the window is + resized, or fullscreen is in effect, they are not. */ +int w, h; +SDL_GetRendererOutputSize(vid_renderer, &w, &h); +if ((double)h / vid_height < (double)w / vid_width) { + r->w = vid_width * h / vid_height; + r->h = h; + r->x = (w - r->w) / 2; + r->y = 0; + } +else { + r->w = w; + r->h = vid_height * w / vid_width; + r->x = 0; + r->y = (h - r->h) / 2; + } +} + void vid_update (void) { SDL_Rect vid_dst; - -vid_dst.x = 0; -vid_dst.y = 0; -vid_dst.w = vid_width; -vid_dst.h = vid_height; - +vid_stretch(&vid_dst); sim_debug (SIM_VID_DBG_VIDEO, vid_dev, "Video Update Event: \n"); if (sim_deb) fflush (sim_deb); if (SDL_RenderClear (vid_renderer)) sim_printf ("%s: Video Update Event: SDL_RenderClear error: %s\n", vid_dname(vid_dev), SDL_GetError()); -if (SDL_RenderCopy (vid_renderer, vid_texture, NULL, NULL)) +if (SDL_RenderCopy (vid_renderer, vid_texture, NULL, &vid_dst)) sim_printf ("%s: Video Update Event: SDL_RenderCopy error: %s\n", vid_dname(vid_dev), SDL_GetError()); SDL_RenderPresent (vid_renderer); }