From 1ba5929ea26e33d5e1547035f030cf175d64e01f Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Thu, 14 May 2020 09:16:09 -0400 Subject: [PATCH] Modified screen display logic to always center image in the center of the window. --- src/drivers/sdl/gui.cpp | 22 +++++++++++++--------- src/drivers/sdl/sdl-video.cpp | 26 ++++++++++++++++---------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index b7ecf013..43a88ec5 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -64,6 +64,8 @@ GtkRadioAction *stateSlot = NULL; bool gtkIsStarted = false; bool menuTogglingEnabled = false; +unsigned int gtk_draw_area_width = NES_WIDTH; +unsigned int gtk_draw_area_height = NES_HEIGHT; static GtkTreeStore *hotkey_store = NULL; // check to see if a particular GTK version is available @@ -3020,6 +3022,9 @@ gboolean handle_resize (GtkWindow * win, GdkEvent * event, gpointer data) double xscale = width / (double) NES_WIDTH; double yscale = height / (double) NES_HEIGHT; + gtk_draw_area_width = gtk_widget_get_allocated_width (evbox); + gtk_draw_area_height = gtk_widget_get_allocated_height (evbox); + // TODO check KeepRatio (where is this) // do this to keep aspect ratio if (xscale > yscale) @@ -3051,26 +3056,25 @@ gboolean handle_resize (GtkWindow * win, GdkEvent * event, gpointer data) */ static gboolean draw_cb (GtkWidget * widget, cairo_t * cr, gpointer data) { - guint width, height; GdkRGBA color; GtkStyleContext *context; - // Only clear the screen if a game is not loaded - if (GameInfo == 0) - { - context = gtk_widget_get_style_context (widget); + gtk_draw_area_width = gtk_widget_get_allocated_width (widget); + gtk_draw_area_height = gtk_widget_get_allocated_height (widget); - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_height (widget); + // Clear the screen on a window redraw + //if (GameInfo == 0) + //{ + context = gtk_widget_get_style_context (widget); color.red = 0, color.blue = 0; color.green = 0; color.alpha = 1.0; - gtk_render_background( context, cr, 0, 0, width, height ); + gtk_render_background( context, cr, 0, 0, gtk_draw_area_width, gtk_draw_area_height ); gdk_cairo_set_source_rgba (cr, &color); cairo_fill (cr); cairo_paint (cr); - } + //} return FALSE; } diff --git a/src/drivers/sdl/sdl-video.cpp b/src/drivers/sdl/sdl-video.cpp index d26b6df9..4c24883d 100644 --- a/src/drivers/sdl/sdl-video.cpp +++ b/src/drivers/sdl/sdl-video.cpp @@ -83,6 +83,8 @@ static int s_paletterefresh; extern bool MaxSpeed; +extern unsigned int gtk_draw_area_width; +extern unsigned int gtk_draw_area_height; /** * Attempts to destroy the graphical video display. Returns 0 on * success, -1 on failure. @@ -181,13 +183,16 @@ InitVideo(FCEUGI *gi) g_config->getOption("SDL.SpecialFilter", &s_sponge); g_config->getOption("SDL.XStretch", &xstretch); g_config->getOption("SDL.YStretch", &ystretch); - g_config->getOption("SDL.LastXRes", &xres); - g_config->getOption("SDL.LastYRes", &yres); + //g_config->getOption("SDL.LastXRes", &xres); + //g_config->getOption("SDL.LastYRes", &yres); g_config->getOption("SDL.ClipSides", &s_clipSides); g_config->getOption("SDL.NoFrame", &noframe); g_config->getOption("SDL.ShowFPS", &show_fps); + xres = gtk_draw_area_width; + yres = gtk_draw_area_height; // check the starting, ending, and total scan lines + FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline); s_tlines = s_erendline - s_srendline + 1; @@ -374,10 +379,10 @@ InitVideo(FCEUGI *gi) } } - int scrw = NWIDTH * s_exs; - if(s_sponge == 3) { - scrw = 301 * s_exs; - } + //int scrw = NWIDTH * s_exs; + //if(s_sponge == 3) { + // scrw = 301 * s_exs; + //} #ifdef OPENGL if(!s_useOpenGL) { @@ -422,7 +427,8 @@ InitVideo(FCEUGI *gi) } #endif - s_screen = SDL_SetVideoMode(scrw, (int)(s_tlines * s_eys), + //s_screen = SDL_SetVideoMode(scrw, (int)(s_tlines * s_eys), + s_screen = SDL_SetVideoMode( xres, yres, desbpp, flags); if(!s_screen) { FCEUD_PrintError(SDL_GetError()); @@ -540,7 +546,7 @@ void ToggleFS() if(noGui == 0) { if(!fullscreen) - showGui(0); + showGui(0); else showGui(1); } @@ -666,14 +672,14 @@ BlitScreen(uint8 *XBuf) dest = (uint8*)TmpScreen->pixels; - if(s_fullscreen) { + //if(s_fullscreen) { // Always do this calculation now. Screen resolution is always provided. xo = (int)(((TmpScreen->w - NWIDTH * s_exs)) / 2); dest += xo * (s_curbpp >> 3); if(TmpScreen->h > (s_tlines * s_eys)) { yo = (int)((TmpScreen->h - s_tlines * s_eys) / 2); dest += yo * TmpScreen->pitch; } - } + //} // XXX soules - again, I'm surprised SDL can't handle this // perform the blit, converting bpp if necessary