From 451b0f84745bf6974b9ed4d0534d53225aa0281b Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 21 Mar 2021 07:17:01 -0400 Subject: [PATCH 1/7] For Qt GUI, change square pixel video option to be a force aspect ratio option and added a small list of preselect aspect options via video config window. Aspect ratio is now a configuration parameter for the video viewport. This addresses most of issue #341. Still TODO add custom aspect entry capability. --- src/drivers/Qt/ConsoleVideoConf.cpp | 79 ++++++++++++++++++++++------- src/drivers/Qt/ConsoleVideoConf.h | 7 ++- src/drivers/Qt/ConsoleViewerGL.cpp | 32 ++++++++++-- src/drivers/Qt/ConsoleViewerGL.h | 18 ++++--- src/drivers/Qt/ConsoleViewerSDL.cpp | 33 ++++++++++-- src/drivers/Qt/ConsoleViewerSDL.h | 14 +++-- src/drivers/Qt/ConsoleWindow.cpp | 57 ++++++++++++++++++--- src/drivers/Qt/ConsoleWindow.h | 2 + src/drivers/Qt/config.cpp | 5 +- 9 files changed, 205 insertions(+), 42 deletions(-) diff --git a/src/drivers/Qt/ConsoleVideoConf.cpp b/src/drivers/Qt/ConsoleVideoConf.cpp index 37e8a119..151c28d8 100644 --- a/src/drivers/Qt/ConsoleVideoConf.cpp +++ b/src/drivers/Qt/ConsoleVideoConf.cpp @@ -161,8 +161,8 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) // Auto Scale on Resize autoScaleCbx = new QCheckBox( tr("Auto Scale on Resize") ); - // Square Pixels - sqrPixCbx = new QCheckBox( tr("Square Pixels") ); + // Force Aspect Ratio + aspectCbx = new QCheckBox( tr("Force Aspect Ratio") ); setCheckBoxFromProperty( autoRegion , "SDL.AutoDetectPAL"); setCheckBoxFromProperty( new_PPU_ena , "SDL.NewPPU"); @@ -176,12 +176,12 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) if ( consoleWindow->viewport_GL ) { autoScaleCbx->setChecked( consoleWindow->viewport_GL->getAutoScaleOpt() ); - sqrPixCbx->setChecked( consoleWindow->viewport_GL->getSqrPixelOpt() ); + aspectCbx->setChecked( consoleWindow->viewport_GL->getForceAspectOpt() ); } else if ( consoleWindow->viewport_SDL ) { autoScaleCbx->setChecked( consoleWindow->viewport_SDL->getAutoScaleOpt() ); - sqrPixCbx->setChecked( consoleWindow->viewport_SDL->getSqrPixelOpt() ); + aspectCbx->setChecked( consoleWindow->viewport_SDL->getForceAspectOpt() ); } } @@ -191,7 +191,7 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) connect(sprtLimCbx , SIGNAL(stateChanged(int)), this, SLOT(useSpriteLimitChanged(int)) ); connect(clipSidesCbx, SIGNAL(stateChanged(int)), this, SLOT(clipSidesChanged(int)) ); connect(showFPS_cbx , SIGNAL(stateChanged(int)), this, SLOT(showFPSChanged(int)) ); - connect(sqrPixCbx , SIGNAL(stateChanged(int)), this, SLOT(sqrPixChanged(int)) ); + connect(aspectCbx , SIGNAL(stateChanged(int)), this, SLOT(aspectEnableChanged(int)) ); connect(autoScaleCbx, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)) ); vbox1->addWidget( autoRegion ); @@ -201,7 +201,27 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) //vbox1->addWidget( clipSidesCbx); vbox1->addWidget( showFPS_cbx ); vbox1->addWidget( autoScaleCbx); - vbox1->addWidget( sqrPixCbx ); + vbox1->addWidget( aspectCbx ); + + aspectSelect = new QComboBox(); + + aspectSelect->addItem( tr("Default (1:1)"), 0 ); + aspectSelect->addItem( tr("NTSC (8:7)"), 1 ); + aspectSelect->addItem( tr("PAL (11:8)"), 2 ); + aspectSelect->addItem( tr("Standard (4:3)"), 3 ); + aspectSelect->addItem( tr("Widescreen (16:9)"), 4 ); + //aspectSelect->addItem( tr("Custom"), 5 ); TODO + + setComboBoxFromProperty( aspectSelect, "SDL.AspectSelect"); + + connect(aspectSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(aspectChanged(int)) ); + + aspectSelectLabel = new QLabel( tr("Aspect:") ); + + hbox1 = new QHBoxLayout(); + hbox1->addWidget( aspectSelectLabel ); + hbox1->addWidget( aspectSelect ); + vbox1->addLayout( hbox1 ); xScaleBox = new QDoubleSpinBox(this); yScaleBox = new QDoubleSpinBox(this); @@ -226,7 +246,7 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) } } - if ( sqrPixCbx->isChecked() ) + if ( aspectCbx->isChecked() ) { xScaleLabel = new QLabel( tr("Scale:") ); } @@ -246,11 +266,16 @@ ConsoleVideoConfDialog_t::ConsoleVideoConfDialog_t(QWidget *parent) hbox1->addWidget( yScaleBox ); vbox1->addLayout( hbox1 ); - if ( sqrPixCbx->isChecked() ) + if ( aspectCbx->isChecked() ) { yScaleLabel->hide(); yScaleBox->hide(); } + else + { + aspectSelectLabel->hide(); + aspectSelect->hide(); + } hbox1 = new QHBoxLayout(); @@ -684,22 +709,28 @@ void ConsoleVideoConfDialog_t::showFPSChanged( int value ) fceuWrapperUnLock(); } //---------------------------------------------------- -void ConsoleVideoConfDialog_t::sqrPixChanged( int value ) +void ConsoleVideoConfDialog_t::aspectEnableChanged( int value ) { //printf("Value:%i \n", value ); - int useSqrPix = (value != Qt::Unchecked); + int forceAspect = (value != Qt::Unchecked); - if ( useSqrPix ) + if ( forceAspect ) { xScaleLabel->setText( tr("Scale:") ); yScaleLabel->hide(); yScaleBox->hide(); + + aspectSelectLabel->show(); + aspectSelect->show(); } else { xScaleLabel->setText( tr("X Scale:") ); yScaleLabel->show(); yScaleBox->show(); + + aspectSelectLabel->hide(); + aspectSelect->hide(); } } @@ -750,6 +781,18 @@ void ConsoleVideoConfDialog_t::regionChanged(int index) } } //---------------------------------------------------- +void ConsoleVideoConfDialog_t::aspectChanged(int index) +{ + int aspectID; + + aspectID = aspectSelect->itemData(index).toInt(); + + g_config->setOption ("SDL.AspectSelect", aspectID); + g_config->save (); + + consoleWindow->setViewportAspect(); +} +//---------------------------------------------------- void ConsoleVideoConfDialog_t::cursorShapeChanged(int index) { int cursorSel; @@ -784,7 +827,7 @@ QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void) if ( consoleWindow ) { QSize w, v; - double xscale, yscale; + double xscale = 1.0, yscale = 1.0, aspectRatio = 1.0; int texture_width = nes_shm->video.ncol; int texture_height = nes_shm->video.nrow; int l=0, r=texture_width; @@ -796,20 +839,22 @@ QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void) if ( consoleWindow->viewport_GL ) { v = consoleWindow->viewport_GL->size(); + aspectRatio = consoleWindow->viewport_GL->getAspectRatio(); } else if ( consoleWindow->viewport_SDL ) { v = consoleWindow->viewport_SDL->size(); + aspectRatio = consoleWindow->viewport_SDL->getAspectRatio(); } dw = w.width() - v.width(); dh = w.height() - v.height(); - if ( sqrPixCbx->isChecked() ) + if ( aspectCbx->isChecked() ) { xscale = xScaleBox->value(); - yscale = xscale * (double)nes_shm->video.xyRatio; + yscale = xscale * aspectRatio * (double)nes_shm->video.xyRatio; } else { @@ -834,7 +879,7 @@ void ConsoleVideoConfDialog_t::applyChanges( void ) float xscale, yscale; QSize s = calcNewScreenSize(); - if ( sqrPixCbx->isChecked() ) + if ( aspectCbx->isChecked() ) { yscale = xscale = xScaleBox->value(); } @@ -846,13 +891,13 @@ void ConsoleVideoConfDialog_t::applyChanges( void ) if ( consoleWindow->viewport_GL ) { - consoleWindow->viewport_GL->setSqrPixelOpt( sqrPixCbx->isChecked() ); + consoleWindow->viewport_GL->setForceAspectOpt( aspectCbx->isChecked() ); consoleWindow->viewport_GL->setAutoScaleOpt( autoScaleCbx->isChecked() ); consoleWindow->viewport_GL->setScaleXY( xscale, yscale ); } if ( consoleWindow->viewport_SDL ) { - consoleWindow->viewport_SDL->setSqrPixelOpt( sqrPixCbx->isChecked() ); + consoleWindow->viewport_SDL->setForceAspectOpt( aspectCbx->isChecked() ); consoleWindow->viewport_SDL->setAutoScaleOpt( autoScaleCbx->isChecked() ); consoleWindow->viewport_SDL->setScaleXY( xscale, yscale ); } diff --git a/src/drivers/Qt/ConsoleVideoConf.h b/src/drivers/Qt/ConsoleVideoConf.h index 1dcd078b..f164702d 100644 --- a/src/drivers/Qt/ConsoleVideoConf.h +++ b/src/drivers/Qt/ConsoleVideoConf.h @@ -34,6 +34,7 @@ class ConsoleVideoConfDialog_t : public QDialog QComboBox *scalerSelect; QComboBox *regionSelect; QComboBox *cursorSelect; + QComboBox *aspectSelect; QCheckBox *autoRegion; QCheckBox *gl_LF_chkBox; QCheckBox *new_PPU_ena; @@ -42,10 +43,11 @@ class ConsoleVideoConfDialog_t : public QDialog QCheckBox *clipSidesCbx; QCheckBox *showFPS_cbx; QCheckBox *autoScaleCbx; - QCheckBox *sqrPixCbx; + QCheckBox *aspectCbx; QCheckBox *cursorVisCbx; QDoubleSpinBox *xScaleBox; QDoubleSpinBox *yScaleBox; + QLabel *aspectSelectLabel; QLabel *xScaleLabel; QLabel *yScaleLabel; QLineEdit *ntsc_start; @@ -71,12 +73,13 @@ class ConsoleVideoConfDialog_t : public QDialog void autoRegionChanged( int value ); void openGL_linearFilterChanged( int value ); void autoScaleChanged( int value ); - void sqrPixChanged( int value ); + void aspectEnableChanged( int value ); void use_new_PPU_changed( int value ); void frameskip_changed( int value ); void useSpriteLimitChanged( int value ); void clipSidesChanged( int value ); void showFPSChanged( int value ); + void aspectChanged(int index); void regionChanged(int index); void driverChanged(int index); void scalerChanged(int index); diff --git a/src/drivers/Qt/ConsoleViewerGL.cpp b/src/drivers/Qt/ConsoleViewerGL.cpp index dc0ed2c3..1791cf00 100644 --- a/src/drivers/Qt/ConsoleViewerGL.cpp +++ b/src/drivers/Qt/ConsoleViewerGL.cpp @@ -50,8 +50,11 @@ ConsoleViewGL_t::ConsoleViewGL_t(QWidget *parent) view_height = 0; gltexture = 0; devPixRatio = 1.0f; + aspectRatio = 1.0f; + aspectX = 1.0f; + aspectY = 1.0f; linearFilter = false; - sqrPixels = true; + forceAspect = true; autoScaleEna = true; xscale = 2.0; yscale = 2.0; @@ -201,8 +204,10 @@ void ConsoleViewGL_t::setScaleXY( double xs, double ys ) xscale = xs; yscale = ys; - if ( sqrPixels ) + if ( forceAspect ) { + xyRatio = xyRatio * aspectRatio; + if ( (xscale*xyRatio) < yscale ) { yscale = (xscale*xyRatio); @@ -214,6 +219,25 @@ void ConsoleViewGL_t::setScaleXY( double xs, double ys ) } } +void ConsoleViewGL_t::setAspectXY( double x, double y ) +{ + aspectX = x; + aspectY = y; + + aspectRatio = aspectY / aspectX; +} + +void ConsoleViewGL_t::getAspectXY( double &x, double &y ) +{ + x = aspectX; + y = aspectY; +} + +double ConsoleViewGL_t::getAspectRatio(void) +{ + return aspectRatio; +} + void ConsoleViewGL_t::transfer2LocalBuffer(void) { int i=0, hq = 0; @@ -314,8 +338,10 @@ void ConsoleViewGL_t::paintGL(void) float xscaleTmp = (float)(view_width) / (float)(texture_width); float yscaleTmp = (float)(view_height) / (float)(texture_height); - if ( sqrPixels ) + if ( forceAspect ) { + xyRatio = xyRatio * aspectRatio; + if ( (xscaleTmp*xyRatio) < yscaleTmp ) { yscaleTmp = (xscaleTmp*xyRatio); diff --git a/src/drivers/Qt/ConsoleViewerGL.h b/src/drivers/Qt/ConsoleViewerGL.h index af9ef37f..f8f68163 100644 --- a/src/drivers/Qt/ConsoleViewerGL.h +++ b/src/drivers/Qt/ConsoleViewerGL.h @@ -14,16 +14,16 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions public: ConsoleViewGL_t(QWidget *parent = 0); - ~ConsoleViewGL_t(void); + ~ConsoleViewGL_t(void); int init( void ); void transfer2LocalBuffer(void); - void setLinearFilterEnable( bool ena ); + void setLinearFilterEnable( bool ena ); - bool getSqrPixelOpt(void){ return sqrPixels; }; - void setSqrPixelOpt( bool val ){ sqrPixels = val; return; }; + bool getForceAspectOpt(void){ return forceAspect; }; + void setForceAspectOpt( bool val ){ forceAspect = val; return; }; bool getAutoScaleOpt(void){ return autoScaleEna; }; void setAutoScaleOpt( bool val ){ autoScaleEna = val; return; }; double getScaleX(void){ return xscale; }; @@ -31,9 +31,12 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions void setScaleXY( double xs, double ys ); void getNormalizedCursorPos( double &x, double &y ); bool getMouseButtonState( unsigned int btn ); + void setAspectXY( double x, double y ); + void getAspectXY( double &x, double &y ); + double getAspectRatio(void); protected: - void initializeGL(void); + void initializeGL(void); void resizeGL(int w, int h); void paintGL(void); void mousePressEvent(QMouseEvent * event); @@ -44,6 +47,9 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions void doRemap(void); double devPixRatio; + double aspectRatio; + double aspectX; + double aspectY; double xscale; double yscale; int view_width; @@ -54,7 +60,7 @@ class ConsoleViewGL_t : public QOpenGLWidget, protected QOpenGLFunctions int rh; GLuint gltexture; bool linearFilter; - bool sqrPixels; + bool forceAspect; bool autoScaleEna; unsigned int mouseButtonMask; diff --git a/src/drivers/Qt/ConsoleViewerSDL.cpp b/src/drivers/Qt/ConsoleViewerSDL.cpp index 07327d14..7b86418a 100644 --- a/src/drivers/Qt/ConsoleViewerSDL.cpp +++ b/src/drivers/Qt/ConsoleViewerSDL.cpp @@ -57,6 +57,10 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent) yscale = 2.0; devPixRatio = 1.0f; + aspectRatio = 1.0f; + aspectX = 1.0f; + aspectY = 1.0f; + sdlWindow = NULL; sdlRenderer = NULL; sdlTexture = NULL; @@ -73,7 +77,7 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent) memset( localBuf, 0, localBufSize ); } - sqrPixels = true; + forceAspect = true; autoScaleEna = true; linearFilter = false; @@ -118,8 +122,10 @@ void ConsoleViewSDL_t::setScaleXY( double xs, double ys ) xscale = xs; yscale = ys; - if ( sqrPixels ) + if ( forceAspect ) { + xyRatio = xyRatio * aspectRatio; + if ( (xscale*xyRatio) < yscale ) { yscale = (xscale*xyRatio); @@ -131,6 +137,25 @@ void ConsoleViewSDL_t::setScaleXY( double xs, double ys ) } } +void ConsoleViewSDL_t::setAspectXY( double x, double y ) +{ + aspectX = x; + aspectY = y; + + aspectRatio = aspectY / aspectX; +} + +void ConsoleViewSDL_t::getAspectXY( double &x, double &y ) +{ + x = aspectX; + y = aspectY; +} + +double ConsoleViewSDL_t::getAspectRatio(void) +{ + return aspectRatio; +} + void ConsoleViewSDL_t::transfer2LocalBuffer(void) { int i=0, hq = 0; @@ -354,8 +379,10 @@ void ConsoleViewSDL_t::render(void) float xscaleTmp = (float)view_width / (float)nesWidth; float yscaleTmp = (float)view_height / (float)nesHeight; - if ( sqrPixels ) + if ( forceAspect ) { + xyRatio = xyRatio * aspectRatio; + if ( (xscaleTmp*xyRatio) < yscaleTmp ) { yscaleTmp = (xscaleTmp*xyRatio); diff --git a/src/drivers/Qt/ConsoleViewerSDL.h b/src/drivers/Qt/ConsoleViewerSDL.h index db4079e6..809661f4 100644 --- a/src/drivers/Qt/ConsoleViewerSDL.h +++ b/src/drivers/Qt/ConsoleViewerSDL.h @@ -23,10 +23,10 @@ class ConsoleViewSDL_t : public QWidget void transfer2LocalBuffer(void); - void setLinearFilterEnable( bool ena ); + void setLinearFilterEnable( bool ena ); - bool getSqrPixelOpt(void){ return sqrPixels; }; - void setSqrPixelOpt( bool val ){ sqrPixels = val; return; }; + bool getForceAspectOpt(void){ return forceAspect; }; + void setForceAspectOpt( bool val ){ forceAspect = val; return; }; bool getAutoScaleOpt(void){ return autoScaleEna; }; void setAutoScaleOpt( bool val ){ autoScaleEna = val; return; }; double getScaleX(void){ return xscale; }; @@ -34,6 +34,9 @@ class ConsoleViewSDL_t : public QWidget void setScaleXY( double xs, double ys ); void getNormalizedCursorPos( double &x, double &y ); bool getMouseButtonState( unsigned int btn ); + void setAspectXY( double x, double y ); + void getAspectXY( double &x, double &y ); + double getAspectRatio(void); protected: @@ -46,6 +49,9 @@ class ConsoleViewSDL_t : public QWidget int view_height; double devPixRatio; + double aspectRatio; + double aspectX; + double aspectY; double xscale; double yscale; int rw; @@ -57,7 +63,7 @@ class ConsoleViewSDL_t : public QWidget bool vsyncEnabled; bool linearFilter; - bool sqrPixels; + bool forceAspect; bool autoScaleEna; uint32_t *localBuf; diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 91a509b7..6176c20c 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -118,6 +118,7 @@ consoleWin_t::consoleWin_t(QWidget *parent) setCentralWidget(viewport_GL); } + setViewportAspect(); setWindowTitle( tr(FCEU_NAME_AND_VERSION) ); setWindowIcon(QIcon(":fceux1.png")); @@ -273,13 +274,13 @@ QSize consoleWin_t::calcRequiredSize(void) QSize out( GL_NES_WIDTH, GL_NES_HEIGHT ); QSize w, v; - double xscale, yscale; + double xscale = 1.0, yscale = 1.0, aspectRatio = 1.0; int texture_width = GL_NES_WIDTH; int texture_height = GL_NES_HEIGHT; int l=0, r=texture_width; int t=0, b=texture_height; int dw=0, dh=0, rw, rh; - bool sqrPixChkd = true; + bool forceAspect = true; CalcVideoDimensions(); @@ -294,14 +295,16 @@ QSize consoleWin_t::calcRequiredSize(void) if ( viewport_GL ) { v = viewport_GL->size(); - sqrPixChkd = viewport_GL->getSqrPixelOpt(); + forceAspect = viewport_GL->getForceAspectOpt(); + aspectRatio = viewport_GL->getAspectRatio(); xscale = viewport_GL->getScaleX(); yscale = viewport_GL->getScaleY(); } else if ( viewport_SDL ) { v = viewport_SDL->size(); - sqrPixChkd = viewport_SDL->getSqrPixelOpt(); + forceAspect = viewport_SDL->getForceAspectOpt(); + aspectRatio = viewport_SDL->getAspectRatio(); xscale = viewport_SDL->getScaleX(); yscale = viewport_SDL->getScaleY(); } @@ -309,9 +312,9 @@ QSize consoleWin_t::calcRequiredSize(void) dw = 0; dh = 0; - if ( sqrPixChkd ) + if ( forceAspect ) { - yscale = xscale * (double)nes_shm->video.xyRatio; + yscale = xscale * aspectRatio * (double)nes_shm->video.xyRatio; } rw=(int)((r-l)*xscale); rh=(int)((b-t)*yscale); @@ -326,6 +329,48 @@ QSize consoleWin_t::calcRequiredSize(void) return out; } +void consoleWin_t::setViewportAspect(void) +{ + int aspectSel; + double x,y; + + g_config->getOption ("SDL.AspectSelect", &aspectSel); + + switch ( aspectSel ) + { + default: + case 0: + x = 1.0; y = 1.0; + break; + case 1: + x = 8.0; y = 7.0; + break; + case 2: + x = 11.0; y = 8.0; + break; + case 3: + x = 4.0; y = 3.0; + break; + case 4: + x = 16.0; y = 9.0; + break; + case 5: + { + x = 1.0; y = 1.0; + } + break; + } + + if ( viewport_GL ) + { + viewport_GL->setAspectXY( x, y ); + } + else if ( viewport_SDL ) + { + viewport_SDL->setAspectXY( x, y ); + } +} + void consoleWin_t::loadCursor(void) { int cursorVis; diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index d9601827..1ea3599c 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -119,6 +119,8 @@ class consoleWin_t : public QMainWindow QSize calcRequiredSize(void); + void setViewportAspect(void); + void loadCursor(void); void setViewerCursor( QCursor s ); void setViewerCursor( Qt::CursorShape s ); diff --git a/src/drivers/Qt/config.cpp b/src/drivers/Qt/config.cpp index 10645443..a12f703b 100644 --- a/src/drivers/Qt/config.cpp +++ b/src/drivers/Qt/config.cpp @@ -261,7 +261,10 @@ InitConfig() config->addOption("SDL.WinSizeY", 0); config->addOption("doublebuf", "SDL.DoubleBuffering", 1); config->addOption("autoscale", "SDL.AutoScale", 1); - config->addOption("keepratio", "SDL.KeepRatio", 1); + config->addOption("forceAspect", "SDL.ForceAspect", 1); + config->addOption("aspectSelect", "SDL.AspectSelect", 0); + config->addOption("aspectX", "SDL.AspectX", 1.000); + config->addOption("aspectY", "SDL.AspectY", 1.000); config->addOption("xscale", "SDL.XScale", 2.000); config->addOption("yscale", "SDL.YScale", 2.000); config->addOption("xstretch", "SDL.XStretch", 0); From b825454feec851310c84eb658e6c5ab9f965b579 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 21 Mar 2021 08:34:08 -0400 Subject: [PATCH 2/7] Added to fix Qt build issue with pre Qt 5.12 builds. --- src/boards/28.cpp | 4 ++-- src/drivers/Qt/ConsoleWindow.cpp | 2 +- src/drivers/Qt/GuiConf.cpp | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/boards/28.cpp b/src/boards/28.cpp index 46131398..473cca45 100644 --- a/src/boards/28.cpp +++ b/src/boards/28.cpp @@ -53,8 +53,8 @@ void Mirror(uint8 value) static void Sync() { - int prglo; - int prghi; + int prglo = 0; + int prghi = 0; int outb = outer << 1; //this can probably be rolled up, but i have no motivation to do so diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 6176c20c..6b55df99 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -444,7 +444,7 @@ void consoleWin_t::setViewerCursor( Qt::CursorShape s ) Qt::CursorShape consoleWin_t::getViewerCursor(void) { - Qt::CursorShape s; + Qt::CursorShape s = Qt::ArrowCursor; if ( viewport_GL ) { diff --git a/src/drivers/Qt/GuiConf.cpp b/src/drivers/Qt/GuiConf.cpp index f282d3cc..1b21df31 100644 --- a/src/drivers/Qt/GuiConf.cpp +++ b/src/drivers/Qt/GuiConf.cpp @@ -727,9 +727,11 @@ static const char *getRoleText( QPalette::ColorRole role ) case QPalette::ToolTipText: rTxt = "ToolTipText"; break; +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) case QPalette::PlaceholderText: rTxt = "PlaceholderText"; break; +#endif case QPalette::Text: rTxt = "Text"; break; From 95aa96a14e291718a46cfa8c3d2f1e31d3339331 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 21 Mar 2021 13:47:12 -0400 Subject: [PATCH 3/7] Aspect ratio pixel scaling fixes for Qt GUI. For issue #341. --- src/drivers/Qt/ConsoleVideoConf.cpp | 18 ++++++++++-- src/drivers/Qt/ConsoleViewerGL.cpp | 45 +++++++++++++++++++++++++---- src/drivers/Qt/ConsoleViewerSDL.cpp | 40 ++++++++++++++++++++++--- src/drivers/Qt/ConsoleWindow.cpp | 18 +++++++++++- 4 files changed, 108 insertions(+), 13 deletions(-) diff --git a/src/drivers/Qt/ConsoleVideoConf.cpp b/src/drivers/Qt/ConsoleVideoConf.cpp index 151c28d8..88793071 100644 --- a/src/drivers/Qt/ConsoleVideoConf.cpp +++ b/src/drivers/Qt/ConsoleVideoConf.cpp @@ -853,8 +853,7 @@ QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void) if ( aspectCbx->isChecked() ) { xscale = xScaleBox->value(); - - yscale = xscale * aspectRatio * (double)nes_shm->video.xyRatio; + yscale = xscale * (double)nes_shm->video.xyRatio; } else { @@ -864,6 +863,21 @@ QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void) rw=(int)((r-l)*xscale); rh=(int)((b-t)*yscale); + if ( aspectCbx->isChecked() ) + { + double rr; + + rr = (double)rh / (double)rw; + + if ( rr > aspectRatio ) + { + rw = (int)( (((double)rh) / aspectRatio) + 0.50); + } + else + { + rh = (int)( (((double)rw) * aspectRatio) + 0.50); + } + } out.setWidth( rw + dw ); out.setHeight( rh + dh ); } diff --git a/src/drivers/Qt/ConsoleViewerGL.cpp b/src/drivers/Qt/ConsoleViewerGL.cpp index 1791cf00..79801980 100644 --- a/src/drivers/Qt/ConsoleViewerGL.cpp +++ b/src/drivers/Qt/ConsoleViewerGL.cpp @@ -206,8 +206,6 @@ void ConsoleViewGL_t::setScaleXY( double xs, double ys ) if ( forceAspect ) { - xyRatio = xyRatio * aspectRatio; - if ( (xscale*xyRatio) < yscale ) { yscale = (xscale*xyRatio); @@ -340,15 +338,13 @@ void ConsoleViewGL_t::paintGL(void) if ( forceAspect ) { - xyRatio = xyRatio * aspectRatio; - if ( (xscaleTmp*xyRatio) < yscaleTmp ) { - yscaleTmp = (xscaleTmp*xyRatio); + yscaleTmp = xscaleTmp * xyRatio; } else { - xscaleTmp = (yscaleTmp/xyRatio); + xscaleTmp = yscaleTmp / xyRatio; } } @@ -368,8 +364,45 @@ void ConsoleViewGL_t::paintGL(void) yscaleTmp = yscale; } } + rw=(int)((r-l)*xscaleTmp); rh=(int)((b-t)*yscaleTmp); + + if ( forceAspect ) + { + int iw, ih, ax, ay; + + ax = (int)(aspectX+0.50); + ay = (int)(aspectY+0.50); + + iw = rw * ay; + ih = rh * ax; + + if ( iw > ih ) + { + rh = (rw * ay) / ax; + } + else + { + rw = (rh * ax) / ay; + } + + if ( rw > view_width ) + { + rw = view_width; + rh = (rw * ay) / ax; + } + + if ( rh > view_height ) + { + rh = view_height; + rw = (rh * ax) / ay; + } + } + + if ( rw > view_width ) rw = view_width; + if ( rh > view_height) rh = view_height; + sx=(view_width-rw)/2; sy=(view_height-rh)/2; diff --git a/src/drivers/Qt/ConsoleViewerSDL.cpp b/src/drivers/Qt/ConsoleViewerSDL.cpp index 7b86418a..5d0d9997 100644 --- a/src/drivers/Qt/ConsoleViewerSDL.cpp +++ b/src/drivers/Qt/ConsoleViewerSDL.cpp @@ -124,8 +124,6 @@ void ConsoleViewSDL_t::setScaleXY( double xs, double ys ) if ( forceAspect ) { - xyRatio = xyRatio * aspectRatio; - if ( (xscale*xyRatio) < yscale ) { yscale = (xscale*xyRatio); @@ -381,8 +379,6 @@ void ConsoleViewSDL_t::render(void) if ( forceAspect ) { - xyRatio = xyRatio * aspectRatio; - if ( (xscaleTmp*xyRatio) < yscaleTmp ) { yscaleTmp = (xscaleTmp*xyRatio); @@ -412,6 +408,42 @@ void ConsoleViewSDL_t::render(void) rw=(int)(nesWidth*xscaleTmp); rh=(int)(nesHeight*yscaleTmp); + + if ( forceAspect ) + { + int iw, ih, ax, ay; + + ax = (int)(aspectX+0.50); + ay = (int)(aspectY+0.50); + + iw = rw * ay; + ih = rh * ax; + + if ( iw > ih ) + { + rh = (rw * ay) / ax; + } + else + { + rw = (rh * ax) / ay; + } + + if ( rw > view_width ) + { + rw = view_width; + rh = (rw * ay) / ax; + } + + if ( rh > view_height ) + { + rh = view_height; + rw = (rh * ax) / ay; + } + } + + if ( rw > view_width ) rw = view_width; + if ( rh > view_height) rh = view_height; + sx=(view_width-rw)/2; sy=(view_height-rh)/2; diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 6b55df99..8f33fafc 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -314,13 +314,29 @@ QSize consoleWin_t::calcRequiredSize(void) if ( forceAspect ) { - yscale = xscale * aspectRatio * (double)nes_shm->video.xyRatio; + yscale = xscale * (double)nes_shm->video.xyRatio; } rw=(int)((r-l)*xscale); rh=(int)((b-t)*yscale); //printf("view %i x %i \n", rw, rh ); + if ( forceAspect ) + { + double rr; + + rr = (double)rh / (double)rw; + + if ( rr > aspectRatio ) + { + rw = (int)( (((double)rh) / aspectRatio) + 0.50); + } + else + { + rh = (int)( (((double)rw) * aspectRatio) + 0.50); + } + } + out.setWidth( rw + dw ); out.setHeight( rh + dh ); From 26ee4ea14a3e40073541b62d1c3667e37ec5bbec Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 21 Mar 2021 14:32:16 -0400 Subject: [PATCH 4/7] Force default mac OS path separator to be / instead of old style : --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 473f1d5c..986e8471 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -175,7 +175,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src ) include_directories( ${CMAKE_SOURCE_DIR}/src/drivers ) if(APPLE) - add_definitions( -DPSS_STYLE=4 ) + add_definitions( -DPSS_STYLE=1 ) else(APPLE) if(UNIX) add_definitions( -DPSS_STYLE=1 ) From b942f07e9f4ac599177a97624e8d663b7e72160f Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 21 Mar 2021 15:00:39 -0400 Subject: [PATCH 5/7] Minor correction to Lua script path line edit box. Added clear buttons for line edit boxes on Lua console window. --- src/drivers/Qt/LuaControl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/drivers/Qt/LuaControl.cpp b/src/drivers/Qt/LuaControl.cpp index a81ffc5d..1a40f3b6 100644 --- a/src/drivers/Qt/LuaControl.cpp +++ b/src/drivers/Qt/LuaControl.cpp @@ -128,7 +128,9 @@ LuaControlDialog_t::LuaControlDialog_t(QWidget *parent) g_config->getOption("SDL.LastLoadLua", &filename); - scriptPath->setText(filename.c_str()); + scriptPath->setText( tr(filename.c_str()) ); + scriptPath->setClearButtonEnabled(true); + scriptArgs->setClearButtonEnabled(true); luaOutput = new QTextEdit(); luaOutput->setReadOnly(true); @@ -401,7 +403,7 @@ void LuaControlDialog_t::openLuaScriptFile(void) g_config->setOption("SDL.LastLoadLua", filename.toStdString().c_str()); - scriptPath->setText(filename.toStdString().c_str()); + scriptPath->setText(filename); #endif } From 04caf3a03f9e2b328b8a44799c19c366e037ed1a Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 21 Mar 2021 18:31:20 -0400 Subject: [PATCH 6/7] Added logic to process all QCoreApplication events in main window loop to ensure that GUI stays responsive when rendering slows app execution down. Mac OS OpenGL was causing odd event processing delays. So now we will ensure all events are processed before attempting any rendering. --- src/drivers/Qt/ConsoleWindow.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 8f33fafc..2f69a286 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -2872,14 +2872,10 @@ void consoleWin_t::syncActionConfig( QAction *act, const char *property ) void consoleWin_t::updatePeriodic(void) { - //struct timespec ts; - //double t; - - //clock_gettime( CLOCK_REALTIME, &ts ); - - //t = (double)ts.tv_sec + (double)(ts.tv_nsec * 1.0e-9); - //printf("Run Frame %f\n", t); + // Process all events before attempting to render viewport + QCoreApplication::processEvents(); + // Update Input Devices FCEUD_UpdateInput(); @@ -2896,7 +2892,6 @@ void consoleWin_t::updatePeriodic(void) else { viewport_GL->transfer2LocalBuffer(); - //viewport_GL->repaint(); viewport_GL->update(); } } From 099f5820e228c9251fa5150aec539dd48f9059ed Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 21 Mar 2021 19:47:00 -0400 Subject: [PATCH 7/7] Bug fix for hot key toggling of background render plane for Qt GUI. --- src/drivers/Qt/input.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/drivers/Qt/input.cpp b/src/drivers/Qt/input.cpp index 8fceaecf..9ad1e9ae 100644 --- a/src/drivers/Qt/input.cpp +++ b/src/drivers/Qt/input.cpp @@ -579,7 +579,7 @@ static void KeyboardCommands (void) } } - if (g_keyState[SDL_SCANCODE_LSHIFT] || g_keyState[SDL_SCANCODE_RSHIFT]) + if (g_keyState[SDL_SCANCODE_LSHIFT] || g_keyState[SDL_SCANCODE_RSHIFT]) { is_shift = 1; } @@ -600,14 +600,11 @@ static void KeyboardCommands (void) if ( Hotkeys[HK_TOGGLE_BG].getRisingEdge() ) { - if (is_shift) - { - FCEUI_SetRenderPlanes (true, false); - } - else - { - FCEUI_SetRenderPlanes (true, true); - } + bool fgOn, bgOn; + + FCEUI_GetRenderPlanes( fgOn, bgOn ); + + FCEUI_SetRenderPlanes( fgOn, !bgOn ); } // Alt-Enter to toggle full-screen