Modified screen display logic to always center image in the center of the window.

This commit is contained in:
Matthew Budd 2020-05-14 09:16:09 -04:00
parent f162600f54
commit 1ba5929ea2
2 changed files with 29 additions and 19 deletions

View File

@ -64,6 +64,8 @@ GtkRadioAction *stateSlot = NULL;
bool gtkIsStarted = false; bool gtkIsStarted = false;
bool menuTogglingEnabled = 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; static GtkTreeStore *hotkey_store = NULL;
// check to see if a particular GTK version is available // 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 xscale = width / (double) NES_WIDTH;
double yscale = height / (double) NES_HEIGHT; 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) // TODO check KeepRatio (where is this)
// do this to keep aspect ratio // do this to keep aspect ratio
if (xscale > yscale) 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) static gboolean draw_cb (GtkWidget * widget, cairo_t * cr, gpointer data)
{ {
guint width, height;
GdkRGBA color; GdkRGBA color;
GtkStyleContext *context; GtkStyleContext *context;
// Only clear the screen if a game is not loaded gtk_draw_area_width = gtk_widget_get_allocated_width (widget);
if (GameInfo == 0) gtk_draw_area_height = gtk_widget_get_allocated_height (widget);
{
context = gtk_widget_get_style_context (widget);
width = gtk_widget_get_allocated_width (widget); // Clear the screen on a window redraw
height = gtk_widget_get_allocated_height (widget); //if (GameInfo == 0)
//{
context = gtk_widget_get_style_context (widget);
color.red = 0, color.blue = 0; color.green = 0; color.alpha = 1.0; 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); gdk_cairo_set_source_rgba (cr, &color);
cairo_fill (cr); cairo_fill (cr);
cairo_paint (cr); cairo_paint (cr);
} //}
return FALSE; return FALSE;
} }

View File

@ -83,6 +83,8 @@ static int s_paletterefresh;
extern bool MaxSpeed; 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 * Attempts to destroy the graphical video display. Returns 0 on
* success, -1 on failure. * success, -1 on failure.
@ -181,13 +183,16 @@ InitVideo(FCEUGI *gi)
g_config->getOption("SDL.SpecialFilter", &s_sponge); g_config->getOption("SDL.SpecialFilter", &s_sponge);
g_config->getOption("SDL.XStretch", &xstretch); g_config->getOption("SDL.XStretch", &xstretch);
g_config->getOption("SDL.YStretch", &ystretch); g_config->getOption("SDL.YStretch", &ystretch);
g_config->getOption("SDL.LastXRes", &xres); //g_config->getOption("SDL.LastXRes", &xres);
g_config->getOption("SDL.LastYRes", &yres); //g_config->getOption("SDL.LastYRes", &yres);
g_config->getOption("SDL.ClipSides", &s_clipSides); g_config->getOption("SDL.ClipSides", &s_clipSides);
g_config->getOption("SDL.NoFrame", &noframe); g_config->getOption("SDL.NoFrame", &noframe);
g_config->getOption("SDL.ShowFPS", &show_fps); 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 // check the starting, ending, and total scan lines
FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline); FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline);
s_tlines = s_erendline - s_srendline + 1; s_tlines = s_erendline - s_srendline + 1;
@ -374,10 +379,10 @@ InitVideo(FCEUGI *gi)
} }
} }
int scrw = NWIDTH * s_exs; //int scrw = NWIDTH * s_exs;
if(s_sponge == 3) { //if(s_sponge == 3) {
scrw = 301 * s_exs; // scrw = 301 * s_exs;
} //}
#ifdef OPENGL #ifdef OPENGL
if(!s_useOpenGL) { if(!s_useOpenGL) {
@ -422,7 +427,8 @@ InitVideo(FCEUGI *gi)
} }
#endif #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); desbpp, flags);
if(!s_screen) { if(!s_screen) {
FCEUD_PrintError(SDL_GetError()); FCEUD_PrintError(SDL_GetError());
@ -666,14 +672,14 @@ BlitScreen(uint8 *XBuf)
dest = (uint8*)TmpScreen->pixels; 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); xo = (int)(((TmpScreen->w - NWIDTH * s_exs)) / 2);
dest += xo * (s_curbpp >> 3); dest += xo * (s_curbpp >> 3);
if(TmpScreen->h > (s_tlines * s_eys)) { if(TmpScreen->h > (s_tlines * s_eys)) {
yo = (int)((TmpScreen->h - s_tlines * s_eys) / 2); yo = (int)((TmpScreen->h - s_tlines * s_eys) / 2);
dest += yo * TmpScreen->pitch; dest += yo * TmpScreen->pitch;
} }
} //}
// XXX soules - again, I'm surprised SDL can't handle this // XXX soules - again, I'm surprised SDL can't handle this
// perform the blit, converting bpp if necessary // perform the blit, converting bpp if necessary