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);