From 9c4b03c3271498f7a35aefa2280eb21fa2642983 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sat, 9 Oct 2021 21:03:55 -0400 Subject: [PATCH] Modified Qt main viewport logic so that side panel coloring so that changes via the color picker dialog are seen immediately. Previous behavior is it would only show change upon accepting new color in dialog. Choosing cancel in dialog will return color to original state. --- src/drivers/Qt/ConsoleViewerGL.cpp | 29 +++++++++++++++++++++++---- src/drivers/Qt/ConsoleViewerGL.h | 2 +- src/drivers/Qt/ConsoleViewerSDL.cpp | 31 ++++++++++++++++++++++++----- src/drivers/Qt/ConsoleViewerSDL.h | 2 +- src/drivers/Qt/ConsoleWindow.h | 2 ++ 5 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/drivers/Qt/ConsoleViewerGL.cpp b/src/drivers/Qt/ConsoleViewerGL.cpp index 4347e322..a99f9b59 100644 --- a/src/drivers/Qt/ConsoleViewerGL.cpp +++ b/src/drivers/Qt/ConsoleViewerGL.cpp @@ -42,6 +42,7 @@ #include "Qt/fceuWrapper.h" #include "Qt/ConsoleViewerGL.h" #include "Qt/ConsoleUtilities.h" +#include "Qt/ConsoleWindow.h" extern unsigned int gui_draw_area_width; extern unsigned int gui_draw_area_height; @@ -49,6 +50,8 @@ extern unsigned int gui_draw_area_height; ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent) : QOpenGLWidget( parent ) { + consoleWin_t *win = qobject_cast (parent); + view_width = 256; view_height = 224; gltexture = 0; @@ -71,8 +74,13 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent) textureType = GL_TEXTURE_2D; //textureType = GL_TEXTURE_RECTANGLE; - bgColor.setRgb( 0, 0, 0 ); + bgColor = NULL; + if ( win ) + { + bgColor = win->getVideoBgColorPtr(); + bgColor->setRgb( 0, 0, 0 ); + } setMinimumWidth( 256 ); setMinimumHeight( 224 ); setFocusPolicy(Qt::StrongFocus); @@ -104,7 +112,10 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent) g_config->getOption ("SDL.ForceAspect", &forceAspect); - fceuLoadConfigColor( "SDL.VideoBgColor", &bgColor ); + if ( bgColor ) + { + fceuLoadConfigColor( "SDL.VideoBgColor", bgColor ); + } } connect( this, SIGNAL(frameSwapped(void)), this, SLOT(renderFinished(void)) ); @@ -370,7 +381,10 @@ void ConsoleViewGL_t::resizeGL(int w, int h) void ConsoleViewGL_t::setBgColor( QColor &c ) { - bgColor = c; + if ( bgColor ) + { + *bgColor = c; + } } void ConsoleViewGL_t::setLinearFilterEnable( bool ena ) @@ -608,7 +622,14 @@ void ConsoleViewGL_t::paintGL(void) glOrtho( 0.0, rw, 0.0, rh, -1.0, 1.0); glDisable(GL_DEPTH_TEST); - glClearColor( bgColor.redF(), bgColor.greenF(), bgColor.blueF(), 1.0f); // Background color to config value. + if ( bgColor ) + { + glClearColor( bgColor->redF(), bgColor->greenF(), bgColor->blueF(), 1.0f); // Background color to config value. + } + else + { + glClearColor( 0.0, 0.0, 0.0, 1.0f); // Background color to config value. + } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/src/drivers/Qt/ConsoleViewerGL.h b/src/drivers/Qt/ConsoleViewerGL.h index b8919af4..49b12b2d 100644 --- a/src/drivers/Qt/ConsoleViewerGL.h +++ b/src/drivers/Qt/ConsoleViewerGL.h @@ -76,7 +76,7 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions unsigned int textureType; unsigned int mouseButtonMask; - QColor bgColor; + QColor *bgColor; uint32_t *localBuf; uint32_t localBufSize; diff --git a/src/drivers/Qt/ConsoleViewerSDL.cpp b/src/drivers/Qt/ConsoleViewerSDL.cpp index 236aec32..443f5781 100644 --- a/src/drivers/Qt/ConsoleViewerSDL.cpp +++ b/src/drivers/Qt/ConsoleViewerSDL.cpp @@ -30,6 +30,7 @@ #include "Qt/fceuWrapper.h" #include "Qt/ConsoleViewerSDL.h" #include "Qt/ConsoleUtilities.h" +#include "Qt/ConsoleWindow.h" extern unsigned int gui_draw_area_width; extern unsigned int gui_draw_area_height; @@ -37,13 +38,21 @@ extern unsigned int gui_draw_area_height; ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent) : QWidget( parent ) { + consoleWin_t *win = qobject_cast (parent); + QPalette pal = palette(); pal.setColor(QPalette::Window, Qt::black); setAutoFillBackground(true); setPalette(pal); - bgColor.setRgb( 0, 0, 0 ); + bgColor = NULL; + + if ( win ) + { + bgColor = win->getVideoBgColorPtr(); + bgColor->setRgb( 0, 0, 0 ); + } setMinimumWidth( 256 ); setMinimumHeight( 224 ); @@ -103,7 +112,10 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent) g_config->getOption ("SDL.ForceAspect", &forceAspect); - fceuLoadConfigColor( "SDL.VideoBgColor", &bgColor ); + if ( bgColor ) + { + fceuLoadConfigColor( "SDL.VideoBgColor", bgColor ); + } } } @@ -128,7 +140,10 @@ ConsoleViewSDL_t::~ConsoleViewSDL_t(void) void ConsoleViewSDL_t::setBgColor( QColor &c ) { - bgColor = c; + if ( bgColor ) + { + *bgColor = c; + } } void ConsoleViewSDL_t::setLinearFilterEnable( bool ena ) @@ -643,8 +658,14 @@ void ConsoleViewSDL_t::render(void) return; } - SDL_SetRenderDrawColor( sdlRenderer, bgColor.red(), bgColor.green(), bgColor.blue(), 255 ); - + if ( bgColor ) + { + SDL_SetRenderDrawColor( sdlRenderer, bgColor->red(), bgColor->green(), bgColor->blue(), 255 ); + } + else + { + SDL_SetRenderDrawColor( sdlRenderer, 0, 0, 0, 255 ); + } SDL_RenderClear(sdlRenderer); uint8_t *textureBuffer; diff --git a/src/drivers/Qt/ConsoleViewerSDL.h b/src/drivers/Qt/ConsoleViewerSDL.h index 905e9a7c..342eba3e 100644 --- a/src/drivers/Qt/ConsoleViewerSDL.h +++ b/src/drivers/Qt/ConsoleViewerSDL.h @@ -71,7 +71,7 @@ class ConsoleViewSDL_t : public QWidget bool linearFilter; bool forceAspect; bool autoScaleEna; - QColor bgColor; + QColor *bgColor; uint32_t *localBuf; uint32_t localBufSize; diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 8bbe3391..62a8cd70 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -177,6 +177,8 @@ class consoleWin_t : public QMainWindow int getPeriodicInterval(void); + QColor *getVideoBgColorPtr(void){ return &videoBgColor; } + protected: consoleMenuBar *menubar;